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

Report as inappropriate.

adamkjelstroem
adamkjelstroem presents ...

2012/8/7

Ping-Pong

Play the classic Ping-Pong game!

Please leave a comment.

10708 views / 11 in the last 7 days

2 votes | 0 in the last 7 days

Tags: game with-source ball arcade board bat

This scenario is a member of: Game AI


open in greenfoot
Your browser does not support the canvas tag.
CockyCocky

2012/8/12

Ich kann es nicht öffnen :(
A new version of this scenario was uploaded on Wed Aug 15 07:49:16 UTC 2012 fixed bug when bouncing off the top.
A new version of this scenario was uploaded on Tue Sep 04 19:20:48 UTC 2012
A new version of this scenario was uploaded on Sat Sep 15 21:22:05 UTC 2012 Improved color layout
A new version of this scenario was uploaded on Sat Sep 15 21:23:11 UTC 2012 Improved color layout
Very nice game but there is one bug I think: Sometimes when the ball hits a wall it just goes along the wall and dosen't get away there. I think you could do this with a loop in your method which tells the ball to turn when he hits the wall, because the problem probably is that the ball hits the wall again and again and again. if you use: while (getY() < 10) { //or another number. I don't know the real number from your game. move(1); //or if this doesn't work use setLocation(getX(), getY()+1); } And maybe you could include a better artificial intelligence This one only follows the ball. And if I hit the ball with a steep angle it doesn't get the ball most time. But all in all a very nice game.
I made an update fixing the problem a while ago. I thought I had fixed it.. Good thing you said it then! And I will see if I can improve the AI.
danpostdanpost

2012/9/18

The easy fix for the wall-hugging problem is using a double condition as follows: if (ySpeed > 0 && getX() > getWorld().getHeight() - 11) ySpeed = -ySpeed; if (ySpeed < 0 && getX() <= 11) ySpeed = -ySpeed; Of course, I chose 11 as an arbitrary number and you should adjust it to the appropriate value for the size of your ball. The two statements can be combined into one larger 'if' by wrapping each set of conditions in parenthesis and ORing them together. if ((ySpeed > 0 && getX() > getWorld().getHeight() - 11) || (ySpeed < 0 && getX() <= 11)) ySpeed = -ySpeed;
To make the ball move, I used the Actor method move(int), but I get your point. to mirror an objects direction I'll just change the angle using the methods i already created.
A new version of this scenario was uploaded on Wed Sep 19 13:45:56 UTC 2012 Fixed color bug

See all comments

Want to leave a comment? You must first log in.

Who likes this?

yedefei Chantal