I am making pac man ( i am quite new to greenfoot so i want to learn, so i decided to by making pacman) I want to add walls so that pacman cannot pass through them (stops at the walls) Here is my pacman code
I just want PacMan to not be able to pass through walls (that you add in, which i dont know how to do so if you could help me with that, that would be nice) Thanks
import greenfoot.*;
/**
* Write a description of class PacMan here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class PacMan extends Actor
{
/**
* Act - do whatever the PacMan wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.isKeyDown("up"))
{
setRotation(0);
turn(-90);
move(5);
}
if (Greenfoot.isKeyDown("down"))
{
setRotation(0);
turn(90);
move(5);
}
if (Greenfoot.isKeyDown("left"))
{
setRotation(0);
turn(0);
move(-5);
}
if (Greenfoot.isKeyDown("right"))
{
setRotation(0);
turn(0);
move(5);
}
}
}
