public class Ball
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private int |
angle |
private PlayField |
playField |
private float |
radius |
private double |
speed |
private float |
x_as |
private double |
x_speed |
private float |
y_as |
private double |
y_speed |
| Constructor and Description |
|---|
Ball(PlayField playField,
float start_x,
float start_y,
float radius,
double speed,
int angle)
constructor The constructor takes the canvas as input, so it knows where it
lives (and can ask the size of its canvas (eg. ceiling and borders)
Furthermore it gets its starting position (start_x, start_y) and its starting
speed and starting angle).
|
| Modifier and Type | Method and Description |
|---|---|
private void |
bounceHorizontal()
Bounce on a horizontal boundary (eg. ceiling or bat/paddle)
|
private void |
bounceVertical()
Bounce on a vertical boundary (eg. one of the walls)
|
void |
draw()
Paint the ball on the canvas.
|
void |
move()
Method move: This method moves the ball.
|
private void |
setSpeeds(double newSpeed)
Set the speed; total speed and the relative speed on the axis of the canvas;
using the sin and cos of the angle.
|
private int angle
private PlayField playField
private float radius
private double speed
private float x_as
private double x_speed
private float y_as
private double y_speed
public Ball(PlayField playField, float start_x, float start_y, float radius, double speed, int angle)
private void bounceHorizontal()
private void bounceVertical()
public void draw()
public void move()
private void setSpeeds(double newSpeed)