User prompt
Develop a 2D top-down zombie survival maze game for PC. 🎮 Core Concept: The player controls a mysterious survivor with a bird’s head, trapped in a dark, maze-like facility filled with zombies. The objective is to eliminate as many zombies as possible and escape the labyrinth alive. Players earn points only by killing zombies — survival time does not increase score. 📌 Key Features: Top-down camera for full map awareness Maze-based level: tight corridors, dead ends, hidden paths Unlimited bullets, but player must manage space and avoid being cornered Zombies spawn continuously and become stronger over time A hidden escape exit allows players to end the game by escaping Skor sadece zombileri öldürdükçe artar (Score increases only by killing zombies) 🕹️ Controls (PC only): Move: W / A / S / D Aim: Mouse Cursor Shoot: Left Mouse Button 🧾 UI and Screens: Main Menu: Start Game, How to Play, Exit How to Play screen: Clear explanation of controls and objectives Game Over screen: Display total zombies killed (score) Minimalist HUD showing Kill Count, Health, and optional Map 🎨 Art Style: Stylized pixel-art or simple cartoon visuals Atmospheric lighting in maze corridors Placeholder sprites acceptable in prototype 🔧 Development Notes: Modular structure for adding enemy types, power-ups, or new maze levels Designed only for PC, with keyboard + mouse control Game ends either on death or successful escape
User prompt
Design a 2D top-down zombie survival maze game for PC only. 🎮 Core Concept: The player controls a mysterious survivor with a bird’s head, trapped in an abandoned labyrinth filled with undead threats. The objective is to navigate the maze, eliminate zombies, and ultimately escape through a hidden exit. There is no ammo limit — survival depends on reflexes, positioning, and map knowledge. 📌 Features: Top-down camera with clear visibility of the maze environment Labyrinth-style map: narrow corridors, blocked paths, multiple routes Waves of zombies increase in difficulty over time The player must find the correct path to escape while surviving constant pressure Escape zone is hidden and may change position in each round (optional) No ammo limit, but limited health — getting surrounded is fatal 🕹️ Controls (PC only): Move: W / A / S / D Shoot: Left Mouse Button Aim: Mouse Cursor 🧾 UI Elements: Main Menu with Start Game, How to Play, Exit "How to Play" screen explaining controls and objective Game Over screen showing time survived and zombies eliminated Clean, minimalist interface, designed for PC experience 🎨 Style: Simple pixel-art or cartoon aesthetic Dark and atmospheric color palette Placeholder assets allowed for initial build 💡 Expansion Potential: Dynamic lighting in the maze Power-ups and keys to unlock shortcut doors Multiple character types (future update) Global leaderboard for fastest escapes / most kills This game should be optimized for PC with keyboard + mouse controls only. Mobile support is not required.
User prompt
Create a 2D top-down zombie survival game with the following features: The main character has a bird’s head and can move freely. The map is designed as a maze (labyrinth) filled with paths, dead ends, and multiple routes. The player must survive as long as possible and optionally escape the maze to win. The character can shoot without ammo limits (infinite bullets). Zombies spawn randomly and chase the player with increasing difficulty. The camera uses a top-down view to show the entire environment from above. UI and Features: Include an English Main Menu with: Start Game, How to Play, Exit Add a "How to Play" screen explaining the controls and the escape objective Game Over screen showing survival time and option to restart Use placeholder sprites for character, zombies, and maze environment Art style: simple cartoon or pixel-art The game should work on both mobile and PC, with on-screen buttons for mobile Make the structure modular and beginner-friendly, allowing future expansion (more enemies, new weapons, timed escape, etc.).
User prompt
Create a 2D top-down zombie survival game with the following features: The main character has a bird’s head and can move freely. The map is designed as a maze (labyrinth) filled with paths, dead ends, and multiple routes. The player must survive as long as possible and optionally escape the maze to win. The character can shoot without ammo limits (infinite bullets). Zombies spawn randomly and chase the player with increasing difficulty. The camera uses a top-down view to show the entire environment from above. UI and Features: Include an English Main Menu with: Start Game, How to Play, Exit Add a "How to Play" screen explaining the controls and the escape objective Game Over screen showing survival time and option to restart Use placeholder sprites for character, zombies, and maze environment Art style: simple cartoon or pixel-art The game should work on both mobile and PC, with on-screen buttons for mobile Make the structure modular and beginner-friendly, allowing future expansion (more enemies, new weapons, timed escape, etc.)
User prompt
Create a 2D side-scrolling zombie survival game where the main character has a bird’s head. The character can move freely and shoot without ammo limits. Include a "How to Play" UI screen that clearly explains the controls and gameplay mechanics.
User prompt
Create a 2D side-scrolling zombie survival game where the character can move freely and shoot without ammo limits. Include a "How to Play" UI screen that clearly explains the controls and gameplay mechanics.
Code edit (1 edits merged)
Please save this source code
User prompt
Zombie Survival Rush
Initial prompt
Create a 2D side-scrolling zombie survival game that works on both mobile devices and PC. The player must survive as long as possible against endless waves of zombies. The game should include a scoring system based on survival time and zombie kills. Features: English user interface Main Menu with: Start Game, How to Play, High Scores, Exit “How to Play” screen explaining controls: PC: Move (A/D), Jump (Space), Shoot (Left Click), Change Weapon (1/2/3) Mobile: On-screen buttons for move, jump, shoot, and switch weapon Increasing difficulty with time (zombies become stronger and faster) Game Over screen showing score and a "Try Again" button Health and weapon pickups Responsive UI that works on both PC and mobile screen sizes Use placeholder sprites for player, zombies, and background Simple, cartoon or pixel-art style Beginner-friendly and modular structure for future expansion
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
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.damage = 25;
self.directionX = 0;
self.directionY = 0;
self.update = function () {
self.x += self.speed * self.directionX;
self.y += self.speed * self.directionY;
};
return self;
});
var HealthPack = Container.expand(function () {
var self = Container.call(this);
var healthGraphics = self.attachAsset('healthPack', {
anchorX: 0.5,
anchorY: 0.5
});
self.healAmount = 30;
self.update = function () {
// Simple floating animation
self.y += Math.sin(LK.ticks * 0.1) * 0.5;
// Check pickup
if (self.intersects(player)) {
player.heal(self.healAmount);
LK.getSound('pickup').play();
self.collected = true;
}
};
return self;
});
var HowToPlay = Container.expand(function () {
var self = Container.call(this);
// Create background overlay
var background = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
width: 2048,
height: 2732,
alpha: 0.9
});
self.addChild(background);
// Title
var titleText = new Text2('HOW TO PLAY', {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.x = 1024;
titleText.y = 200;
self.addChild(titleText);
// Controls section
var controlsTitle = new Text2('CONTROLS', {
size: 80,
fill: 0xFFFF00
});
controlsTitle.anchor.set(0.5, 0);
controlsTitle.x = 1024;
controlsTitle.y = 400;
self.addChild(controlsTitle);
// Mobile controls
var mobileText = new Text2('MOBILE:', {
size: 60,
fill: 0x00FF00
});
mobileText.anchor.set(0, 0);
mobileText.x = 200;
mobileText.y = 520;
self.addChild(mobileText);
var mobileControls = new Text2('• Touch direction buttons to move\n• Touch anywhere to shoot toward that direction\n• Move freely in all directions', {
size: 45,
fill: 0xFFFFFF
});
mobileControls.anchor.set(0, 0);
mobileControls.x = 200;
mobileControls.y = 600;
self.addChild(mobileControls);
// Gameplay section
var gameplayTitle = new Text2('GAMEPLAY', {
size: 80,
fill: 0xFFFF00
});
gameplayTitle.anchor.set(0.5, 0);
gameplayTitle.x = 1024;
gameplayTitle.y = 950;
self.addChild(gameplayTitle);
var gameplayText = new Text2('• Navigate through a maze labyrinth\n• Collect health packs (red circles)\n• Collect weapon upgrades (blue boxes)\n• Zombies spawn and chase you\n• Escape through the green exit to win', {
size: 45,
fill: 0xFFFFFF
});
gameplayText.anchor.set(0, 0);
gameplayText.x = 200;
gameplayText.y = 1050;
self.addChild(gameplayText);
// Objectives
var objectiveTitle = new Text2('OBJECTIVES', {
size: 80,
fill: 0xFFFF00
});
objectiveTitle.anchor.set(0.5, 0);
objectiveTitle.x = 1024;
objectiveTitle.y = 1400;
self.addChild(objectiveTitle);
var objectiveText = new Text2('• Find your way through the maze\n• Avoid or kill zombies\n• Reach the green exit to escape\n• Use walls for protection and strategy', {
size: 45,
fill: 0xFFFFFF
});
objectiveText.anchor.set(0, 0);
objectiveText.x = 200;
objectiveText.y = 1500;
self.addChild(objectiveText);
// Close button
var closeButton = LK.getAsset('player', {
width: 200,
height: 100,
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8
});
closeButton.x = 1024;
closeButton.y = 1900;
self.addChild(closeButton);
var closeText = new Text2('TAP TO START', {
size: 60,
fill: 0x000000
});
closeText.anchor.set(0.5, 0.5);
closeText.x = 1024;
closeText.y = 1900;
self.addChild(closeText);
closeButton.down = function () {
self.visible = false;
gameStarted = true;
};
background.down = function () {
self.visible = false;
gameStarted = true;
};
return self;
});
var MazeExit = Container.expand(function () {
var self = Container.call(this);
var exitGraphics = self.attachAsset('exit', {
anchorX: 0,
anchorY: 0
});
self.update = function () {
// Pulsing effect for exit
exitGraphics.alpha = 0.7 + Math.sin(LK.ticks * 0.1) * 0.3;
// Check if player reached exit
if (self.intersects(player)) {
LK.showYouWin();
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
// Add bird head
var birdHead = self.attachAsset('playerHead', {
anchorX: 0.5,
anchorY: 0.5
});
birdHead.x = 0;
birdHead.y = -8; // Position head above body
// Add bird beak
var birdBeak = self.attachAsset('playerBeak', {
anchorX: 0,
anchorY: 0.5
});
birdBeak.x = 15; // Position to right of head
birdBeak.y = -8; // Same height as head
self.health = 100;
self.maxHealth = 100;
self.speed = 4;
self.weapon = 1;
self.maxWeapon = 3;
self.takeDamage = function (damage) {
self.health -= damage;
if (self.health <= 0) {
self.health = 0;
gameOver = true;
}
// Flash red when taking damage
LK.effects.flashObject(self, 0xFF0000, 500);
};
self.heal = function (amount) {
self.health = Math.min(self.maxHealth, self.health + amount);
};
self.upgradeWeapon = function () {
if (self.weapon < self.maxWeapon) {
self.weapon++;
}
};
self.checkWallCollision = function (newX, newY) {
// Check collision with maze walls
for (var i = 0; i < walls.length; i++) {
var wall = walls[i];
if (newX < wall.x + 80 && newX + 40 > wall.x && newY < wall.y + 80 && newY + 40 > wall.y) {
return true;
}
}
return false;
};
self.update = function () {
// No gravity or ground collision in top-down view
};
return self;
});
var Wall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.attachAsset('wall', {
anchorX: 0,
anchorY: 0
});
return self;
});
var WeaponPickup = Container.expand(function () {
var self = Container.call(this);
var weaponGraphics = self.attachAsset('weaponPickup', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Simple floating animation
self.y += Math.sin(LK.ticks * 0.1) * 0.5;
// Check pickup
if (self.intersects(player)) {
player.upgradeWeapon();
LK.getSound('pickup').play();
self.collected = true;
}
};
return self;
});
var Zombie = Container.expand(function () {
var self = Container.call(this);
var zombieGraphics = self.attachAsset('zombie', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 50;
self.speed = 1.5;
self.damage = 20;
self.lastAttackTime = 0;
self.moveTimer = 0;
self.targetX = 0;
self.targetY = 0;
self.takeDamage = function (damage) {
self.health -= damage;
LK.effects.flashObject(self, 0xFFFFFF, 200);
if (self.health <= 0) {
return true; // Zombie is dead
}
return false;
};
self.checkWallCollision = function (newX, newY) {
// Check collision with maze walls
for (var i = 0; i < walls.length; i++) {
var wall = walls[i];
if (newX < wall.x + 80 && newX + 35 > wall.x && newY < wall.y + 80 && newY + 35 > wall.y) {
return true;
}
}
return false;
};
self.update = function () {
// Simple AI: move towards player if path is clear
var deltaX = player.x - self.x;
var deltaY = player.y - self.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
if (distance > 0) {
var moveX = deltaX / distance * self.speed;
var moveY = deltaY / distance * self.speed;
var newX = self.x + moveX;
var newY = self.y + moveY;
// Only move if not hitting walls
if (!self.checkWallCollision(newX, self.y)) {
self.x = newX;
}
if (!self.checkWallCollision(self.x, newY)) {
self.y = newY;
}
}
// Check collision with player
if (self.intersects(player)) {
var currentTime = LK.ticks;
if (currentTime - self.lastAttackTime > 60) {
// Attack every second
player.takeDamage(self.damage);
self.lastAttackTime = currentTime;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2d4a2d
});
/****
* Game Code
****/
// Game variables
var player;
var zombies = [];
var bullets = [];
var healthPacks = [];
var weaponPickups = [];
var walls = [];
var mazeExit;
var gameOver = false;
var gameStarted = false;
var score = 0;
var zombieSpawnTimer = 0;
var pickupSpawnTimer = 0;
var howToPlayScreen;
// Movement controls
var moveUp = false;
var moveDown = false;
var moveLeft = false;
var moveRight = false;
var shooting = false;
var shootTimer = 0;
var shootTargetX = 0;
var shootTargetY = 0;
// Create maze layout (simplified maze pattern)
var mazePattern = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1], [1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1], [1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1], [1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1], [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1], [1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]];
// Build maze walls
for (var row = 0; row < mazePattern.length; row++) {
for (var col = 0; col < mazePattern[row].length; col++) {
var cellX = col * 80;
var cellY = row * 80;
if (mazePattern[row][col] === 1) {
// Wall
var wall = game.addChild(new Wall());
wall.x = cellX;
wall.y = cellY;
walls.push(wall);
} else if (mazePattern[row][col] === 2) {
// Exit
mazeExit = game.addChild(new MazeExit());
mazeExit.x = cellX;
mazeExit.y = cellY;
}
}
}
// Create player
player = game.addChild(new Player());
player.x = 120; // Start position in maze
player.y = 120;
// UI Elements
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
scoreText.x = 150;
scoreText.y = 50;
LK.gui.topLeft.addChild(scoreText);
var healthText = new Text2('Health: 100', {
size: 60,
fill: 0xFF0000
});
healthText.anchor.set(0, 0);
healthText.x = 150;
healthText.y = 120;
LK.gui.topLeft.addChild(healthText);
var objectiveText = new Text2('Find the Exit!', {
size: 50,
fill: 0x00FF00
});
objectiveText.anchor.set(1, 0);
objectiveText.x = 1948;
objectiveText.y = 50;
LK.gui.topRight.addChild(objectiveText);
// Control buttons for mobile
var upButton = LK.getAsset('player', {
width: 80,
height: 80,
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.4
});
upButton.x = 150;
upButton.y = 2500;
LK.gui.addChild(upButton);
var downButton = LK.getAsset('player', {
width: 80,
height: 80,
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.4
});
downButton.x = 150;
downButton.y = 2650;
LK.gui.addChild(downButton);
var leftButton = LK.getAsset('player', {
width: 80,
height: 80,
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.4
});
leftButton.x = 75;
leftButton.y = 2575;
LK.gui.addChild(leftButton);
var rightButton = LK.getAsset('player', {
width: 80,
height: 80,
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.4
});
rightButton.x = 225;
rightButton.y = 2575;
LK.gui.addChild(rightButton);
// Button event handlers
upButton.down = function () {
moveUp = true;
};
upButton.up = function () {
moveUp = false;
};
downButton.down = function () {
moveDown = true;
};
downButton.up = function () {
moveDown = false;
};
leftButton.down = function () {
moveLeft = true;
};
leftButton.up = function () {
moveLeft = false;
};
rightButton.down = function () {
moveRight = true;
};
rightButton.up = function () {
moveRight = false;
};
// Create How to Play screen
howToPlayScreen = game.addChild(new HowToPlay());
howToPlayScreen.visible = true;
// Game event handlers
game.down = function (x, y, obj) {
// Set shoot target position
shootTargetX = x;
shootTargetY = y;
shooting = true;
};
game.up = function (x, y, obj) {
shooting = false;
};
// Spawn functions
function spawnZombie() {
var zombie = new Zombie();
// Find a random open space in the maze
var spawnAttempts = 0;
do {
zombie.x = Math.random() * 1920 + 80;
zombie.y = Math.random() * 1520 + 80;
spawnAttempts++;
} while (zombie.checkWallCollision(zombie.x, zombie.y) && spawnAttempts < 50);
zombies.push(zombie);
game.addChild(zombie);
}
function spawnHealthPack() {
var healthPack = new HealthPack();
// Find a random open space in the maze
var spawnAttempts = 0;
do {
healthPack.x = Math.random() * 1920 + 80;
healthPack.y = Math.random() * 1520 + 80;
spawnAttempts++;
} while (spawnAttempts < 50 && isPositionBlocked(healthPack.x, healthPack.y));
healthPacks.push(healthPack);
game.addChild(healthPack);
}
function spawnWeaponPickup() {
var weaponPickup = new WeaponPickup();
// Find a random open space in the maze
var spawnAttempts = 0;
do {
weaponPickup.x = Math.random() * 1920 + 80;
weaponPickup.y = Math.random() * 1520 + 80;
spawnAttempts++;
} while (spawnAttempts < 50 && isPositionBlocked(weaponPickup.x, weaponPickup.y));
weaponPickups.push(weaponPickup);
game.addChild(weaponPickup);
}
function isPositionBlocked(x, y) {
// Check if position overlaps with walls
for (var i = 0; i < walls.length; i++) {
var wall = walls[i];
if (x < wall.x + 80 && x + 25 > wall.x && y < wall.y + 80 && y + 25 > wall.y) {
return true;
}
}
return false;
}
function shootBullet() {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
bullet.damage = 25 * player.weapon; // More damage with better weapons
// Calculate direction toward shoot target
var deltaX = shootTargetX - player.x;
var deltaY = shootTargetY - player.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
if (distance > 0) {
bullet.directionX = deltaX / distance;
bullet.directionY = deltaY / distance;
} else {
bullet.directionX = 1; // Default right
bullet.directionY = 0;
}
bullets.push(bullet);
game.addChild(bullet);
LK.getSound('shoot').play();
}
// Main game update
game.update = function () {
if (!gameStarted) {
return; // Don't start game until player dismisses how to play screen
}
if (gameOver) {
LK.showGameOver();
return;
}
// Update score based on survival time
score += 1;
LK.setScore(score);
// Handle player movement with wall collision
var newX = player.x;
var newY = player.y;
if (moveLeft) {
newX = player.x - player.speed;
}
if (moveRight) {
newX = player.x + player.speed;
}
if (moveUp) {
newY = player.y - player.speed;
}
if (moveDown) {
newY = player.y + player.speed;
}
// Check wall collisions and move if valid
if (!player.checkWallCollision(newX, player.y)) {
player.x = newX;
}
if (!player.checkWallCollision(player.x, newY)) {
player.y = newY;
}
// Handle shooting
if (shooting && LK.ticks - shootTimer > 30 / player.weapon) {
// Faster shooting with better weapons
shootBullet();
shootTimer = LK.ticks;
}
// Spawn zombies
zombieSpawnTimer++;
var spawnRate = Math.max(180, 120); // Spawn every 3-2 seconds
if (zombieSpawnTimer >= spawnRate) {
spawnZombie();
zombieSpawnTimer = 0;
}
// Spawn pickups occasionally
pickupSpawnTimer++;
if (pickupSpawnTimer >= 900) {
// Every 15 seconds
if (Math.random() < 0.7) {
spawnHealthPack();
} else {
spawnWeaponPickup();
}
pickupSpawnTimer = 0;
}
// Update bullets and check collisions
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Check if bullet is off screen or hits walls
if (bullet.x < 0 || bullet.x > 2000 || bullet.y < 0 || bullet.y > 1600) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check wall collision
var bulletHitWall = false;
for (var w = 0; w < walls.length; w++) {
var wall = walls[w];
if (bullet.x < wall.x + 80 && bullet.x + 12 > wall.x && bullet.y < wall.y + 80 && bullet.y + 12 > wall.y) {
bulletHitWall = true;
break;
}
}
if (bulletHitWall) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check bullet-zombie collisions
var hit = false;
for (var j = zombies.length - 1; j >= 0; j--) {
var zombie = zombies[j];
if (bullet.intersects(zombie)) {
if (zombie.takeDamage(bullet.damage)) {
// Zombie died
score += 50;
LK.getSound('zombieHit').play();
zombie.destroy();
zombies.splice(j, 1);
}
bullet.destroy();
bullets.splice(i, 1);
hit = true;
break;
}
}
}
// Update health packs
for (var i = healthPacks.length - 1; i >= 0; i--) {
var healthPack = healthPacks[i];
if (healthPack.collected) {
healthPack.destroy();
healthPacks.splice(i, 1);
}
}
// Update weapon pickups
for (var i = weaponPickups.length - 1; i >= 0; i--) {
var weaponPickup = weaponPickups[i];
if (weaponPickup.collected) {
weaponPickup.destroy();
weaponPickups.splice(i, 1);
}
}
// Update UI
scoreText.setText('Score: ' + score);
healthText.setText('Health: ' + player.health);
// Exit reached condition handled by MazeExit class
}; ===================================================================
--- original.js
+++ change.js
@@ -11,19 +11,15 @@
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 12;
+ self.speed = 10;
self.damage = 25;
self.directionX = 0;
self.directionY = 0;
self.update = function () {
self.x += self.speed * self.directionX;
self.y += self.speed * self.directionY;
- // Check wall collisions
- if (checkWallCollision(self.x, self.y)) {
- self.destroyed = true;
- }
};
return self;
});
var HealthPack = Container.expand(function () {
@@ -84,9 +80,9 @@
mobileText.anchor.set(0, 0);
mobileText.x = 200;
mobileText.y = 520;
self.addChild(mobileText);
- var mobileControls = new Text2('• Touch direction buttons to move\n• Touch shoot button to fire\n• Touch anywhere to shoot in direction\n• Navigate the maze carefully', {
+ var mobileControls = new Text2('• Touch direction buttons to move\n• Touch anywhere to shoot toward that direction\n• Move freely in all directions', {
size: 45,
fill: 0xFFFFFF
});
mobileControls.anchor.set(0, 0);
@@ -101,9 +97,9 @@
gameplayTitle.anchor.set(0.5, 0);
gameplayTitle.x = 1024;
gameplayTitle.y = 950;
self.addChild(gameplayTitle);
- var gameplayText = new Text2('• Navigate through the maze\n• Survive zombie attacks\n• Collect health packs (red circles)\n• Collect weapon upgrades (blue boxes)\n• Find the green exit to escape!', {
+ var gameplayText = new Text2('• Navigate through a maze labyrinth\n• Collect health packs (red circles)\n• Collect weapon upgrades (blue boxes)\n• Zombies spawn and chase you\n• Escape through the green exit to win', {
size: 45,
fill: 0xFFFFFF
});
gameplayText.anchor.set(0, 0);
@@ -118,9 +114,9 @@
objectiveTitle.anchor.set(0.5, 0);
objectiveTitle.x = 1024;
objectiveTitle.y = 1400;
self.addChild(objectiveTitle);
- var objectiveText = new Text2('• Escape the maze to win!\n• Survive zombie encounters\n• Use walls for protection\n• Collect items to stay alive longer', {
+ var objectiveText = new Text2('• Find your way through the maze\n• Avoid or kill zombies\n• Reach the green exit to escape\n• Use walls for protection and strategy', {
size: 45,
fill: 0xFFFFFF
});
objectiveText.anchor.set(0, 0);
@@ -155,96 +151,22 @@
gameStarted = true;
};
return self;
});
-var Maze = Container.expand(function () {
+var MazeExit = Container.expand(function () {
var self = Container.call(this);
- self.tileSize = 64;
- self.cols = 32; // 2048 / 64
- self.rows = 42; // 2732 / 64
- self.maze = [];
- self.exitX = 0;
- self.exitY = 0;
- // Simple maze generation
- self.generateMaze = function () {
- // Initialize maze with walls
- for (var y = 0; y < self.rows; y++) {
- self.maze[y] = [];
- for (var x = 0; x < self.cols; x++) {
- self.maze[y][x] = 1; // 1 = wall, 0 = path
- }
+ var exitGraphics = self.attachAsset('exit', {
+ anchorX: 0,
+ anchorY: 0
+ });
+ self.update = function () {
+ // Pulsing effect for exit
+ exitGraphics.alpha = 0.7 + Math.sin(LK.ticks * 0.1) * 0.3;
+ // Check if player reached exit
+ if (self.intersects(player)) {
+ LK.showYouWin();
}
- // Create paths using simple algorithm
- for (var y = 1; y < self.rows - 1; y += 2) {
- for (var x = 1; x < self.cols - 1; x += 2) {
- self.maze[y][x] = 0; // Create room
- // Create random connections
- if (x < self.cols - 2 && Math.random() < 0.7) {
- self.maze[y][x + 1] = 0; // Right corridor
- }
- if (y < self.rows - 2 && Math.random() < 0.7) {
- self.maze[y + 1][x] = 0; // Down corridor
- }
- }
- }
- // Ensure player starting area is clear
- self.maze[1][1] = 0;
- self.maze[1][2] = 0;
- self.maze[2][1] = 0;
- // Place exit in opposite corner
- self.exitX = self.cols - 2;
- self.exitY = self.rows - 2;
- self.maze[self.exitY][self.exitX] = 2; // 2 = exit
};
- self.renderMaze = function () {
- for (var y = 0; y < self.rows; y++) {
- for (var x = 0; x < self.cols; x++) {
- if (self.maze[y][x] === 1) {
- // Wall
- var wall = self.attachAsset('mazeWall', {
- anchorX: 0,
- anchorY: 0
- });
- wall.x = x * self.tileSize;
- wall.y = y * self.tileSize;
- } else if (self.maze[y][x] === 0) {
- // Floor
- var floor = self.attachAsset('mazeFloor', {
- anchorX: 0,
- anchorY: 0
- });
- floor.x = x * self.tileSize;
- floor.y = y * self.tileSize;
- } else if (self.maze[y][x] === 2) {
- // Exit
- var exit = self.attachAsset('mazeExit', {
- anchorX: 0,
- anchorY: 0
- });
- exit.x = x * self.tileSize;
- exit.y = y * self.tileSize;
- }
- }
- }
- };
- self.isWall = function (x, y) {
- var gridX = Math.floor(x / self.tileSize);
- var gridY = Math.floor(y / self.tileSize);
- if (gridX < 0 || gridX >= self.cols || gridY < 0 || gridY >= self.rows) {
- return true; // Out of bounds
- }
- return self.maze[gridY][gridX] === 1;
- };
- self.isExit = function (x, y) {
- var gridX = Math.floor(x / self.tileSize);
- var gridY = Math.floor(y / self.tileSize);
- if (gridX < 0 || gridX >= self.cols || gridY < 0 || gridY >= self.rows) {
- return false;
- }
- return self.maze[gridY][gridX] === 2;
- };
- self.generateMaze();
- self.renderMaze();
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
@@ -287,26 +209,31 @@
if (self.weapon < self.maxWeapon) {
self.weapon++;
}
};
- self.move = function (dx, dy) {
- var newX = self.x + dx;
- var newY = self.y + dy;
- // Check wall collision
- if (!checkWallCollision(newX, newY)) {
- self.x = newX;
- self.y = newY;
+ self.checkWallCollision = function (newX, newY) {
+ // Check collision with maze walls
+ for (var i = 0; i < walls.length; i++) {
+ var wall = walls[i];
+ if (newX < wall.x + 80 && newX + 40 > wall.x && newY < wall.y + 80 && newY + 40 > wall.y) {
+ return true;
+ }
}
- // Check exit collision
- if (maze.isExit(self.x, self.y)) {
- gameWon = true;
- }
+ return false;
};
self.update = function () {
- // Top-down movement - no gravity needed
+ // No gravity or ground collision in top-down view
};
return self;
});
+var Wall = Container.expand(function () {
+ var self = Container.call(this);
+ var wallGraphics = self.attachAsset('wall', {
+ anchorX: 0,
+ anchorY: 0
+ });
+ return self;
+});
var WeaponPickup = Container.expand(function () {
var self = Container.call(this);
var weaponGraphics = self.attachAsset('weaponPickup', {
anchorX: 0.5,
@@ -334,41 +261,45 @@
self.speed = 1.5;
self.damage = 20;
self.lastAttackTime = 0;
self.moveTimer = 0;
+ self.targetX = 0;
+ self.targetY = 0;
self.takeDamage = function (damage) {
self.health -= damage;
LK.effects.flashObject(self, 0xFFFFFF, 200);
if (self.health <= 0) {
return true; // Zombie is dead
}
return false;
};
+ self.checkWallCollision = function (newX, newY) {
+ // Check collision with maze walls
+ for (var i = 0; i < walls.length; i++) {
+ var wall = walls[i];
+ if (newX < wall.x + 80 && newX + 35 > wall.x && newY < wall.y + 80 && newY + 35 > wall.y) {
+ return true;
+ }
+ }
+ return false;
+ };
self.update = function () {
- self.moveTimer++;
- // Move towards player every few frames for performance
- if (self.moveTimer % 10 === 0) {
- var dx = player.x - self.x;
- var dy = player.y - self.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance > 0) {
- var moveX = dx / distance * self.speed;
- var moveY = dy / distance * self.speed;
- // Try to move towards player
- var newX = self.x + moveX;
- var newY = self.y + moveY;
- if (!checkWallCollision(newX, newY)) {
- self.x = newX;
- self.y = newY;
- } else {
- // Try moving only horizontally or vertically
- if (!checkWallCollision(newX, self.y)) {
- self.x = newX;
- } else if (!checkWallCollision(self.x, newY)) {
- self.y = newY;
- }
- }
+ // Simple AI: move towards player if path is clear
+ var deltaX = player.x - self.x;
+ var deltaY = player.y - self.y;
+ var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+ if (distance > 0) {
+ var moveX = deltaX / distance * self.speed;
+ var moveY = deltaY / distance * self.speed;
+ var newX = self.x + moveX;
+ var newY = self.y + moveY;
+ // Only move if not hitting walls
+ if (!self.checkWallCollision(newX, self.y)) {
+ self.x = newX;
}
+ if (!self.checkWallCollision(self.x, newY)) {
+ self.y = newY;
+ }
}
// Check collision with player
if (self.intersects(player)) {
var currentTime = LK.ticks;
@@ -385,46 +316,62 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x87CEEB
+ backgroundColor: 0x2d4a2d
});
/****
* Game Code
****/
// Game variables
var player;
-var maze;
var zombies = [];
var bullets = [];
var healthPacks = [];
var weaponPickups = [];
+var walls = [];
+var mazeExit;
var gameOver = false;
var gameStarted = false;
-var gameWon = false;
var score = 0;
-var waveNumber = 1;
var zombieSpawnTimer = 0;
var pickupSpawnTimer = 0;
var howToPlayScreen;
// Movement controls
-var moveLeft = false;
-var moveRight = false;
var moveUp = false;
var moveDown = false;
+var moveLeft = false;
+var moveRight = false;
var shooting = false;
var shootTimer = 0;
-// Utility function for wall collision
-function checkWallCollision(x, y) {
- return maze.isWall(x, y);
+var shootTargetX = 0;
+var shootTargetY = 0;
+// Create maze layout (simplified maze pattern)
+var mazePattern = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1], [1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1], [1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1], [1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1], [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1], [1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]];
+// Build maze walls
+for (var row = 0; row < mazePattern.length; row++) {
+ for (var col = 0; col < mazePattern[row].length; col++) {
+ var cellX = col * 80;
+ var cellY = row * 80;
+ if (mazePattern[row][col] === 1) {
+ // Wall
+ var wall = game.addChild(new Wall());
+ wall.x = cellX;
+ wall.y = cellY;
+ walls.push(wall);
+ } else if (mazePattern[row][col] === 2) {
+ // Exit
+ mazeExit = game.addChild(new MazeExit());
+ mazeExit.x = cellX;
+ mazeExit.y = cellY;
+ }
+ }
}
-// Create maze
-maze = game.addChild(new Maze());
-// Create player at maze start
+// Create player
player = game.addChild(new Player());
-player.x = 96; // Start in maze path
-player.y = 96;
+player.x = 120; // Start position in maze
+player.y = 120;
// UI Elements
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
@@ -440,78 +387,58 @@
healthText.anchor.set(0, 0);
healthText.x = 150;
healthText.y = 120;
LK.gui.topLeft.addChild(healthText);
-var waveText = new Text2('Wave: 1', {
- size: 60,
- fill: 0xFFFF00
+var objectiveText = new Text2('Find the Exit!', {
+ size: 50,
+ fill: 0x00FF00
});
-waveText.anchor.set(1, 0);
-LK.gui.topRight.addChild(waveText);
-// Control buttons for mobile - 4 direction movement
-var leftButton = LK.getAsset('player', {
+objectiveText.anchor.set(1, 0);
+objectiveText.x = 1948;
+objectiveText.y = 50;
+LK.gui.topRight.addChild(objectiveText);
+// Control buttons for mobile
+var upButton = LK.getAsset('player', {
width: 80,
height: 80,
anchorX: 0.5,
anchorY: 0.5,
- alpha: 0.3
+ alpha: 0.4
});
-leftButton.x = 80;
-leftButton.y = 2600;
-LK.gui.addChild(leftButton);
-var rightButton = LK.getAsset('player', {
+upButton.x = 150;
+upButton.y = 2500;
+LK.gui.addChild(upButton);
+var downButton = LK.getAsset('player', {
width: 80,
height: 80,
anchorX: 0.5,
anchorY: 0.5,
- alpha: 0.3
+ alpha: 0.4
});
-rightButton.x = 240;
-rightButton.y = 2600;
-LK.gui.addChild(rightButton);
-var upButton = LK.getAsset('player', {
+downButton.x = 150;
+downButton.y = 2650;
+LK.gui.addChild(downButton);
+var leftButton = LK.getAsset('player', {
width: 80,
height: 80,
anchorX: 0.5,
anchorY: 0.5,
- alpha: 0.3
+ alpha: 0.4
});
-upButton.x = 160;
-upButton.y = 2520;
-LK.gui.addChild(upButton);
-var downButton = LK.getAsset('player', {
+leftButton.x = 75;
+leftButton.y = 2575;
+LK.gui.addChild(leftButton);
+var rightButton = LK.getAsset('player', {
width: 80,
height: 80,
anchorX: 0.5,
anchorY: 0.5,
- alpha: 0.3
+ alpha: 0.4
});
-downButton.x = 160;
-downButton.y = 2680;
-LK.gui.addChild(downButton);
-var shootButton = LK.getAsset('bullet', {
- width: 100,
- height: 100,
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.3
-});
-shootButton.x = 1900;
-shootButton.y = 2600;
-LK.gui.addChild(shootButton);
+rightButton.x = 225;
+rightButton.y = 2575;
+LK.gui.addChild(rightButton);
// Button event handlers
-leftButton.down = function () {
- moveLeft = true;
-};
-leftButton.up = function () {
- moveLeft = false;
-};
-rightButton.down = function () {
- moveRight = true;
-};
-rightButton.up = function () {
- moveRight = false;
-};
upButton.down = function () {
moveUp = true;
};
upButton.up = function () {
@@ -522,82 +449,94 @@
};
downButton.up = function () {
moveDown = false;
};
-shootButton.down = function () {
- shooting = true;
+leftButton.down = function () {
+ moveLeft = true;
};
-shootButton.up = function () {
- shooting = false;
+leftButton.up = function () {
+ moveLeft = false;
};
+rightButton.down = function () {
+ moveRight = true;
+};
+rightButton.up = function () {
+ moveRight = false;
+};
// Create How to Play screen
howToPlayScreen = game.addChild(new HowToPlay());
howToPlayScreen.visible = true;
// Game event handlers
game.down = function (x, y, obj) {
- // Handle shooting in direction of touch
- if (gameStarted && !gameOver && !gameWon) {
- shootBullet(x, y);
- }
+ // Set shoot target position
+ shootTargetX = x;
+ shootTargetY = y;
+ shooting = true;
};
game.up = function (x, y, obj) {
- // Touch release events
+ shooting = false;
};
// Spawn functions
function spawnZombie() {
- var attempts = 0;
var zombie = new Zombie();
- // Try to spawn in valid maze location
+ // Find a random open space in the maze
+ var spawnAttempts = 0;
do {
- zombie.x = Math.random() * 1800 + 124;
- zombie.y = Math.random() * 2400 + 124;
- attempts++;
- } while (checkWallCollision(zombie.x, zombie.y) && attempts < 50);
- // Scale difficulty based on wave
- zombie.health += (waveNumber - 1) * 10;
- zombie.speed += (waveNumber - 1) * 0.2;
- zombie.damage += (waveNumber - 1) * 5;
+ zombie.x = Math.random() * 1920 + 80;
+ zombie.y = Math.random() * 1520 + 80;
+ spawnAttempts++;
+ } while (zombie.checkWallCollision(zombie.x, zombie.y) && spawnAttempts < 50);
zombies.push(zombie);
game.addChild(zombie);
}
function spawnHealthPack() {
- var attempts = 0;
var healthPack = new HealthPack();
- // Try to spawn in valid maze location
+ // Find a random open space in the maze
+ var spawnAttempts = 0;
do {
- healthPack.x = Math.random() * 1800 + 124;
- healthPack.y = Math.random() * 2400 + 124;
- attempts++;
- } while (checkWallCollision(healthPack.x, healthPack.y) && attempts < 50);
+ healthPack.x = Math.random() * 1920 + 80;
+ healthPack.y = Math.random() * 1520 + 80;
+ spawnAttempts++;
+ } while (spawnAttempts < 50 && isPositionBlocked(healthPack.x, healthPack.y));
healthPacks.push(healthPack);
game.addChild(healthPack);
}
function spawnWeaponPickup() {
- var attempts = 0;
var weaponPickup = new WeaponPickup();
- // Try to spawn in valid maze location
+ // Find a random open space in the maze
+ var spawnAttempts = 0;
do {
- weaponPickup.x = Math.random() * 1800 + 124;
- weaponPickup.y = Math.random() * 2400 + 124;
- attempts++;
- } while (checkWallCollision(weaponPickup.x, weaponPickup.y) && attempts < 50);
+ weaponPickup.x = Math.random() * 1920 + 80;
+ weaponPickup.y = Math.random() * 1520 + 80;
+ spawnAttempts++;
+ } while (spawnAttempts < 50 && isPositionBlocked(weaponPickup.x, weaponPickup.y));
weaponPickups.push(weaponPickup);
game.addChild(weaponPickup);
}
-function shootBullet(targetX, targetY) {
+function isPositionBlocked(x, y) {
+ // Check if position overlaps with walls
+ for (var i = 0; i < walls.length; i++) {
+ var wall = walls[i];
+ if (x < wall.x + 80 && x + 25 > wall.x && y < wall.y + 80 && y + 25 > wall.y) {
+ return true;
+ }
+ }
+ return false;
+}
+function shootBullet() {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
bullet.damage = 25 * player.weapon; // More damage with better weapons
- // Calculate direction to target
- var dx = targetX - player.x;
- var dy = targetY - player.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
+ // Calculate direction toward shoot target
+ var deltaX = shootTargetX - player.x;
+ var deltaY = shootTargetY - player.y;
+ var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
if (distance > 0) {
- bullet.directionX = dx / distance;
- bullet.directionY = dy / distance;
+ bullet.directionX = deltaX / distance;
+ bullet.directionY = deltaY / distance;
} else {
- bullet.directionX = 1;
+ bullet.directionX = 1; // Default right
bullet.directionY = 0;
}
bullets.push(bullet);
game.addChild(bullet);
@@ -611,52 +550,42 @@
if (gameOver) {
LK.showGameOver();
return;
}
- if (gameWon) {
- LK.showYouWin();
- return;
- }
// Update score based on survival time
score += 1;
LK.setScore(score);
- // Handle player movement - top-down 4-directional
+ // Handle player movement with wall collision
+ var newX = player.x;
+ var newY = player.y;
if (moveLeft) {
- player.move(-player.speed, 0);
+ newX = player.x - player.speed;
}
if (moveRight) {
- player.move(player.speed, 0);
+ newX = player.x + player.speed;
}
if (moveUp) {
- player.move(0, -player.speed);
+ newY = player.y - player.speed;
}
if (moveDown) {
- player.move(0, player.speed);
+ newY = player.y + player.speed;
}
+ // Check wall collisions and move if valid
+ if (!player.checkWallCollision(newX, player.y)) {
+ player.x = newX;
+ }
+ if (!player.checkWallCollision(player.x, newY)) {
+ player.y = newY;
+ }
// Handle shooting
- if (shooting && LK.ticks - shootTimer > 60 / player.weapon) {
- // Find nearest zombie to shoot at
- var nearestZombie = null;
- var nearestDistance = Infinity;
- for (var i = 0; i < zombies.length; i++) {
- var dx = zombies[i].x - player.x;
- var dy = zombies[i].y - player.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < nearestDistance) {
- nearestDistance = distance;
- nearestZombie = zombies[i];
- }
- }
- if (nearestZombie) {
- shootBullet(nearestZombie.x, nearestZombie.y);
- } else {
- shootBullet(player.x + 50, player.y); // Default shoot right
- }
+ if (shooting && LK.ticks - shootTimer > 30 / player.weapon) {
+ // Faster shooting with better weapons
+ shootBullet();
shootTimer = LK.ticks;
}
// Spawn zombies
zombieSpawnTimer++;
- var spawnRate = Math.max(120 - waveNumber * 10, 30); // Slower spawning for maze
+ var spawnRate = Math.max(180, 120); // Spawn every 3-2 seconds
if (zombieSpawnTimer >= spawnRate) {
spawnZombie();
zombieSpawnTimer = 0;
}
@@ -673,14 +602,28 @@
}
// Update bullets and check collisions
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
- // Check if bullet hit wall or is off screen
- if (bullet.destroyed || bullet.x < -50 || bullet.x > 2098 || bullet.y < -50 || bullet.y > 2782) {
+ // Check if bullet is off screen or hits walls
+ if (bullet.x < 0 || bullet.x > 2000 || bullet.y < 0 || bullet.y > 1600) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
+ // Check wall collision
+ var bulletHitWall = false;
+ for (var w = 0; w < walls.length; w++) {
+ var wall = walls[w];
+ if (bullet.x < wall.x + 80 && bullet.x + 12 > wall.x && bullet.y < wall.y + 80 && bullet.y + 12 > wall.y) {
+ bulletHitWall = true;
+ break;
+ }
+ }
+ if (bulletHitWall) {
+ bullet.destroy();
+ bullets.splice(i, 1);
+ continue;
+ }
// Check bullet-zombie collisions
var hit = false;
for (var j = zombies.length - 1; j >= 0; j--) {
var zombie = zombies[j];
@@ -714,14 +657,9 @@
weaponPickup.destroy();
weaponPickups.splice(i, 1);
}
}
- // Update wave progression
- if (LK.ticks % 1800 === 0) {
- // Every 30 seconds
- waveNumber++;
- }
// Update UI
scoreText.setText('Score: ' + score);
healthText.setText('Health: ' + player.health);
- waveText.setText('Wave: ' + waveNumber);
+ // Exit reached condition handled by MazeExit class
};
\ No newline at end of file
Human. In-Game asset. 2d. High contrast. No shadows
Zombie. In-Game asset. 2d. High contrast. No shadows
Health. In-Game asset. 2d. High contrast. No shadows
Weapon. In-Game asset. 2d. High contrast. No shadows
Exit. In-Game asset. 2d. High contrast. No shadows
Maze exit. In-Game asset. 2d. High contrast. No shadows
Bullet. In-Game asset. 2d. High contrast. No shadows
Player Health. In-Game asset. 2d. High contrast. No shadows