adding 502 error

This commit is contained in:
2025-02-01 16:17:45 +01:00
parent eae424d582
commit ee644cb950
99 changed files with 1156 additions and 3 deletions

23
games/pacman404/js/ai.js Normal file
View File

@@ -0,0 +1,23 @@
var updateEnemies = function(modifier){
for (var i= 0; i < enemies.length; i++){
var enemy = enemies[i];
if (isCollidingBlocks(enemy,enemy.direction)){
changeDirection(enemy);
} else {
move(enemy, modifier);
}
}
}
var changeDirection = function(enemy){
var tol = p(-5,0);
var randomDirection = randomBetween(0, 3);
switch(randomDirection){
case 0: if (!isCollidingBlocks(enemy, LEFT, tol)) enemy.direction = LEFT;break;
case 1: if (!isCollidingBlocks(enemy, RIGHT, tol)) enemy.direction = RIGHT;break;
case 2: if (!isCollidingBlocks(enemy, UP, tol)) enemy.direction = UP;break;
default: if (!isCollidingBlocks(enemy, DOWN, tol)) enemy.direction = DOWN;break;
}
}