Hey guys, I am in need of some help I have a game where my Alien isnt appearing and i cant figure out why. The main part of the problem is the last section of my code. Any help would be much appreciated
class Bullet
{
private PVector loc = new PVector();
private float angle;
private Cannon c;
private int age = 0;
PVector center;
PVector turret;
public Bullet(Cannon c, float x, float y)
{
this.c = c;
loc.x = x;
loc.y = y;
center = new PVector(c.loc.x,c.loc.y);
turret = new PVector(c.cX,c.cY);
}
void run()
{
noStroke();
fill(200);
ellipse(loc.x,loc.y,10,10);
PVector vel = PVector.sub(turret,center);
loc.add(new PVector(vel.x/15,vel.y/15));
age++;
if (age>100) bullets.remove(this);
}
}
public PFont font = createFont("Arial-MT",15);
ArrayList cannons = new ArrayList();
ArrayList bullets = new ArrayList();
ArrayList targets = new ArrayList();
public int points = 0;
int targetInterval = 150;
int counter = 0;
int bulletCounter = 0;
int hitCounter = 0;
float accuracy;
int seconds = 0;
int sc = 0;
int c = 0;
int speed = 3;
boolean playing = false;
import ddf.minim.* ;
Minim minim;
AudioPlayer mySound;
void setup()
{
minim = new Minim(this) ;
mySound = minim.loadFile("war2_x.wav");
cannons = new ArrayList();
bullets = new ArrayList();
targets = new ArrayList();
points = 0;
targetInterval = 150;
counter = 0;
bulletCounter = 0;
hitCounter = 0;
accuracy = 0;
seconds = 0;
sc = 0;
c = 0;
speed = 3;
size(500,500);
cursor(CROSS);
textFont(font);
background(250);
cannons.add(new Cannon(150,150));
targets.add(new Target(random(50,425),random(50,425),int(random(5,9))));
playing = true;
frameRate(50);
}
void draw()
{
if (playing)
play();
else
lose();
}
void mousePressed()
{
if (playing)
{
for (int k=0;k<cannons.size();k++)
{
bullets.add(new Bullet(getC(k),(getC(k)).cX,(getC(k)).cY));
bulletCounter++;
}
}
}
public Cannon getC(int index)
{
if (index<cannons.size())
return ((Cannon)cannons.get(index));
else
return null;
}
void play()
{
font = createFont("Arial-MT",15);
textFont(font);
background(0);
counter++;
sc++;
c++;
if (sc == 50)
{
seconds++;
sc=0;
}
if (c>=100)
{
targetInterval--;
c=0;
}
if (counter>=targetInterval)
{
targets.add(new Target(random(50,425),random(50,425),int(random(5,9))));
counter = 0;
}
for(int k=0;k<bullets.size();k++)
{
((Bullet)bullets.get(k)).run();
}
for(int j=0;j<targets.size();j++)
{
((Target)targets.get(j)).draw();
}
for(int i=0;i<cannons.size();i++)
{
((Cannon)cannons.get(i)).show();
}
if (keyPressed&&key==CODED)
{
if (keyCode == UP)
{
for (int k=0;k<cannons.size();k++)
{
((Cannon)cannons.get(k)).loc.y-=speed;
}
}
if (keyCode == DOWN)
{
for (int k=0;k<cannons.size();k++)
{
((Cannon)cannons.get(k)).loc.y+=speed;
}
}
if (keyCode == LEFT)
{
for (int k=0;k<cannons.size();k++)
{
((Cannon)cannons.get(k)).loc.x-=speed;
}
}
if (keyCode == RIGHT)
{
for (int k=0;k<cannons.size();k++)
{
((Cannon)cannons.get(k)).loc.x+=speed;
}
}
}
for (int k=0;k<cannons.size();k++)
{
if (((Cannon)cannons.get(k)).loc.x>width)
((Cannon)cannons.get(k)).loc.x=width;
else if (((Cannon)cannons.get(k)).loc.x<0)
((Cannon)cannons.get(k)).loc.x=0;
else if (((Cannon)cannons.get(k)).loc.y>height)
((Cannon)cannons.get(k)).loc.y=height;
else if (((Cannon)cannons.get(k)).loc.y<0)
((Cannon)cannons.get(k)).loc.y=0;
}
textAlign(LEFT);
fill(255);
text("Points: " + points,5,15);
if (bulletCounter > 0)
{
accuracy = int((hitCounter/bulletCounter)*100);
int h = bulletCounter - hitCounter;
int p = int(h/bulletCounter);
}
else if (bulletCounter == 0)
{
accuracy = 0;
}
//text("Accuracy: " + accuracy + "%", 5, 50);
text("Seconds: " + seconds, 5, 35);
if (targets.size()>5)
{
playing = false;
}
}
void lose()
{
int score = int(((points*seconds)*54.73)-((bulletCounter-hitCounter)*10));
background(0);
font = createFont("Arial-MT",50);
textFont(font);
textAlign(CENTER);
text("You Lost!!", width/2, height/2-50);
font = createFont("Arial-MT",25);
textFont(font);
text("Your score was: " + score, width/2, height/2-25);
text("Press 'r' to Play Again!" , width/2, height/2+10);
}
void keyPressed()
{
if (!playing)
{
if (key == 'r')
setup();
}
}
int BodyX;
int BodyY;
int BodyLength;
int BodyHeight;
int AntX;
int AntY;
int AntLength;
int AntHeight;
int LineX;
int LineY;
int LineLength;
int LineHeight;
int EyeX;
int EyeY;
int EyeLength;
int EyeHeight;
int EyeColX;
int EyeColY;
int EyeColLength;
int EyeColHeight;
int IrisX;
int IrisY;
int IrisLength;
int IrisHeight;
int Eye2X;
int Eye2Y;
int Eye2Length;
int Eye2Height;
int EyeCol2X;
int EyeCol2Y;
int EyeCol2Length;
int EyeCol2Height;
int Iris2X;
int Iris2Y;
int Iris2Length;
int Iris2Height;
int Eye3X;
int Eye3Y;
int Eye3Length;
int Eye3Height;
int EyeCol3X;
int EyeCol3Y;
int EyeCol3Length;
int EyeCol3Height;
int Iris3X;
int Iris3Y;
int Iris3Length;
int Iris3Height;
int MouthX;
int MouthY;
int MouthLength;
int MouthWidth;
class Target
{
float x;
float y;
int lives;
Target(float X, float Y, int LIVES)
{
x = X;
y = Y;
this.lives = LIVES;
}