Groups | Blog | Home
all groups > flash actionscript > november 2004 >

flash actionscript : character walking


blindRKside
11/14/2004 4:50:05 PM
newsgroup user, if ur reading this, here is the code i used to make my
character movie clip to move. if anyone else wants to experiment with this go
ahead, just make a movie clip and put this code on it:

onClipEvent (load) {
movespeed = 10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
play ();
_rotation = 90;
_x += movespeed;
}
if (Key.isDown(Key.LEFT)) {
play ();
_rotation = 270;
_x -= movespeed;
}
if (Key.isDown(Key.UP)) {
play ();
_rotation = 0;
_y -= movespeed;
}
if (Key.isDown(Key.DOWN)) {
play ();
_rotation = 180;
_y += movespeed;
}
if (Key.isDown(Key.RIGHT) && Key.isDown(Key.UP)) {
_rotation = 45;
}
if (Key.isDown(Key.LEFT) && Key.isDown(Key.UP)) {
_rotation = 315;
}
if (Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN)) {
_rotation = 135;
}
if (Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN)) {
_rotation = 225;
}
}

i wasnt sure how to incorporate the code given to me into this.

thankyou,


blindRKside
blindRKside
11/14/2004 5:30:44 PM
here is the code to stop the guy from walking through the wall:


// You want to go left ...
if (hero.hitTest(leftWall)) {
// Hero has struck the wall
hero._x+= hero._width / 2;
// Moves hero to the right by one half of hero's width
// This would make a "bouncing" effect
} else {
// Hero has not struck the wall, so ...
hero._x-= 5;
// Keep moving hero left by 5 pixels
}

AddThis Social Bookmark Button