# Pushing blocks

**URL:** <https://forum.kirupa.com/t/pushing-blocks/9629>\
**Category:** Uncategorized\
**Created:** [December 15, 2002, 6:08pm UTC](https://forum.kirupa.com/t/pushing-blocks/9629 "2002-12-15T18:08:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ntt](https://avatars.discourse-cdn.com/v4/letter/n/e480ec/32.png) [@ntt](https://forum.kirupa.com/u/ntt)\
**Post date:** [December 15, 2002, 6:08pm UTC](https://forum.kirupa.com/t/pushing-blocks/9629/1 "2002-12-15T18:08:32Z")

</div>

hi

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

ok so i found this code

```auto

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](http://www.angelfire.com/sd2/flashstuff/project.html)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 15, 2002, 8:09pm UTC](https://forum.kirupa.com/t/pushing-blocks/9629/2 "2002-12-15T20:09:04Z")

</div>

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

```auto

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 17, 2002, 7:15pm UTC](https://forum.kirupa.com/t/pushing-blocks/9629/3 "2002-12-17T19:15:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 17, 2002, 11:37pm UTC](https://forum.kirupa.com/t/pushing-blocks/9629/4 "2002-12-17T23:37:16Z")

</div>

thanks, but thats not what i was looking for.

take a look here [http://www.angelfire.com/sd2/flashstuff/push.html](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
