PDA

View Full Version : hittest to keep it from passing bounderies


paradox555
01-01-2009, 09:41 PM
Hello, I am making a game and finished coding for the character but have run into a bit of a roadblock. I'm using hittest to keep it from passing bounderies, but it isn't working. Here is my code, and could you tell me what is wrong?



onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {

if (!_root.player.hitTest(_root.wall,wall2)) {
_root.player._x -= 10;
}
}
if (Key.isDown(Key.RIGHT)) {
if (!_root.player.hitTest(_root.wall,wall2)) {
_root.player._x += 10;
}
}

if(Key.isDown(Key.DOWN)) {
if (!_root.player.hitTest(_root.wall,wall2)) {
_root.player._y += 10;
}
}

if(Key.isDown(Key.UP)) {
if (!_root.player.hitTest(_root.wall,wall2)) {
_root.player._y -= 10;
}
}
}


Whats wrong with the code?

orange gold
01-01-2009, 11:22 PM
post your fla and ill fix it in a giffy and explain what i did

paradox555
01-02-2009, 02:32 AM
I cant post it, the site wont let me

orange gold
01-02-2009, 05:01 AM
upload it to mediafire.com

paradox555
01-02-2009, 11:46 PM
here you go:

http://www.mediafire.com/?sharekey=821678bd2a61d330d2db6fb9a8902bda

orange gold
01-03-2009, 12:36 AM
first.. take all of the code out of your mario sprite except the shooting code or whatever.

second...

add this code to your main frame... not inside of the character...
btw your wall isnt named wall1 its just named wall.. if you change it to wall1 you will have to change my code

player.onEnterFrame = function() {
if (Key.isDown(Key.LEFT)) {
player._x += -5
}
if (Key.isDown(Key.RIGHT)) {
player._x += +5
}
if (Key.isDown(Key.UP)) {
player._y += -5
}
if (Key.isDown(Key.DOWN)) {
player._y += +5
}
if (player.hitTest(_root.wall)) {
player._x += +5
}
if (player.hitTest(_root.wall2)) {
player._y += -5
}
}