User prompt
make them faster and worth 8 points
User prompt
make the red enemies faster
User prompt
make the red enemies more rare
User prompt
make the red enemies faster
User prompt
they're still red
User prompt
now the non homing enemies are red too
User prompt
the homing enemies are not red
User prompt
make the enemies sometimes be red and home in on the player
User prompt
add a score counter in the corner
User prompt
it doesn't display the score on the game over screen
User prompt
add a score system that adds 1 to the score each time you defeat an enemy and displays the score on the game over screen
User prompt
make it so the game resets when you hit the enemies
User prompt
make it so when you click it fires
Initial prompt
dodge the lasers
/**** * Classes ****/ // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.move = function (x, y) { self.x = x; self.y = y; }; }); // 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 = 2; self.move = function () { self.y += self.speed; }; }); // Laser class var Laser = Container.expand(function () { var self = Container.call(this); var laserGraphics = self.attachAsset('laser', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.move = function () { self.y += self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Fire lasers when the game area is clicked // Initialize player, enemy, and laser assets for the game. var score = 0; game.on('down', function () { var laser = new Laser(); laser.x = player.x; laser.y = player.y - 30; // Start slightly above the player lasers.push(laser); game.addChild(laser); }); var player = game.addChild(new Player()); player.x = 1024; // Center horizontally player.y = 2500; // Position towards the bottom var enemies = []; var lasers = []; // Create enemies at intervals var enemySpawnTimer = LK.setInterval(function () { var enemy = new Enemy(); enemy.x = Math.random() * 2048; // Random horizontal position enemy.y = 0; // Start at the top enemies.push(enemy); game.addChild(enemy); }, 2000); // Handle touch move to control player game.on('move', function (obj) { var pos = obj.event.getLocalPosition(game); player.move(pos.x, pos.y); }); // Main game loop LK.on('tick', function () { // Move enemies for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].move(); // Remove enemies that go off screen if (enemies[i].y > 2732) { enemies[i].destroy(); enemies.splice(i, 1); } } // Move lasers for (var j = lasers.length - 1; j >= 0; j--) { lasers[j].move(); // Remove lasers that go off screen if (lasers[j].y < 0) { lasers[j].destroy(); lasers.splice(j, 1); } } // Check for collisions between lasers and enemies for (var k = lasers.length - 1; k >= 0; k--) { for (var l = enemies.length - 1; l >= 0; l--) { if (lasers[k].intersects(enemies[l])) { // Destroy both laser and enemy on collision lasers[k].destroy(); lasers.splice(k, 1); enemies[l].destroy(); enemies.splice(l, 1); score++; break; // Exit the inner loop after a collision } } } // Check for collisions between player and enemies, and reset the game if a collision occurs for (var m = enemies.length - 1; m >= 0; m--) { if (player.intersects(enemies[m])) { LK.showGameOver('Your score: ' + LK.getScore()); } } });
===================================================================
--- original.js
+++ change.js
@@ -112,8 +112,8 @@
}
// Check for collisions between player and enemies, and reset the game if a collision occurs
for (var m = enemies.length - 1; m >= 0; m--) {
if (player.intersects(enemies[m])) {
- LK.showGameOver('Your score: ' + score);
+ LK.showGameOver('Your score: ' + LK.getScore());
}
}
});
\ No newline at end of file
green cartoon laser. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
red cartoon laser. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pink cartoon laser. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
sci-fi cartoon spaceship. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.