At line 126, I've used an ArrayList in order to spam minions (as in "enemies.add").
Code:
int screenSize, arraySize,readScore;
int[] timer;
int[] score;
boolean startGame;
boolean pauseGame;
boolean endGame;
SPACE zone;
AVATAR player;
MINION enemy;
ArrayList enemies;
void setup()
{
screenSize = 400;
size (screenSize,screenSize);
frameRate(30);
arraySize = 4;
timer = new int [arraySize];
score = new int [arraySize];
readScore = arraySize - 1;
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;
for(int i = 0; i < timer.length; i++)
{
timer[i] = 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;
player.move();
//TIMER
if (pauseGame == false)
{
timer[0]++;
if (timer[0] > 9)
{
timer[1]++;
timer[0] = 0;
if(timer [1] > 9)
{
timer[2]++;
timer[1] = 0;
if(timer[2] > 9)
{
timer[3]++;
timer[2] = 0;
if(timer[3] > 9)
{
for(int i = 0; i < timer.length; i++)
{
timer [i] = 9;
}
}
}
}
}
}
if(
timer [2] == 1 && timer[3] == 0 ||
timer [2] == 2 && timer[3] == 0 ||
timer [2] == 3 && timer[3] == 0 ||
timer [2] == 4 && timer[3] == 0 ||
timer [2] == 5 && timer[3] == 0 ||
timer [2] == 6 && timer[3] == 0 ||
timer [2] == 7 && timer[3] == 0 ||
timer [2] == 8 && timer[3] == 0)
{
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);
enemy.display();
enemy.move();
}
}
if(pauseGame == true && startGame == false)
{
zone.pause();
}
}
if(endGame == true)
{
startGame = false;
pauseGame = false;
player.end();
zone.end();
score = reverse(timer);
for(int i = enemies.size()-1; i >= 0; i--)
{
enemies.remove(i);
}
}
}
The game runs, but the minios never appear...
Here is the MINION class:
Code:
public class MINION
{
color c;
public float xspam, yspam, xSpamDirection,ySpamDirection,
xpos,ypos;
public int playerXpos,playerYpos,playerSize,minionSize,
xspeed,yspeed;
public boolean spam;
public MINION(
color writeColor, int writePlayerXpos, int writePlayerYpos,
int writePlayerSize, int writeMinionSize, int writeSpeed)
{
c = writeColor;
playerXpos = writePlayerXpos;
playerYpos = writePlayerYpos;
playerSize = writePlayerSize;
minionSize = writeMinionSize;
xspeed = writeSpeed;
yspeed = writeSpeed;
xspam = random (0,1);
yspam = random (0,1);
xSpamDirection = random (0,1);
ySpamDirection = random (0,1);
spam = true;
}
public void display()
{
if(spam == true)
{
if(xspam == 0)
{
xpos = random((((height + width)/ 2) / 15), (playerXpos - playerSize));
}
else
{
xpos = random((playerXpos + playerSize),(((height + width)/ 2) - (((height + width)/ 2)/15)));
}
if(yspam == 0)
{
ypos = random((((height + width)/ 2)/15), (playerYpos - playerSize));
}
else
{
ypos = random((playerYpos + playerSize), (((height + width)/ 2) - (((height + width)/ 2)/15)));
}
spam = false;
}
noFill();
strokeWeight(((width + height) /2) /80);
stroke(c);
rectMode(CENTER);
rect(xpos, ypos, minionSize, minionSize);
}
public void move()
{
xpos = xpos + xspeed;
ypos = ypos + yspeed;
if(spam == true)
{
xspeed = xspeed * (xSpamDirection == 0? 1 : -1);
yspeed = yspeed * (ySpamDirection == 0? 1 : -1);
}
if(xpos >= (width - (minionSize))
|| xpos <= (0 + (minionSize)))
{
xspeed = xspeed * (-1);
}
if(ypos >= (height - (minionSize))
|| ypos <= (0 + (minionSize)))
{
yspeed = yspeed * (-1);
}
}
}
Help?