57 lines
1007 B
Java
57 lines
1007 B
Java
public class Ball extends Picture {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
public float speedX = 0.00000011f;
|
|
public float speedY = 0.0000001f;
|
|
public float posiX = 300;
|
|
public float posiY = 350;
|
|
|
|
public Ball() {
|
|
|
|
super("player");
|
|
|
|
}
|
|
|
|
public int getPosi(char coordinate, long dt) {
|
|
if (coordinate == 'x') {
|
|
posiX -= speedX * dt;
|
|
return (int) posiX;
|
|
} else if (coordinate == 'y') {
|
|
posiY += speedY * dt;
|
|
return (int) posiY;
|
|
} else
|
|
return 0;
|
|
}
|
|
|
|
public void setPosi(char coordinate, int posi) {
|
|
if (coordinate == 'x') {
|
|
posiX = posi;
|
|
} else if (coordinate == 'y') {
|
|
posiY = posi;
|
|
}
|
|
}
|
|
|
|
public void changeDir(char coordinate) {
|
|
if (coordinate == 'x') {
|
|
speedX = -speedX;
|
|
} else if (coordinate == 'y') {
|
|
speedY = -speedY;
|
|
}
|
|
}
|
|
|
|
public void sonic() {
|
|
if (speedX > 0) {
|
|
speedX += 0.00000000004f;
|
|
} else {
|
|
speedX -= 0.00000000004f;
|
|
}
|
|
if(speedY > 0) {
|
|
speedY += 0.00000000004f;
|
|
} else {
|
|
speedY -= 0.00000000004f;
|
|
}
|
|
}
|
|
|
|
}
|