Hi, I just wanted to know how people code buildings so that the character doesn’t bump into them. I tried to do it, but somehow it didn’t work. Attached is a sample FLA (Flash 8) explaining my problem. Just move the blue circle with the arrow keys and try to see what happens when you bump into the gray block.
The code I have for the circle is:
onClipEvent (load) {
moveSpeed = 3;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= moveSpeed;
} else if (Key.isDown(Key.DOWN)) {
this._y += moveSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x -= moveSpeed;
} else if (Key.isDown(Key.RIGHT)) {
this._x += moveSpeed;
}
}
And the code I have for the gray block is:
onClipEvent (enterFrame) {
if (_root.ball.hitTest(this)) {
if (Key.isDown(Key.LEFT)) {
_root.ball._x += _root.ball.moveSpeed;
} else if (Key.isDown(Key.RIGHT)) {
_root.ball._x -= _root.ball.moveSpeed;
} else if (Key.isDown(Key.UP)) {
_root.ball._y += _root.ball.moveSpeed;
} else if (Key.isDown(Key.DOWN)) {
_root.ball._y -= _root.ball.moveSpeed;
}
}
}
Thanks in advance for any help.