I’m putting together a flash arcade game, sort of pacman feel to it, but with upgrades, weapons, achievements etc.
Anyway, I’ve got most things sorted for it, but I’m really stuck with the enemies.
I want to prevent diagonal movement as my main character only moves up down left and right, but due to the way i’ve coded them, the enemies can move diagonally.
This ruins my coding of the walls in the game, which bounce the hero and enemies (in theory) back in the opositte direction they hit it from. however, if they hit it with diagonal movement, it allows them to move into the walls, which isn’t so helpful.
This is my main problem, I’m also trying to work out a better ai coding for following the hero, at the moment i’m using x and y pos with less than and more than and adjusting direction according to that. however, this means when there is a wall between the hero and enemy, the enemy just stops on the other side rather than working out a way around the wall.
I’m using AS2 because thats what I’m comfortable with. heres some of the coding:
the enemies:
onClipEvent (enterFrame) {
speed = (_root.enspeed);
if (this._x<_root.char._x) {
(_root.endir1 = 4);
this._x += speed;
}
if (this._x>_root.char._x) {
(_root.chardir = 3);
this._x -= speed;
}
if (this._y<_root.char._y) {
(_root.chardir = 1);
this._y += speed;
}
if (this._y>_root.char._y) {
(_root.chardir = 2);
this._y -= speed;
}
if (_root.char.hitTest(this)) {
_parent.gotoAndStop(4);
}
}
the walls:
onClipEvent (enterFrame) {
if (_root.char.hitTest(this)) {
if (_root.chardir == 1){
_root.char._y += (_root.charspeed);
}
else if (_root.chardir == 2){
_root.char._y -= (_root.charspeed);
}
else if (_root.chardir == 3){
_root.char._x += (_root.charspeed);
}
else if (_root.chardir == 4){
_root.char._x -= (_root.charspeed);
}
}
if (_root.enemy1.hitTest(this)) {
if (_root.endir1 == 1){
_root.enemy1._y += (_root.enspeed);
}
else if (_root.endir1 == 2){
_root.enemy1._y -= (_root.enspeed);
}
else if (_root.endir1 == 3){
_root.enemy1._x += (_root.enspeed);
}
else if (_root.endir1 == 4){
_root.enemy1._x -= (_root.enspeed);
}
}
}