/**** * Classes ****/ var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics; if (Math.random() < 0.01) { return new Enemy4(); } else if (Math.random() < 0.02) { // 1 in 50 chance to be an instance of Enemy3 return new Enemy3(); } else if (Math.random() < 0.1) { enemyGraphics = self.attachAsset('enemy2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; } else { enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; } self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; self.x = Math.random() * 2048; for (var i = 0; i < 2; i++) { var newEnemy = new Enemy(); enemyCounter++; // Increment enemy counter newEnemy.x = Math.random() * 2048; newEnemy.y = 0; game.addChild(newEnemy); } if (enemyCounter === 0) { LK.showYouWin(); // Trigger win condition } if (!shootButton.visible) { shootButton.visible = true; } } if (ship.intersects(self)) { LK.showGameOver(); } else { game.children.forEach(function (child) { if (child instanceof Shot && child.intersects(self)) { child.destroy(); self.destroy(); enemyCounter--; // Decrement enemy counter LK.setScore(LK.getScore() + 1); // Increment score } }); } }; }); var Enemy2 = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; self.x = Math.random() * 2048; } if (ship.intersects(self)) { LK.showGameOver(); } }; }); var Enemy3 = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy3', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2.5; self.update = function () { // Follow the ship if (self.x < ship.x) { self.x += self.speed; } else if (self.x > ship.x) { self.x -= self.speed; } if (self.y < ship.y) { self.y += self.speed; } else if (self.y > ship.y) { self.y -= self.speed; } // Check for collision with the ship if (ship.intersects(self)) { LK.showGameOver(); } }; }); var Enemy4 = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy4', { anchorX: 0.5, anchorY: 0.5 }); self.hits = 0; self.update = function () { if (LK.ticks % 300 == 0) { var newEnemy3 = new Enemy3(); newEnemy3.x = self.x; newEnemy3.y = self.y; game.addChild(newEnemy3); } game.children.forEach(function (child) { if (child instanceof Shot && child.intersects(self)) { self.hits++; if (self.hits >= 20) { self.destroy(); } } }); }; }); var Shot = Container.expand(function () { var self = Container.call(this); var shotGraphics = self.attachAsset('shot', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -10; self.hits = 0; self.update = function () { self.y += self.speed; if (self.y < 0) { self.destroy(); } game.children.forEach(function (child) { if (child instanceof Enemy || child instanceof Enemy2 || child instanceof Enemy3) { if (self.intersects(child)) { child.destroy(); self.hits++; if (self.hits >= 20) { self.destroy(); } } } }); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var enemy = game.addChild(new Enemy()); enemy.x = 1024; enemy.y = 500; var ship = game.addChild(LK.getAsset('ship', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); var shootButton = game.addChild(LK.getAsset('button', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 2500 })); shootButton.visible = false; // Hide the shoot button initially shootButton.down = function (x, y, obj) { var shot = game.addChild(new Shot()); shot.x = ship.x; shot.y = ship.y - 50; LK.getSound('shipshot').play(); }; game.down = function (x, y, obj) { if (y < shootButton.y - shootButton.height / 2) { ship.x = x; ship.y = y; LK.getSound('ShipMove').play(); } }; var enemyCounter = 1; // Initialize enemy counter with the first enemy already added
/****
* Classes
****/
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics;
if (Math.random() < 0.01) {
return new Enemy4();
} else if (Math.random() < 0.02) {
// 1 in 50 chance to be an instance of Enemy3
return new Enemy3();
} else if (Math.random() < 0.1) {
enemyGraphics = self.attachAsset('enemy2', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
} else {
enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
}
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
for (var i = 0; i < 2; i++) {
var newEnemy = new Enemy();
enemyCounter++; // Increment enemy counter
newEnemy.x = Math.random() * 2048;
newEnemy.y = 0;
game.addChild(newEnemy);
}
if (enemyCounter === 0) {
LK.showYouWin(); // Trigger win condition
}
if (!shootButton.visible) {
shootButton.visible = true;
}
}
if (ship.intersects(self)) {
LK.showGameOver();
} else {
game.children.forEach(function (child) {
if (child instanceof Shot && child.intersects(self)) {
child.destroy();
self.destroy();
enemyCounter--; // Decrement enemy counter
LK.setScore(LK.getScore() + 1); // Increment score
}
});
}
};
});
var Enemy2 = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy2', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
if (ship.intersects(self)) {
LK.showGameOver();
}
};
});
var Enemy3 = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy3', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2.5;
self.update = function () {
// Follow the ship
if (self.x < ship.x) {
self.x += self.speed;
} else if (self.x > ship.x) {
self.x -= self.speed;
}
if (self.y < ship.y) {
self.y += self.speed;
} else if (self.y > ship.y) {
self.y -= self.speed;
}
// Check for collision with the ship
if (ship.intersects(self)) {
LK.showGameOver();
}
};
});
var Enemy4 = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy4', {
anchorX: 0.5,
anchorY: 0.5
});
self.hits = 0;
self.update = function () {
if (LK.ticks % 300 == 0) {
var newEnemy3 = new Enemy3();
newEnemy3.x = self.x;
newEnemy3.y = self.y;
game.addChild(newEnemy3);
}
game.children.forEach(function (child) {
if (child instanceof Shot && child.intersects(self)) {
self.hits++;
if (self.hits >= 20) {
self.destroy();
}
}
});
};
});
var Shot = Container.expand(function () {
var self = Container.call(this);
var shotGraphics = self.attachAsset('shot', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10;
self.hits = 0;
self.update = function () {
self.y += self.speed;
if (self.y < 0) {
self.destroy();
}
game.children.forEach(function (child) {
if (child instanceof Enemy || child instanceof Enemy2 || child instanceof Enemy3) {
if (self.intersects(child)) {
child.destroy();
self.hits++;
if (self.hits >= 20) {
self.destroy();
}
}
}
});
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var enemy = game.addChild(new Enemy());
enemy.x = 1024;
enemy.y = 500;
var ship = game.addChild(LK.getAsset('ship', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
var shootButton = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2500
}));
shootButton.visible = false; // Hide the shoot button initially
shootButton.down = function (x, y, obj) {
var shot = game.addChild(new Shot());
shot.x = ship.x;
shot.y = ship.y - 50;
LK.getSound('shipshot').play();
};
game.down = function (x, y, obj) {
if (y < shootButton.y - shootButton.height / 2) {
ship.x = x;
ship.y = y;
LK.getSound('ShipMove').play();
}
};
var enemyCounter = 1; // Initialize enemy counter with the first enemy already added
futuristic spaceship old nintendo game sprite. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
UFO sprite old nintendo game. 2d. No shadows
meteorite sprite old nintendo game. 2d. Blank background. High contrast. No shadows
Alien Mothership. 2d. Blank background. High contrast. No shadows