xxxxxxxxxx
var posX = 200;
var posY = 150;
var speedX = 6;
var shiftDown = 75;
var invader = [];
function preload(){
aliens = loadImage("Spaceinvaders1.png");
}
function setup(){
createCanvas(windowWidth, windowHeight);
for (var i = 0; i < 1; i++){
invader[i] = new Img(posX + i*400, posY, speedX, shiftDown);
}
}
function draw(){
background(200);
for (var i = 0; i < invader.length; i++){
invader[i].display();
invader[i].move();
}
}
function Img(x, y, z, w) {
this.x = x;
this.y = y;
this.speedX = z;
this.shiftDown = w;
this.display = function(){
tint(7, 39, 91);
imageMode(CENTER);
image(aliens, this.x, this.y, 0, 0);
}
this.move = function(){
this.x += this.speedX;
if ((this.x >= width - 150) || (this.x <= + 150)){
this.speedX = this.speedX * -1;
this.y = this.y + this.shiftDown;
}
}
}