User prompt
And enemies shall move to player when they see player
User prompt
Health bar shall be a hotbar (rectangle).
User prompt
No, without all enemies are defeated. When just player gets close to portal
User prompt
Make a "You Won" screen with the same codes of "Game Over" screen. The "You Won" screen shall work when player is so close to portal
User prompt
When the shoots of enemies touch the wall, they shall disappear
User prompt
Enemies' shoots can only get forward on only the dark green area
User prompt
The enemies shall be able to move on only the dark green area
User prompt
Make the "You Won" screen with the same codes of "Game Over" screen
User prompt
When player is close to the portal, stop everything. And write to screen "You Won" and "Play Again" under it. Like the "Game Over" screen
User prompt
The enemies shan't be in the walls as they moving randomly
User prompt
The enemies shall be able to move randomly and they shall have a triangle vision in front of themselves. If the player is in their vision, they shall start to walk to the player.
User prompt
When the player is so close to the portal, generate the next level and next level should start
User prompt
When the player enters the portal, generate the next level
User prompt
Now, I wanna update something. In the levels, there can be spawned Skin Color Tanks between 5 and 10, there can be spawned Red Tanks between 10 and 15, there can be spawned Green Tanks between 7 and 14 in a level.
User prompt
Please fix the bug: 'keyboard is not defined' in or related to this line: 'keyboard.onKeyDown(function (key) {' Line Number: 442
User prompt
Please fix the bug: 'keyboard is not defined' in or related to this line: 'keyboard.onKeyDown(function (key) {' Line Number: 442
User prompt
Please fix the bug: 'keyboard is not defined' in or related to this line: 'keyboard.onKeyDown(function (key) {' Line Number: 442
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'keyboard is not defined' in or related to this line: 'keyboard.onKeyDown(function (key) {' Line Number: 442
User prompt
Please fix the bug: 'keyboard is not defined' in or related to this line: 'keyboard.onKeyDown(function (key) {' Line Number: 442
User prompt
Please fix the bug: 'keyboard is not defined' in or related to this line: 'keyboard.onKeyDown(function (key) {' Line Number: 442
User prompt
Please fix the bug: 'keyboard is not defined' in or related to this line: 'keyboard.onKeyDown(function (key) {' Line Number: 442
User prompt
Please fix the bug: 'keyboard is not defined' in or related to this line: 'keyboard.onKeyDown(function (key) {' Line Number: 442
User prompt
playerTank movements = WASD
User prompt
Player Movements = WASD
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var AcidBomb = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('acidBomb', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.directionX = 0; self.directionY = 0; self.damage = 5; self.poisonDamage = 2; self.poisonDuration = 180; self.update = function () { self.x += self.directionX * self.speed; self.y += self.directionY * self.speed; }; return self; }); var Dynamite = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('dynamite', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.directionX = 0; self.directionY = 0; self.damage = 25; self.explosionRadius = 80; self.update = function () { self.x += self.directionX * self.speed; self.y += self.directionY * self.speed; }; return self; }); var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('enemyBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4; self.directionX = 0; self.directionY = 0; self.damage = 10; self.update = function () { self.x += self.directionX * self.speed; self.y += self.directionY * self.speed; }; return self; }); var GreenTank = Container.expand(function () { var self = Container.call(this); var tankGraphics = self.attachAsset('greenTank', { anchorX: 0.5, anchorY: 0.5 }); self.health = 40; self.speed = 0.8; self.shootCooldown = 0; self.update = function () { if (self.shootCooldown > 0) { self.shootCooldown--; } // Initialize movement direction if not set if (self.moveDirection === undefined) { self.moveDirection = Math.random() * Math.PI * 2; self.moveTimer = 0; } var dx = playerTank.x - self.x; var dy = playerTank.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); // Triangle vision detection (60 degree cone, 200 pixel range) var angleToPlayer = Math.atan2(dy, dx); var visionAngle = self.moveDirection; var angleDiff = Math.abs(angleToPlayer - visionAngle); if (angleDiff > Math.PI) angleDiff = Math.PI * 2 - angleDiff; var inVision = distance < 200 && angleDiff < Math.PI / 6; // 60 degree cone if (inVision) { // Move toward player when in vision var moveX = dx > 0 ? self.speed : -self.speed; var moveY = dy > 0 ? self.speed : -self.speed; var newX = self.x + moveX; var newY = self.y + moveY; if (!checkWallCollision(newX, self.y)) { self.x = newX; } if (!checkWallCollision(self.x, newY)) { self.y = newY; } } else { // Random movement when player not in vision self.moveTimer++; if (self.moveTimer > 100) { // Change direction every 100 frames self.moveDirection = Math.random() * Math.PI * 2; self.moveTimer = 0; } var moveX = Math.cos(self.moveDirection) * self.speed; var moveY = Math.sin(self.moveDirection) * self.speed; var newX = self.x + moveX; var newY = self.y + moveY; if (!checkWallCollision(newX, self.y)) { self.x = newX; } else { self.moveDirection = Math.random() * Math.PI * 2; // Change direction on wall hit } if (!checkWallCollision(self.x, newY)) { self.y = newY; } else { self.moveDirection = Math.random() * Math.PI * 2; // Change direction on wall hit } } if (distance < 200 && self.shootCooldown <= 0) { var length = Math.sqrt(dx * dx + dy * dy); var dirX = dx / length; var dirY = dy / length; var acidBomb = new AcidBomb(); acidBomb.x = self.x; acidBomb.y = self.y; acidBomb.directionX = dirX; acidBomb.directionY = dirY; acidBombs.push(acidBomb); game.addChild(acidBomb); self.shootCooldown = 150; LK.getSound('shoot').play(); } }; return self; }); var PlayerBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('playerBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.directionX = 0; self.directionY = 0; self.damage = 10; self.update = function () { self.x += self.directionX * self.speed; self.y += self.directionY * self.speed; }; return self; }); var PlayerTank = Container.expand(function () { var self = Container.call(this); var tankGraphics = self.attachAsset('playerTank', { anchorX: 0.5, anchorY: 0.5 }); self.maxHealth = 100; self.health = 100; self.speed = 3; self.shootCooldown = 0; self.poisonTimer = 0; self.poisonDamage = 0; self.update = function () { if (self.shootCooldown > 0) { self.shootCooldown--; } if (self.poisonTimer > 0) { self.poisonTimer--; if (LK.ticks % 30 === 0) { self.health -= self.poisonDamage; if (self.health <= 0) { LK.showGameOver(); } } } }; return self; }); var Portal = Container.expand(function () { var self = Container.call(this); var portalGraphics = self.attachAsset('portal', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.rotation += 0.05; }; return self; }); var RedTank = Container.expand(function () { var self = Container.call(this); var tankGraphics = self.attachAsset('redTank', { anchorX: 0.5, anchorY: 0.5 }); self.health = 80; self.speed = 1; self.shootCooldown = 0; self.update = function () { if (self.shootCooldown > 0) { self.shootCooldown--; } // Initialize movement direction if not set if (self.moveDirection === undefined) { self.moveDirection = Math.random() * Math.PI * 2; self.moveTimer = 0; } var dx = playerTank.x - self.x; var dy = playerTank.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); // Triangle vision detection (60 degree cone, 250 pixel range) var angleToPlayer = Math.atan2(dy, dx); var visionAngle = self.moveDirection; var angleDiff = Math.abs(angleToPlayer - visionAngle); if (angleDiff > Math.PI) angleDiff = Math.PI * 2 - angleDiff; var inVision = distance < 250 && angleDiff < Math.PI / 6; // 60 degree cone if (inVision) { // Move toward player when in vision var moveX = dx > 0 ? self.speed : -self.speed; var moveY = dy > 0 ? self.speed : -self.speed; var newX = self.x + moveX; var newY = self.y + moveY; if (!checkWallCollision(newX, self.y)) { self.x = newX; } if (!checkWallCollision(self.x, newY)) { self.y = newY; } } else { // Random movement when player not in vision self.moveTimer++; if (self.moveTimer > 80) { // Change direction every 80 frames self.moveDirection = Math.random() * Math.PI * 2; self.moveTimer = 0; } var moveX = Math.cos(self.moveDirection) * self.speed; var moveY = Math.sin(self.moveDirection) * self.speed; var newX = self.x + moveX; var newY = self.y + moveY; if (!checkWallCollision(newX, self.y)) { self.x = newX; } else { self.moveDirection = Math.random() * Math.PI * 2; // Change direction on wall hit } if (!checkWallCollision(self.x, newY)) { self.y = newY; } else { self.moveDirection = Math.random() * Math.PI * 2; // Change direction on wall hit } } if (distance < 250 && self.shootCooldown <= 0) { var length = Math.sqrt(dx * dx + dy * dy); var dirX = dx / length; var dirY = dy / length; var dynamite = new Dynamite(); dynamite.x = self.x; dynamite.y = self.y; dynamite.directionX = dirX; dynamite.directionY = dirY; dynamites.push(dynamite); game.addChild(dynamite); self.shootCooldown = 120; LK.getSound('shoot').play(); } }; return self; }); var SkinTank = Container.expand(function () { var self = Container.call(this); var tankGraphics = self.attachAsset('skinTank', { anchorX: 0.5, anchorY: 0.5 }); self.health = 50; self.speed = 1.5; self.shootCooldown = 0; self.explosionRadius = 100; self.lastPlayerX = 0; self.lastPlayerY = 0; self.update = function () { if (self.shootCooldown > 0) { self.shootCooldown--; } // Initialize movement direction if not set if (self.moveDirection === undefined) { self.moveDirection = Math.random() * Math.PI * 2; self.moveTimer = 0; } var dx = playerTank.x - self.x; var dy = playerTank.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); // Triangle vision detection (60 degree cone, 200 pixel range) var angleToPlayer = Math.atan2(dy, dx); var visionAngle = self.moveDirection; var angleDiff = Math.abs(angleToPlayer - visionAngle); if (angleDiff > Math.PI) angleDiff = Math.PI * 2 - angleDiff; var inVision = distance < 200 && angleDiff < Math.PI / 6; // 60 degree cone if (inVision) { // Move toward player when in vision var moveX = dx > 0 ? self.speed : -self.speed; var moveY = dy > 0 ? self.speed : -self.speed; var newX = self.x + moveX; var newY = self.y + moveY; if (!checkWallCollision(newX, self.y)) { self.x = newX; } if (!checkWallCollision(self.x, newY)) { self.y = newY; } } else { // Random movement when player not in vision self.moveTimer++; if (self.moveTimer > 60) { // Change direction every 60 frames self.moveDirection = Math.random() * Math.PI * 2; self.moveTimer = 0; } var moveX = Math.cos(self.moveDirection) * self.speed; var moveY = Math.sin(self.moveDirection) * self.speed; var newX = self.x + moveX; var newY = self.y + moveY; if (!checkWallCollision(newX, self.y)) { self.x = newX; } else { self.moveDirection = Math.random() * Math.PI * 2; // Change direction on wall hit } if (!checkWallCollision(self.x, newY)) { self.y = newY; } else { self.moveDirection = Math.random() * Math.PI * 2; // Change direction on wall hit } } if (distance < 300 && self.shootCooldown <= 0) { var length = Math.sqrt(dx * dx + dy * dy); var dirX = dx / length; var dirY = dy / length; var bullet = new EnemyBullet(); bullet.x = self.x; bullet.y = self.y; bullet.directionX = dirX; bullet.directionY = dirY; bullet.damage = 3; enemyBullets.push(bullet); game.addChild(bullet); self.shootCooldown = 90; LK.getSound('shoot').play(); } }; return self; }); var Wall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.attachAsset('wall', { anchorX: 0.5, anchorY: 0.5 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2F4F2F }); /**** * Game Code ****/ var gridWidth = 32; var gridHeight = 42; var cellSize = 64; var walls = []; var skinTanks = []; var redTanks = []; var greenTanks = []; var playerBullets = []; var enemyBullets = []; var dynamites = []; var acidBombs = []; var explosions = []; var playerTank; var portal; var currentLevel = 1; var gameStarted = false; var healthBar = new Text2('Health: 100/100', { size: 40, fill: 0xFFFFFF }); healthBar.anchor.set(0, 1); LK.gui.bottomLeft.addChild(healthBar); var levelText = new Text2('Level: 1', { size: 50, fill: 0xFFFFFF }); levelText.anchor.set(0.5, 0); LK.gui.top.addChild(levelText); function generateMaze() { walls = []; for (var x = 0; x < gridWidth; x++) { for (var y = 0; y < gridHeight; y++) { if (x === 0 || x === gridWidth - 1 || y === 0 || y === gridHeight - 1) { var wall = new Wall(); wall.x = x * cellSize + cellSize / 2; wall.y = y * cellSize + cellSize / 2; walls.push(wall); game.addChild(wall); } else if (Math.random() < 0.3) { var wall = new Wall(); wall.x = x * cellSize + cellSize / 2; wall.y = y * cellSize + cellSize / 2; walls.push(wall); game.addChild(wall); } } } } function spawnEnemies() { var skinCount = Math.floor(Math.random() * 6) + 5; // 5-10 skin tanks var redCount = Math.floor(Math.random() * 6) + 10; // 10-15 red tanks var greenCount = Math.floor(Math.random() * 8) + 7; // 7-14 green tanks for (var i = 0; i < skinCount; i++) { var tank = new SkinTank(); do { tank.x = Math.random() * (2048 - 200) + 100; tank.y = Math.random() * (2732 - 200) + 100; } while (checkWallCollision(tank.x, tank.y) || getDistanceToPlayer(tank.x, tank.y) < 200); skinTanks.push(tank); game.addChild(tank); } for (var i = 0; i < redCount; i++) { var tank = new RedTank(); do { tank.x = Math.random() * (2048 - 200) + 100; tank.y = Math.random() * (2732 - 200) + 100; } while (checkWallCollision(tank.x, tank.y) || getDistanceToPlayer(tank.x, tank.y) < 200); redTanks.push(tank); game.addChild(tank); } for (var i = 0; i < greenCount; i++) { var tank = new GreenTank(); do { tank.x = Math.random() * (2048 - 200) + 100; tank.y = Math.random() * (2732 - 200) + 100; } while (checkWallCollision(tank.x, tank.y) || getDistanceToPlayer(tank.x, tank.y) < 200); greenTanks.push(tank); game.addChild(tank); } } function checkWallCollision(x, y) { for (var i = 0; i < walls.length; i++) { var wall = walls[i]; var dx = Math.abs(x - wall.x); var dy = Math.abs(y - wall.y); if (dx < 32 && dy < 32) { return true; } } return false; } function getDistanceToPlayer(x, y) { if (!playerTank) { return 1000; } var dx = x - playerTank.x; var dy = y - playerTank.y; return Math.sqrt(dx * dx + dy * dy); } function createExplosion(x, y, radius, damage) { var explosion = LK.getAsset('explosion', { anchorX: 0.5, anchorY: 0.5, x: x, y: y, scaleX: radius / 60, scaleY: radius / 60, alpha: 0.8 }); game.addChild(explosion); explosions.push(explosion); tween(explosion, { alpha: 0, scaleX: explosion.scaleX * 1.5, scaleY: explosion.scaleY * 1.5 }, { duration: 500, onFinish: function onFinish() { explosion.destroy(); var index = explosions.indexOf(explosion); if (index > -1) { explosions.splice(index, 1); } } }); var dx = playerTank.x - x; var dy = playerTank.y - y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < radius) { playerTank.health -= damage; LK.getSound('hit').play(); if (playerTank.health <= 0) { LK.showGameOver(); } } LK.getSound('explosion').play(); } function startLevel() { for (var i = walls.length - 1; i >= 0; i--) { walls[i].destroy(); } walls = []; for (var i = skinTanks.length - 1; i >= 0; i--) { skinTanks[i].destroy(); } skinTanks = []; for (var i = redTanks.length - 1; i >= 0; i--) { redTanks[i].destroy(); } redTanks = []; for (var i = greenTanks.length - 1; i >= 0; i--) { greenTanks[i].destroy(); } greenTanks = []; generateMaze(); spawnEnemies(); playerTank = new PlayerTank(); playerTank.x = 1024; playerTank.y = 1366; playerTank.health = 100; game.addChild(playerTank); portal = new Portal(); do { portal.x = Math.random() * (2048 - 200) + 100; portal.y = Math.random() * (2732 - 200) + 100; } while (checkWallCollision(portal.x, portal.y) || getDistanceToPlayer(portal.x, portal.y) < 300); game.addChild(portal); levelText.setText('Level: ' + currentLevel); gameStarted = true; } var dragStartX = 0; var dragStartY = 0; var isDragging = false; // Keyboard functionality removed - game uses touch controls only game.down = function (x, y, obj) { dragStartX = x; dragStartY = y; isDragging = true; }; game.move = function (x, y, obj) { if (!gameStarted || !playerTank || !isDragging) { return; } var dx = x - dragStartX; var dy = y - dragStartY; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 20) { var moveX = dx > 0 ? playerTank.speed : -playerTank.speed; var moveY = dy > 0 ? playerTank.speed : -playerTank.speed; var newX = playerTank.x + moveX; var newY = playerTank.y + moveY; if (!checkWallCollision(newX, playerTank.y)) { playerTank.x = newX; } if (!checkWallCollision(playerTank.x, newY)) { playerTank.y = newY; } dragStartX = x; dragStartY = y; } }; game.up = function (x, y, obj) { if (!gameStarted || !playerTank) { return; } isDragging = false; if (playerTank.shootCooldown <= 0) { var dx = x - playerTank.x; var dy = y - playerTank.y; var length = Math.sqrt(dx * dx + dy * dy); if (length > 0) { var dirX = dx / length; var dirY = dy / length; var bullet = new PlayerBullet(); bullet.x = playerTank.x; bullet.y = playerTank.y; bullet.directionX = dirX; bullet.directionY = dirY; playerBullets.push(bullet); game.addChild(bullet); playerTank.shootCooldown = 15; LK.getSound('shoot').play(); } } }; game.update = function () { if (!gameStarted) { startLevel(); return; } // Movement is handled via touch/drag in game.move method for (var i = playerBullets.length - 1; i >= 0; i--) { var bullet = playerBullets[i]; if (bullet.x < 0 || bullet.x > 2048 || bullet.y < 0 || bullet.y > 2732) { bullet.destroy(); playerBullets.splice(i, 1); continue; } if (checkWallCollision(bullet.x, bullet.y)) { bullet.destroy(); playerBullets.splice(i, 1); continue; } for (var j = skinTanks.length - 1; j >= 0; j--) { if (bullet.intersects(skinTanks[j])) { skinTanks[j].health -= 3; bullet.destroy(); playerBullets.splice(i, 1); if (skinTanks[j].health <= 0) { createExplosion(skinTanks[j].x, skinTanks[j].y, 100, 15); skinTanks[j].destroy(); skinTanks.splice(j, 1); LK.setScore(LK.getScore() + 10); } break; } } for (var j = redTanks.length - 1; j >= 0; j--) { if (bullet.intersects(redTanks[j])) { redTanks[j].health -= 10; bullet.destroy(); playerBullets.splice(i, 1); if (redTanks[j].health <= 0) { redTanks[j].destroy(); redTanks.splice(j, 1); LK.setScore(LK.getScore() + 20); } break; } } for (var j = greenTanks.length - 1; j >= 0; j--) { if (bullet.intersects(greenTanks[j])) { greenTanks[j].health -= 25; bullet.destroy(); playerBullets.splice(i, 1); if (greenTanks[j].health <= 0) { greenTanks[j].destroy(); greenTanks.splice(j, 1); LK.setScore(LK.getScore() + 30); } break; } } } for (var i = enemyBullets.length - 1; i >= 0; i--) { var bullet = enemyBullets[i]; if (bullet.x < 0 || bullet.x > 2048 || bullet.y < 0 || bullet.y > 2732) { bullet.destroy(); enemyBullets.splice(i, 1); continue; } if (checkWallCollision(bullet.x, bullet.y)) { bullet.destroy(); enemyBullets.splice(i, 1); continue; } if (bullet.intersects(playerTank)) { playerTank.health -= bullet.damage; bullet.destroy(); enemyBullets.splice(i, 1); LK.getSound('hit').play(); if (playerTank.health <= 0) { LK.showGameOver(); } continue; } } for (var i = dynamites.length - 1; i >= 0; i--) { var dynamite = dynamites[i]; if (dynamite.x < 0 || dynamite.x > 2048 || dynamite.y < 0 || dynamite.y > 2732) { createExplosion(dynamite.x, dynamite.y, dynamite.explosionRadius, dynamite.damage); dynamite.destroy(); dynamites.splice(i, 1); continue; } if (checkWallCollision(dynamite.x, dynamite.y)) { createExplosion(dynamite.x, dynamite.y, dynamite.explosionRadius, dynamite.damage); dynamite.destroy(); dynamites.splice(i, 1); continue; } if (dynamite.intersects(playerTank)) { createExplosion(dynamite.x, dynamite.y, dynamite.explosionRadius, dynamite.damage); dynamite.destroy(); dynamites.splice(i, 1); continue; } } for (var i = acidBombs.length - 1; i >= 0; i--) { var acidBomb = acidBombs[i]; if (acidBomb.x < 0 || acidBomb.x > 2048 || acidBomb.y < 0 || acidBomb.y > 2732) { acidBomb.destroy(); acidBombs.splice(i, 1); continue; } if (checkWallCollision(acidBomb.x, acidBomb.y)) { acidBomb.destroy(); acidBombs.splice(i, 1); continue; } if (acidBomb.intersects(playerTank)) { playerTank.health -= acidBomb.damage; playerTank.poisonTimer = acidBomb.poisonDuration; playerTank.poisonDamage = acidBomb.poisonDamage; acidBomb.destroy(); acidBombs.splice(i, 1); LK.getSound('hit').play(); if (playerTank.health <= 0) { LK.showGameOver(); } continue; } } for (var i = skinTanks.length - 1; i >= 0; i--) { if (skinTanks[i].intersects(playerTank)) { createExplosion(skinTanks[i].x, skinTanks[i].y, skinTanks[i].explosionRadius, 20); skinTanks[i].destroy(); skinTanks.splice(i, 1); } } for (var i = redTanks.length - 1; i >= 0; i--) { if (redTanks[i].intersects(playerTank)) { playerTank.health -= 15; LK.getSound('hit').play(); if (playerTank.health <= 0) { LK.showGameOver(); } } } // Check proximity to portal for win condition var portalDistance = Math.sqrt(Math.pow(playerTank.x - portal.x, 2) + Math.pow(playerTank.y - portal.y, 2)); if (portalDistance < 80) { // Stop everything and show win screen gameStarted = false; // Create win text var winText = new Text2('You Won', { size: 120, fill: 0xFFFFFF }); winText.anchor.set(0.5, 0.5); winText.x = 1024; winText.y = 1200; game.addChild(winText); // Create play again text var playAgainText = new Text2('Play Again', { size: 80, fill: 0xFFFFFF }); playAgainText.anchor.set(0.5, 0.5); playAgainText.x = 1024; playAgainText.y = 1400; game.addChild(playAgainText); } healthBar.setText('Health: ' + Math.max(0, playerTank.health) + '/100'); };
===================================================================
--- original.js
+++ change.js
@@ -740,33 +740,30 @@
LK.showGameOver();
}
}
}
- // Check proximity to portal for level progression
+ // Check proximity to portal for win condition
var portalDistance = Math.sqrt(Math.pow(playerTank.x - portal.x, 2) + Math.pow(playerTank.y - portal.y, 2));
- if (portalDistance < 80 && skinTanks.length === 0 && redTanks.length === 0 && greenTanks.length === 0) {
- currentLevel++;
+ if (portalDistance < 80) {
+ // Stop everything and show win screen
gameStarted = false;
- portal.destroy();
- playerTank.destroy();
- // Clear all remaining projectiles
- for (var i = playerBullets.length - 1; i >= 0; i--) {
- playerBullets[i].destroy();
- playerBullets.splice(i, 1);
- }
- for (var i = enemyBullets.length - 1; i >= 0; i--) {
- enemyBullets[i].destroy();
- enemyBullets.splice(i, 1);
- }
- for (var i = dynamites.length - 1; i >= 0; i--) {
- dynamites[i].destroy();
- dynamites.splice(i, 1);
- }
- for (var i = acidBombs.length - 1; i >= 0; i--) {
- acidBombs[i].destroy();
- acidBombs.splice(i, 1);
- }
- // Start next level
- startLevel();
+ // Create win text
+ var winText = new Text2('You Won', {
+ size: 120,
+ fill: 0xFFFFFF
+ });
+ winText.anchor.set(0.5, 0.5);
+ winText.x = 1024;
+ winText.y = 1200;
+ game.addChild(winText);
+ // Create play again text
+ var playAgainText = new Text2('Play Again', {
+ size: 80,
+ fill: 0xFFFFFF
+ });
+ playAgainText.anchor.set(0.5, 0.5);
+ playAgainText.x = 1024;
+ playAgainText.y = 1400;
+ game.addChild(playAgainText);
}
healthBar.setText('Health: ' + Math.max(0, playerTank.health) + '/100');
};
\ No newline at end of file
pixel art dynamite. In-Game asset. 2d. High contrast. No shadows
skin color tank pixel art top down. In-Game asset. 2d. High contrast. No shadows
green tank pixel art top down. In-Game asset. 2d. High contrast. No shadows
red tank pixel art top down. In-Game asset. 2d. High contrast. No shadows
blue tank pixel art top down. In-Game asset. 2d. High contrast. No shadows
pixel art bullet. In-Game asset. 2d. High contrast. No shadows
a green bomb (pixel art) writes "Acid" on it. In-Game asset. 2d. High contrast. No shadows
medkit pixel art. In-Game asset. 2d. High contrast. No shadows
dark green square 16*16 pixels pixel art. In-Game asset. 2d. High contrast. No shadows
orange circle pixel art. In-Game asset. 2d. High contrast. No shadows
A portal, outline is purple, and inside is magenta. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat pixel art
dark gray square 16*16 pixels pixel art.. In-Game asset. 2d. High contrast. No shadows
pixel art blackhole. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat