xxxxxxxxxx
113
let x = 200;
let y = 350;
var speedX =2;
var speedY =2;
let shooting = false;
var s = 45 ;
var r,g,b;
var minX = 0;
var maxX = 400;
var minY = 0;
var maxY = 400;
var laserY = 0;
var speed = -10;
var shootLaser = false;
var LASERSOUND;
var landscapeButton;
// SOUND STUFF
function preload() {
LASERSOUND = loadSound("Laser_shoot 6.wav");
}
function keyPressed() {
console.log(keyCode);
if (keyCode == 32) {
// spacebar
if (LASERSOUND.isPlaying()) {
LASERSOUND.pause();
} else {
LASERSOUND.play();
}
shootLaser = true;
laserY = y - 20;
}
}
var instructions = "Spacebar shoots laser, Mouse Moves the space Ship";
var textSizeInstruction = 16;
function setup() {
createCanvas(400, 400);
landscapeButton = createButton("Click here Generate The Galaxy Color");
landscapeButton.mousePressed(landscape);
OGBackgroundColor = color (50);
noStroke();
}
function landscape() {
let r = random(200);
let g = random(0);
let b = random(200);
OGBackgroundColor = color ( r, g, b);
}
function ufo(x, y) {
fill(127, 255, 0);
circle(x, y, 40);
fill(128, 0, 255);
ellipse(x, y, 100, 10);
}
function draw() {
background(OGBackgroundColor);
// Move the UFO w/ Mouse
x = constrain(lerp(x, mouseX, 0.09), minX, maxX);
y = constrain(lerp(y, mouseY, 0.02), minY, maxY);
/* UFO Function =] */
ufo(x, y);
PLANET(200, 50);
if (shootLaser) {
fill("red");
noStroke();
rect(x - 5, laserY - 50, 10, 50);
laserY += speed;
if (laserY < 20) {
shootLaser = false;
}
}
function PLANET(x, y) {
fill(r,g,b);
circle(x , y , s);
x=x+speedX;
y+= speedY;
if (x + 50 > width || x - 50 < 0) {
speedX *= -1;}
if (y + 50 > height || y - 50 < 0) {
speedY *= -1;}
if (frameCount % 60 == 0) {
r = random(0, 255);
g = (0);
b = random(0, 255);
s = random(10, 200)
}
}
fill(255);
textSize(textSizeInstruction);
textAlign(CENTER, LEFT);
text(instructions,20,20, 30);
}