xxxxxxxxxx
120
let stars =[];
let rockets=[];
function setup() {
createCanvas(600, 700);
for (let i = 0; i < 100; i++) {
stars[i] = new Star(random(width), random(height), random(1, 5));
}
rocket = new Rocket(width / 2, height, 5);
moon = new Moon(500,100,50);
// Add mouse click event listener
mouseClicked = function() {
let x = mouseX;
let y = mouseY;
let rocket = new Rocket(x, y, 5);
rockets.push(rocket);
}
}
function draw() {
background(1,22,64);
//Drawing the stars
for (let star of stars) {
star.show();
}
//Drawing the moon
moon.show();
//Drawing the rockets
for (let i = 0; i < rockets.length; i++) {
rockets[i].update();
rockets[i].show();
}
}
//Class making the randomized stars in the background
class Star {
constructor(x, y, size) {
this.x = x;
this.y = y;
this.size = size;
}
//Drawing the stars
show() {
stroke(255);
strokeWeight(this.size);
point(this.x, this.y);
}
}
//Making the moon
class Moon {
constructor(x, y, diameter) {
this.x = x;
this.y = y;
this.diameter = diameter;
}
show() {
//The main body
noStroke()
fill(254, 252, 215);
ellipse(this.x, this.y, this.diameter, this.diameter);
// Adding shadows
fill(234, 232, 185);
ellipse(this.x + this.diameter / 4, this.y, this.diameter / 2, this.diameter / 2);
ellipse(this.x+5 - this.diameter / 4, this.y + this.diameter / 4, this.diameter / 2, this.diameter / 4);
}
}
//Class making the rocket
class Rocket {
constructor(x, y, velocity) {
this.x = x;
this.y = y;
this.velocity = velocity;
}
update() {
this.y -= this.velocity;
}
//Body of rocket
show() {
//Flames
noStroke()
fill(255,185,0)
ellipse(this.x,this.y+35,20,60)
//Side fins
fill(30,144,255);
arc(this.x,this.y + 36,40,40,PI,0,CHORD)
// Body
fill(255,0,0)
ellipse(this.x,this.y,30,80)
//Windows
fill(255);
ellipse(this.x,this.y-12.15,15)
fill(255);
ellipse(this.x,this.y+6.15,15)
//Front fin
fill(30,144,255);
ellipse(this.x,this.y+32,5,30)
}
}