Space Invaders Basic

This is a cool space invaders type games

Its got quite a lot of code – but you can make changes to the code and see how it works.


PFont fontA;
int sphereDiameter = 10;
boolean shoot = false;

int randx()
{
return int(random(600));
}

int[] sphereXCoords = { randx(), randx(), randx(), randx(), randx() };
int[] sphereYCoords = { 0, 0, 0, 0, 0 };

void setup()
{
size(600,620);
}

void draw()
{
background(0);
fill(color(0,255,0));
stroke(color(0,255,0));
triangle(mouseX-8, 580, mouseX+8, 580, mouseX, 565);
fill(color(255,0,0));
stroke(color(255,0,0));

if(shoot==true)
{
sphereKiller(mouseX);
shoot = false;
}

sphereDropper();
gameEnder();
}

void mousePressed()
{
shoot = true;
}

void sphereDropper()
{
stroke(255);
fill(255);
for (int i=0; i<5; i++)
{
ellipse(sphereXCoords[i], sphereYCoords[i]++,
sphereDiameter, sphereDiameter);
}
}

void sphereKiller(int shotX)
{
boolean hit = false;
for (int i = 0; i < 5; i++) { if((shotX >= (sphereXCoords[i]-sphereDiameter/2)) &&
(shotX <= (sphereXCoords[i]+sphereDiameter/2)))
{
hit = true;
line(mouseX, 565, mouseX, sphereYCoords[i]);
ellipse(sphereXCoords[i], sphereYCoords[i],
sphereDiameter+25, sphereDiameter+25);
sphereXCoords[i] = randx();
sphereYCoords[i] = 0;
}
}

if(hit == false)
{
line(mouseX, 565, mouseX, 0);
}

}

void gameEnder()
{
for (int i=0; i< 5; i++)
{
if(sphereYCoords[i]==600)
{
fill(color(255,0,0));
noLoop();
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s