Hello, im working on pacman and everytime it reaches right wall everything is ok. However, when it hits left wall firstly it stops but then, when i press arrow down or up it starts going across. Like it should go 90 or 270 degrees but instead it goes something like 135 or 225 degrees.
My code:
THANK YOU!!
import greenfoot.*;
public class Pacman extends Actor
{
public Pacman()
{
GreenfootImage image = getImage();
image.scale(image.getWidth() - 832, image.getHeight() - 972);
setImage(image);
}
public void act()
{
moveE(4);
}
public void moveE(int moveAmt)
{
if(Greenfoot.isKeyDown("left"))
{
setRotation(180);
}
if(Greenfoot.isKeyDown("right"))
{
setRotation(0);
}
if(Greenfoot.isKeyDown("up"))
{
setRotation(270);
}
if(Greenfoot.isKeyDown("down"))
{
setRotation(90);
}
int x = getX();
int y = getY();
for (int i = 0; i < moveAmt; i++)
{ move(1);
if (getOneIntersectingObject(wall2.class) != null)
{
if(getRotation() == 180)
{
setLocation(x+3, getY());
}
else
{
setLocation(x-3, getY());
}
}
}
}
}
