This site requires JavaScript, please enable it in your browser!
Greenfoot back
Taeyo
Taeyo wrote ...

2020/7/1

how to bounce back a ball when it hits the player

1
2
Taeyo Taeyo

2020/7/5

#
the ball gets stuck for secs when it hits the player
danpost danpost

2020/7/5

#
Taeyo wrote...
the ball gets stuck for secs when it hits the player
The code given can't be right. It does not look like it would even compile. Also, that cannot be the entire class as there is no class declaration line shown.
Taeyo Taeyo

2020/7/5

#
public static int xSpeed, ySpeed; public int direction = 5; public void act() { move(direction); } Actor player1 = getOneIntersectingObject(player1.class); if (player_1!=null) { if(isTouching(player1.class)) { direction = -1*direction; turn(90+Greenfoot.getRandomNumber(180)); World myWorld = getWorld(); MyWorld myworld = (MyWorld)myWorld; Counter1 counter1 = myworld.get Counter1(); counter1.addScore(1); } Actor player2 = getOneIntersectingObject(player2.class); if (player_2!=null) { if(isTouching(player2.class)) { direction = -1*direction; turn(90+Greenfoot.getRandomNumber(180)); World myWorld = getWorld(); MyWorld myworld = (MyWorld)myWorld; Counter2 counter2 = myworld.getCounter2(); counter2addScore(1); } Actor player_3 = getOneIntersectingObject(player3.class); if (player_3!=null){ if(isTouching(player3.class)) { turn(90+Greenfoot.getRandomNumber(180)); World myWorld = getWorld(); MyWorld myworld = (MyWorld)myWorld; Counter1 counter1 = myworld.get Counter1(); counter1.addScore(1); } Actor player_4 = getOneIntersectingObject(player4.class); if (player_4!=null){ if(isTouchingplayer4.class)) { turn(90+Greenfoot.getRandomNumber(180)); World myWorld = getWorld(); MyWorld myworld = (MyWorld)myWorld; Counter2 counter2 = myworld.getCounter2(); counter2addScore(1); } if(isAtEdge()){ turn(90+Greenfoot.getRandomNumber(180)); } xSpeed = getX(); ySpeed = getY(); } }
danpost danpost

2020/7/5

#
Again that cannot be the entire class codes. Plus, there is no way it could possibly compile as is. How can you possibly determine that the actor gets stuck anywhere (as it cannot run until it compiles properly)?
You need to login to post a reply.
1
2