int
sizes?
Maybe you should use double
for the highest precision.
Also, are you sure your math is right?
If there are 10 bricks per row, there are 9 gaps between them and 2 more gaps around the edges.
Also, are you sure you're using the right values for the width/height of the overall game window?
You should use getWidth()
and getHeight()
for this, not the constants like APPLICATION_WIDTH
.
getWidth()
and getHeight()
for this, not the constants like APPLICATION_WIDTH
.
Try resizing the window larger to see if the paddle shows up.
private double vx; private double vy;
RandomGenerator rgen = new RandomGenerator(); vx = rgen.nextDouble(VELOCITY_MIN, VELOCITY_MAX); if (rgen.nextBoolean(0.5)) { vx = -vx; // randomly use -1.0 .. -3.0 half the time } // don't just say rgen.nextDouble(-3.0, 3.0) ... why not?
NullPointerException
if you try to call any methods on a variable that stores null
.
This would be the case if you have a field that is supposed to store a graphical object, but you never set its value.
getElementAt
method to ask what graphical object (if any) occupies a given x/y pixel position.
For example, if you store your game's paddle in a field named paddle
, you could check to see if the ball collided with the paddle by writing code such as:
GObject collider = getElementAt(x, y); if (collider == paddle) { ... }
The above code is oversimplified, though, because you are actually supposed to check for each of the four points around the edges of the ball.
You might want to write a method named getCollidingObject
or similar that checks all four of these points and returns the object that the ball collided with, or null
if there is none.
You could use it roughly as follows:
GObject collider = getCollidingObject(); if (collider == paddle) { ... }