Actionscript: HitTest with one symbol

Started by: Bonk | Replies: 16 | Views: 1,604

Scorpioxxx
2

Posts: 1,454
Joined: Apr 2006
Rep: 10

View Profile
Apr 27, 2008 10:31 AM #124643
Um, I may have fixed your problem. I found some code in an old RPG I half made.

onClipEvent (load) {
speed = 4;
radius = 8;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
if (!_root.wall.hitTest(_x-speed-radius, _y, true)) {
_x -= speed;
}
}
if (Key.isDown(Key.RIGHT)) {
if (!_root.wall.hitTest(_x+speed+radius, _y, true)) {
_x += speed;
}
}
if (Key.isDown(Key.UP)) {
if (!_root.wall.hitTest(_x, _y-speed-radius, true)) {
_y -= speed;
}
}
if (Key.isDown(Key.DOWN)) {
if (!_root.wall.hitTest(_x, _y+speed+radius, true)) {
_y += speed;
}
}
}


It goes in the player and ALL the walls are given the instance 'wall'.
Godfather
2

Posts: 427
Joined: Feb 2008
Rep: 10

View Profile
Apr 27, 2008 10:57 AM #124660
Wait, what kind of game is it? Shooting, Adventure, Sports? Tell me and i might be able to help.