You are on page 1of 5

Class Driver Floating_Alien

//**************************************************************
//Matthew Mitchell
//8/18/15
//floating_alien.java
//Al alien animation program
//**************************************************************
import java.awt.*;
int x = 75;
int y = 75;
int red = 0;
int blue = 0;
int green = 0;
public boolean click = false;
ArrayList <Alien> aliens;
Teleporter gun;
ArrayList <Beam> rays;
int aliensToAdd = 11;
void setup()
{
size(1000, 700);
background(0, 100, 200);
fill(red, green, blue);
//making the arrays and objects
aliens = new ArrayList<Alien>();
gun = new Teleporter(75, height - 100);
rays = new ArrayList<Beam>();
Alien al = new Alien(x, y);
aliens.add(al);
}
void draw()
{
background(0, 100, 200);
if (aliens.size() > 0)
{

int size = aliens.size();


Alien lastAlien = aliens.get(size-1);
//adding another alien to the list
if (lastAlien.cX > Alien.WINGSPAN+70 && aliensToAdd > 0)
{
Alien al = new Alien(x, y);
aliens.add(al);
aliensToAdd--;
}
}
//processing the alien nation
for (Alien al : aliens)
{
al.cX+=al.xVelocity;
red++;
fill(red, green, blue);
al.draw();
}
//drawing ray
gun.draw();
for (Beam ray : rays)
{
ray.cY+=ray.yVelocity;
ray.draw();
// for (Alien al : aliens)
for (int a = 0; a < aliens.size(); a++)
{
Alien al = aliens.get(a);
//checking if alien is hit by ray
if (ray.cX > al.cX-20 && ray.cX < al.cX+Alien.HEADWIDTH && ray.cY > al.cY &&
ray.cY < al.cY+Alien.HEADHEIGHT ||
ray.cX > al.cX && ray.cX < al.cX+Alien.BODYWIDTH && ray.cY > al.cY && ray.cY <
al.cY+Alien.BODYHEIGHT ||
ray.cX > al.cX-80 && ray.cX < al.cX+Alien.WIDTH && ray.cY > al.cY && ray.cY <
al.cY+30 ||
ray.cX > al.cX && ray.cX < al.cX+20 && ray.cY > al.cY+70 && ray.cY <
al.cY+Alien.HEIGHT ||
ray.cX > al.cX+50 && ray.cX < al.cX-30 && ray.cY > al.cY+70 && ray.cY <
al.cY+Alien.HEIGHT)
{
aliens.remove(al);

}
}
}
}
void mouseClicked()
{
rays.add(new Beam(gun.cX + gun.midpoint, gun.cY + 60));
}
Class Alien
class Alien
{
public int cX;
public int cY;
public int xVelocity = 7;
//height of alien not counting head
final static int HEIGHT = 130;
//length from cX to end of left hand
final static int WIDTH = 130;
//total width of alien
final static int WINGSPAN = 210;
//total height of alien head to toe
final static int HEADTOTOE = 180;
final static int HEADHEIGHT = 50;
final static int HEADWIDTH = 70;
final static int BODYHEIGHT = 70;
final static int BODYWIDTH = 50;
//public int yVelocity = 1;
Alien(int x, int y)
{
cX = x;
cY = y;
}
void draw()
{
noFill();
//alien movement

if (cX+120 > width )


{
xVelocity *= - 1;
cY+=Alien.HEADTOTOE;
}
if (cX-50 < 0)
{
xVelocity *= - 1;
cY+=Alien.HEADTOTOE;
}
if (cY+120 > height-35 && cX+Alien.WIDTH > width)
{
cY = 75;
cX = 80;
xVelocity *= -1;
}
//alien drawing
//body
rect(cX, cY, 50, 70);
//head
triangle(cX-20, cY, cX+25, cY-50, cX+70, cY);
//aliens right arm/hand
rect(cX, cY, -60, 30);
triangle(cX-60, cY, cX-80, cY+15, cX-60, cY+30);
//aliens left arm/hand
rect(cX+50, cY, 60, 30);
triangle(cX+110, cY, cX+130, cY+15, cX+110,cY+30);
//alien right leg
rect(cX, cY+70, 20, 60);
//alien left leg
rect(cX+50, cY+70, -20, 60);
}
}
Class Beam
class Beam
{

public int cX;


public int cY;
public double yVelocity=-2;
Beam(int x, int y)
{
cX=x;
cY=y;
}
void draw()
{
//ray
cY+=yVelocity;
fill(255, 100, 0);
rect(cX, cY, 3, 8);
}
}
Class Teleporter
class Teleporter
{
public int cX;
public int cY;
public int telWidth = 60;
public int midpoint = telWidth/2;
Teleporter(int x, int y)
{
cX=x;
cY=y;
}
void draw()
{
//teleporter gun
fill(150,0,200);
rect(mouseX, height - 30, 60, 10);
cX=mouseX;
}
}

You might also like