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 ****/ // RedEnemy class var RedEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('redEnemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.move = function () { // Calculate direction towards player var dx = player.x - self.x; var dy = player.y - self.y; var len = Math.sqrt(dx * dx + dy * dy); dx /= len; dy /= len; // Move towards player self.x += dx * self.speed; self.y += dy * self.speed; }; }); // 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 scoreTxt = new Text2('0', { size: 100, fill: '#ffffff' }); LK.gui.topLeft.addChild(scoreTxt); 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 () { // Randomly decide whether to create a normal enemy or a red enemy var isRed = Math.random() < 0.1; var enemy = isRed ? new RedEnemy() : 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 or go too far to the left or right if (enemies[i].y > 2732 || enemies[i].x < 0 || enemies[i].x > 2048) { 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 += 8; scoreTxt.setText(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
@@ -7,9 +7,9 @@
var enemyGraphics = self.attachAsset('redEnemy', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 6;
+ self.speed = 10;
self.move = function () {
// Calculate direction towards player
var dx = player.x - self.x;
var dy = player.y - self.y;
@@ -131,9 +131,9 @@
lasers[k].destroy();
lasers.splice(k, 1);
enemies[l].destroy();
enemies.splice(l, 1);
- score++;
+ score += 8;
scoreTxt.setText(score);
break; // Exit the inner loop after a collision
}
}
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.