Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/*
Assignment 2 - Interactive Toy
Laser Pixel Glitch
By: Vanessa Urnos
Instructor: Fredd Eyles

Game:
Destroy the enemy targets coming on to the screen with a laser shot attack from 
the ship, enemies gradually get faster once hit. Difficult of game is relied on 
speed and gravity as well as the background to create confusion for the player. 

*/


/////////Referenced code from Code Orienteering
////////Referenced code from Previous Year Examples

//Requirement 2/7
///////Variables////////

//Gradient Background Variables
float boxGradientPosX;
float boxGradientPosY;
float gradientX=50;
float gradientY=400;

//Ship Variables
float shipSizeW = 10;
float shipSizeH = 40;
float shipPosX = 370;

//Enemy Variables
float enemySizeW = 15;
float enemySizeH = 15;
float enemyY = random(40,360);
float enemyX = 0;
float Speed = 0.2;
Float Gravity = 0.20;

void setup() {
//Requirement 1/7
  size(400, 400);
  noStroke();
  //slows down the colour change of the background overall 
  frameRate(20);
  rectMode(CORNER);
}

void draw() 
{
//Required 6/7
  //Background
  drawDullGradientBackground();
  //Ship
  drawShip();
  //Enemy Targets
  drawEnemies();
}


////Background


//Required 5/7
//Required 7/7
/////////Referenced code from Code Orienteering
void drawDullGradientBackground()
//randomizes colours in the bacground
{
  boxGradientPosX=0;
  while (boxGradientPosX<width) {
    boxGradientPosY=0;
    while (boxGradientPosY<height) {
      noStroke();
      fill(random(150),random(150),random(150));
      rect(boxGradientPosX, boxGradientPosY, gradientX, gradientY);

      boxGradientPosY+=gradientY;
    }
    boxGradientPosX+=gradientX;
  }
}

/////Ship
void drawShip()
{
  stroke  (222,236,6);
  strokeWeight(4);
  noFill();
  rect(shipPosX,mouseY,shipSizeW,shipSizeH);
}

//Required 7/7
//Enemy Targets
void drawEnemies()
{
  stroke(200);
  strokeWeight(3);
  fill(random(150,255),random(150,255),random(150,255));
  rect(enemyX, enemyY,enemySizeW,enemySizeH);
  Speed = Speed + Gravity;
  enemyX = enemyX + Speed;

//Required 7/7
//Reset Enemy Position when hit by laser
  if (enemyX>height){
    enemyX=0;
    Speed=0;
    enemyY=random(20,360);
}
//Requirement 3/7
//Ship Attack
if (mousePressed){
  stroke(random(255),random(255),random(255));
  strokeWeight(3);
  line(mouseX,mouseY+20,width-50,mouseY+20);
 }

//When player shoots enemy, enemy gradually moves faster
if (mousePressed && enemyY-10<mouseY && enemyY+10>mouseY) {
  enemyY=random(40,340);
  enemyX=0;
  Speed=Speed + 0.005;
  Speed = Speed + Gravity;
  enemyX = enemyX +Speed;
}
}