xxxxxxxxxx
var w = 64;
var h = 64;
var dx = 0;
var topAlien = [];
var fr = 0;
var speed = 2;
function preload(){
aliens = loadImage("Spaceinvaders1.png");
}
function setup() {
createCanvas(windowWidth, windowHeight);
for (var i = 0; i < 10; i++) {
topAlien.push(new Alien1(i*80));
}
for (var i = 0; i < 10; i++){
topAlien.push(new Alien2(i*80));
}
frameRate(2);
//print(topAlien);
}
function draw() {
background(0);
update();
for (var i=0; i< topAlien.length; i++) {
topAlien[i].display();
}
for (var i=0; i< topAlien.length; i++) {
topAlien[i].display();
}
}
function update(){
fr = fr + 1;
if (fr >= 2){
fr = 0;
}
}
function Alien1(dx){
this.dx = dx;
this.display = function(){
dx = dx + speed;
if (fr == 0){
copy(aliens, 242, 104, 65, h, dx, 100, w, h);
}
}
}
function Alien2(dx){
this.dx = dx;
this.display = function(){
dx = dx + speed;
if (fr == 1){
copy(aliens, 338, 104, 65, h, dx, 100, w, h);
}
}
}