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

2012/12/19

Maze Game Help

iPixel iPixel

2012/12/19

#
I am in the process of making a maze game. I am new to Greenfoot. One problem I encountered while trying to make my maze game is that the player can go through walls. How would I stop this? Thanks. Please reply fast!
actinium actinium

2012/12/20

#
Show the code or no one can help. Greenfoot has good collision detection so thats one strategy.
iPixel iPixel

2012/12/20

#
    public void act() 
    {
        if (Greenfoot.isKeyDown("left"))
        {
            setRotation(180);
            move(4);
        }
        
        if (Greenfoot.isKeyDown("right"))
        {
            setRotation(0);
            move(4);
        }
        
        if (Greenfoot.isKeyDown("up"))
        {
            setRotation(270);
            move(4);
        }
        
        if (Greenfoot.isKeyDown("down"))
        {
            setRotation(90);
            move(4);
        }
       
    } 
There's the code. Thanks for the fast reply!
danpost danpost

2012/12/20

#
Check out the Greenfoot documentation for the Actor class. Find out what method you might use to determine if the move made will1 make the actor go into/through a wall. Create a query and action combination to prevent going into/through the wall.
ManiacalPenguin ManiacalPenguin

2012/12/24

#
to stop an Actor from passing through walls, first create a variable to store x and y: private int x; private int y; the method is: public void stopAtWalls() { if (getOneIntersectingObject(Wall.class) != null) { setLocation(x,y); } else { x = getX(); y = getY(); } }
You need to login to post a reply.