bio photo

Email

####Intro

I used to play Asteroids growing up. My objective is to build this game in p5. I will vary its functionality to learn weekly course objectives.

####random()

1/ Testing out the random() function by building stars that flicker in space
2/ Declaring var and objective

var pos = {
	x : 5
	y : 5
};


3/ Building random() sparkling stars

  //sparkling stars
  pos.x = random(0,width);
  pos.y = random(0,height);
  fill(255);
  ellipse(pos.x, pos.y, 10, 10);
  


####mouseX and mouseY

1/ In the game the spaceship responds to arrow keys to rotate.
2/ Wanted to rotate the spaceship with mouseX and mouseY while it is centered. Couldn’t figure that out.
3/ Wrote the following for the spaceship (a simple triangle) to move with mouseX and mouseY

  // center space ship moves to mouse
  stroke(255);
  noFill();
  triangle(mouseX+65,mouseY+65,mouseX+75,mouseY+75,mouseX+85,mouseY+45);
 

####mouseIsPressed and firing missiles

  1. mouseIsPressed loops within draw(), unlike mousePressed(), the function which is an event
  2. Would like small ellipses to leave the tip of the triangle() on mousepressed.
  3. Need help!
  4. Instead, I get the ellpises to get circle highlights,
 if (mouseIsPressed) {

  stroke(255);
  noFill();
  ellipse(pos.x,pos.y,25,25); 


Here’s the program, and the snapshot below: