User prompt
make the empty ammo UI units transparent, so that the ones that have been used have 25% transparency instead of being fully invisible
User prompt
move the ammo UI to the left
User prompt
remake the ammo UI elements, so that instead of arranging them one bellow the other, arrange them one above the other. so the first starting ammo UI element is the bottom most item, and the subsequent ammo assets are created above instead of below it
Code edit (1 edits merged)
Please save this source code
User prompt
increase the explosion speed for both the enemies and the civlians. double the speed it takes for it to grow to it's full size
User prompt
enemy explosions should destroy the civilians, triggering the civilians explosion as well
User prompt
enemy explosions should trigger the civilians explosion as well
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'hitboxIntersects')' in or related to this line: 'if (midgroundContainer.children[e].hitboxIntersects(civilians[c])) {' Line Number: 310
User prompt
let's create a more complex system for bullets targeting. right now you target the closest enemy near the player, however, we need to add a flag that checks if the bullet has been fired. once fired, exclude that enemy from the targeting mechanism, and consider it killed. don't actually kill the enemy, just exclude that enemy from the targeting. the next fired bullet should be the next closest enemy near the player and so on. the intention is to only fire a single bullet towards an enemy
User prompt
Once you fire a bullet towards the nearest enemy, consider that enemy already killed, so the next bullet you're going to shoot is going to be the next nearest enemy.
User prompt
increase the civilians radius
User prompt
civilians shouldcollide with enemies, so they don't intersect.
User prompt
civilians should only follow enemies when they are inside in their range
User prompt
civilians should actually follow the enemies around instead of moving away from them
Code edit (1 edits merged)
Please save this source code
User prompt
civilians also need to avoid the edges of the screen.
User prompt
civilians are also spawned on the map similar to the enemies, but they have no effect on the player. they move around randomly on the map. they try to run away from both the player and the enemy. they have an invisible radius of 300 pixels, and if any enemy or player comes in thi range they change direction drying to avoid them. they spawn once every 2 second and there can only be 5 civilians on the map. they can only be destroyed by explosions not bullets. when destroyed, similar to the enemies they also explode. their explosion can kill other enemies and civilians.
User prompt
after each pont added enemies spawn a bit faster, but I need that value reduced so they don't spawn as fast per point
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'hitboxIntersects')' in or related to this line: 'self.hitboxIntersects = function (target) {' Line Number: 318
User prompt
the explosion should kill the enemy when it hits any part of it's hitbox,, not just it's center
User prompt
if an enemy touches the player go to game over
User prompt
for every point increase of the score, make enemies spawn faster
Code edit (1 edits merged)
Please save this source code
User prompt
decrease enmy acceleration
User prompt
enemies should have acceleration
/**** * Classes ****/ // Ammo class var Ammo = Container.expand(function () { var self = Container.call(this); var ammoGraphics = self.attachAsset('ammo', { anchorX: 0.5, anchorY: 0.5 }); }); // BackgroundContainer class var BackgroundContainer = Container.expand(function () { var self = Container.call(this); }); //<Assets used in the game will automatically appear here> // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.direction = { x: 0, y: -1 }; // Default direction self.targetedEnemy = null; // Add a flag to store the targeted enemy self.update = function () { self.x += self.direction.x * self.speed; self.y += self.direction.y * self.speed; }; }); // Civilian class var Civilian = Container.expand(function () { var self = Container.call(this); var civilianGraphics = self.attachAsset('civilian', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.direction = { x: Math.random() * 2 - 1, y: Math.random() * 2 - 1 }; self.update = function () { // Check for collision with enemies for (var i = 0; i < enemySpawners.length; i++) { if (self.intersects(enemySpawners[i])) { // Move civilian away from the enemy var dx = self.x - enemySpawners[i].x; var dy = self.y - enemySpawners[i].y; var magnitude = Math.sqrt(dx * dx + dy * dy); self.direction.x = dx / magnitude; self.direction.y = dy / magnitude; self.x += self.direction.x * self.speed; self.y += self.direction.y * self.speed; } } // Move civilian self.x += self.direction.x * self.speed; self.y += self.direction.y * self.speed; // Follow enemies within a radius of 500 pixels var closestEnemy = null; var closestDistance = Infinity; for (var i = 0; i < enemySpawners.length; i++) { var distance = Math.sqrt(Math.pow(enemySpawners[i].x - self.x, 2) + Math.pow(enemySpawners[i].y - self.y, 2)); if (distance < closestDistance) { closestEnemy = enemySpawners[i]; closestDistance = distance; } } if (closestEnemy !== null && closestDistance <= 500) { self.direction.x = closestEnemy.x - self.x; self.direction.y = closestEnemy.y - self.y; var magnitude = Math.sqrt(self.direction.x * self.direction.x + self.direction.y * self.direction.y); self.direction.x /= magnitude; self.direction.y /= magnitude; } // Avoid edges of the screen if (self.x < 100) { self.direction.x = Math.abs(self.direction.x); } if (self.x > 1948) { self.direction.x = -Math.abs(self.direction.x); } if (self.y < 100) { self.direction.y = Math.abs(self.direction.y); } if (self.y > 2632) { self.direction.y = -Math.abs(self.direction.y); } }; }); // EnemySpawner class var EnemySpawner = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2.5; self.acceleration = 0.01; // Decrease acceleration property self.update = function () { var dx = player.x - self.x; var dy = player.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > self.speed) { self.speed += self.acceleration; // Increase speed by acceleration self.x += dx * self.speed / distance; self.y += dy * self.speed / distance; } }; }); // Explosion class var Explosion = Container.expand(function () { var self = Container.call(this); var explosionGraphics = self.attachAsset('explosion', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.01, scaleY: 0.01 }); self.expandTime = 150; // 150 milliseconds self.startTime = Date.now(); self.hitboxIntersects = function (target) { var selfBounds = self.getBounds(); var targetBounds = target.getBounds(); return selfBounds.x < targetBounds.x + targetBounds.width && selfBounds.x + selfBounds.width > targetBounds.x && selfBounds.y < targetBounds.y + targetBounds.height && selfBounds.y + selfBounds.height > targetBounds.y; }; self.update = function () { var elapsedTime = Date.now() - self.startTime; var scale = Math.min(1, elapsedTime / self.expandTime); explosionGraphics.scale.set(scale, scale); if (scale >= 1) { // Check for collisions with enemies for (var i = enemySpawners.length - 1; i >= 0; i--) { if (self.hitboxIntersects(enemySpawners[i])) { var newExplosion = new Explosion(); newExplosion.x = enemySpawners[i].x; newExplosion.y = enemySpawners[i].y; midgroundContainer.addChild(newExplosion); enemySpawners[i].destroy(); enemySpawners.splice(i, 1); } } // Check for collisions with civilians for (var c = civilians.length - 1; c >= 0; c--) { if (self.hitboxIntersects(civilians[c])) { var newExplosion = new Explosion(); newExplosion.x = civilians[c].x; newExplosion.y = civilians[c].y; midgroundContainer.addChild(newExplosion); civilians[c].destroy(); civilians.splice(c, 1); } } self.destroy(); } }; }); // ForegroundContainer class var ForegroundContainer = Container.expand(function () { var self = Container.call(this); }); // MidgroundContainer class var MidgroundContainer = Container.expand(function () { var self = Container.call(this); }); // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.x += self.direction.x * self.speed; self.y += self.direction.y * 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.shoot = function () { var newBullet = new Bullet(); newBullet.x = self.x; newBullet.y = self.y; // Find the closest enemy that hasn't been targeted var closestEnemy = null; var closestDistance = Infinity; for (var i = 0; i < enemySpawners.length; i++) { var alreadyTargeted = bullets.some(function (bullet) { return bullet.targetedEnemy === enemySpawners[i]; }); if (alreadyTargeted) { continue; // Skip already targeted enemies } var distance = Math.sqrt(Math.pow(enemySpawners[i].x - self.x, 2) + Math.pow(enemySpawners[i].y - self.y, 2)); if (distance < closestDistance) { closestEnemy = enemySpawners[i]; closestDistance = distance; } } if (closestEnemy === null) { return; // No enemies to target } if (ammoCount <= 0) { console.log("Out of ammo!"); return; // Out of ammo } ammoCount--; var ammoToRemove = ammoDisplay.pop(); ammoToRemove.alpha = 0.25; // Set the bullet's direction towards the closest enemy var dx = closestEnemy.x - self.x; var dy = closestEnemy.y - self.y; var magnitude = Math.sqrt(dx * dx + dy * dy); newBullet.direction = { x: dx / magnitude, y: dy / magnitude }; newBullet.targetedEnemy = closestEnemy; // Mark the enemy as targeted bullets.push(newBullet); midgroundContainer.addChild(newBullet); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize arrays and variables var bullets = []; var obstacles = []; var enemySpawners = []; var ammos = []; var backgroundContainer = game.addChild(new BackgroundContainer()); var civilians = []; var foregroundContainer = game.addChild(new ForegroundContainer()); var ammoCount = 10; var ammoDisplay = []; for (var i = 0; i < ammoCount; i++) { var ammo = new Ammo(); ammo.x = 60; // Position to the left ammo.y = 2732 - 50 - i * 60; // Stack vertically from bottom to top ammoDisplay.push(ammo); ammo.alpha = 1; foregroundContainer.addChild(ammo); } var midgroundContainer = game.addChild(new MidgroundContainer()); var player = midgroundContainer.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 200; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Handle touch down event game.down = function (x, y, obj) { player.shoot(); }; // Update game state game.update = function () { // Player moves towards the Ammo if (ammos.length > 0) { var dx = ammos[0].x - player.x; var dy = ammos[0].y - player.y; var distance = Math.sqrt(dx * dx + dy * dy); var speed = 10; if (distance > speed) { player.x += dx * speed / distance; player.y += dy * speed / distance; } } // Update bullets for (var i = bullets.length - 1; i >= 0; i--) { bullets[i].update(); if (bullets[i].y < -50) { bullets[i].destroy(); bullets.splice(i, 1); } } // Update obstacles for (var j = obstacles.length - 1; j >= 0; j--) { obstacles[j].update(); if (obstacles[j].y > 2732 + 50) { obstacles[j].destroy(); obstacles.splice(j, 1); } } // Update explosions for (var e = midgroundContainer.children.length - 1; e >= 0; e--) { if (midgroundContainer.children[e] instanceof Explosion) { midgroundContainer.children[e].update(); // Check for collisions with civilians for (var c = civilians.length - 1; c >= 0; c--) { if (typeof civilians[c].hitboxIntersects === 'function' && midgroundContainer.children[e].hitboxIntersects(civilians[c])) { var newExplosion = new Explosion(); newExplosion.x = civilians[c].x; newExplosion.y = civilians[c].y; midgroundContainer.addChild(newExplosion); civilians[c].destroy(); civilians.splice(c, 1); } } } } // Check for collisions for (var k = bullets.length - 1; k >= 0; k--) { for (var l = enemySpawners.length - 1; l >= 0; l--) { if (bullets[k].intersects(enemySpawners[l])) { bullets[k].destroy(); var explosion = new Explosion(); explosion.x = enemySpawners[l].x; explosion.y = enemySpawners[l].y; midgroundContainer.addChild(explosion); enemySpawners[l].destroy(); bullets.splice(k, 1); enemySpawners.splice(l, 1); LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); break; } } } // Spawn new enemy spawners if (LK.ticks % Math.max(10, 90 - LK.getScore()) == 0) { var newEnemySpawner = new EnemySpawner(); var edge = Math.floor(Math.random() * 4); switch (edge) { case 0: // Top edge newEnemySpawner.x = Math.random() * 2048; newEnemySpawner.y = -50; break; case 1: // Right edge newEnemySpawner.x = 2048 + 50; newEnemySpawner.y = Math.random() * 2732; break; case 2: // Bottom edge newEnemySpawner.x = Math.random() * 2048; newEnemySpawner.y = 2732 + 50; break; case 3: // Left edge newEnemySpawner.x = -50; newEnemySpawner.y = Math.random() * 2732; break; } enemySpawners.push(newEnemySpawner); midgroundContainer.addChild(newEnemySpawner); } // Spawn new civilians if (LK.ticks % 120 == 0 && civilians.length < 5) { var newCivilian = new Civilian(); newCivilian.x = Math.random() * 2048; newCivilian.y = Math.random() * 2732; civilians.push(newCivilian); midgroundContainer.addChild(newCivilian); } // Update civilians for (var c = civilians.length - 1; c >= 0; c--) { civilians[c].update(); } // Spawn new Ammo only when there is no existing Ammo on the screen if (ammos.length == 0) { var newAmmo = new Ammo(); newAmmo.x = 200 + Math.random() * (2048 - 400); newAmmo.y = 200 + Math.random() * (2732 - 400); ammos.push(newAmmo); midgroundContainer.addChild(newAmmo); } // Check for game over for (var m = obstacles.length - 1; m >= 0; m--) { if (obstacles[m].intersects(player)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } for (var n = enemySpawners.length - 1; n >= 0; n--) { if (enemySpawners[n].intersects(player)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Check for Ammo collection for (var n = ammos.length - 1; n >= 0; n--) { if (ammos[n].intersects(player)) { ammos[n].destroy(); ammos.splice(n, 1); if (ammoCount < 10) { ammoCount++; var newAmmoDisplay = new Ammo(); newAmmoDisplay.x = 60; // Position to the left newAmmoDisplay.y = 2732 - 50 - (ammoCount - 1) * 60; // Stack vertically from bottom to top ammoDisplay.push(newAmmoDisplay); foregroundContainer.addChild(newAmmoDisplay); } } } };
===================================================================
--- original.js
+++ change.js
@@ -216,9 +216,9 @@
return; // Out of ammo
}
ammoCount--;
var ammoToRemove = ammoDisplay.pop();
- ammoToRemove.destroy();
+ ammoToRemove.alpha = 0.25;
// Set the bullet's direction towards the closest enemy
var dx = closestEnemy.x - self.x;
var dy = closestEnemy.y - self.y;
var magnitude = Math.sqrt(dx * dx + dy * dy);
@@ -256,8 +256,9 @@
var ammo = new Ammo();
ammo.x = 60; // Position to the left
ammo.y = 2732 - 50 - i * 60; // Stack vertically from bottom to top
ammoDisplay.push(ammo);
+ ammo.alpha = 1;
foregroundContainer.addChild(ammo);
}
var midgroundContainer = game.addChild(new MidgroundContainer());
var player = midgroundContainer.addChild(new Player());
8-bit pixelated isometric cute watermelon with a rotor above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit pixelated radial watermelon red juice explosion splash. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit pixelated isometric blueberry-shaped UFO with a cute fruit inside. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit pixelated isometric blueberry projectile. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit pixelated isometric blueberry projectile icon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create a minimal and stylized 8-bit pixelated background of an alien village made of pineapple-shaped huts, viewed from a distance so the buildings appear small and occupy a small lower part of the background. The sky should be light blue and occupy the majority of the image, with the huts constructed from various fruits and having primitive shapes. Use a softer color palette to ensure the background does not distract from the main game elements, capturing the essence of classic 8-bit era video games. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.