Results 1 to 7 of 7
Thread: Processing exercise, Need HELP!
- 10-23-2014, 04:48 PM #1
Member
- Join Date
- Oct 2014
- Posts
- 2
- Rep Power
- 0
Processing exercise, Need HELP!
im 1st year mmu games design student and im stuck on this exercise, all i'm trying to do is get this ball to bounce around the screen and ive gotten so far but not sure how to proceed any suggestions.
the ball keeps disappearing.
//bouncing ball
float x; //ball x position
float dx = 3; //ball x direction is right, step 5
float y; //ball y position
float dy = 3;
void setup () //runs once at start
{
size(500, 250);
}
void draw() //runs repeatedly
{
background(0); //black
stroke(255, 0, 0); //pen red
fill(255, 255, 0); //yellow
ellipse(x, y, 10, 10);
x = x + dx; //move ball x right
y = y + dy; //move ball y
//Collision detection
//collide right hand edge?
if (x>=500)
dx = -dx; //reverse x direction
else if (y>=250)
dy = -dy;
else if (x<=-500)
dx = +dx;
else if (y<=-250)
dy = +dy;
}
- 10-23-2014, 05:07 PM #2
Re: Processing exercise, Need HELP!
I am not familiar with the framework this runs in, but is it really neccessary to set the background all the time? It looks like it's a race between the ball and the background.
Other than that, you might want to take the width of the ball into account for the right hand edge. It bounces at x >= 500, but I assume the base coordinate of the ball is its top left. You would then want to bounce at x >= 500 - width_of_the_ball. Same for the bottom."It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013
- 10-23-2014, 05:07 PM #3
Re: Processing exercise, Need HELP!
Can you make a small complete program that compiles, executes and shows the problem?
Be sure to wrap your code with code tags:
[code]
YOUR CODE GOES HERE
[/code]
to get highlighting and preserve formatting.If you don't understand my response, don't ignore it, ask a question.
- 10-23-2014, 05:27 PM #4
Re: Processing exercise, Need HELP!
This is Processing, so this actually *is* an SSCCE/MCVE.
And yeah, setting the background like that is correct. It's just clearing the previous frame.
Anyway, you have two problems that I see:
First, the y value of the top of the window is 0, but you're trying to bounce your ball off of y value -250, which is above the top of the window.
Secondly, this doesn't do what you think it does:
dy = +dy;
You might be looking for an absolute value function here? If you're confused about what I'm saying, set up a little example program that uses the println function to print out the value of dy after the above line.How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
- 10-23-2014, 05:34 PM #5
- 10-24-2014, 08:13 PM #6
Member
- Join Date
- Oct 2014
- Posts
- 2
- Rep Power
- 0
- 10-27-2014, 02:31 PM #7
Re: Processing exercise, Need HELP!
How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
Similar Threads
-
Got exercise, right.... But don't know why...Can you help?
By Honijahu in forum New To JavaReplies: 5Last Post: 03-19-2013, 12:30 PM -
Have I done this exercise right?
By ccie007 in forum New To JavaReplies: 7Last Post: 09-28-2010, 06:54 PM -
I/O exercise
By Feldom in forum New To JavaReplies: 1Last Post: 10-28-2007, 05:48 PM -
help with exercise
By e_as're in forum New To JavaReplies: 3Last Post: 09-25-2007, 11:14 AM
Bookmarks