i was doing an assignment for my basic level computer course. what i wanted was to draw pac man ghosts in different colors (3 color choices) and 3 pac man ghosts at time = 3 which will slowly increase as the ghosts are killed. i havent went to the killing part yet because i cant draw the ghosts properly. my code draws all 3 ghosts and stacks them on top of each other. how do i draw 3 separate ghosts of random colors (from the 3 colors )
PImage startpage1;
PImage charaA;
PImage ball;
int t=3;
PImage enemy[] = new PImage [t] ;
int startTxtPo;
int textboxend;
int extX, extY;
boolean gamestart;
int state = 0;
int xPo, yPo, xPoRec, yPoRec;
int recWidth, recHeight, fillspeed;
int time;
int movespeed;
int enemymove[] = new int[t];
int enemyX[] = new int [t];
int enemyY[] = new int [t];
int type;
PImage gamepage2;
int charaWid, charaHght;
int charaStartX, charaStartY;
boolean isUp, isDown, isLeft, isRight;
void setup()
{
size(1500,900);
startpage1 = loadImage("startpage1.png");
charaA = loadImage("charaA.png");
gamepage2 = loadImage("gamepage2.png");
ball = loadImage("ball.png");
startTxtPo = 880;
textboxend = 1437;
gamestart = false;
xPo = yPo = xPoRec = yPoRec = 0;
recWidth = 0;
recHeight = height;
fillspeed = 25;
movespeed = 4;
charaWid = charaHght = 75;
charaStartX = width/2;
charaStartY = height/2;
extX = 38;
extY = 864;
time = 0;
type = 0;
for (int i = 0; i<enemy.length; i= i+1)
{
enemy[i] = loadImage("enemy"+i+".png");
enemyX[i] = int(random(0,width - charaWid));
enemyY[i] = -75;
enemymove[i] = 2;
}
isUp = false;
isDown = false;
isLeft = false;
isRight = false;
}
void draw()
{
if (state == 0)
{
homePage();
}else if (state == 1)
{
gamestart();
}
else if (state == 2)
{
fill(0);
rect(xPoRec,yPoRec,recWidth,recHeight);
recWidth = recWidth + fillspeed;
if (recWidth >= width)
{
helpPage();
fill(0);
rect(xPoRec,yPoRec,recWidth,recHeight);
xPoRec = xPoRec + fillspeed;
if (xPoRec >= width)
{
xPoRec = xPoRec;
}
}
}else if (state == 3)
{
fill(0);
rect(xPoRec,yPoRec,recWidth,recHeight);
recWidth = recWidth + fillspeed;
if (recWidth >= width)
{
scoreboardPage();
fill(0);
rect(xPoRec,yPoRec,recWidth,recHeight);
xPoRec = xPoRec + fillspeed;
if (xPoRec >= width)
{
xPoRec = xPoRec;
}
}
}
}
void homePage()
{
image(startpage1, xPo, yPo, width, height);
image(charaA, 300, 500, 300,300);
//println("(" + mouseX +" , " +mouseY+")"); //find out the X/Y coordinates of mouse
fill(255,255,255);
textSize(150);
text("All-Terrain War", 216, 165);
textSize(100);
text("Start", startTxtPo, 384);
text("Help", startTxtPo, 534);
text("Scoreboard", startTxtPo, 684);
textSize(50);
text("Exit", extX, extY);
xPoRec = 0;
recWidth = 0;
}
void gamestart()
{
gamestart = true;
image(gamepage2, xPo, yPo, width, height);
image(charaA, charaStartX, charaStartY, charaWid, charaHght);
time = time +1;
fill(0);
textSize(25);
text("Time: " + time/60 + " s", extX, extY);
for(int i=0; i< enemy.length; i = i+1)
{
if (time/60 >= 3)
{
enemySpwn(enemyX[i], enemyY[i], charaWid, charaHght, type);
if (enemyY[i] <= charaStartY)
{
enemyY[i] = enemyY[i] + enemymove[i];
}else if (enemyY[i] > charaStartY)
{
enemyY[i] = enemyY[i] - enemymove[i];
}
if (enemyX[i] < charaStartX)
{
enemyX[i] = enemyX[i] + enemymove[i];
}else if (enemyX[i] > charaStartX)
{
enemyX[i] = enemyX[i] - enemymove[i];
}
type = type +1;
if (type >= enemy.length)
{
type = 0;
}
}
}
if (isUp == true)
{
charaStartY = charaStartY - movespeed;
if (charaStartY <= 0)
{
charaStartY = 0;
}
}
if (isDown == true)
{
charaStartY = charaStartY + movespeed;
if (charaStartY >= height - 75)
{
charaStartY = height - 75;
}
}
if (isLeft == true)
{
charaStartX = charaStartX - movespeed;
if (charaStartX <= 0)
{
charaStartX = 0;
}
}
if (isRight == true)
{
charaStartX = charaStartX + movespeed;
if (charaStartX >= width - 75)
{
charaStartX = width -75;
}
}
}
void enemySpwn(int x, int y, int w, int h, int c)
{
for(c=0; c<enemy.length; c=c+1)
{
image(enemy[c], x, y, w, h);
}
}
void helpPage()
{
image(startpage1, xPo, yPo, width, height);
image(charaA, 300, 500, 300,300);
fill(255,255,255);
textSize(50);
text("w,a,s,d to move,", startTxtPo, 384);
text("mouseclick to shoot", startTxtPo, 434);
text("Press p or P to pause", startTxtPo, 534);
textSize(50);
text("Exit", extX, extY);
}
void scoreboardPage()
{
image(startpage1, xPo, yPo, width, height);
image(charaA, 300, 500, 300,300);
//println("(" + mouseX +" , " +mouseY+")"); //find out the X/Y coordinates of mouse
fill(255,255,255);
textSize(100);
text("High Scores", 814, 220);
textSize(50);
text("Exit", extX, extY);
}
void mousePressed()
{
if (mouseX > startTxtPo && mouseX < textboxend && mouseY > 300 && mouseY < 384)
{
state = 1;
gamestart = true;
}else if (mouseX > startTxtPo && mouseX < textboxend && mouseY > 450 && mouseY < 534)
{
state = 2;
//println("help");
}else if (mouseX > startTxtPo && mouseX < textboxend && mouseY > 600 && mouseY < 684)
{
state = 3;
//println("scoreboard");
}
if (mouseX > extX && mouseX < extX + 100 && mouseY > extY-50 && mouseY < extY && state == 2)
{
state = 0;
}else if (mouseX > extX && mouseX < extX + 100 && mouseY > extY-50 && mouseY < extY && state == 3)
{
state = 0;
}
}
void keyPressed()
{
if(key == 'w'||key == 'W')
{
isUp = true;
}
if(key == 's'||key == 'S')
{
isDown = true;
}
if(key == 'a'||key == 'A')
{
isLeft = true;
}
if(key =='d'||key == 'D')
{
isRight = true;
}
}
void keyReleased()
{
if(key == 'w'||key == 'W')
{
isUp = false;
}
if(key == 's'||key == 'S')
{
isDown = false;
}
if(key == 'a'||key == 'A')
{
isLeft = false;
}
if(key =='d'||key == 'D')
{
isRight = false;
}
}