/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/ 
function startStage(stageNumber) {
	// Reset player position
	player.x = 2048 / 2;
	player.y = 2732 - player.height;
	// Hide the open portal
	portalOpen.visible = false;
	// Add more enemies for the current stage
	enemies = [];
	for (var i = 0; i < 5 + stageNumber; i++) {
		var newEnemy = LK.getAsset('Enemy', {
			anchorX: 0.5,
			anchorY: 0.5
		});
		newEnemy.x = Math.random() * 2048;
		newEnemy.y = Math.random() * 500;
		game.addChild(newEnemy);
		enemies.push(newEnemy);
	}
}
var background = LK.getAsset('Background', {
	anchorX: 0.5,
	anchorY: 0.5
});
background.x = 2048 / 2;
background.y = 2732 / 2;
game.addChild(background);
LK.playMusic('Background_music');
var player = LK.getAsset('Player', {
	anchorX: 0.5,
	anchorY: 0.5
});
player.x = 2048 / 2;
player.y = 2732 - player.height;
game.addChild(player);
var enemy = LK.getAsset('Enemy', {
	anchorX: 0.5,
	anchorY: 0.5
});
enemy.x = 2048 / 2;
enemy.y = enemy.height;
game.addChild(enemy);
var portal = LK.getAsset('Portal', {
	anchorX: 0.5,
	anchorY: 0.5
});
portal.x = 2048 / 2;
portal.y = 2732 / 2;
game.addChild(portal);
var aim = LK.getAsset('Aim', {
	anchorX: 0.5,
	anchorY: 0.5
});
aim.x = player.x;
aim.y = player.y - player.height / 2;
game.addChild(aim);
var portalOpen = LK.getAsset('Portal_open', {
	anchorX: 0.5,
	anchorY: 0.5
});
portalOpen.x = 2048 / 2;
portalOpen.y = 2732 / 2 + 100;
portalOpen.visible = false; // Initially hide the open portal
game.addChild(portalOpen);
var currentStage = 1;
var enemies = [];
var bullets = [];
function shootBullet() {
	var bullet = LK.getAsset('Bullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	bullet.x = player.x;
	bullet.y = player.y - player.height / 2;
	bullets.push(bullet);
	game.addChild(bullet);
	LK.getSound('Shoot').play();
}
game.down = function (x, y, obj) {
	shootBullet();
	player.x = x;
	player.y = y;
};
game.update = function () {
	// Enemy follows the player
	enemies.forEach(function (enemy) {
		var dx = player.x - enemy.x;
		var dy = player.y - enemy.y;
		var distance = Math.sqrt(dx * dx + dy * dy);
		if (distance > 5) {
			// Only move if the enemy is not too close
			enemy.x += dx / distance * 2; // Move enemy towards player
			enemy.y += dy / distance * 2;
		}
	});
	for (var i = bullets.length - 1; i >= 0; i--) {
		bullets[i].y -= 10;
		if (bullets[i].y < 0) {
			bullets[i].destroy();
			bullets.splice(i, 1);
		} else {
			for (var j = enemies.length - 1; j >= 0; j--) {
				if (bullets[i].intersects(enemies[j])) {
					bullets[i].destroy();
					bullets.splice(i, 1);
					enemies[j].destroy(); // Destroy the correct enemy
					enemies.splice(j, 1); // Remove the correct enemy from the array
					break; // Exit the loop once the bullet hits an enemy
				}
			}
			if (enemies.length === 0) {
				portal.visible = false; // Hide the closed portal
				portalOpen.visible = true; // Show the open portal
			}
			LK.setScore(LK.getScore() + 100); // Increase score by 100
			// Check if player is hit by any enemy
			enemies.forEach(function (enemy) {
				if (enemy.intersects(player)) {
					LK.effects.flashScreen(0xff0000, 1000); // Flash screen red
					LK.showGameOver(); // Show game over screen
					return; // Stop further processing in this update
				}
			});
			// Automatically move player to open portal if all enemies are defeated
			if (!portal.visible && portalOpen.visible) {
				var portalDx = portalOpen.x - player.x;
				var portalDy = portalOpen.y - player.y;
				var portalDistance = Math.sqrt(portalDx * portalDx + portalDy * portalDy);
				if (portalDistance > 5) {
					player.x += portalDx / portalDistance * 5; // Move player towards open portal faster
					player.y += portalDy / portalDistance * 5;
				}
			}
			if (player.intersects(portalOpen)) {
				// Player reached the portal, proceed to the next stage
				currentStage++;
				startStage(currentStage);
			}
		}
	}
}; /**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/ 
function startStage(stageNumber) {
	// Reset player position
	player.x = 2048 / 2;
	player.y = 2732 - player.height;
	// Hide the open portal
	portalOpen.visible = false;
	// Add more enemies for the current stage
	enemies = [];
	for (var i = 0; i < 5 + stageNumber; i++) {
		var newEnemy = LK.getAsset('Enemy', {
			anchorX: 0.5,
			anchorY: 0.5
		});
		newEnemy.x = Math.random() * 2048;
		newEnemy.y = Math.random() * 500;
		game.addChild(newEnemy);
		enemies.push(newEnemy);
	}
}
var background = LK.getAsset('Background', {
	anchorX: 0.5,
	anchorY: 0.5
});
background.x = 2048 / 2;
background.y = 2732 / 2;
game.addChild(background);
LK.playMusic('Background_music');
var player = LK.getAsset('Player', {
	anchorX: 0.5,
	anchorY: 0.5
});
player.x = 2048 / 2;
player.y = 2732 - player.height;
game.addChild(player);
var enemy = LK.getAsset('Enemy', {
	anchorX: 0.5,
	anchorY: 0.5
});
enemy.x = 2048 / 2;
enemy.y = enemy.height;
game.addChild(enemy);
var portal = LK.getAsset('Portal', {
	anchorX: 0.5,
	anchorY: 0.5
});
portal.x = 2048 / 2;
portal.y = 2732 / 2;
game.addChild(portal);
var aim = LK.getAsset('Aim', {
	anchorX: 0.5,
	anchorY: 0.5
});
aim.x = player.x;
aim.y = player.y - player.height / 2;
game.addChild(aim);
var portalOpen = LK.getAsset('Portal_open', {
	anchorX: 0.5,
	anchorY: 0.5
});
portalOpen.x = 2048 / 2;
portalOpen.y = 2732 / 2 + 100;
portalOpen.visible = false; // Initially hide the open portal
game.addChild(portalOpen);
var currentStage = 1;
var enemies = [];
var bullets = [];
function shootBullet() {
	var bullet = LK.getAsset('Bullet', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	bullet.x = player.x;
	bullet.y = player.y - player.height / 2;
	bullets.push(bullet);
	game.addChild(bullet);
	LK.getSound('Shoot').play();
}
game.down = function (x, y, obj) {
	shootBullet();
	player.x = x;
	player.y = y;
};
game.update = function () {
	// Enemy follows the player
	enemies.forEach(function (enemy) {
		var dx = player.x - enemy.x;
		var dy = player.y - enemy.y;
		var distance = Math.sqrt(dx * dx + dy * dy);
		if (distance > 5) {
			// Only move if the enemy is not too close
			enemy.x += dx / distance * 2; // Move enemy towards player
			enemy.y += dy / distance * 2;
		}
	});
	for (var i = bullets.length - 1; i >= 0; i--) {
		bullets[i].y -= 10;
		if (bullets[i].y < 0) {
			bullets[i].destroy();
			bullets.splice(i, 1);
		} else {
			for (var j = enemies.length - 1; j >= 0; j--) {
				if (bullets[i].intersects(enemies[j])) {
					bullets[i].destroy();
					bullets.splice(i, 1);
					enemies[j].destroy(); // Destroy the correct enemy
					enemies.splice(j, 1); // Remove the correct enemy from the array
					break; // Exit the loop once the bullet hits an enemy
				}
			}
			if (enemies.length === 0) {
				portal.visible = false; // Hide the closed portal
				portalOpen.visible = true; // Show the open portal
			}
			LK.setScore(LK.getScore() + 100); // Increase score by 100
			// Check if player is hit by any enemy
			enemies.forEach(function (enemy) {
				if (enemy.intersects(player)) {
					LK.effects.flashScreen(0xff0000, 1000); // Flash screen red
					LK.showGameOver(); // Show game over screen
					return; // Stop further processing in this update
				}
			});
			// Automatically move player to open portal if all enemies are defeated
			if (!portal.visible && portalOpen.visible) {
				var portalDx = portalOpen.x - player.x;
				var portalDy = portalOpen.y - player.y;
				var portalDistance = Math.sqrt(portalDx * portalDx + portalDy * portalDy);
				if (portalDistance > 5) {
					player.x += portalDx / portalDistance * 5; // Move player towards open portal faster
					player.y += portalDy / portalDistance * 5;
				}
			}
			if (player.intersects(portalOpen)) {
				// Player reached the portal, proceed to the next stage
				currentStage++;
				startStage(currentStage);
			}
		}
	}
};
:quality(85)/https://cdn.frvr.ai/67283ebdf77c0bb2345fdb96.png%3F3) 
 character with a gun looking from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/67283f03f77c0bb2345fdba6.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/67283fa4f77c0bb2345fdbb4.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/67283fc2f77c0bb2345fdbb9.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/67283ff3f77c0bb2345fdbc1.png%3F3) 
 Bullet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/67284047f77c0bb2345fdbd2.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/6728412ef77c0bb2345fdbde.png%3F3) 
 background of an abandoned street. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.