/**** * Classes ****/ // Define the Alien class var Alien = Container.expand(function () { var self = Container.call(this); var alienGraphics = self.attachAsset('alien', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4; self.update = function () { // Alien moves in a straight line until it hits a wall if (self.direction === undefined) { self.direction = Math.floor(Math.random() * 4); } switch (self.direction) { case 0: // Move up if (self.y - self.speed < 0) { self.direction = 1; // Change direction to down } else { self.y -= self.speed; } break; case 1: // Move down if (self.y + self.speed > 2732) { self.direction = 0; // Change direction to up } else { self.y += self.speed; } break; case 2: // Move left if (self.x - self.speed < 0) { self.direction = 3; // Change direction to right } else { self.x -= self.speed; } break; case 3: // Move right if (self.x + self.speed > 2048) { self.direction = 2; // Change direction to left } else { self.x += self.speed; } break; } }; }); var BombShard = Container.expand(function () { var self = Container.call(this); var bombShardGraphics = self.attachAsset('bombShard', { anchorX: 0.5, anchorY: 0.5 }); }); // Define the Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Define the 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.update = function () { // Player update logic }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var cityBackground = game.attachAsset('city', { anchorX: 0, anchorY: 0 }); // Initialize player, aliens, obstacles and bomb shards var player = game.addChild(new Player()); player.x = 1024; player.y = 1366; var aliens = []; for (var i = 0; i < 7; i++) { var alien = new Alien(); do { alien.x = Math.random() * 2048; alien.y = Math.random() * 2732; } while (Math.hypot(player.x - alien.x, player.y - alien.y) < 500); aliens.push(alien); game.addChild(alien); } var obstacles = []; for (var j = 0; j < 10; j++) { var obstacle = new Obstacle(); obstacle.x = Math.random() * 2048; obstacle.y = Math.random() * 2732; obstacles.push(obstacle); game.addChild(obstacle); } var bombShards = []; var bombShardsCollected = 0; // Initialize bombShardsCollected to 0 for (var k = 0; k < 20; k++) { var bombShard = new BombShard(); bombShard.x = Math.random() * 2048; bombShard.y = Math.random() * 2732; bombShards.push(bombShard); game.addChild(bombShard); } // Joystick variables var joystickBase = null; var joystickKnob = null; var joystickActive = false; var joystickCenter = { x: 0, y: 0 }; var joystickRadius = 100; // Create joystick base joystickBase = LK.getAsset('city', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.15, scaleY: 0.15, alpha: 0.3 }); joystickBase.x = 200; joystickBase.y = 2400; LK.gui.bottomLeft.addChild(joystickBase); // Create joystick knob joystickKnob = LK.getAsset('bombShard', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5, alpha: 0.7 }); joystickKnob.x = 0; joystickKnob.y = 0; joystickBase.addChild(joystickKnob); // Handle touch input for joystick game.down = function (x, y, obj) { var localPos = LK.gui.bottomLeft.toLocal({ x: x, y: y }); var distance = Math.hypot(localPos.x - joystickBase.x, localPos.y - joystickBase.y); if (distance <= joystickRadius) { joystickActive = true; joystickCenter.x = joystickBase.x; joystickCenter.y = joystickBase.y; } }; game.move = function (x, y, obj) { if (joystickActive) { var localPos = LK.gui.bottomLeft.toLocal({ x: x, y: y }); var dx = localPos.x - joystickCenter.x; var dy = localPos.y - joystickCenter.y; var distance = Math.hypot(dx, dy); if (distance > joystickRadius) { dx = dx / distance * joystickRadius; dy = dy / distance * joystickRadius; } joystickKnob.x = dx; joystickKnob.y = dy; // Move player based on joystick input var moveSpeed = player.speed; var normalizedX = dx / joystickRadius; var normalizedY = dy / joystickRadius; var newX = player.x + normalizedX * moveSpeed; var newY = player.y + normalizedY * moveSpeed; // Keep player within bounds if (newX >= 0 && newX <= 2048) { player.x = newX; } if (newY >= 0 && newY <= 2732) { player.y = newY; } } }; game.up = function (x, y, obj) { if (joystickActive) { joystickActive = false; joystickKnob.x = 0; joystickKnob.y = 0; } }; // Play background music LK.playMusic('tttttt'); // Update game logic game.update = function () { // Update player player.update(); // Update aliens for (var i = 0; i < aliens.length; i++) { // Check if player is hiding behind an obstacle var isHiding = false; for (var j = 0; j < obstacles.length; j++) { if (player.intersects(obstacles[j])) { isHiding = true; break; } } // If player is not hiding and 3 seconds have passed, make the closest alien chase the player if (!isHiding && LK.ticks > 180) { var closestAlien = aliens.reduce(function (prev, curr) { var d1 = Math.hypot(player.x - prev.x, player.y - prev.y); var d2 = Math.hypot(player.x - curr.x, player.y - curr.y); return d1 < d2 ? prev : curr; }); var dx = player.x - closestAlien.x; var dy = player.y - closestAlien.y; var angle = Math.atan2(dy, dx); closestAlien.x += Math.cos(angle) * (closestAlien.speed / 4); closestAlien.y += Math.sin(angle) * (closestAlien.speed / 4); } // Check for collision with player if (player.intersects(aliens[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Check for player intersecting with bomb shards for (var k = 0; k < bombShards.length; k++) { if (player.intersects(bombShards[k])) { // Player has collected a bomb shard bombShardsCollected++; bombShards[k].destroy(); // Destroy the collected bomb shard bombShards.splice(k, 1); // Remove the collected bomb shard from the array k--; // Decrement k to account for the removed bomb shard } } // If all bomb shards are collected, destroy all aliens and end game if (bombShardsCollected === 20) { for (var i = 0; i < aliens.length; i++) { aliens[i].destroy(); } aliens = []; // Clear the aliens array LK.showYouWin(); // End game once all aliens are destroyed } };
===================================================================
--- original.js
+++ change.js
@@ -205,8 +205,10 @@
joystickKnob.x = 0;
joystickKnob.y = 0;
}
};
+// Play background music
+LK.playMusic('tttttt');
// Update game logic
game.update = function () {
// Update player
player.update();
An alien with high tec weaponry and armory. Single Game Texture. In-Game asset. 2d. Blank background. High contrast
A barier wall with vines on it. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
A man in the army suited with weapons. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
peice of a hi tech bomb. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows