User prompt
Make the hero always move towards last touch point.
User prompt
If the player got hit by the zombie, then that is game over.
User prompt
Let's add the second layer of the background, or the sky, please.
User prompt
Move the hero from left and right through player inputs.
User prompt
Let's edit the background with an open road for the player to move.
User prompt
Let's add the background, like, for example, a city, please.
User prompt
Let's add a combo multiplier. Every time you shoot the zombie, you get a combo. More combos, more points.
User prompt
Let's choose classes. Every time you choose a class, you get new weapons for shooting zombies.
User prompt
Let's add the score to Killing the Zombies.
Initial prompt
Simply Zombies
/**** * Classes ****/ // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -10; self.move = function () { self.y += self.speed; }; }); // Assets will be automatically created based on usage in the code. // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.move = function (direction) { if (direction === 'left' && self.x > 0) { self.x -= self.speed; } else if (direction === 'right' && self.x < 2048) { self.x += self.speed; } }; }); // Zombie class var Zombie = Container.expand(function () { var self = Container.call(this); var zombieGraphics = self.attachAsset('zombie', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.move = function () { self.y += self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var sky = game.addChild(LK.getAsset('sky', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); var background = game.addChild(LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); var player = game.addChild(new Player('player')); player.x = 1024; // Center horizontally player.y = 2500; // Near bottom var zombies = []; var bullets = []; var score = 0; var combo = 0; var scoreTxt = new Text2(score.toString(), { size: 150, fill: "#ffffff" }); LK.gui.top.addChild(scoreTxt); // Create zombies at intervals var zombieInterval = LK.setInterval(function () { var zombie = new Zombie(); zombie.x = Math.random() * 2048; // Random horizontal position zombie.y = 0; // Start from top zombies.push(zombie); game.addChild(zombie); }, 2000); // Touch event to move player and shoot bullets var lastTouchPoint = null; game.on('move', function (obj) { lastTouchPoint = obj.event.getLocalPosition(game); }); game.on('down', function (obj) { var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; bullets.push(bullet); game.addChild(bullet); }); // Game tick LK.on('tick', function () { // Move zombies for (var i = zombies.length - 1; i >= 0; i--) { zombies[i].move(); if (zombies[i].y > 2732) { // Off screen zombies[i].destroy(); zombies.splice(i, 1); } } // Move player towards last touch point if (lastTouchPoint) { if (lastTouchPoint.x < player.x) { player.move('left'); } else if (lastTouchPoint.x > player.x) { player.move('right'); } } // Move bullets for (var j = bullets.length - 1; j >= 0; j--) { bullets[j].move(); if (bullets[j].y < 0) { // Off screen bullets[j].destroy(); bullets.splice(j, 1); combo = 0; // Reset combo multiplier when a bullet misses } } // Check for bullet-zombie collisions for (var b = bullets.length - 1; b >= 0; b--) { for (var z = zombies.length - 1; z >= 0; z--) { if (bullets[b] && zombies[z] && bullets[b].intersects(zombies[z])) { bullets[b].destroy(); bullets.splice(b, 1); zombies[z].destroy(); zombies.splice(z, 1); combo += 1; // Increase combo multiplier on zombie kill score += combo; // Increase score by combo multiplier LK.setScore(score); scoreTxt.setText(score.toString()); if (score === 10) { player.destroy(); player = game.addChild(new Player('playerType2')); player.x = 1024; // Center horizontally player.y = 2500; // Near bottom } else if (score === 20) { player.destroy(); player = game.addChild(new Player('playerType3')); player.x = 1024; // Center horizontally player.y = 2500; // Near bottom } break; } // Check for player-zombie collisions if (player && zombies[z] && player.intersects(zombies[z])) { // Game over LK.showGameOver(); break; } } } });
===================================================================
--- original.js
+++ change.js
@@ -85,15 +85,11 @@
zombies.push(zombie);
game.addChild(zombie);
}, 2000);
// Touch event to move player and shoot bullets
+var lastTouchPoint = null;
game.on('move', function (obj) {
- var pos = obj.event.getLocalPosition(game);
- if (pos.x < player.x) {
- player.move('left');
- } else if (pos.x > player.x) {
- player.move('right');
- }
+ lastTouchPoint = obj.event.getLocalPosition(game);
});
game.on('down', function (obj) {
var bullet = new Bullet();
bullet.x = player.x;
@@ -111,8 +107,16 @@
zombies[i].destroy();
zombies.splice(i, 1);
}
}
+ // Move player towards last touch point
+ if (lastTouchPoint) {
+ if (lastTouchPoint.x < player.x) {
+ player.move('left');
+ } else if (lastTouchPoint.x > player.x) {
+ player.move('right');
+ }
+ }
// Move bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].move();
if (bullets[j].y < 0) {
Soldier in a zombie infested world. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Bullet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Open road in a city that is plagued by zombies. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
zombie. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Orange coved sky for the zombie infested town. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.