Ok..I was making a game base on a tutorial called The Basic of RPG(role playing game) and tried to make a hitTest(so the player won't go through building) but it didn't work.
I put the following code:
::The Wall::
Code:
onClipEvent (load) {
movespeed = 2;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_x -= movespeed;
if (_root.man.hitTest(this)) {
_x += movespeed;
}
}
if (Key.isDown(Key.LEFT)) {
_x += movespeed;
if (_root.man.hitTest(this)) {
_x -= movespeed;
}
}
if (Key.isDown(Key.UP)) {
_y += movespeed;
if (_root.man.hitTest(this)) {
_y -= movespeed;
}
}
if (Key.isDown(Key.DOWN)) {
_y -= movespeed;
if (_root.man.hitTest(this)) {
_y += movespeed;
}
}
}
::Background:not the frame)
Same as the Wall script but changed 'this' into '_root.wall'.
::Character::
Code:
onClipEvent (load) {
movespeed = 0;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP) or Key.isDown(Key.DOWN) or Key.isDown(Key.RIGHT) or Key.isDown(Key.LEFT)) {
energy -= .2;
}
if (Key.isDown(Key.RIGHT)) {
_rotation = 90;
}
if (Key.isDown(Key.LEFT)) {
_rotation = 270;
}
if (Key.isDown(Key.UP)) {
_rotation = 0;
}
if (Key.isDown(Key.DOWN)) {
_rotation = 180;
}
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'll give many thanks to the people who would help me.