xxxxxxxxxx
86
let star= [];
let words = ["Click to add", "new shooting star", "and use", "the arrow keys", "to move the rocket"];
let i = 0;
let a = 75;
let b = 400;
function setup() {
createCanvas(400, 500);
}
function draw() {
background(2, 2, 58, 5);
noStroke();
//rocket side legs
fill('rgb(231,35,35)');
triangle(a, b, a-15, b+50, a+15, b+50);
triangle(a+50, b, a+35, b+50, a+65, b+50);
//rocket body
fill('rgb(158,159,170)');
ellipse(a+25, b-10, 70, 115);
//rocket roof
fill('rgb(231,35,35)');
triangle(a+25, b-90, a-15, b-30, a+65, b-30);
//rocket middle leg
rect(a+23, b+17, 5, 40);
//rocket window
fill('rgb(143,190,224)');
circle(a+25, b-10, 25);
//code for moving the stars
for(let i =0; i<star.length; i++){
star[i].move();
star[i].bounce();
star[i].show();
}
//text
textAlign(CENTER, CENTER);
fill('white');
textSize(25);
text(words[i], 190, 200);
text('🌠', 70, 200);
text('🌠', 310, 200);
//moving the rocket up and down
if (keyIsPressed){
if (keyCode == UP_ARROW){
b--;
} else if (keyCode == DOWN_ARROW){
b++;
}
}
//moving the rocket right and left
if (keyIsPressed){
if (keyCode == LEFT_ARROW){
a--;
} else if (keyCode == RIGHT_ARROW){
a++;
}
}
}
function mousePressed(){
//adding new star
let interactiveStar = new Star(mouseX, mouseY, random(-5,5), random(-5,5));
star.push(interactiveStar);
//changing text
i = i + 1;
if (i == words.length) {
i = 0;
}
}