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
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,27 @@
/****
* Classes
****/
+// RedEnemy class
+var RedEnemy = 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 () {
+ // 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', {
@@ -69,9 +89,11 @@
var enemies = [];
var lasers = [];
// Create enemies at intervals
var enemySpawnTimer = LK.setInterval(function () {
- var enemy = new Enemy();
+ // Randomly decide whether to create a normal enemy or a red enemy
+ var isRed = Math.random() < 0.5;
+ 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);
@@ -85,10 +107,10 @@
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) {
+ // 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);
}
}
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.