/**** * Classes ****/ // Bullet class var Bullet = Container.expand(function (startX, startY, direction) { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.x = startX; self.y = startY; self.speed = 10; self.direction = direction; self.update = function () { self.x += self.direction.x * self.speed; self.y += self.direction.y * self.speed; if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) { self.destroy(); } }; }); // Enemy class var Enemy = Container.expand(function (startX, startY) { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.x = startX; self.y = startY; self.speed = 2; self.update = function () { var dx = player.x - self.x; var dy = player.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; if (self.intersects(player)) { // Handle player damage playerHealth -= 10; self.destroy(); } }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.shootDirection = { x: 0, y: 0 }; self.update = function () { // Player shooting logic if (LK.ticks % 15 === 0) { var bullet = new Bullet(self.x, self.y, self.shootDirection); game.addChild(bullet); bullets.push(bullet); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player var player = game.addChild(new Player()); player.x = 1024; player.y = 1366; // Initialize bullets and enemies arrays var bullets = []; var enemies = []; // Player health var playerHealth = 100; // Game update function game.update = function () { // Update player direction based on pointer game.move = function (x, y, obj) { var dx = x - player.x; var dy = y - player.y; var distance = Math.sqrt(dx * dx + dy * dy); player.shootDirection = { x: dx / distance, y: dy / distance }; }; // Spawn enemies at random edges if (LK.ticks % 60 === 0) { var edge = Math.floor(Math.random() * 4); var startX, startY; if (edge === 0) { // Top startX = Math.random() * 2048; startY = 0; } else if (edge === 1) { // Right startX = 2048; startY = Math.random() * 2732; } else if (edge === 2) { // Bottom startX = Math.random() * 2048; startY = 2732; } else { // Left startX = 0; startY = Math.random() * 2732; } var enemy = new Enemy(startX, startY); game.addChild(enemy); enemies.push(enemy); } // Update bullets for (var i = bullets.length - 1; i >= 0; i--) { bullets[i].update(); // Check for collision with enemies for (var j = enemies.length - 1; j >= 0; j--) { if (bullets[i].intersects(enemies[j])) { // Destroy both bullet and enemy bullets[i].destroy(); bullets.splice(i, 1); enemies[j].destroy(); enemies.splice(j, 1); break; } } if (bullets[i] && bullets[i].destroyed) { bullets.splice(i, 1); } } // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (enemies[j].destroyed) { enemies.splice(j, 1); } } };
===================================================================
--- original.js
+++ change.js
@@ -146,9 +146,5 @@
if (enemies[j].destroyed) {
enemies.splice(j, 1);
}
}
- // Check for game over
- if (playerHealth <= 0) {
- LK.showGameOver();
- }
};
\ No newline at end of file
fire with eyes and mouth. Single Game Texture. In-Game asset. 2d. High contrast. No shadows
A cartoon firefighter. Single Game Texture. In-Game asset. 2d. High contrast. No shadows
a blue hydrant round icon Single Game Texture. In-Game asset. 2d. High contrast. No shadows
Heart. Single Game Texture. In-Game asset. 2d. High contrast. No shadows