Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/*******************************************************************
Star Ship Battle

Created by Adriana Matic 

Instructions:

Moving the mouse back and forth with control a small fleet of ships and the rotation of the planet in the background
Clicking will fire laser bolts
*******************************************************************/

void setup(){
//Setup + Background
size(400, 400);

 

}

void draw(){
 background(0);
 frameRate(30);
 
 //stars + twinkling animation 
 strokeWeight(2);
 fill(255);
 ellipse(40,60,5,sin(frameCount*25)*5);
 ellipse(40,60,sin(frameCount*25)*5,5);
 ellipse(10,315,5,sin(frameCount*25)*5);
 ellipse(10,315,sin(frameCount*25)*5,5);
 ellipse(21,330,5,sin(frameCount*25)*5);
 ellipse(21,330,sin(frameCount*25)*5,5);
 ellipse(48,217,5,sin(frameCount*25)*5);
 ellipse(48,217,sin(frameCount*25)*5,5);
 ellipse(69,98,5,sin(frameCount*25)*5);
 ellipse(69,98,sin(frameCount*25)*5,5);
 ellipse(85,42,5,sin(frameCount*25)*5);
 ellipse(85,42,sin(frameCount*25)*5,5);
 ellipse(97,23,5,sin(frameCount*25)*5);
 ellipse(97,23,sin(frameCount*25)*5,5);
 ellipse(103,78,5,sin(frameCount*25)*5);
 ellipse(103,78,sin(frameCount*25)*5,5);
 ellipse(120,127,5,sin(frameCount*25)*5);
 ellipse(120,127,sin(frameCount*25)*5,5);
 ellipse(137,76,5,sin(frameCount*25)*5);
 ellipse(137,76,sin(frameCount*25)*5,5);
 ellipse(154,21,5,sin(frameCount*25)*5);
 ellipse(154,21,sin(frameCount*25)*5,5);
 ellipse(173,102,5,sin(frameCount*25)*5);
 ellipse(173,102,sin(frameCount*25)*5,5);
 ellipse(212,49,5,sin(frameCount*25)*5);
 ellipse(212,49,sin(frameCount*25)*5,5);
 ellipse(231,12,5,sin(frameCount*25)*5);
 ellipse(231,12,sin(frameCount*25)*5,5); 
 ellipse(229,87,5,sin(frameCount*25)*5);
 ellipse(229,87,sin(frameCount*25)*5,5);
 ellipse(241,114,5,sin(frameCount*25)*5);
 ellipse(241,114,sin(frameCount*25)*5,5);
 ellipse(278,31,5,sin(frameCount*25)*5);
 ellipse(278,31,sin(frameCount*25)*5,5); 
 ellipse(295,162,5,sin(frameCount*25)*5);
 ellipse(295,162,sin(frameCount*25)*5,5); 
 ellipse(314,110,5,sin(frameCount*25)*5);
 ellipse(314,110,sin(frameCount*25)*5,5);
 ellipse(335,14,5,sin(frameCount*25)*5);
 ellipse(335,14,sin(frameCount*25)*5,5);
 ellipse(341, 57,5,sin(frameCount*25)*5);
 ellipse(341,57,sin(frameCount*25)*5,5);
 ellipse(362,29,5,sin(frameCount*25)*5);
 ellipse(362,29,sin(frameCount*25)*5,5);
 ellipse(371,112,5,sin(frameCount*25)*5);
 ellipse(371,112,sin(frameCount*25)*5,5);
 
/*******************************************************************
Planet
*******************************************************************/
fill(19,129,134);
stroke(254,255,209,100);
strokeWeight(10);
ellipseMode(CORNER);
ellipse(mouseX/15+10,80,width, height);


/*******************************************************************
Republic Ship
*******************************************************************/

ellipseMode(CENTER);

//Hangar Bay Door 
noStroke();
fill(190);
triangle(170,270,190,315,240,300);
triangle(220,310,195,290,240,295);

//Star Destroyer Side Right
noStroke();
fill(127);
triangle(200,282,240,290,240,310);
triangle(210,285,220,310,240,310);
triangle(210,310,220,270,240,310);

//Star Destroyer Top
fill(225);
triangle(160,265,260,269,220,286);
triangle(217,285,240,290,260,269);
triangle(230,285,160,290,150,270);

//Star Destroyer Panel Front Right
fill(178);
triangle(240,310,258,280,255,275);
triangle(239,289,240,310,260,270);

//Republic Colour Top
fill(225,14,14);
triangle(155,265,255,268,160,275);

//Star Destroyer Bridge
noStroke();
fill(225);
rect(105,210,30,90);
//Shading
fill(80);
rect(110,205,25,10);
//Bridge Top
fill(200);
rect(85,199,35,10,4);
fill(225);
rect(100,200,40,10,4);
//Bridge Tower
fill(120);
rect(98,200,10,10);
rect(82,199,5,10);
fill(100);
rect(100,210,10,90);
rect(85,209,10,90);
fill(80);
rect(90,209,10,90);
fill(225);
triangle(110,220,100,280,200,280);
//Bridge Middle
triangle(100,240,60,280,120,280);
triangle(0,280,80,260,80,280);
fill(100);
rect(0,280,20,40);
fill(200);
rect(20,280,80,40);

//Star Destroyer Right Top Wing
fill(225);
noStroke();
triangle(80,280,180,280,220,320);

//Star Destroyer Back Right Wing
fill(50);
noStroke();
triangle(220,320,80,280,80,320);
triangle(80,319,220,340,80,343);
triangle(80,319,220,320,220,341);

//Star Destroyer Engine
fill(90);
noStroke();
triangle(110,300,115,338,65,345);
triangle(65,320,115,338,110,300);
ellipse(110,320,15,40);
triangle(21,320,41,340,81,300);
triangle(80,300,100,330,40,340);

//Engine Light
fill(188,245,255);
ellipse(70,330,25,35);
ellipse(30,330,25,35);

//Turrets
stroke(150);
strokeWeight(4);
point(160,274);
point(145,277);
strokeWeight(1);
line(100,280,160,270);

/*******************************************************************
Seperatist Ship 
*******************************************************************/
//Front
noStroke();
fill(74,105,252);
triangle(220,220,360,200,360,220);
rect(360,200,40,20);

fill(20,60,165);
triangle(280,260,360,260,360,280);
rect(360,260,40,20);

fill(222,214,123);
triangle(250,220,400,220,400,260);
triangle(300,260,340,220,400,260);

stroke(90);
strokeWeight(4);
line(320,240,400,240);



/*******************************************************************
Fighter Ships
*******************************************************************/
strokeWeight(9);
stroke(0);
point(mouseX+2, mouseY-92);
point(mouseX-2, mouseY-88);


point(mouseX+32, mouseY-102);
point(mouseX+28, mouseY-98);

point(mouseX+22, mouseY-72);
point(mouseX+18, mouseY-68);

stroke(200);
point(mouseX, mouseY-90);
point(mouseX+30, mouseY-100);
point(mouseX+20, mouseY-70);

}



void mousePressed(){
/*******************************************************************
On click blaster bolts fire and gun explosions denote turret locations
*******************************************************************/
 
  //blaster bolts
  strokeWeight(4);
  frameRate(4);
  stroke(5,73,255,200);
  line(170,250,200,240);
  line(240,260,260,240);
  line(260,220,220,240);
  
  stroke(255,0,0,200);
  line(300,220,280,240);
  line(225,245,205,260);
  
  //explosion
  ellipse(180,270,10,15);
  ellipse(160,275,10,15);
  ellipse(140,280, 10, 15);
  ellipse(320,220,15,10);
  ellipse(280,220,15,10);
  ellipse(300,220,15,10);
}