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

2015/3/22

Actor shouldn't walk through walls while scrolling

OwlyL OwlyL

2015/3/22

#
I have the problem that my player can walk through the walls.class from the left side when the screen starts to scroll. Before the screen starts scrolling my method works. (player can't walk through walls from the left and right direction). thats my Player code
 public void checkWallR()
    {
        Actor wall = getOneIntersectingObject (Wall.class);
        if (wall !=null)
        {
            move (X -10);
        }
    }

    /**
     * Checks if the Player touches a Wall and sets the Player back 
     */
    public void checkWallL()
    {
        Actor wall = getOneIntersectingObject (Wall.class);
        if (wall !=null)
        {
            move (X +10);
        }
    }

    /**
     * The animation method that Herman changes the frames by walking
     */
    public void mAnimation()
    {
        if (Greenfoot.isKeyDown("Right"))
        {                   
            if(animationCount % 6 == 0)    //slows the animation down
                animation1();                   //calls the animation method

            animationCount += 1;

        }
        else if (Greenfoot.isKeyDown("Left"))
        {                 
            if (animationCount % 6 == 0)    //slows the animation down
                animation2();                   //calls the animation method

            animationCount += 1;

        }
    }

    /**
     * This is the Method for the left and right movement of the Player
     * it checks if the left or right button is pressed and moves the Player left or right with an animation of the walking
     */
    public void checkKeys ()
    {
        Level1 theWorld = (Level1) getWorld();
        Scroll scroll = (Scroll) theWorld.getScroll();
        if(Greenfoot.isKeyDown("Right") && scroll.shouldScroll == false)  //checks if the right Key is Pressed and the Scroll method from class Scroll
        {
            moveRight();                    //moves the Player right by pressing left arrow
            checkWallR();
        }

        else if(Greenfoot.isKeyDown("Left") && scroll.shouldScroll == false) //checks if the left Key is Pressed and the Scroll method from class Scroll
        {
            moveLeft();                     //moves the Player left by pressing left arrow
            checkWallL();
        }
    }
danpost danpost

2015/3/22

#
Again, it is because of your checking the scrolling in the class of the actor. Just code the actor normally as if there was no scrolling and let the world class alone deal with the scrolling.
OwlyL OwlyL

2015/3/23

#
There must be another way, because the whole game is based on this scrolling system and I have to finish the game until Wednesday.
You need to login to post a reply.