Pushing blocks

hi

im working on a overhead view game where you control the player.

ok so i found this code


onClipEvent (load) {
    posy = _x;
    movey = 120;
    // move back 120 px
    maxy = posy-movey;
    // max y movemen
    activate = true;
    // if move is completed stop  checking for hitTests
}
onClipEvent (enterFrame) {
    if (activate) {
        if (this.hitTest(_root.hero._x-12, _root.hero._y, true) and Key.isDown(Key.LEFT)) {
            if (_x<maxy) {
                _x = maxy;
                activate = false;
            }
            _x--;
            _root.hero.speed = 1;
            // slow down hero
        }
    }
    // end activate
}

this works great, but i can only push the box to the left. any idea on how i could push it in all 4 directions, and have it stop once it hits my movieclip??
THANKS!
game

ok i got it going in all four directions!! the code is kind of long and im sure there is a shorter way, but this is how i have it


onClipEvent (load) {
    posy = _x;
    movey = 120;
    // move back 120 px
    maxy = posy-movey;
    // max y movemen
    activate = true;
    // if move is completed stop  checking for hitTests
}
onClipEvent (enterFrame) {
    if (activate) {
        if (this.hitTest(_root.hero._x-12, _root.hero._y, true) and Key.isDown(Key.LEFT)) {
            if (_x<maxy) {
                _x = maxy;
                activate = false;
            }
            _x--;
            _root.hero.speed = 1;
            // slow down hero
        }
    }
    // end activate
    if (activate) {
        if (this.hitTest(_root.hero._x+12, _root.hero._y, true) and Key.isDown(Key.RIGHT)) {
            _x++;
            _root.hero.speed = 1;
            // slow down hero
        }
    }
    if (activate) {
        if (this.hitTest(_root.hero._x, _root.hero._y-12, true) and Key.isDown(Key.UP)) {
            _y--;
            _root.hero.speed = 1;
            // slow down hero
        }
        if (activate) {
            if (this.hitTest(_root.hero._x, _root.hero._y+12, true) and Key.isDown(Key.DOWN)) {
                _y++;
                _root.hero.speed = 1;
                // slow down hero
            }
        }
    }
}

i still cant get it so that it stops when it hits a wall. any ideas on that?

I’ve attached an .fla.

I’m not sure if this is exactly what you want. If it isn’t, let me know, and I will try to modify it for you.

thanks, but thats not what i was looking for.

take a look here http://www.angelfire.com/sd2/flashstuff/push.html

the fla and swf are available. i got it to stop once it hit the walls but i can move it in all directions once it hits the wall ( if i push it into the right wall i cannot move it down but i can move it up)

thanks