Results 1 to 7 of 7
Thread: creating a jump
- 07-21-2010, 04:30 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
creating a jump
I'm just working on making a simple ball game right now and I want the ball to go up 100 pixels then come down when you hit space bar. But for some reason I either get the ball to go up and not come down or it just freezes. Here the space bar part of my code where it just keeps floating up:
else if (key == 32)
{
if (y_pos > 150)
{
y_speed = -1;
}
else
{
y_speed = 1;
}
}
yes there is another if above the else if so thats not it.
- 07-21-2010, 04:44 PM #2
Where do you paint the ball?I want the ball to go up 100 pixels then come down
How does that code determine where to paint the ball?
What does this mean: key == 32
Is it the same as: key == ' '
Have you tried debugging the code by adding println()s to show how the values for the y location of the ball changes?Last edited by Norm; 07-21-2010 at 05:01 PM.
- 07-21-2010, 04:47 PM #3
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
key == 32 is the detection of the space bar being pressed. I draw a circle like this:
public void paint (Graphics g)
{
g.setColor (Color.red);
g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius);
}
- 07-21-2010, 04:48 PM #4
Have you tried debugging the code by adding println()s to show how the values for the y location of the ball changes?
Last edited by Norm; 07-21-2010 at 05:01 PM.
- 07-21-2010, 04:49 PM #5
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
O yeah and x and y pos are determined like this:
x_pos += x_speed;
y_pos += y_speed;
- 07-21-2010, 04:50 PM #6
Member
- Join Date
- Jul 2010
- Posts
- 74
- Rep Power
- 0
Umm I just compile using the javac code and then I put it in a web page coding.
- 07-21-2010, 05:01 PM #7
Similar Threads
-
Creating jar
By nitinverma in forum AWT / SwingReplies: 1Last Post: 07-12-2010, 11:07 AM -
Creating files stopped creating...
By Dieter in forum Advanced JavaReplies: 3Last Post: 09-25-2009, 11:45 PM -
Creating .Jar files
By Deathmonger in forum New To JavaReplies: 6Last Post: 06-22-2008, 11:59 PM -
Eclipse- jump to method definition
By Java Tip in forum Java TipReplies: 0Last Post: 11-07-2007, 03:34 PM -
To truncate jump of line in jsp
By Eric in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 06-09-2007, 03:58 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks