1
Fork 0
mirror of https://github.com/Steffo99/iiiiil-gioco.git synced 2024-11-21 23:44:21 +00:00

AI dei nemici migliorata

This commit is contained in:
Steffo 2016-01-07 18:34:43 +01:00
parent 096130d1cf
commit 0d40fdc4c2

110
main.cpp
View file

@ -202,49 +202,77 @@ class Enemy : public Entity
} }
else else
{ {
//Muoviti in una direzione casuale //Se il giocatore è vicino, muoviti verso di lui
bool moving = true; if(map[x-2][y] == PLAYER && map[x-1][y] == EMPTY) //Due a sinistra
while(moving)
{ {
int direction = rand() % 4; map[x][y] = EMPTY;
switch(direction) map[x-1][y] = ENEMY;
x--;
}
else if(map[x+2][y] == PLAYER && map[x+1][y] == EMPTY) //Due a destra
{
map[x][y] = EMPTY;
map[x+1][y] = ENEMY;
x++;
}
else if(map[x][y-2] == PLAYER && map[x][y-1] == EMPTY) //Due in su
{
map[x][y] = EMPTY;
map[x][y-1] = ENEMY;
y--;
}
else if(map[x][y+2] == PLAYER && map[x][y+1] == EMPTY) //Due in giù
{
map[x][y] = EMPTY;
map[x][y+1] = ENEMY;
y++;
}
else
{
//Muoviti in una direzione casuale
bool moving = true;
while(moving)
{ {
case 0: //Sinistra int direction = rand() % 4;
if(map[x-1][y] == EMPTY) switch(direction)
{ {
map[x][y] = EMPTY; case 0: //Sinistra
map[x-1][y] = ENEMY; if(map[x-1][y] == EMPTY)
x--; {
moving = false; map[x][y] = EMPTY;
} map[x-1][y] = ENEMY;
break; x--;
case 1: //Destra moving = false;
if(map[x+1][y] == EMPTY) }
{ break;
map[x][y] = EMPTY; case 1: //Destra
map[x+1][y] = ENEMY; if(map[x+1][y] == EMPTY)
x++; {
moving = false; map[x][y] = EMPTY;
} map[x+1][y] = ENEMY;
break; x++;
case 2: //Su moving = false;
if(map[x][y-1] == EMPTY) }
{ break;
map[x][y] = EMPTY; case 2: //Su
map[x][y-1] = ENEMY; if(map[x][y-1] == EMPTY)
y--; {
moving = false; map[x][y] = EMPTY;
} map[x][y-1] = ENEMY;
break; y--;
case 3: //Giù moving = false;
if(map[x][y+1] == EMPTY) }
{ break;
map[x][y] = EMPTY; case 3: //Giù
map[x][y+1] = ENEMY; if(map[x][y+1] == EMPTY)
y++; {
moving = false; map[x][y] = EMPTY;
} map[x][y+1] = ENEMY;
break; y++;
moving = false;
}
break;
}
} }
} }
} }