Your browser does not support the canvas tag.

previous        Show / Hide Source    Download        next
//Adam Quesnel
//Student ID:991470931
//October 2nd, 2017
//Target Buster

//Global Variables
float targetTOPY1;
float targetRIGHTX1;
float targetBOTTOMY2;
float targetLEFTX2;
float randomHeight1 = random(-300, 0);
float randomWidth1 = random(400,700);
float randomWidth2 = random(400,700);
float randomHeight2= random(-300, 0);
int playerPosX= 200;
int playerPosY= 200;
int playerPosW = 150;
int playerPosA = 150;
int playerPosS = 250;
int playerPosD = 250;
int speed;

void setup()
{
  size(400, 400);
  targetTOPY1 = randomHeight1;
  targetRIGHTX1 = randomWidth1;
  targetBOTTOMY2 = randomWidth2;
  targetLEFTX2 = randomHeight2;
  
  //written gameplay instructions
  println("USE W,A,S,D KEYS TO MOVE POSITIONS AND BUST TARGETS");
}


void draw()
{
  background(255, 30, 0);


  speed = 2;
  targetTOPY1 += speed;
  targetRIGHTX1 -= speed;
  targetBOTTOMY2 -= speed;
  targetLEFTX2 += speed;

  targetreset1();
  targetreset2();
  targetreset3();
  targetreset4();
  platform();
  player();

  
  //Create Targets
  fill(125);
  ellipse(200, targetTOPY1, 25, 25);
  ellipse(targetRIGHTX1, 200, 25, 25);
  ellipse(200, targetBOTTOMY2, 25, 25);
  ellipse(targetLEFTX2, 200, 25, 25);
}



//Targets Reset after reaching the end of the triangle
void targetreset1()
{
  if (targetTOPY1 >= 160)
  {
    targetTOPY1=randomHeight1;
  }
}

void targetreset2()
{
  if (targetRIGHTX1 <= 245)
  {
    println(targetRIGHTX1);
    
    targetRIGHTX1=400;
  }
}

void targetreset3()
{
  if (targetBOTTOMY2 <= 250)
  {
    targetBOTTOMY2=randomWidth2;
  }
}

void targetreset4()
{
  if (targetLEFTX2 >= 160)
  {
    targetLEFTX2=randomHeight2;
  }
}


//Triangles that the Targets follow
void platform()
{
  fill(255);
  noStroke();
  triangle(200, 160, 230, -5, 170, -5);
  triangle(240, 200, 400, 180, 400, 230);
  triangle(200, 240, 230, 405, 170, 405);
  triangle(160, 200, 0, 180, 0, 230);
}


//creates the player
void player()
{
  fill(0);
  stroke(0);
  rectMode(CENTER);
  rect(playerPosX, playerPosY, 20, 20);



//Player cordinates which place to be with movements bined keys W,A,S,D
  if (keyPressed && key == 'w')
  {
    playerPosY = playerPosW;
    playerPosX = width/2;
  }
  else if (keyPressed && key == 'a')
  {
    playerPosX = playerPosA;
    playerPosY = height/2;
  }
  else if (keyPressed && key == 's')
  {
    playerPosY = playerPosS;
    playerPosX = width/2;
  }
  else if (keyPressed && key == 'd')
  {
    playerPosX = playerPosD;
    playerPosY = height/2;
  }


//Colour chnage to indicate ball has connected with player
  fill(0,125,10,75);
  if (playerPosY == playerPosW && targetTOPY1 >= 130)
{
  rectMode(CORNERS);
  rect(0,0,400,400);
 
 }
  
 
if (playerPosX == playerPosA && targetLEFTX2 >= 130)
{
  rectMode(CORNERS);
  rect(0,0,400,400);
 
 }
  
 
if (playerPosY == playerPosS && targetBOTTOMY2 >= 400)
{
  rectMode(CORNERS);
  rect(0,0,400,400);
 
 }
  
 
if (playerPosX == playerPosD && targetRIGHTX1 >= 380)
{
  rectMode(CORNERS);
  rect(0,0,400,400);
 
 }



}