Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Ball extends Actor
- {
- /**
- * Act - do whatever the Ball wants to do. This method is called whenever
- * the 'Act' or 'Run' button gets pressed in the environment.
- */
- private int speedY = -5;
- private int speedX = 5;
- public Ball(){
- }
- public void act()
- {
- move();
- atWorldEdge();
- bounce();
- }
- public boolean canSee(Class bounce)
- {
- Actor actor = getOneObjectAtOffset(0, 0, bounce);
- return actor != null;
- }
- private void move(){
- int y = getY()+speedY;
- setLocation(getX(),y);
- int x = getX()+speedX;
- setLocation(getY(),x);
- }
- private void atWorldEdge()
- {
- if(getX() == 0 || getX() == 599)
- {
- speedX = -speedX;
- }
- if(getY() == 0 || getY() ==799)
- {
- speedY = -speedY;
- }
- }
- private void bounce()
- {
- if (canSee(Paddle.class))
- {
- speedY = -speedY;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement