/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * 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 }; }); // Define the PowerUp class var PowerUp = Container.expand(function () { var self = Container.call(this); var powerupGraphics = self.attachAsset('powerup', { anchorX: 0.5, anchorY: 0.5 }); self.type = 'speed'; // Default powerup type self.duration = 5000; // 5 seconds duration // Add pulsing animation tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { // Restart the pulsing animation tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 1000, easing: tween.easeInOut, onFinish: arguments.callee }); } }); } }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ //<Write imports for supported plugins here> //<Assets used in the game will automatically appear here> 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; } }; var powerups = []; var lastPowerupSpawn = 0; var playerSpeedBoost = 0; var playerSpeedBoostEndTime = 0; // Play background music LK.playMusic('tttttt'); // Update game logic game.update = function () { // Spawn powerup every 30 seconds (1800 ticks at 60fps) if (LK.ticks - lastPowerupSpawn >= 1800) { var powerup = new PowerUp(); powerup.x = Math.random() * 1848 + 100; // Keep away from edges powerup.y = Math.random() * 2532 + 100; // Keep away from edges powerups.push(powerup); game.addChild(powerup); lastPowerupSpawn = LK.ticks; } // Check for powerup collection for (var p = 0; p < powerups.length; p++) { if (player.intersects(powerups[p])) { // Apply speed boost playerSpeedBoost = 3; playerSpeedBoostEndTime = LK.ticks + 300; // 5 seconds at 60fps player.speed = 8; // Increase speed powerups[p].destroy(); powerups.splice(p, 1); p--; } } // Check if speed boost expired if (LK.ticks >= playerSpeedBoostEndTime && playerSpeedBoost > 0) { playerSpeedBoost = 0; player.speed = 5; // Reset to normal speed } // 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
@@ -1,5 +1,10 @@
/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
* Classes
****/
// Define the Alien class
var Alien = Container.expand(function () {
@@ -78,8 +83,47 @@
self.update = function () {
// Player update logic
};
});
+// Define the PowerUp class
+var PowerUp = Container.expand(function () {
+ var self = Container.call(this);
+ var powerupGraphics = self.attachAsset('powerup', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.type = 'speed'; // Default powerup type
+ self.duration = 5000; // 5 seconds duration
+ // Add pulsing animation
+ tween(self, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(self, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ // Restart the pulsing animation
+ tween(self, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: arguments.callee
+ });
+ }
+ });
+ }
+ });
+ return self;
+});
/****
* Initialize Game
****/
@@ -89,8 +133,10 @@
/****
* Game Code
****/
+//<Write imports for supported plugins here>
+//<Assets used in the game will automatically appear here>
var cityBackground = game.attachAsset('city', {
anchorX: 0,
anchorY: 0
});
@@ -205,12 +251,42 @@
joystickKnob.x = 0;
joystickKnob.y = 0;
}
};
+var powerups = [];
+var lastPowerupSpawn = 0;
+var playerSpeedBoost = 0;
+var playerSpeedBoostEndTime = 0;
// Play background music
LK.playMusic('tttttt');
// Update game logic
game.update = function () {
+ // Spawn powerup every 30 seconds (1800 ticks at 60fps)
+ if (LK.ticks - lastPowerupSpawn >= 1800) {
+ var powerup = new PowerUp();
+ powerup.x = Math.random() * 1848 + 100; // Keep away from edges
+ powerup.y = Math.random() * 2532 + 100; // Keep away from edges
+ powerups.push(powerup);
+ game.addChild(powerup);
+ lastPowerupSpawn = LK.ticks;
+ }
+ // Check for powerup collection
+ for (var p = 0; p < powerups.length; p++) {
+ if (player.intersects(powerups[p])) {
+ // Apply speed boost
+ playerSpeedBoost = 3;
+ playerSpeedBoostEndTime = LK.ticks + 300; // 5 seconds at 60fps
+ player.speed = 8; // Increase speed
+ powerups[p].destroy();
+ powerups.splice(p, 1);
+ p--;
+ }
+ }
+ // Check if speed boost expired
+ if (LK.ticks >= playerSpeedBoostEndTime && playerSpeedBoost > 0) {
+ playerSpeedBoost = 0;
+ player.speed = 5; // Reset to normal speed
+ }
// Update player
player.update();
// Update aliens
for (var i = 0; i < aliens.length; i++) {
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