Star Destroya

John Racine and Josh Childs
Star Destroya

In Star Destoya you are a small spaceship character and you have to destroy the incoming spaceships
before they reach the bottom of the screen.

The slider on the box moves the character along the bottom of the screen and the
button on the box fires a laser that destroys the enemy spaceships.

During the creation of the program there wasn't much confusion until the end when we had to use firmata in order to run arduino in processing in order to have both the slider and the button read at the same time.





PFont fontA;
PFont fontB;
PImage ship;
PImage ground;
PImage eship;
PImage boss1;
PImage enda;


import processing.serial.*; //Import the serial library into your sketch

import cc.arduino.*;        //Import the Arduino-Firmata library into your sketch

Arduino arduino;      //Create an instance of Arduino named arduino (can be any name) 
int atm;      // Data received from the serial port



int buttonPin = 12;
int buttonState = 0;
int val;
int sphereDiameter = 25;
int endaDiameter = 25;
boolean shoot = false;
float speed=1;
float stop=0;
int hitcount=0;
int score;
float Espeed=6;
int randx()
{
  return int(random(20, 580));
}

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

int[] ender2= {
  2, 1, 1, 1, 1
};




void setup()
{
  size(600, 620);
  fontA = loadFont("font1.vlw");
  fontB = loadFont("font2.vlw");
  textFont(fontA); 
  arduino = new Arduino(this, Arduino.list()[1], 57600);
  arduino.pinMode(buttonPin, Arduino.INPUT);
  ship=loadImage("ship2.png");
  ground=loadImage("Backround.png");
  eship=loadImage("enemy1.png");
  boss1=loadImage("Boss1.png");
  enda=loadImage("EndA.png");
}

void draw()
{
  background(0);
  image(ground, 0, 0);
  fill(color(255, 0, 0));
  textFont(fontA);
  text("POINTSa: " + score, 5, 610);
  text("Star Destroya", 214, 30); 
  text("Star Destroya", 214, 30); 
  textFont(fontB); 
  text("The Firsta Clasha", 240, 45);
  text("Highscora:38304", 445, 25);
  text("The Star Masta:JSRa", 435, 40);
  atm = arduino.analogRead(2);
  atm=int(map(atm, 0, 1023, 0, 600));
  println(atm);


  {
    if (keyPressed == true) 
    {  
      background(0);
      textFont(fontA);
      text("PAUSED", 250, 250);
      textFont(fontA);
      text("POINTSa: " + score, 5, 610);
      text("Star Destroya", 214, 30); 
      text("Star Destroya", 214, 30); 
      textFont(fontB); 
      text("The Firsta Clasha", 240, 45);

      stroke(225);
      fill(0, 0, 255);
      for (int i=0; i<5; i++)
      {
        image(ground, sphereXCoords[i]-11, sphereYCoords[i]-=speed, 
        sphereDiameter, sphereDiameter);
        if (keyPressed == true) image(ground, sphereXCoords[i]-11, sphereYCoords[i]+=stop, 
        sphereDiameter, sphereDiameter);
      }
    }
    {



      fill(255);
    }
    rect(-50, -50, 50, 50);
  }



  fill(color(190, 190, 255));
  stroke(color(00, 250, 100));


  fill(color(0, 0, 255));
  stroke(color(100, 250, 255));
  image(ship, atm-17, 555);
  fill(color(255, 0, 0));
  stroke(color(255, 0, 0));


  val = arduino.digitalRead(buttonPin);      // read input value and store it in val

  if (val != buttonState) {          // the button state has changed!
    if (val == 1) {                // check if the button is pressed
      shoot=true;
    }
  }
  buttonState = val;
  if (shoot==true)
  {
    sphereKiller(atm);
    shoot = false;
  }

  sphereDropper();
  gameEnder();
}

void mousePressed()
{
  shoot = true;
}

void sphereDropper()
{  

  stroke(225);
  fill(0, 0, 255);
  for (int i=0; i<5; i++)
  {
    if (i==0) 
    {
      image(enda, sphereXCoords[i]-11, sphereYCoords[i]+=speed*ender2[i], 
      sphereDiameter, sphereDiameter);
      if (keyPressed == true) image(enda, sphereXCoords[i]-11, sphereYCoords[i]+=stop, 
      sphereDiameter, sphereDiameter);
    }
    else {
      image(eship, sphereXCoords[i]-11, sphereYCoords[i]+=speed*ender2[i], 
      sphereDiameter, sphereDiameter);
      if (keyPressed == true) image(eship, sphereXCoords[i]-11, sphereYCoords[i]+=stop, 
      sphereDiameter, sphereDiameter);
    }
  }
}

void sphereKiller(int shotX)
{
  fill(255, 0, 0);
  boolean hit = false;
  for (int i = 0; i < 5; i++)
  {
    if ((shotX >= (sphereXCoords[i]-sphereDiameter/2)) && 
      (shotX <= (sphereXCoords[i]+sphereDiameter/2)))
    {
      hit = true;
      score = score +152;
      line(atm, 565, atm, sphereYCoords[i]);
      ellipse(sphereXCoords[i], sphereYCoords[i], 
      sphereDiameter+10, sphereDiameter+10);
      sphereXCoords[i] = randx();
      sphereYCoords[i] = 0;
      hitcount++;
      if (hitcount>4)
      {
        hitcount=0;
        speed=speed*1.02;

        {
          hit = true;
          score = score +152;
          line(atm, 565, atm, sphereYCoords[i]);
          ellipse(sphereXCoords[i], sphereYCoords[i], 
          sphereDiameter+10, sphereDiameter+10);
          sphereXCoords[i] = randx();
          sphereYCoords[i] = 0;
          hitcount++;
          if (hitcount>7)
          {
            hitcount=0;
            ender=ender2;

            {
              image(enda, sphereXCoords[i]-11, sphereYCoords[i]+=Espeed, 
              sphereDiameter, sphereDiameter);
              if (keyPressed == true) image(enda, sphereXCoords[i]-11, sphereYCoords[i]+=stop, 
              sphereDiameter, sphereDiameter);
            }
          }
        }
      }
    }
  }

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

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


Comments