User prompt
Add a powerup that Doubles the bullets
User prompt
Enemies have 2 health
User prompt
Make it play the "Shoot" Sound when shooting
User prompt
Make bullets shoot multiple times like the player on the enemy
User prompt
Make enemy bullets clone
User prompt
Make enemys shoot too
Initial prompt
Ferious Shooter
/**** * Classes ****/ // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732 + enemyGraphics.height / 2) { self.destroy(); enemies.splice(enemies.indexOf(self), 1); } }; self.shoot = function () { for (var i = 0; i < 3; i++) { var bullet = new EnemyBullet(); bullet.x = self.x + i * 50 - 50; // Offset each bullet for spread effect bullet.y = self.y + enemyGraphics.height / 2; game.addChild(bullet); enemyBullets.push(bullet); LK.getSound('Shoot').play(); } }; }); // EnemyBullet class var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('enemyBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { self.y += self.speed; if (self.y > 2732 + bulletGraphics.height / 2) { self.destroy(); enemyBullets.splice(enemyBullets.indexOf(self), 1); } }; }); //<Assets used in the game will automatically appear here> // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Hero update logic }; self.shoot = function () { var bullet = new HeroBullet(); bullet.x = self.x; bullet.y = self.y - heroGraphics.height / 2; game.addChild(bullet); heroBullets.push(bullet); if (self.doubleBullets) { var bullet2 = new HeroBullet(); bullet2.x = self.x + 50; bullet2.y = self.y - heroGraphics.height / 2; game.addChild(bullet2); heroBullets.push(bullet2); } LK.getSound('Shoot').play(); }; self.powerUp = function () { self.doubleBullets = true; LK.setTimeout(function () { self.doubleBullets = false; }, 10000); }; }); // HeroBullet class var HeroBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('heroBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -15; self.update = function () { self.y += self.speed; if (self.y < -bulletGraphics.height / 2) { self.destroy(); heroBullets.splice(heroBullets.indexOf(self), 1); } }; }); // PowerUp class var PowerUp = Container.expand(function () { var self = Container.call(this); var powerUpGraphics = self.attachAsset('powerUp', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732 + powerUpGraphics.height / 2) { self.destroy(); powerUps.splice(powerUps.indexOf(self), 1); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ function spawnPowerUp() { var powerUp = new PowerUp(); powerUp.x = Math.random() * 2048; powerUp.y = -powerUp.height / 2; game.addChild(powerUp); powerUps.push(powerUp); } var hero; var enemies = []; var heroBullets = []; var enemyBullets = []; var powerUps = []; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); function spawnEnemy() { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = -enemy.height / 2; game.addChild(enemy); enemies.push(enemy); } function handleMove(x, y, obj) { hero.x = x; hero.y = y; } game.down = function (x, y, obj) { handleMove(x, y, obj); }; game.move = handleMove; game.update = function () { if (LK.ticks % 60 == 0) { spawnEnemy(); } if (LK.ticks % 600 == 0) { spawnPowerUp(); } for (var i = heroBullets.length - 1; i >= 0; i--) { heroBullets[i].update(); } for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].update(); if (LK.ticks % 120 == 0) { enemies[i].shoot(); } } for (var i = enemyBullets.length - 1; i >= 0; i--) { enemyBullets[i].update(); } for (var i = heroBullets.length - 1; i >= 0; i--) { for (var j = enemies.length - 1; j >= 0; j--) { if (heroBullets[i].intersects(enemies[j])) { score++; scoreTxt.setText(score); heroBullets[i].destroy(); enemies[j].destroy(); heroBullets.splice(i, 1); enemies.splice(j, 1); break; } } } for (var i = enemyBullets.length - 1; i >= 0; i--) { if (enemyBullets[i].intersects(hero)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); break; } } }; hero = new Hero(); hero.x = 2048 / 2; hero.y = 2732 - 200; game.addChild(hero); LK.setInterval(function () { hero.shoot(); }, 500); for (var i = powerUps.length - 1; i >= 0; i--) { powerUps[i].update(); if (powerUps[i].intersects(hero)) { powerUps[i].destroy(); powerUps.splice(i, 1); hero.powerUp(); } }
===================================================================
--- original.js
+++ change.js
@@ -3,9 +3,8 @@
****/
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
- self.health = 2;
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
@@ -61,10 +60,23 @@
bullet.x = self.x;
bullet.y = self.y - heroGraphics.height / 2;
game.addChild(bullet);
heroBullets.push(bullet);
+ if (self.doubleBullets) {
+ var bullet2 = new HeroBullet();
+ bullet2.x = self.x + 50;
+ bullet2.y = self.y - heroGraphics.height / 2;
+ game.addChild(bullet2);
+ heroBullets.push(bullet2);
+ }
LK.getSound('Shoot').play();
};
+ self.powerUp = function () {
+ self.doubleBullets = true;
+ LK.setTimeout(function () {
+ self.doubleBullets = false;
+ }, 10000);
+ };
});
// HeroBullet class
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
@@ -80,8 +92,24 @@
heroBullets.splice(heroBullets.indexOf(self), 1);
}
};
});
+// PowerUp class
+var PowerUp = Container.expand(function () {
+ var self = Container.call(this);
+ var powerUpGraphics = self.attachAsset('powerUp', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732 + powerUpGraphics.height / 2) {
+ self.destroy();
+ powerUps.splice(powerUps.indexOf(self), 1);
+ }
+ };
+});
/****
* Initialize Game
****/
@@ -91,12 +119,20 @@
/****
* Game Code
****/
+function spawnPowerUp() {
+ var powerUp = new PowerUp();
+ powerUp.x = Math.random() * 2048;
+ powerUp.y = -powerUp.height / 2;
+ game.addChild(powerUp);
+ powerUps.push(powerUp);
+}
var hero;
var enemies = [];
var heroBullets = [];
var enemyBullets = [];
+var powerUps = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
@@ -121,8 +157,11 @@
game.update = function () {
if (LK.ticks % 60 == 0) {
spawnEnemy();
}
+ if (LK.ticks % 600 == 0) {
+ spawnPowerUp();
+ }
for (var i = heroBullets.length - 1; i >= 0; i--) {
heroBullets[i].update();
}
for (var i = enemies.length - 1; i >= 0; i--) {
@@ -136,17 +175,14 @@
}
for (var i = heroBullets.length - 1; i >= 0; i--) {
for (var j = enemies.length - 1; j >= 0; j--) {
if (heroBullets[i].intersects(enemies[j])) {
- enemies[j].health--;
- if (enemies[j].health <= 0) {
- score++;
- scoreTxt.setText(score);
- enemies[j].destroy();
- enemies.splice(j, 1);
- }
+ score++;
+ scoreTxt.setText(score);
heroBullets[i].destroy();
+ enemies[j].destroy();
heroBullets.splice(i, 1);
+ enemies.splice(j, 1);
break;
}
}
}
@@ -163,5 +199,13 @@
hero.y = 2732 - 200;
game.addChild(hero);
LK.setInterval(function () {
hero.shoot();
-}, 500);
\ No newline at end of file
+}, 500);
+for (var i = powerUps.length - 1; i >= 0; i--) {
+ powerUps[i].update();
+ if (powerUps[i].intersects(hero)) {
+ powerUps[i].destroy();
+ powerUps.splice(i, 1);
+ hero.powerUp();
+ }
+}
\ No newline at end of file
A space shooter enemy that shoots bullets. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A bullet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A spaceship shooter. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.