Hello,
I am working on a Ping Pong game for school but i don't know how to change the angle when teh ball touches the left or the right side of the paddle. Can someone help me?
public class speler2 extends spelers
{
/**
* Act - do whatever the PingpongRood wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
bewegen();
}
public void bewegen()
{
if (Greenfoot.isKeyDown("W")) {
setLocation(getX(), getY() - 3);
}
if (Greenfoot.isKeyDown("S")) {
setLocation(getX(), getY() + 3);
}
}
}
public class Bal extends Actor
{
public int balX=8;
public int balY=8;
/**
* Act - do whatever the Bal wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
balBeweging();
raaktSpelers();
}
public void balBeweging()
{
setLocation(getX()+balX,getY());
if(getY()<5 || getY()>551)
{
balY = balY*-1;
}
}
public void raaktSpelers()
{
Actor spelers = getOneIntersectingObject (spelers.class);
if(spelers != null)
{
balX = balX * -1;
}
}
}