xxxxxxxxxx
83
var imgX = 200;
var imgY = 350;
var imgWidth;
var imgHeight;
move_spaceship = 4;
let enemy = [];
class Projectile {
constructor(x1, y1, color) {
this.x1 = random(width);
this.y1 = -20;
this.color = color;
}
draw_enemy() {
image(enemy_ship, this.x1, this.y1)
}
move_enemy() {
this.y1 += 1;
this.y2+=1
this.y3+=1
if (this.y1 > 500 ) {
}
}
}
function preload() {
spaceship = loadImage("spaceship.png");
space_theme = loadImage("spacetheme.jpg");
enemy_ship = loadImage("spaceship_enemy.png")
}
function setup() {
createCanvas(600, 500);
setInterval(function () {
let enemies = new Projectile();
enemy.push(enemies);
}, 1000);
}
function draw() {
background(0);
stroke(0);
rect(width / 2, height / 2, 20, 20);
// for (let xpos = 10; xpos < width; xpos = xpos + 10) {
// for (let ypos = 10; ypos < height; ypos = ypos + 10) {
// stroke(255, 255, 255);
// //circle(random(width), random(height), 0.0001);
// //line(xpos, ypos, xpos, ypos);
// }
// }
image(space_theme, 0, 0);
for (let x = 0; x < enemy.length; x+=5) {
enemy[x].draw_enemy();
enemy[x].move_enemy();
}
if (keyIsDown(LEFT_ARROW)) {
imgX -= move_spaceship;
}
if (keyIsDown(RIGHT_ARROW)) {
imgX += move_spaceship;
}
if (keyIsDown(UP_ARROW)) {
imgY -= move_spaceship;
}
if (keyIsDown(DOWN_ARROW)) {
imgY += move_spaceship;
}
image(spaceship, imgX, imgY);
}
function mouseClicked() {}