PDA

View Full Version : RPG hittesting!!!



SVIX
June 13th, 2005, 10:44 AM
im having a little trouble with hittesting... i have made an RPG where you move around a character with arrow keys, but im having trouble making him stop when he walks into a wall.

this is the code i have for the character:


onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_root.Character.gotoAndStop(4);
} else if (Key.isDown(Key.LEFT)) {
_root.Character.gotoAndStop(3);
} else if (Key.isDown(Key.UP)) {
_root.Character.gotoAndStop(2);
} else if (Key.isDown(Key.DOWN)) {
_root.Character.gotoAndStop(11);
}
}
onClipEvent (keyUp) {
if (Key.getCode() == Key.DOWN) {
_root.Character.gotoAndStop(1);
} else if (Key.getCode() == Key.UP) {
_root.Character.gotoAndStop(12);
} else if (Key.getCode() == Key.LEFT) {
_root.Character.gotoAndStop(13);
} else if (Key.getCode() == Key.RIGHT) {
_root.Character.gotoAndStop(14);
}
}


and this is the code im using for the background:



onClipEvent (load) {
movespeed = 8;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_x-= movespeed;
}
else if (Key.isDown(Key.LEFT)) {
_x+= movespeed;
}
else if (Key.isDown(Key.UP)) {
_y+= movespeed;
}
else if (Key.isDown(Key.DOWN)) {
_y-= movespeed;
}
}

Yh its a game where the background moves around the guy and he always stays in the middle of the screen.

In the background i have a movieclip called walls. and i need some help with the code to make the background stop moving when the character hits the wall.

Thanks for all the help you guys have given me recently.

nathan99
June 13th, 2005, 05:42 PM
have you tried a basic one,


if (this.hitTest(_root.wall)){
_root.wall.movespeed*=-1-1;
}