Hello again, my game program is hitting wall after walls of bugs, this time I've tried to apply a hitTest conditonal to an ArrayList of enemies the player must avoid. Out of nowhere the player dies while not being hit by any of the minions, my theory is that he's doing hitTests with all enemies at once. How could I fix this?
Here's the code:
Code:
int screenSize, arraySize, timer;
boolean startGame;
boolean pauseGame;
boolean endGame;
SPACE zone;
AVATAR player;
MINION enemy;
ArrayList enemies;
void setup()
{
screenSize = 400;
size (screenSize,screenSize);
frameRate(30);
startGame = false;
pauseGame = false;
endGame = false;
zone = new SPACE
(
loadImage("figura1.png"), loadImage("figura2.png"),
loadImage("figura3.png"), color(27,214,219), (screenSize/2),
(screenSize/2), (screenSize/15)
);
player = new AVATAR
(
color(31,155,16), (screenSize/2), (screenSize/2),
(screenSize/15),(screenSize/80)
);
enemies = new ArrayList();
}
void mousePressed()
{
startGame =! startGame;
pauseGame = true;
if(endGame == true)
{
endGame = false;
timer = 0;
}
}
void keyPressed()
{
if(key == 't')
{
endGame =! endGame;
}
}
void draw()
{
background(color(#141B5D));
//smooth();
zone.display();
if (endGame == false)
{
player.avatarSize = screenSize/15;
player.display();
if (startGame == true)
{
zone.alphaTest = true;
timer++;
player.move();
if(timer % 100 == 0 && enemies.size() < 10)
{
enemies.add (new MINION(color(193,12,12), player.xpos,
player.ypos, player.avatarSize, (screenSize/15),
(screenSize/80)));
}
for(int i = enemies.size()-1; i >= 0; i--)
{
MINION enemy = (MINION) enemies.get(i);
println(enemies);
enemy.move();
enemy.display();
if(enemy.xpos + (enemy.minionSize/2) >= player.xpos - (player.avatarSize/2) &&
enemy.xpos + (enemy.minionSize/2) <= player.xpos + (player.avatarSize/2) ||
enemy.xpos - (enemy.minionSize/2) >= player.xpos - (player.avatarSize) &&
enemy.xpos - (enemy.minionSize/2) <= player.xpos + (player.avatarSize))
{
if(enemy.ypos + (enemy.minionSize/2) >= player.ypos - (player.avatarSize/2) &&
enemy.ypos + (enemy.minionSize/2) <= player.ypos + (player.avatarSize/2) ||
enemy.ypos - (enemy.minionSize/2) >= player.xpos - (player.avatarSize/2) &&
enemy.ypos - (enemy.minionSize/2) <= player.xpos + (player.avatarSize/2))
{
endGame = true;
}
}
}
}
if(pauseGame == true && startGame == false)
{
zone.pause();
}
}
if(endGame == true)
{
startGame = false;
pauseGame = false;
player.end();
zone.end();
/*for(int i = enemies.size()-1; i >= 0; i--)
{
MINION enemy = (MINION) enemies.get(i);
enemy.end();
}
if(enemy.materialize == screenSize)
{*/
for(int i = enemies.size()-1; i >= 0; i--)
{
enemies.remove(i);
}
//}
}
}