User prompt
Instead of writing "you won" it should say "you completed the dungeon" with dungeon style
User prompt
snake boss should not release red things
User prompt
make a cooldown for mage
User prompt
mage is so hard fix tjat
User prompt
Let our character scream when he dies
User prompt
Every time we kill a boss, a win sound will be heard.
User prompt
Reduce the number of stone throws by the first boss
User prompt
make the first room sound is a dungeon but 2. room is a rock sound
User prompt
put the dungeon sound I chose in the background
User prompt
bosslar chestin ve npcnin içinde doğmasın
User prompt
bosslar kapıda spawnlanmasın
User prompt
Thedemon boss can stun us, throw something at us and freeze us for 1 second and it says stunned above us ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
3. boss çok güçlü düzelt
User prompt
Delete the pink things in the top left
User prompt
başlangıç ekranı buglu lütfen düzelt
User prompt
I can't click anywhere,ü
User prompt
At the beginning of the game, it asks us which language we want to play in and it can be Turkish or English. ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Let there be a labyrinth in the room where the snake is
User prompt
There should be an ultimate button next to the heal button, but it should come every 10 seconds.
User prompt
let the background be dark and let there be light behind our player
User prompt
After the mage sends us a ball, let it have a cooldown
User prompt
The devil in the 2nd room will shoot fire from the ground and if we stay in the right place the boss will die
User prompt
After the monster in the first room sends us its stones, it does not send them for 2 seconds.
User prompt
The monster in the first room sends us stones ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
The color of the life bar should be white but the inside should be red
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Chest class var Chest = Container.expand(function () { var self = Container.call(this); // Attach chest asset (brown box) var chestSprite = self.attachAsset('chest', { anchorX: 0.5, anchorY: 0.5 }); self.width = chestSprite.width; self.height = chestSprite.height; self.opened = false; return self; }); // Dark Mage - Room 3 var DarkMage = Container.expand(function () { var self = Container.call(this); // Use mage asset instead of monster asset var mageSprite = self.attachAsset('mage', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.1, scaleY: 1.1 }); // Set larger hitbox for easier collision detection self.width = mageSprite.width * 0.4; self.height = mageSprite.height * 0.4; // Monster health system self.maxHealth = 3; self.health = self.maxHealth; self.speed = 0.6; // Create heart-based health display self.hearts = []; var heartSize = 30; var heartSpacing = 35; var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize; var startX = -totalHeartsWidth / 2; for (var h = 0; h < self.maxHealth; h++) { var heart = LK.getAsset('trap', { width: heartSize, height: heartSize, anchorX: 0.5, anchorY: 0.5 }); heart.tint = 0xFF1744; heart.x = startX + h * heartSpacing; heart.y = -mageSprite.height / 2 - 40; self.addChild(heart); self.hearts.push(heart); } // Update heart display self.updateHealthBar = function () { // Update heart visibility based on current health for (var h = 0; h < self.hearts.length; h++) { if (h < self.health) { self.hearts[h].visible = true; self.hearts[h].tint = 0xFF1744; // Red for full hearts self.hearts[h].alpha = 1.0; } else { self.hearts[h].visible = true; self.hearts[h].tint = 0x444444; // Dark gray for empty hearts self.hearts[h].alpha = 0.5; } } }; // Take damage function with animation self.takeDamage = function () { self.health -= 1; self.updateHealthBar(); // Flash damage animation tween(mageSprite, { tint: 0xFF0000 }, { duration: 150, onFinish: function onFinish() { tween(mageSprite, { tint: 0xFFFFFF }, { duration: 200 }); } }); // Shake animation var originalX = self.x; tween(self, { x: originalX + 15 }, { duration: 50, onFinish: function onFinish() { tween(self, { x: originalX - 15 }, { duration: 50, onFinish: function onFinish() { tween(self, { x: originalX }, { duration: 50 }); } }); } }); }; // Movement direction self.vx = 0; self.vy = 0; // Set random direction self.setRandomDirection = function () { var angle = Math.random() * Math.PI * 2; self.vx = Math.cos(angle) * self.speed; self.vy = Math.sin(angle) * self.speed; }; self.setRandomDirection(); // Shooting timer self.shootTimer = 0; self.shootInterval = 90; // Shoot every 1.5 seconds at 60fps // Called every tick self.update = function () { // Check if hero is close to this monster FIRST (within encounter distance) var dx = hero.x - self.x; var dy = hero.y - self.y; var distToHero = Math.sqrt(dx * dx + dy * dy); // If hero is within encounter distance, trigger freeze and stop moving if (distToHero < 120) { // Reduced from 200 to 120 for less aggressive encounter if (!gameFrozen) { // Trigger freeze effect gameFrozen = true; freezeTimer = FREEZE_DURATION; freezeBuffer = FREEZE_BUFFER_TIME; // Set buffer to prevent immediate damage console.log("Freeze triggered! Buffer set to:", FREEZE_BUFFER_TIME); // Apply freeze visual effect to all characters tween(hero, { tint: 0x8888ff }, { duration: 300 }); tween(self, { tint: 0x8888ff }, { duration: 300 }); for (var m = 0; m < monsters.length; m++) { if (monsters[m] !== self) { tween(monsters[m], { tint: 0x8888ff }, { duration: 300 }); } } } // Monster stays still when encountering hero return; } // Don't move if game is frozen if (gameFrozen) { return; } // Mage shooting logic - shoot projectiles at hero self.shootTimer++; if (self.shootTimer >= self.shootInterval) { self.shootTimer = 0; // Create magic ball projectile var ball = new MageBall(); ball.x = self.x; ball.y = self.y; ball.setDirection(hero.x, hero.y); game.addChild(ball); mageBalls.push(ball); // Visual effect when shooting tween(mageSprite, { scaleX: 1.3, scaleY: 1.3 }, { duration: 200, onFinish: function onFinish() { tween(mageSprite, { scaleX: 1.1, scaleY: 1.1 }, { duration: 200 }); } }); } self.x += self.vx; self.y += self.vy; // Bounce off room walls if (self.x < roomBounds.x + self.width / 2) { self.x = roomBounds.x + self.width / 2; self.vx *= -1; } if (self.x > roomBounds.x + roomBounds.width - self.width / 2) { self.x = roomBounds.x + roomBounds.width - self.width / 2; self.vx *= -1; } if (self.y < roomBounds.y + self.height / 2) { self.y = roomBounds.y + self.height / 2; self.vy *= -1; } if (self.y > roomBounds.y + roomBounds.height - self.height / 2) { self.y = roomBounds.y + roomBounds.height - self.height / 2; self.vy *= -1; } }; // Update hearts for new health self.hearts = []; var heartSize = 30; var heartSpacing = 35; var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize; var startX = -totalHeartsWidth / 2; for (var h = 0; h < self.maxHealth; h++) { var heart = LK.getAsset('trap', { width: heartSize, height: heartSize, anchorX: 0.5, anchorY: 0.5 }); heart.tint = 0xFF1744; heart.x = startX + h * heartSpacing; heart.y = -mageSprite.height / 2 - 40; self.addChild(heart); self.hearts.push(heart); } self.updateHealthBar(); return self; }); // Door class (for next room) var Door = Container.expand(function () { var self = Container.call(this); // Attach door asset (purple box) var doorSprite = self.attachAsset('door', { anchorX: 0.5, anchorY: 0.5 }); self.width = doorSprite.width; self.height = doorSprite.height; return self; }); // Dragon Lord - Final Boss Room 5 var DragonLord = Container.expand(function () { var self = Container.call(this); // Use dragon asset instead of monster asset var dragonSprite = self.attachAsset('dragon', { anchorX: 0.5, anchorY: 0.5, scaleX: 2.0, scaleY: 2.0 }); // Set larger hitbox for easier collision detection self.width = dragonSprite.width * 0.4; self.height = dragonSprite.height * 0.4; // Monster health system self.maxHealth = 6; self.health = self.maxHealth; self.speed = 0.2; // Create heart-based health display self.hearts = []; var heartSize = 30; var heartSpacing = 35; var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize; var startX = -totalHeartsWidth / 2; for (var h = 0; h < self.maxHealth; h++) { var heart = LK.getAsset('trap', { width: heartSize, height: heartSize, anchorX: 0.5, anchorY: 0.5 }); heart.tint = 0xFF1744; heart.x = startX + h * heartSpacing; heart.y = -dragonSprite.height / 2 - 40; self.addChild(heart); self.hearts.push(heart); } // Update heart display self.updateHealthBar = function () { // Update heart visibility based on current health for (var h = 0; h < self.hearts.length; h++) { if (h < self.health) { self.hearts[h].visible = true; self.hearts[h].tint = 0xFF1744; // Red for full hearts self.hearts[h].alpha = 1.0; } else { self.hearts[h].visible = true; self.hearts[h].tint = 0x444444; // Dark gray for empty hearts self.hearts[h].alpha = 0.5; } } }; // Take damage function with animation self.takeDamage = function () { self.health -= 1; self.updateHealthBar(); // Flash damage animation tween(dragonSprite, { tint: 0xFF0000 }, { duration: 150, onFinish: function onFinish() { tween(dragonSprite, { tint: 0xFFFFFF }, { duration: 200 }); } }); // Shake animation var originalX = self.x; tween(self, { x: originalX + 15 }, { duration: 50, onFinish: function onFinish() { tween(self, { x: originalX - 15 }, { duration: 50, onFinish: function onFinish() { tween(self, { x: originalX }, { duration: 50 }); } }); } }); }; // Movement direction self.vx = 0; self.vy = 0; // Set random direction self.setRandomDirection = function () { var angle = Math.random() * Math.PI * 2; self.vx = Math.cos(angle) * self.speed; self.vy = Math.sin(angle) * self.speed; }; self.setRandomDirection(); // Called every tick self.update = function () { // Check if hero is close to this monster FIRST (within encounter distance) var dx = hero.x - self.x; var dy = hero.y - self.y; var distToHero = Math.sqrt(dx * dx + dy * dy); // If hero is within encounter distance, trigger freeze and stop moving if (distToHero < 120) { // Reduced from 200 to 120 for less aggressive encounter if (!gameFrozen) { // Trigger freeze effect gameFrozen = true; freezeTimer = FREEZE_DURATION; freezeBuffer = FREEZE_BUFFER_TIME; // Set buffer to prevent immediate damage console.log("Freeze triggered! Buffer set to:", FREEZE_BUFFER_TIME); // Apply freeze visual effect to all characters tween(hero, { tint: 0x8888ff }, { duration: 300 }); tween(self, { tint: 0x8888ff }, { duration: 300 }); for (var m = 0; m < monsters.length; m++) { if (monsters[m] !== self) { tween(monsters[m], { tint: 0x8888ff }, { duration: 300 }); } } } // Monster stays still when encountering hero return; } // Don't move if game is frozen if (gameFrozen) { return; } self.x += self.vx; self.y += self.vy; // Bounce off room walls if (self.x < roomBounds.x + self.width / 2) { self.x = roomBounds.x + self.width / 2; self.vx *= -1; } if (self.x > roomBounds.x + roomBounds.width - self.width / 2) { self.x = roomBounds.x + roomBounds.width - self.width / 2; self.vx *= -1; } if (self.y < roomBounds.y + self.height / 2) { self.y = roomBounds.y + self.height / 2; self.vy *= -1; } if (self.y > roomBounds.y + roomBounds.height - self.height / 2) { self.y = roomBounds.y + roomBounds.height - self.height / 2; self.vy *= -1; } }; // Update hearts for new health self.hearts = []; var heartSize = 30; var heartSpacing = 35; var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize; var startX = -totalHeartsWidth / 2; for (var h = 0; h < self.maxHealth; h++) { var heart = LK.getAsset('trap', { width: heartSize, height: heartSize, anchorX: 0.5, anchorY: 0.5 }); heart.tint = 0xFF1744; heart.x = startX + h * heartSpacing; heart.y = -dragonSprite.height / 2 - 40; self.addChild(heart); self.hearts.push(heart); } self.updateHealthBar(); return self; }); // Fire Demon - Room 4 var FireDemon = Container.expand(function () { var self = Container.call(this); // Use demon asset instead of monster asset var demonSprite = self.attachAsset('demon', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.6, scaleY: 1.6 }); // Set larger hitbox for easier collision detection self.width = demonSprite.width * 0.4; self.height = demonSprite.height * 0.4; // Monster health system self.maxHealth = 4; self.health = self.maxHealth; self.speed = 0.3; // Create heart-based health display self.hearts = []; var heartSize = 30; var heartSpacing = 35; var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize; var startX = -totalHeartsWidth / 2; for (var h = 0; h < self.maxHealth; h++) { var heart = LK.getAsset('trap', { width: heartSize, height: heartSize, anchorX: 0.5, anchorY: 0.5 }); heart.tint = 0xFF1744; heart.x = startX + h * heartSpacing; heart.y = -demonSprite.height / 2 - 40; self.addChild(heart); self.hearts.push(heart); } // Update heart display self.updateHealthBar = function () { // Update heart visibility based on current health for (var h = 0; h < self.hearts.length; h++) { if (h < self.health) { self.hearts[h].visible = true; self.hearts[h].tint = 0xFF1744; // Red for full hearts self.hearts[h].alpha = 1.0; } else { self.hearts[h].visible = true; self.hearts[h].tint = 0x444444; // Dark gray for empty hearts self.hearts[h].alpha = 0.5; } } }; // Take damage function with animation self.takeDamage = function () { self.health -= 1; self.updateHealthBar(); // Flash damage animation tween(demonSprite, { tint: 0xFF0000 }, { duration: 150, onFinish: function onFinish() { tween(demonSprite, { tint: 0xFFFFFF }, { duration: 200 }); } }); // Shake animation var originalX = self.x; tween(self, { x: originalX + 15 }, { duration: 50, onFinish: function onFinish() { tween(self, { x: originalX - 15 }, { duration: 50, onFinish: function onFinish() { tween(self, { x: originalX }, { duration: 50 }); } }); } }); }; // Movement direction self.vx = 0; self.vy = 0; // Set random direction self.setRandomDirection = function () { var angle = Math.random() * Math.PI * 2; self.vx = Math.cos(angle) * self.speed; self.vy = Math.sin(angle) * self.speed; }; self.setRandomDirection(); // Called every tick self.update = function () { // Check if hero is close to this monster FIRST (within encounter distance) var dx = hero.x - self.x; var dy = hero.y - self.y; var distToHero = Math.sqrt(dx * dx + dy * dy); // If hero is within encounter distance, trigger freeze and stop moving if (distToHero < 120) { // Reduced from 200 to 120 for less aggressive encounter if (!gameFrozen) { // Trigger freeze effect gameFrozen = true; freezeTimer = FREEZE_DURATION; freezeBuffer = FREEZE_BUFFER_TIME; // Set buffer to prevent immediate damage console.log("Freeze triggered! Buffer set to:", FREEZE_BUFFER_TIME); // Apply freeze visual effect to all characters tween(hero, { tint: 0x8888ff }, { duration: 300 }); tween(self, { tint: 0x8888ff }, { duration: 300 }); for (var m = 0; m < monsters.length; m++) { if (monsters[m] !== self) { tween(monsters[m], { tint: 0x8888ff }, { duration: 300 }); } } } // Monster stays still when encountering hero return; } // Don't move if game is frozen if (gameFrozen) { return; } self.x += self.vx; self.y += self.vy; // Bounce off room walls if (self.x < roomBounds.x + self.width / 2) { self.x = roomBounds.x + self.width / 2; self.vx *= -1; } if (self.x > roomBounds.x + roomBounds.width - self.width / 2) { self.x = roomBounds.x + roomBounds.width - self.width / 2; self.vx *= -1; } if (self.y < roomBounds.y + self.height / 2) { self.y = roomBounds.y + self.height / 2; self.vy *= -1; } if (self.y > roomBounds.y + roomBounds.height - self.height / 2) { self.y = roomBounds.y + roomBounds.height - self.height / 2; self.vy *= -1; } }; // Update hearts for new health self.hearts = []; var heartSize = 30; var heartSpacing = 35; var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize; var startX = -totalHeartsWidth / 2; for (var h = 0; h < self.maxHealth; h++) { var heart = LK.getAsset('trap', { width: heartSize, height: heartSize, anchorX: 0.5, anchorY: 0.5 }); heart.tint = 0xFF1744; heart.x = startX + h * heartSpacing; heart.y = -demonSprite.height / 2 - 40; self.addChild(heart); self.hearts.push(heart); } self.updateHealthBar(); return self; }); // Hero class var Hero = Container.expand(function () { var self = Container.call(this); // Attach hero asset (red box) var heroSprite = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.width = heroSprite.width; self.height = heroSprite.height; // Attach sword to hero var swordSprite = self.attachAsset('sword', { anchorX: 0.5, anchorY: 0.5 }); swordSprite.x = -heroSprite.width * 0.3; // Position sword to the left of hero swordSprite.y = 0; // Center vertically with hero swordSprite.rotation = -Math.PI / 4; // Angle the sword pointing left // Hero stats self.maxHealth = 3; self.health = self.maxHealth; self.invincible = false; self.invincibleTimer = 0; // Create health bar above character // Health bar border (white outline) self.healthBarBorder = LK.getAsset('trap', { width: 200, height: 40, anchorX: 0.5, anchorY: 0.5 }); self.healthBarBorder.tint = 0xFFFFFF; // White border self.healthBarBorder.x = 0; self.healthBarBorder.y = -heroSprite.height / 2 - 50; // Position above character self.addChild(self.healthBarBorder); // Health bar background (dark) self.healthBarBackground = LK.getAsset('trap', { width: 180, height: 24, anchorX: 0.5, anchorY: 0.5 }); self.healthBarBackground.tint = 0x222222; // Dark gray background self.healthBarBackground.x = 0; self.healthBarBackground.y = -heroSprite.height / 2 - 50; // Position above character self.addChild(self.healthBarBackground); // Health bar fill (red color) self.healthBarFill = LK.getAsset('trap', { width: 180, height: 24, anchorX: 0.0, anchorY: 0.5 }); self.healthBarFill.tint = 0xFF0000; // Red for health bar self.healthBarFill.x = -90; // Left-aligned within background self.healthBarFill.y = -heroSprite.height / 2 - 50; // Position above character self.addChild(self.healthBarFill); // Update health bar display self.updateHealthBar = function () { var healthPercent = self.health / self.maxHealth; self.healthBarFill.scaleX = healthPercent; // Keep health bar red color self.healthBarFill.tint = 0xFF0000; // Always red // Add pulsing effect when health is critical if (healthPercent <= 0.25) { tween(self.healthBarFill, { alpha: 0.5 }, { duration: 500, loop: true, pingpong: true }); } else { tween.stop(self.healthBarFill, { alpha: true }); self.healthBarFill.alpha = 1.0; } }; // Initialize health bar self.updateHealthBar(); // Flash when hit self.flash = function () { tween(heroSprite, { tint: 0xffffff }, { duration: 100, onFinish: function onFinish() { tween(heroSprite, { tint: 0xd83318 }, { duration: 200 }); } }); }; // Take damage self.takeDamage = function () { if (self.invincible) return; self.health -= 1; self.flash(); self.invincible = true; self.invincibleTimer = 60; // 1 second at 60fps LK.effects.flashObject(self, 0xff0000, 300); self.updateHealthBar(); // Create blood flow effect for (var b = 0; b < 8; b++) { var bloodDrop = LK.getAsset('trap', { width: 12 + Math.random() * 8, height: 12 + Math.random() * 8, anchorX: 0.5, anchorY: 0.5 }); bloodDrop.tint = 0xAA0000; // Dark red blood color bloodDrop.x = self.x + (Math.random() - 0.5) * 60; // Random spread around hero bloodDrop.y = self.y + (Math.random() - 0.5) * 40; bloodDrop.alpha = 0.8 + Math.random() * 0.2; game.addChild(bloodDrop); // Animate blood drop falling and fading var fallDistance = 80 + Math.random() * 120; var fallDuration = 800 + Math.random() * 400; tween(bloodDrop, { y: bloodDrop.y + fallDistance, alpha: 0, scaleX: 0.3, scaleY: 0.3 }, { duration: fallDuration, easing: tween.easeIn, onFinish: function onFinish() { bloodDrop.destroy(); } }); } if (self.health <= 0) { LK.effects.flashScreen(0xff0000, 800); // Create dungeon-themed game over overlay var dungeonGameOverOverlay = new Container(); dungeonGameOverOverlay.zIndex = 10000; // ensure on top // Dark background var background = LK.getAsset('trap', { width: 2048, height: 2732, anchorX: 0, anchorY: 0, x: 0, y: 0 }); background.tint = 0x000000; background.alpha = 0.8; dungeonGameOverOverlay.addChild(background); // Main message var gameOverText = new Text2("You couldn't pass the dungeon...", { size: 120, fill: 0xFF4444, font: "Impact, Arial Black, Tahoma" }); gameOverText.anchor.set(0.5, 0.5); gameOverText.x = 2048 / 2; gameOverText.y = 1200; dungeonGameOverOverlay.addChild(gameOverText); // Subtitle var subtitleText = new Text2("The darkness consumed you in Room " + currentRoom, { size: 80, fill: 0x888888 }); subtitleText.anchor.set(0.5, 0.5); subtitleText.x = 2048 / 2; subtitleText.y = 1400; dungeonGameOverOverlay.addChild(subtitleText); // Score display var finalScoreText = new Text2("Monsters Defeated: " + monstersDefeated, { size: 70, fill: 0xFFFF88 }); finalScoreText.anchor.set(0.5, 0.5); finalScoreText.x = 2048 / 2; finalScoreText.y = 1600; dungeonGameOverOverlay.addChild(finalScoreText); game.addChild(dungeonGameOverOverlay); // Auto restart after 3 seconds LK.setTimeout(function () { LK.showGameOver(); }, 3000); } }; // Heal self.heal = function () { if (self.health < self.maxHealth) { self.health += 1; self.updateHealthBar(); LK.effects.flashObject(self, 0x83de44, 300); } }; // Called every tick self.update = function () { if (self.invincible) { self.invincibleTimer--; if (self.invincibleTimer <= 0) { self.invincible = false; } } }; return self; }); /**** * Asset Initialization ****/ // Hero: red box // Monster: green ellipse // Trap: yellow box // Treasure: blue ellipse // Door: purple box // Key class var Key = Container.expand(function () { var self = Container.call(this); // Attach key asset (gold ellipse) var keySprite = self.attachAsset('key', { anchorX: 0.5, anchorY: 0.5 }); self.width = keySprite.width; self.height = keySprite.height; return self; }); // Mage Ball projectile class var MageBall = Container.expand(function () { var self = Container.call(this); // Create ball visual using trap asset var ballSprite = self.attachAsset('trap', { anchorX: 0.5, anchorY: 0.5, width: 60, height: 60 }); ballSprite.tint = 0x8A2BE2; // Purple magic ball self.width = ballSprite.width; self.height = ballSprite.height; // Ball properties self.vx = 0; self.vy = 0; self.speed = 4; self.lifetime = 300; // 5 seconds at 60fps // Set direction toward hero self.setDirection = function (targetX, targetY) { var dx = targetX - self.x; var dy = targetY - self.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist > 0) { self.vx = dx / dist * self.speed; self.vy = dy / dist * self.speed; } }; // Update ball movement self.update = function () { self.x += self.vx; self.y += self.vy; self.lifetime--; // Add magical sparkle effect ballSprite.rotation += 0.2; // Bounce off room walls if (self.x < roomBounds.x + self.width / 2) { self.x = roomBounds.x + self.width / 2; self.vx *= -1; } if (self.x > roomBounds.x + roomBounds.width - self.width / 2) { self.x = roomBounds.x + roomBounds.width - self.width / 2; self.vx *= -1; } if (self.y < roomBounds.y + self.height / 2) { self.y = roomBounds.y + self.height / 2; self.vy *= -1; } if (self.y > roomBounds.y + roomBounds.height - self.height / 2) { self.y = roomBounds.y + roomBounds.height - self.height / 2; self.vy *= -1; } }; return self; }); // Base Monster class var Monster = Container.expand(function () { var self = Container.call(this); // Attach monster asset (green ellipse) var monsterSprite = self.attachAsset('monster', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); // Set larger hitbox for easier collision detection self.width = monsterSprite.width * 0.4; self.height = monsterSprite.height * 0.4; // Monster health system self.maxHealth = 1; self.health = self.maxHealth; // Create heart-based health display self.hearts = []; var heartSize = 30; var heartSpacing = 35; var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize; var startX = -totalHeartsWidth / 2; for (var h = 0; h < self.maxHealth; h++) { var heart = LK.getAsset('trap', { width: heartSize, height: heartSize, anchorX: 0.5, anchorY: 0.5 }); heart.tint = 0xFF1744; // Red heart color heart.x = startX + h * heartSpacing; heart.y = -monsterSprite.height / 2 - 40; // Position above monster self.addChild(heart); self.hearts.push(heart); } // Update heart display self.updateHealthBar = function () { // Update heart visibility based on current health for (var h = 0; h < self.hearts.length; h++) { if (h < self.health) { self.hearts[h].visible = true; self.hearts[h].tint = 0xFF1744; // Red for full hearts self.hearts[h].alpha = 1.0; } else { self.hearts[h].visible = true; self.hearts[h].tint = 0x444444; // Dark gray for empty hearts self.hearts[h].alpha = 0.5; } } }; // Initialize heart display self.updateHealthBar(); // Take damage function with animation self.takeDamage = function () { self.health -= 1; self.updateHealthBar(); // Flash damage animation tween(monsterSprite, { tint: 0xFF0000 }, { duration: 150, onFinish: function onFinish() { tween(monsterSprite, { tint: 0xFFFFFF }, { duration: 200 }); } }); // Shake animation var originalX = self.x; tween(self, { x: originalX + 15 }, { duration: 50, onFinish: function onFinish() { tween(self, { x: originalX - 15 }, { duration: 50, onFinish: function onFinish() { tween(self, { x: originalX }, { duration: 50 }); } }); } }); }; // Movement direction self.vx = 0; self.vy = 0; self.speed = 0.3 + Math.random() * 0.4; // Reduced speed from 1-2 to 0.3-0.7 // Set random direction self.setRandomDirection = function () { var angle = Math.random() * Math.PI * 2; self.vx = Math.cos(angle) * self.speed; self.vy = Math.sin(angle) * self.speed; }; self.setRandomDirection(); // Called every tick self.update = function () { // Check if hero is close to this monster FIRST (within encounter distance) var dx = hero.x - self.x; var dy = hero.y - self.y; var distToHero = Math.sqrt(dx * dx + dy * dy); // If hero is within encounter distance, trigger freeze and stop moving if (distToHero < 120) { // Reduced from 200 to 120 for less aggressive encounter if (!gameFrozen) { // Trigger freeze effect gameFrozen = true; freezeTimer = FREEZE_DURATION; freezeBuffer = FREEZE_BUFFER_TIME; // Set buffer to prevent immediate damage console.log("Freeze triggered! Buffer set to:", FREEZE_BUFFER_TIME); // Apply freeze visual effect to all characters tween(hero, { tint: 0x8888ff }, { duration: 300 }); tween(self, { tint: 0x8888ff }, { duration: 300 }); for (var m = 0; m < monsters.length; m++) { if (monsters[m] !== self) { tween(monsters[m], { tint: 0x8888ff }, { duration: 300 }); } } } // Monster stays still when encountering hero return; } // Don't move if game is frozen if (gameFrozen) { return; } self.x += self.vx; self.y += self.vy; // Bounce off room walls if (self.x < roomBounds.x + self.width / 2) { self.x = roomBounds.x + self.width / 2; self.vx *= -1; } if (self.x > roomBounds.x + roomBounds.width - self.width / 2) { self.x = roomBounds.x + roomBounds.width - self.width / 2; self.vx *= -1; } if (self.y < roomBounds.y + self.height / 2) { self.y = roomBounds.y + self.height / 2; self.vy *= -1; } if (self.y > roomBounds.y + roomBounds.height - self.height / 2) { self.y = roomBounds.y + roomBounds.height - self.height / 2; self.vy *= -1; } }; return self; }); // NPC Wizard class - appears in first room to wish good luck var NPCWizard = Container.expand(function () { var self = Container.call(this); // Attach wizard sprite var wizardSprite = self.attachAsset('wizard', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.8, scaleY: 0.8 }); self.width = wizardSprite.width; self.height = wizardSprite.height; // Speech bubble properties self.showingSpeech = false; self.speechBubble = null; self.speechText = null; // Show speech bubble with good luck message self.showSpeech = function () { if (self.showingSpeech) return; self.showingSpeech = true; // Create speech bubble background self.speechBubble = LK.getAsset('door', { width: 400, height: 180, anchorX: 0.5, anchorY: 1.0 }); self.speechBubble.tint = 0xFFFFFF; self.speechBubble.alpha = 0.9; self.speechBubble.x = 0; self.speechBubble.y = -wizardSprite.height / 2 - 20; self.addChild(self.speechBubble); // Create speech text self.speechText = new Text2("Good luck in the dungeon,\nbrave adventurer!", { size: 45, fill: 0xFFFFFF, font: "Impact, Arial Black, Tahoma" }); self.speechText.anchor.set(0.5, 0.5); self.speechText.x = 0; self.speechText.y = -wizardSprite.height / 2 - 110; self.addChild(self.speechText); // Auto-hide speech after 4 seconds LK.setTimeout(function () { self.hideSpeech(); }, 4000); }; // Hide speech bubble self.hideSpeech = function () { if (!self.showingSpeech) return; self.showingSpeech = false; if (self.speechBubble) { self.speechBubble.destroy(); self.speechBubble = null; } if (self.speechText) { self.speechText.destroy(); self.speechText = null; } }; return self; }); // Orc Warrior - Room 2 var OrcWarrior = Container.expand(function () { var self = Container.call(this); // Use orc asset instead of monster asset var orcSprite = self.attachAsset('orc', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.4, scaleY: 1.4 }); // Set larger hitbox for easier collision detection self.width = orcSprite.width * 0.4; self.height = orcSprite.height * 0.4; // Monster health system self.maxHealth = 2; self.health = self.maxHealth; self.speed = 0.4; // Create heart-based health display self.hearts = []; var heartSize = 30; var heartSpacing = 35; var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize; var startX = -totalHeartsWidth / 2; for (var h = 0; h < self.maxHealth; h++) { var heart = LK.getAsset('trap', { width: heartSize, height: heartSize, anchorX: 0.5, anchorY: 0.5 }); heart.tint = 0xFF1744; heart.x = startX + h * heartSpacing; heart.y = -orcSprite.height / 2 - 40; self.addChild(heart); self.hearts.push(heart); } // Update heart display self.updateHealthBar = function () { // Update heart visibility based on current health for (var h = 0; h < self.hearts.length; h++) { if (h < self.health) { self.hearts[h].visible = true; self.hearts[h].tint = 0xFF1744; // Red for full hearts self.hearts[h].alpha = 1.0; } else { self.hearts[h].visible = true; self.hearts[h].tint = 0x444444; // Dark gray for empty hearts self.hearts[h].alpha = 0.5; } } }; // Take damage function with animation self.takeDamage = function () { self.health -= 1; self.updateHealthBar(); // Flash damage animation tween(orcSprite, { tint: 0xFF0000 }, { duration: 150, onFinish: function onFinish() { tween(orcSprite, { tint: 0xFFFFFF }, { duration: 200 }); } }); // Shake animation var originalX = self.x; tween(self, { x: originalX + 15 }, { duration: 50, onFinish: function onFinish() { tween(self, { x: originalX - 15 }, { duration: 50, onFinish: function onFinish() { tween(self, { x: originalX }, { duration: 50 }); } }); } }); }; // Movement direction self.vx = 0; self.vy = 0; // Set random direction self.setRandomDirection = function () { var angle = Math.random() * Math.PI * 2; self.vx = Math.cos(angle) * self.speed; self.vy = Math.sin(angle) * self.speed; }; self.setRandomDirection(); // Called every tick self.update = function () { // Check if hero is close to this monster FIRST (within encounter distance) var dx = hero.x - self.x; var dy = hero.y - self.y; var distToHero = Math.sqrt(dx * dx + dy * dy); // If hero is within encounter distance, trigger freeze and stop moving if (distToHero < 120) { // Reduced from 200 to 120 for less aggressive encounter if (!gameFrozen) { // Trigger freeze effect gameFrozen = true; freezeTimer = FREEZE_DURATION; freezeBuffer = FREEZE_BUFFER_TIME; // Set buffer to prevent immediate damage console.log("Freeze triggered! Buffer set to:", FREEZE_BUFFER_TIME); // Apply freeze visual effect to all characters tween(hero, { tint: 0x8888ff }, { duration: 300 }); tween(self, { tint: 0x8888ff }, { duration: 300 }); for (var m = 0; m < monsters.length; m++) { if (monsters[m] !== self) { tween(monsters[m], { tint: 0x8888ff }, { duration: 300 }); } } } // Monster stays still when encountering hero return; } // Don't move if game is frozen if (gameFrozen) { return; } self.x += self.vx; self.y += self.vy; // Bounce off room walls if (self.x < roomBounds.x + self.width / 2) { self.x = roomBounds.x + self.width / 2; self.vx *= -1; } if (self.x > roomBounds.x + roomBounds.width - self.width / 2) { self.x = roomBounds.x + roomBounds.width - self.width / 2; self.vx *= -1; } if (self.y < roomBounds.y + self.height / 2) { self.y = roomBounds.y + self.height / 2; self.vy *= -1; } if (self.y > roomBounds.y + roomBounds.height - self.height / 2) { self.y = roomBounds.y + roomBounds.height - self.height / 2; self.vy *= -1; } }; // Update hearts for new health self.hearts = []; var heartSize = 30; var heartSpacing = 35; var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize; var startX = -totalHeartsWidth / 2; for (var h = 0; h < self.maxHealth; h++) { var heart = LK.getAsset('trap', { width: heartSize, height: heartSize, anchorX: 0.5, anchorY: 0.5 }); heart.tint = 0xFF1744; heart.x = startX + h * heartSpacing; heart.y = -orcSprite.height / 2 - 40; self.addChild(heart); self.hearts.push(heart); } self.updateHealthBar(); return self; }); // Skeleton Boss - Room 1 var SkeletonBoss = Container.expand(function () { var self = Container.call(this); // Use skeleton asset instead of monster asset var skeletonSprite = self.attachAsset('skeleton', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); // Set larger hitbox for easier collision detection self.width = skeletonSprite.width * 0.4; self.height = skeletonSprite.height * 0.4; // Monster health system self.maxHealth = 1; self.health = self.maxHealth; self.speed = 0.5; // Create heart-based health display self.hearts = []; var heartSize = 30; var heartSpacing = 35; var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize; var startX = -totalHeartsWidth / 2; for (var h = 0; h < self.maxHealth; h++) { var heart = LK.getAsset('trap', { width: heartSize, height: heartSize, anchorX: 0.5, anchorY: 0.5 }); heart.tint = 0xFF1744; heart.x = startX + h * heartSpacing; heart.y = -skeletonSprite.height / 2 - 40; self.addChild(heart); self.hearts.push(heart); } // Update heart display self.updateHealthBar = function () { // Update heart visibility based on current health for (var h = 0; h < self.hearts.length; h++) { if (h < self.health) { self.hearts[h].visible = true; self.hearts[h].tint = 0xFF1744; // Red for full hearts self.hearts[h].alpha = 1.0; } else { self.hearts[h].visible = true; self.hearts[h].tint = 0x444444; // Dark gray for empty hearts self.hearts[h].alpha = 0.5; } } }; // Take damage function with animation self.takeDamage = function () { self.health -= 1; self.updateHealthBar(); // Flash damage animation tween(skeletonSprite, { tint: 0xFF0000 }, { duration: 150, onFinish: function onFinish() { tween(skeletonSprite, { tint: 0xFFFFFF }, { duration: 200 }); } }); // Shake animation var originalX = self.x; tween(self, { x: originalX + 15 }, { duration: 50, onFinish: function onFinish() { tween(self, { x: originalX - 15 }, { duration: 50, onFinish: function onFinish() { tween(self, { x: originalX }, { duration: 50 }); } }); } }); }; // Movement direction self.vx = 0; self.vy = 0; // Set random direction self.setRandomDirection = function () { var angle = Math.random() * Math.PI * 2; self.vx = Math.cos(angle) * self.speed; self.vy = Math.sin(angle) * self.speed; }; self.setRandomDirection(); // Called every tick self.update = function () { // Check if hero is close to this monster FIRST (within encounter distance) var dx = hero.x - self.x; var dy = hero.y - self.y; var distToHero = Math.sqrt(dx * dx + dy * dy); // If hero is within encounter distance, trigger freeze and stop moving if (distToHero < 120) { // Reduced from 200 to 120 for less aggressive encounter if (!gameFrozen) { // Trigger freeze effect gameFrozen = true; freezeTimer = FREEZE_DURATION; freezeBuffer = FREEZE_BUFFER_TIME; // Set buffer to prevent immediate damage console.log("Freeze triggered! Buffer set to:", FREEZE_BUFFER_TIME); // Apply freeze visual effect to all characters tween(hero, { tint: 0x8888ff }, { duration: 300 }); tween(self, { tint: 0x8888ff }, { duration: 300 }); for (var m = 0; m < monsters.length; m++) { if (monsters[m] !== self) { tween(monsters[m], { tint: 0x8888ff }, { duration: 300 }); } } } // Monster stays still when encountering hero return; } // Don't move if game is frozen if (gameFrozen) { return; } self.x += self.vx; self.y += self.vy; // Bounce off room walls if (self.x < roomBounds.x + self.width / 2) { self.x = roomBounds.x + self.width / 2; self.vx *= -1; } if (self.x > roomBounds.x + roomBounds.width - self.width / 2) { self.x = roomBounds.x + roomBounds.width - self.width / 2; self.vx *= -1; } if (self.y < roomBounds.y + self.height / 2) { self.y = roomBounds.y + self.height / 2; self.vy *= -1; } if (self.y > roomBounds.y + roomBounds.height - self.height / 2) { self.y = roomBounds.y + roomBounds.height - self.height / 2; self.vy *= -1; } }; // Skeleton stats self.maxHealth = 1; self.health = self.maxHealth; self.speed = 0.5; // Update hearts for new health self.hearts = []; var heartSize = 30; var heartSpacing = 35; var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize; var startX = -totalHeartsWidth / 2; for (var h = 0; h < self.maxHealth; h++) { var heart = LK.getAsset('trap', { width: heartSize, height: heartSize, anchorX: 0.5, anchorY: 0.5 }); heart.tint = 0xFF1744; heart.x = startX + h * heartSpacing; heart.y = -skeletonSprite.height / 2 - 40; self.addChild(heart); self.hearts.push(heart); } self.updateHealthBar(); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2C1810 }); /**** * Game Code ****/ // Create dungeon floor texture with pixel-by-pixel stone pattern var dungeonFloor = new Container(); var stoneColors = [0x4A4A4A, 0x3A3A3A, 0x5A5A5A, 0x2A2A2A, 0x6A6A6A]; // Various gray stone colors var mossColors = [0x2D4A2D, 0x1F3A1F, 0x3D5A3D]; // Mossy accents var dirtColors = [0x4A3A2A, 0x5A4A3A, 0x3A2A1A]; // Dirt between stones // Create pixelated stone floor for (var row = 0; row < 68; row++) { // Cover full height (2732/40 = ~68 rows) for (var col = 0; col < 52; col++) { // Cover full width (2048/40 = ~52 cols) var pixelSize = 40; var x = col * pixelSize; var y = row * pixelSize; // Determine pixel type based on position for realistic stone pattern var isStone = (row + col) % 3 !== 0; // Most pixels are stone var isMoss = Math.random() < 0.05; // 5% chance for moss var isDirt = Math.random() < 0.08; // 8% chance for dirt var color; if (isMoss) { color = mossColors[Math.floor(Math.random() * mossColors.length)]; } else if (isDirt) { color = dirtColors[Math.floor(Math.random() * dirtColors.length)]; } else { color = stoneColors[Math.floor(Math.random() * stoneColors.length)]; } var pixel = LK.getAsset('trap', { width: pixelSize, height: pixelSize, anchorX: 0, anchorY: 0, x: x, y: y }); pixel.tint = color; dungeonFloor.addChild(pixel); } } // Add dungeon floor as background layer game.addChildAt(dungeonFloor, 0); // Add at bottom layer // Tween plugin for animations // --- Start Screen Overlay --- var startScreenOverlay = new Container(); startScreenOverlay.zIndex = 10000; // ensure on top // Dark background for better text readability var startBackground = LK.getAsset('trap', { width: 2048, height: 2732, anchorX: 0, anchorY: 0, x: 0, y: 0 }); startBackground.tint = 0x000000; startBackground.alpha = 0.85; startScreenOverlay.addChild(startBackground); // Welcome message var welcomeText = new Text2("Welcome, Hero!", { size: 120, fill: 0xFFD700, font: "Impact, Arial Black, Tahoma" }); welcomeText.anchor.set(0.5, 0.5); welcomeText.x = 2048 / 2; welcomeText.y = 600; startScreenOverlay.addChild(welcomeText); // Title var titleText = new Text2("Brave Adventurer", { size: 180, fill: "#fff", font: "Impact, Arial Black, Tahoma" }); titleText.anchor.set(0.5, 0.5); titleText.x = 2048 / 2; titleText.y = 800; startScreenOverlay.addChild(titleText); // Story introduction var storyText = new Text2("Enter the dark dungeon and face legendary monsters.\nDefeat bosses, collect treasures, and prove your courage!", { size: 60, fill: 0xCCCCCC, font: "Impact, Arial Black, Tahoma" }); storyText.anchor.set(0.5, 0.5); storyText.x = 2048 / 2; storyText.y = 1000; startScreenOverlay.addChild(storyText); // Subtitle var subtitleText = new Text2("Tap to move and attack. Collect keys from chests to proceed!", { size: 70, fill: 0xB8B031 }); subtitleText.anchor.set(0.5, 0.5); subtitleText.x = 2048 / 2; subtitleText.y = 1200; startScreenOverlay.addChild(subtitleText); // Play Button var playBtnWidth = 600; var playBtnHeight = 180; var playBtn = LK.getAsset('door', { width: playBtnWidth, height: playBtnHeight, anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 1600 }); playBtn.tint = 0x4A8B3B; // Green tint for play button startScreenOverlay.addChild(playBtn); var playBtnText = new Text2("START ADVENTURE", { size: 90, fill: "#fff", font: "Impact, Arial Black, Tahoma" }); playBtnText.anchor.set(0.5, 0.5); playBtnText.x = 2048 / 2; playBtnText.y = 1600; startScreenOverlay.addChild(playBtnText); // Add pulsing animation to play button tween(playBtn, { scaleX: 1.1, scaleY: 1.1 }, { duration: 800, loop: true, pingpong: true }); tween(playBtnText, { scaleX: 1.1, scaleY: 1.1 }, { duration: 800, loop: true, pingpong: true }); // Instructions text var instructionsText = new Text2("Tap the button above to begin your quest", { size: 50, fill: 0x888888, font: "Impact, Arial Black, Tahoma" }); instructionsText.anchor.set(0.5, 0.5); instructionsText.x = 2048 / 2; instructionsText.y = 1800; startScreenOverlay.addChild(instructionsText); // Add overlay to game game.addChild(startScreenOverlay); // Block game input until started var gameStarted = false; // Start game handler function startGame() { if (gameStarted) return; gameStarted = true; // Fade out start screen with smooth transition tween(startScreenOverlay, { alpha: 0 }, { duration: 500, onFinish: function onFinish() { startScreenOverlay.visible = false; startScreenOverlay.alpha = 1; // Reset for potential restart } }); // Flash screen to indicate game start LK.effects.flashScreen(0x4A8B3B, 300); } // Listen for tap/click on play button startScreenOverlay.down = function (x, y, obj) { // Check if tap is inside play button var local = playBtn.toLocal(startScreenOverlay.toGlobal({ x: x, y: y })); if (local.x > -playBtnWidth / 2 && local.x < playBtnWidth / 2 && local.y > -playBtnHeight / 2 && local.y < playBtnHeight / 2) { startGame(); } }; // Intercept all input until game started var oldGameDown = game.down; game.down = function (x, y, obj) { if (!gameStarted) { if (typeof startScreenOverlay.down === "function") startScreenOverlay.down(x, y, obj); return; } if (typeof oldGameDown === "function") oldGameDown(x, y, obj); }; var oldGameMove = game.move; game.move = function (x, y, obj) { if (!gameStarted) return; if (typeof oldGameMove === "function") oldGameMove(x, y, obj); }; var oldGameUp = game.up; game.up = function (x, y, obj) { if (!gameStarted) return; if (typeof oldGameUp === "function") oldGameUp(x, y, obj); }; // Room bounds (centered, with margin) var roomMargin = 120; var roomBounds = { x: roomMargin, y: roomMargin + 100, // leave top 100px for menu width: 2048 - roomMargin * 2, height: 2732 - roomMargin * 2 - 100 }; // Game state var hero; var monsters = []; var mageBalls = []; // Track mage projectiles var door; var keys = []; var chests = []; var hasKey = false; var draggingHero = false; var lastMoveX = 0, lastMoveY = 0; var currentRoom = 1; var maxRooms = 5; var monstersDefeated = 0; var roomCleared = false; var gameFrozen = false; var freezeTimer = 0; var FREEZE_DURATION = 120; // 2 seconds at 60fps var freezeBuffer = 0; // Buffer to prevent immediate damage after freeze var FREEZE_BUFFER_TIME = 30; // 30 frames buffer after freeze starts (0.5 seconds) var healUsesRemaining = 3; // Player can use heal 3 times total // GUI elements var scoreTxt = new Text2('Score: 0', { size: 90, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); scoreTxt.y = 20; LK.gui.top.addChild(scoreTxt); // Room indicator var roomTxt = new Text2('Room 1', { size: 80, fill: 0xFFD700 }); roomTxt.anchor.set(0, 0); roomTxt.x = 120; roomTxt.y = 20; LK.gui.topLeft.addChild(roomTxt); // Health indicator text var healthTxt = new Text2('Health: Full', { size: 70, fill: 0xFF4444 }); healthTxt.anchor.set(1, 0); healthTxt.x = -20; healthTxt.y = 20; LK.gui.topRight.addChild(healthTxt); // Helper to update health display - now updates the health bar on the character function updateHealthDisplay() { // This will be handled by the health bar on the character } // Helper to update score display function updateScoreDisplay() { var score = monstersDefeated * 5; scoreTxt.setText('Score: ' + score); } // Helper to update room display function updateRoomDisplay() { roomTxt.setText('Room ' + currentRoom); } // Helper to update health display // Helper to clear room function clearRoom() { for (var i = 0; i < monsters.length; i++) monsters[i].destroy(); for (var i = 0; i < keys.length; i++) keys[i].destroy(); for (var i = 0; i < chests.length; i++) chests[i].destroy(); for (var i = 0; i < mageBalls.length; i++) mageBalls[i].destroy(); monsters = []; keys = []; chests = []; mageBalls = []; if (door) { door.destroy(); door = null; } // Clear NPC reference if it exists if (game.npcWizard) { game.npcWizard.destroy(); game.npcWizard = null; } roomCleared = false; hasKey = false; } // Helper to generate a room function generateRoom(roomNum) { clearRoom(); // Place hero at entrance (bottom center) hero.x = roomBounds.x + roomBounds.width / 2; hero.y = roomBounds.y + roomBounds.height - hero.height; // Helper function to check if position is safe from hero spawn area function isPositionSafeFromHeroSpawn(x, y, heroStartX, heroStartY, safeDistance) { var dx = x - heroStartX; var dy = y - heroStartY; var dist = Math.sqrt(dx * dx + dy * dy); return dist > safeDistance; } // Place monsters - exactly 1 boss monster per room based on room number var monsterCount = 1; var heroStartX = roomBounds.x + roomBounds.width / 2; var heroStartY = roomBounds.y + roomBounds.height - hero.height; var heroSafeDistance = 400; // Increased safe distance around hero spawn for (var i = 0; i < monsterCount; i++) { var m; // Create different boss types based on room number if (roomNum === 1) { m = new SkeletonBoss(); } else if (roomNum === 2) { m = new OrcWarrior(); } else if (roomNum === 3) { m = new DarkMage(); } else if (roomNum === 4) { m = new FireDemon(); } else if (roomNum === 5) { m = new DragonLord(); } else { // Fallback for any additional rooms m = new Monster(); } var validPosition = false; var attempts = 0; // Try to find a position that's not too close to hero spawn while (!validPosition && attempts < 50) { m.x = roomBounds.x + 100 + Math.random() * (roomBounds.width - 200); m.y = roomBounds.y + 200 + Math.random() * (roomBounds.height - 400); if (isPositionSafeFromHeroSpawn(m.x, m.y, heroStartX, heroStartY, heroSafeDistance)) { validPosition = true; } attempts++; } monsters.push(m); game.addChild(m); } // Key will come from chest after killing all monsters, so don't place it randomly // Place chest (always one per room) var c = new Chest(); var validPosition = false; var attempts = 0; while (!validPosition && attempts < 50) { c.x = roomBounds.x + 100 + Math.random() * (roomBounds.width - 200); c.y = roomBounds.y + 200 + Math.random() * (roomBounds.height - 400); if (isPositionSafeFromHeroSpawn(c.x, c.y, heroStartX, heroStartY, heroSafeDistance)) { validPosition = true; } attempts++; } chests.push(c); game.addChild(c); // Place door (top center) door = new Door(); door.x = roomBounds.x + roomBounds.width / 2; door.y = roomBounds.y + door.height / 2; game.addChild(door); door.visible = false; // Only show when room is cleared // Place NPC wizard only in first room if (roomNum === 1) { var npcWizard = new NPCWizard(); npcWizard.x = roomBounds.x + 200; // Position near left wall npcWizard.y = roomBounds.y + roomBounds.height / 2; // Center vertically game.addChild(npcWizard); // Store reference for proximity check game.npcWizard = npcWizard; } roomCleared = false; updateRoomDisplay(); updateHealthDisplay(); } // Create hero hero = new Hero(); game.addChild(hero); // Start first room generateRoom(currentRoom); updateScoreDisplay(); // Dragging logic game.down = function (x, y, obj) { // Only start drag if touch is on hero var local = hero.toLocal(game.toGlobal({ x: x, y: y })); if (local.x > -hero.width / 2 && local.x < hero.width / 2 && local.y > -hero.height / 2 && local.y < hero.height / 2) { draggingHero = true; lastMoveX = x; lastMoveY = y; } }; game.up = function (x, y, obj) { draggingHero = false; }; function clamp(val, min, max) { return Math.max(min, Math.min(max, val)); } // Walk-to destination variables var walkToActive = false; var walkToX = 0; var walkToY = 0; var walkToSpeed = 22; // Attack button for attacking monsters - round dungeon-themed button var killButton = LK.getAsset('monster', { width: 280, height: 280, anchorX: 0.5, anchorY: 0.5, x: 2048 - 160, y: 2732 - 160 }); killButton.tint = 0x4A4A4A; // Dark steel gray for shield-like appearance killButton.alpha = 0.9; // Slightly transparent for better integration game.addChild(killButton); var killButtonText = new Text2("ATTACK", { size: 60, fill: 0xFFD700, font: "Impact, Arial Black, Tahoma" }); killButtonText.anchor.set(0.5, 0.5); killButtonText.x = 2048 - 160; killButtonText.y = 2732 - 160; game.addChild(killButtonText); // Heal pot button next to attack button var healButton = LK.getAsset('chest', { width: 280, height: 280, anchorX: 0.5, anchorY: 0.5, x: 2048 - 460, // Position to the left of attack button y: 2732 - 160 }); healButton.tint = 0xFF4444; // Red tint for health potion healButton.alpha = 0.9; game.addChild(healButton); var healButtonText = new Text2("HEAL", { size: 60, fill: 0xFFD700, font: "Impact, Arial Black, Tahoma" }); healButtonText.anchor.set(0.5, 0.5); healButtonText.x = 2048 - 460; healButtonText.y = 2732 - 160; game.addChild(healButtonText); // Open chest text var openChestText = new Text2("OPEN CHEST", { size: 80, fill: 0xFFD700, font: "Impact, Arial Black, Tahoma" }); openChestText.anchor.set(0.5, 0.5); openChestText.x = 2048 / 2; openChestText.y = 2732 - 200; openChestText.visible = false; game.addChild(openChestText); // Sword swing state management var swordSwinging = false; var swordCooldown = 0; var SWORD_COOLDOWN_TIME = 15; // frames (0.25 seconds at 60fps) // Move handler game.move = function (x, y, obj) { if (draggingHero) { // Clamp hero inside room bounds var hx = clamp(x, roomBounds.x + hero.width / 2, roomBounds.x + roomBounds.width - hero.width / 2); var hy = clamp(y, roomBounds.y + hero.height / 2, roomBounds.y + roomBounds.height - hero.height / 2); hero.x = hx; hero.y = hy; walkToActive = false; // Cancel walk-to if dragging } }; // Tap-to-walk logic: on down, if not on hero, set walk-to destination var oldGameDown = game.down; game.down = function (x, y, obj) { // Only start drag if touch is on hero var local = hero.toLocal(game.toGlobal({ x: x, y: y })); // Check if heal button was tapped var healButtonLocal = healButton.toLocal(game.toGlobal({ x: x, y: y })); if (healButtonLocal.x > -healButton.width / 2 && healButtonLocal.x < healButton.width / 2 && healButtonLocal.y > -healButton.height / 2 && healButtonLocal.y < healButton.height / 2) { // Check if we have heal uses remaining if (healUsesRemaining > 0) { // Use heal function from hero hero.heal(); healUsesRemaining--; } return; // Don't process other touch logic } // Check if kill button was tapped var killButtonLocal = killButton.toLocal(game.toGlobal({ x: x, y: y })); if (killButtonLocal.x > -killButton.width / 2 && killButtonLocal.x < killButton.width / 2 && killButtonLocal.y > -killButton.height / 2 && killButtonLocal.y < killButton.height / 2) { // Check if sword is available (not swinging and cooldown expired) if (!swordSwinging && swordCooldown <= 0) { // Get sword sprite from hero for animation var swordSprite = hero.children[1]; // Sword is the second child (index 1) // Stop any existing tweens on the sword tween.stop(swordSprite, { rotation: true }); // Set swinging state swordSwinging = true; swordCooldown = SWORD_COOLDOWN_TIME; // Create sword swing effect var originalRotation = swordSprite.rotation; tween(swordSprite, { rotation: originalRotation + Math.PI / 2 }, { duration: 150, easing: tween.easeOut, onFinish: function onFinish() { tween(swordSprite, { rotation: originalRotation }, { duration: 200, easing: tween.easeIn, onFinish: function onFinish() { swordSwinging = false; } }); } }); // Kill button tapped - damage all monsters within 350px of hero for (var i = monsters.length - 1; i >= 0; i--) { var m = monsters[i]; var dx = hero.x - m.x; var dy = hero.y - m.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < 500) { // Deal damage to monster m.takeDamage(); // Optional: flash hero for feedback LK.effects.flashObject(hero, 0xffffff, 120); // Check if monster is dead if (m.health <= 0) { // Remove monster m.destroy(); monsters.splice(i, 1); monstersDefeated++; updateScoreDisplay(); } // Unfreeze game when monster dies if (gameFrozen) { gameFrozen = false; freezeTimer = 0; // Remove freeze visual effects tween(hero, { tint: 0xffffff }, { duration: 300 }); for (var j = 0; j < monsters.length; j++) { tween(monsters[j], { tint: 0xffffff }, { duration: 300 }); } } } } } return; // Don't process other touch logic } if (local.x > -hero.width / 2 && local.x < hero.width / 2 && local.y > -hero.height / 2 && local.y < hero.height / 2) { draggingHero = true; lastMoveX = x; lastMoveY = y; walkToActive = false; } else { // Set walk-to destination if tap is inside room var hx = clamp(x, roomBounds.x + hero.width / 2, roomBounds.x + roomBounds.width - hero.width / 2); var hy = clamp(y, roomBounds.y + hero.height / 2, roomBounds.y + roomBounds.height - hero.height / 2); walkToX = hx; walkToY = hy; walkToActive = true; } if (typeof oldGameDown === "function") oldGameDown(x, y, obj); }; // In update, move hero toward walk-to destination if active var oldGameUpdate = game.update; game.update = function () { // Walk-to logic if (walkToActive && !draggingHero) { var dx = walkToX - hero.x; var dy = walkToY - hero.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist > walkToSpeed) { hero.x += dx / dist * walkToSpeed; hero.y += dy / dist * walkToSpeed; } else { hero.x = walkToX; hero.y = walkToY; walkToActive = false; } } if (typeof oldGameUpdate === "function") oldGameUpdate(); }; // Main update loop game.update = function () { if (!gameStarted) return; // Handle freeze timer if (gameFrozen) { freezeTimer--; if (freezeTimer <= 0) { // Unfreeze game gameFrozen = false; // Remove freeze visual effects tween(hero, { tint: 0xffffff }, { duration: 300 }); for (var m = 0; m < monsters.length; m++) { tween(monsters[m], { tint: 0xffffff }, { duration: 300 }); } } } // Update sword cooldown if (swordCooldown > 0) { swordCooldown--; } // Update freeze buffer if (freezeBuffer > 0) { freezeBuffer--; } // Update hero (only if not frozen) if (!gameFrozen) { hero.update(); } // Update monsters for (var i = 0; i < monsters.length; i++) { monsters[i].update(); } // Update mage balls for (var i = mageBalls.length - 1; i >= 0; i--) { var ball = mageBalls[i]; ball.update(); // Remove ball if lifetime expired if (ball.lifetime <= 0) { ball.destroy(); mageBalls.splice(i, 1); continue; } // Check collision with hero (only when not invincible and no freeze buffer) if (!hero.invincible && freezeBuffer <= 0 && hero.intersects(ball)) { hero.takeDamage(); // Destroy ball on hit ball.destroy(); mageBalls.splice(i, 1); // Create impact effect LK.effects.flashObject(hero, 0x8A2BE2, 200); } } // Attack button is always visible killButton.visible = true; killButtonText.visible = true; // Heal button visibility and text update based on remaining uses if (healUsesRemaining > 0) { healButton.visible = true; healButtonText.visible = true; healButton.alpha = 0.9; healButtonText.setText("HEAL (" + healUsesRemaining + ")"); } else { healButton.visible = true; healButtonText.visible = true; healButton.alpha = 0.3; // Make button appear disabled healButtonText.setText("NO HEALS"); } // Check if hero is close to chest and all monsters are defeated var nearChest = false; if (monsters.length === 0) { for (var i = 0; i < chests.length; i++) { var c = chests[i]; if (!c.opened) { var dx = hero.x - c.x; var dy = hero.y - c.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < 200) { nearChest = true; break; } } } } // Show/hide open chest text based on proximity and game state openChestText.visible = nearChest; // Check collisions: hero vs monsters (only when game is not frozen, no freeze buffer, and hero is not invincible) if (!gameFrozen && freezeBuffer <= 0 && !hero.invincible) { for (var i = monsters.length - 1; i >= 0; i--) { var m = monsters[i]; if (hero.intersects(m)) { hero.takeDamage(); // No knockback - hero stays in place when touching monsters // Hero can only kill monsters with the kill button, not by collision } } } // Check collisions: hero vs keys for (var i = keys.length - 1; i >= 0; i--) { var k = keys[i]; if (hero.intersects(k)) { k.destroy(); keys.splice(i, 1); hasKey = true; LK.effects.flashObject(hero, 0xFFD700, 300); } } // Check collisions: hero vs chests for (var i = 0; i < chests.length; i++) { var c = chests[i]; if (hero.intersects(c) && monsters.length === 0 && !c.opened) { c.opened = true; LK.effects.flashObject(c, 0x83de44, 600); updateScoreDisplay(); // Spawn key from chest after all monsters are defeated var k = new Key(); k.x = c.x; k.y = c.y; keys.push(k); game.addChild(k); } } // Room clear check - need to defeat all monsters first, then open chest, then collect key if (!roomCleared && monsters.length === 0 && chests.length > 0 && chests[0].opened && hasKey) { roomCleared = true; door.visible = true; LK.effects.flashObject(door, 0x83de44, 600); } // Check if hero is near NPC wizard in first room if (currentRoom === 1 && game.npcWizard && !game.npcWizard.showingSpeech) { var dx = hero.x - game.npcWizard.x; var dy = hero.y - game.npcWizard.y; var distToNPC = Math.sqrt(dx * dx + dy * dy); if (distToNPC < 250) { // Show speech when hero gets close game.npcWizard.showSpeech(); } } // Check hero at door to next room if (roomCleared && door && hero.intersects(door)) { if (currentRoom < maxRooms) { currentRoom++; generateRoom(currentRoom); } else { // Win! LK.setScore(monstersDefeated * 5); LK.showYouWin(); } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Chest class
var Chest = Container.expand(function () {
var self = Container.call(this);
// Attach chest asset (brown box)
var chestSprite = self.attachAsset('chest', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = chestSprite.width;
self.height = chestSprite.height;
self.opened = false;
return self;
});
// Dark Mage - Room 3
var DarkMage = Container.expand(function () {
var self = Container.call(this);
// Use mage asset instead of monster asset
var mageSprite = self.attachAsset('mage', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.1,
scaleY: 1.1
});
// Set larger hitbox for easier collision detection
self.width = mageSprite.width * 0.4;
self.height = mageSprite.height * 0.4;
// Monster health system
self.maxHealth = 3;
self.health = self.maxHealth;
self.speed = 0.6;
// Create heart-based health display
self.hearts = [];
var heartSize = 30;
var heartSpacing = 35;
var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize;
var startX = -totalHeartsWidth / 2;
for (var h = 0; h < self.maxHealth; h++) {
var heart = LK.getAsset('trap', {
width: heartSize,
height: heartSize,
anchorX: 0.5,
anchorY: 0.5
});
heart.tint = 0xFF1744;
heart.x = startX + h * heartSpacing;
heart.y = -mageSprite.height / 2 - 40;
self.addChild(heart);
self.hearts.push(heart);
}
// Update heart display
self.updateHealthBar = function () {
// Update heart visibility based on current health
for (var h = 0; h < self.hearts.length; h++) {
if (h < self.health) {
self.hearts[h].visible = true;
self.hearts[h].tint = 0xFF1744; // Red for full hearts
self.hearts[h].alpha = 1.0;
} else {
self.hearts[h].visible = true;
self.hearts[h].tint = 0x444444; // Dark gray for empty hearts
self.hearts[h].alpha = 0.5;
}
}
};
// Take damage function with animation
self.takeDamage = function () {
self.health -= 1;
self.updateHealthBar();
// Flash damage animation
tween(mageSprite, {
tint: 0xFF0000
}, {
duration: 150,
onFinish: function onFinish() {
tween(mageSprite, {
tint: 0xFFFFFF
}, {
duration: 200
});
}
});
// Shake animation
var originalX = self.x;
tween(self, {
x: originalX + 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX - 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX
}, {
duration: 50
});
}
});
}
});
};
// Movement direction
self.vx = 0;
self.vy = 0;
// Set random direction
self.setRandomDirection = function () {
var angle = Math.random() * Math.PI * 2;
self.vx = Math.cos(angle) * self.speed;
self.vy = Math.sin(angle) * self.speed;
};
self.setRandomDirection();
// Shooting timer
self.shootTimer = 0;
self.shootInterval = 90; // Shoot every 1.5 seconds at 60fps
// Called every tick
self.update = function () {
// Check if hero is close to this monster FIRST (within encounter distance)
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var distToHero = Math.sqrt(dx * dx + dy * dy);
// If hero is within encounter distance, trigger freeze and stop moving
if (distToHero < 120) {
// Reduced from 200 to 120 for less aggressive encounter
if (!gameFrozen) {
// Trigger freeze effect
gameFrozen = true;
freezeTimer = FREEZE_DURATION;
freezeBuffer = FREEZE_BUFFER_TIME; // Set buffer to prevent immediate damage
console.log("Freeze triggered! Buffer set to:", FREEZE_BUFFER_TIME);
// Apply freeze visual effect to all characters
tween(hero, {
tint: 0x8888ff
}, {
duration: 300
});
tween(self, {
tint: 0x8888ff
}, {
duration: 300
});
for (var m = 0; m < monsters.length; m++) {
if (monsters[m] !== self) {
tween(monsters[m], {
tint: 0x8888ff
}, {
duration: 300
});
}
}
}
// Monster stays still when encountering hero
return;
}
// Don't move if game is frozen
if (gameFrozen) {
return;
}
// Mage shooting logic - shoot projectiles at hero
self.shootTimer++;
if (self.shootTimer >= self.shootInterval) {
self.shootTimer = 0;
// Create magic ball projectile
var ball = new MageBall();
ball.x = self.x;
ball.y = self.y;
ball.setDirection(hero.x, hero.y);
game.addChild(ball);
mageBalls.push(ball);
// Visual effect when shooting
tween(mageSprite, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 200,
onFinish: function onFinish() {
tween(mageSprite, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200
});
}
});
}
self.x += self.vx;
self.y += self.vy;
// Bounce off room walls
if (self.x < roomBounds.x + self.width / 2) {
self.x = roomBounds.x + self.width / 2;
self.vx *= -1;
}
if (self.x > roomBounds.x + roomBounds.width - self.width / 2) {
self.x = roomBounds.x + roomBounds.width - self.width / 2;
self.vx *= -1;
}
if (self.y < roomBounds.y + self.height / 2) {
self.y = roomBounds.y + self.height / 2;
self.vy *= -1;
}
if (self.y > roomBounds.y + roomBounds.height - self.height / 2) {
self.y = roomBounds.y + roomBounds.height - self.height / 2;
self.vy *= -1;
}
};
// Update hearts for new health
self.hearts = [];
var heartSize = 30;
var heartSpacing = 35;
var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize;
var startX = -totalHeartsWidth / 2;
for (var h = 0; h < self.maxHealth; h++) {
var heart = LK.getAsset('trap', {
width: heartSize,
height: heartSize,
anchorX: 0.5,
anchorY: 0.5
});
heart.tint = 0xFF1744;
heart.x = startX + h * heartSpacing;
heart.y = -mageSprite.height / 2 - 40;
self.addChild(heart);
self.hearts.push(heart);
}
self.updateHealthBar();
return self;
});
// Door class (for next room)
var Door = Container.expand(function () {
var self = Container.call(this);
// Attach door asset (purple box)
var doorSprite = self.attachAsset('door', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = doorSprite.width;
self.height = doorSprite.height;
return self;
});
// Dragon Lord - Final Boss Room 5
var DragonLord = Container.expand(function () {
var self = Container.call(this);
// Use dragon asset instead of monster asset
var dragonSprite = self.attachAsset('dragon', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2.0,
scaleY: 2.0
});
// Set larger hitbox for easier collision detection
self.width = dragonSprite.width * 0.4;
self.height = dragonSprite.height * 0.4;
// Monster health system
self.maxHealth = 6;
self.health = self.maxHealth;
self.speed = 0.2;
// Create heart-based health display
self.hearts = [];
var heartSize = 30;
var heartSpacing = 35;
var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize;
var startX = -totalHeartsWidth / 2;
for (var h = 0; h < self.maxHealth; h++) {
var heart = LK.getAsset('trap', {
width: heartSize,
height: heartSize,
anchorX: 0.5,
anchorY: 0.5
});
heart.tint = 0xFF1744;
heart.x = startX + h * heartSpacing;
heart.y = -dragonSprite.height / 2 - 40;
self.addChild(heart);
self.hearts.push(heart);
}
// Update heart display
self.updateHealthBar = function () {
// Update heart visibility based on current health
for (var h = 0; h < self.hearts.length; h++) {
if (h < self.health) {
self.hearts[h].visible = true;
self.hearts[h].tint = 0xFF1744; // Red for full hearts
self.hearts[h].alpha = 1.0;
} else {
self.hearts[h].visible = true;
self.hearts[h].tint = 0x444444; // Dark gray for empty hearts
self.hearts[h].alpha = 0.5;
}
}
};
// Take damage function with animation
self.takeDamage = function () {
self.health -= 1;
self.updateHealthBar();
// Flash damage animation
tween(dragonSprite, {
tint: 0xFF0000
}, {
duration: 150,
onFinish: function onFinish() {
tween(dragonSprite, {
tint: 0xFFFFFF
}, {
duration: 200
});
}
});
// Shake animation
var originalX = self.x;
tween(self, {
x: originalX + 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX - 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX
}, {
duration: 50
});
}
});
}
});
};
// Movement direction
self.vx = 0;
self.vy = 0;
// Set random direction
self.setRandomDirection = function () {
var angle = Math.random() * Math.PI * 2;
self.vx = Math.cos(angle) * self.speed;
self.vy = Math.sin(angle) * self.speed;
};
self.setRandomDirection();
// Called every tick
self.update = function () {
// Check if hero is close to this monster FIRST (within encounter distance)
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var distToHero = Math.sqrt(dx * dx + dy * dy);
// If hero is within encounter distance, trigger freeze and stop moving
if (distToHero < 120) {
// Reduced from 200 to 120 for less aggressive encounter
if (!gameFrozen) {
// Trigger freeze effect
gameFrozen = true;
freezeTimer = FREEZE_DURATION;
freezeBuffer = FREEZE_BUFFER_TIME; // Set buffer to prevent immediate damage
console.log("Freeze triggered! Buffer set to:", FREEZE_BUFFER_TIME);
// Apply freeze visual effect to all characters
tween(hero, {
tint: 0x8888ff
}, {
duration: 300
});
tween(self, {
tint: 0x8888ff
}, {
duration: 300
});
for (var m = 0; m < monsters.length; m++) {
if (monsters[m] !== self) {
tween(monsters[m], {
tint: 0x8888ff
}, {
duration: 300
});
}
}
}
// Monster stays still when encountering hero
return;
}
// Don't move if game is frozen
if (gameFrozen) {
return;
}
self.x += self.vx;
self.y += self.vy;
// Bounce off room walls
if (self.x < roomBounds.x + self.width / 2) {
self.x = roomBounds.x + self.width / 2;
self.vx *= -1;
}
if (self.x > roomBounds.x + roomBounds.width - self.width / 2) {
self.x = roomBounds.x + roomBounds.width - self.width / 2;
self.vx *= -1;
}
if (self.y < roomBounds.y + self.height / 2) {
self.y = roomBounds.y + self.height / 2;
self.vy *= -1;
}
if (self.y > roomBounds.y + roomBounds.height - self.height / 2) {
self.y = roomBounds.y + roomBounds.height - self.height / 2;
self.vy *= -1;
}
};
// Update hearts for new health
self.hearts = [];
var heartSize = 30;
var heartSpacing = 35;
var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize;
var startX = -totalHeartsWidth / 2;
for (var h = 0; h < self.maxHealth; h++) {
var heart = LK.getAsset('trap', {
width: heartSize,
height: heartSize,
anchorX: 0.5,
anchorY: 0.5
});
heart.tint = 0xFF1744;
heart.x = startX + h * heartSpacing;
heart.y = -dragonSprite.height / 2 - 40;
self.addChild(heart);
self.hearts.push(heart);
}
self.updateHealthBar();
return self;
});
// Fire Demon - Room 4
var FireDemon = Container.expand(function () {
var self = Container.call(this);
// Use demon asset instead of monster asset
var demonSprite = self.attachAsset('demon', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.6,
scaleY: 1.6
});
// Set larger hitbox for easier collision detection
self.width = demonSprite.width * 0.4;
self.height = demonSprite.height * 0.4;
// Monster health system
self.maxHealth = 4;
self.health = self.maxHealth;
self.speed = 0.3;
// Create heart-based health display
self.hearts = [];
var heartSize = 30;
var heartSpacing = 35;
var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize;
var startX = -totalHeartsWidth / 2;
for (var h = 0; h < self.maxHealth; h++) {
var heart = LK.getAsset('trap', {
width: heartSize,
height: heartSize,
anchorX: 0.5,
anchorY: 0.5
});
heart.tint = 0xFF1744;
heart.x = startX + h * heartSpacing;
heart.y = -demonSprite.height / 2 - 40;
self.addChild(heart);
self.hearts.push(heart);
}
// Update heart display
self.updateHealthBar = function () {
// Update heart visibility based on current health
for (var h = 0; h < self.hearts.length; h++) {
if (h < self.health) {
self.hearts[h].visible = true;
self.hearts[h].tint = 0xFF1744; // Red for full hearts
self.hearts[h].alpha = 1.0;
} else {
self.hearts[h].visible = true;
self.hearts[h].tint = 0x444444; // Dark gray for empty hearts
self.hearts[h].alpha = 0.5;
}
}
};
// Take damage function with animation
self.takeDamage = function () {
self.health -= 1;
self.updateHealthBar();
// Flash damage animation
tween(demonSprite, {
tint: 0xFF0000
}, {
duration: 150,
onFinish: function onFinish() {
tween(demonSprite, {
tint: 0xFFFFFF
}, {
duration: 200
});
}
});
// Shake animation
var originalX = self.x;
tween(self, {
x: originalX + 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX - 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX
}, {
duration: 50
});
}
});
}
});
};
// Movement direction
self.vx = 0;
self.vy = 0;
// Set random direction
self.setRandomDirection = function () {
var angle = Math.random() * Math.PI * 2;
self.vx = Math.cos(angle) * self.speed;
self.vy = Math.sin(angle) * self.speed;
};
self.setRandomDirection();
// Called every tick
self.update = function () {
// Check if hero is close to this monster FIRST (within encounter distance)
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var distToHero = Math.sqrt(dx * dx + dy * dy);
// If hero is within encounter distance, trigger freeze and stop moving
if (distToHero < 120) {
// Reduced from 200 to 120 for less aggressive encounter
if (!gameFrozen) {
// Trigger freeze effect
gameFrozen = true;
freezeTimer = FREEZE_DURATION;
freezeBuffer = FREEZE_BUFFER_TIME; // Set buffer to prevent immediate damage
console.log("Freeze triggered! Buffer set to:", FREEZE_BUFFER_TIME);
// Apply freeze visual effect to all characters
tween(hero, {
tint: 0x8888ff
}, {
duration: 300
});
tween(self, {
tint: 0x8888ff
}, {
duration: 300
});
for (var m = 0; m < monsters.length; m++) {
if (monsters[m] !== self) {
tween(monsters[m], {
tint: 0x8888ff
}, {
duration: 300
});
}
}
}
// Monster stays still when encountering hero
return;
}
// Don't move if game is frozen
if (gameFrozen) {
return;
}
self.x += self.vx;
self.y += self.vy;
// Bounce off room walls
if (self.x < roomBounds.x + self.width / 2) {
self.x = roomBounds.x + self.width / 2;
self.vx *= -1;
}
if (self.x > roomBounds.x + roomBounds.width - self.width / 2) {
self.x = roomBounds.x + roomBounds.width - self.width / 2;
self.vx *= -1;
}
if (self.y < roomBounds.y + self.height / 2) {
self.y = roomBounds.y + self.height / 2;
self.vy *= -1;
}
if (self.y > roomBounds.y + roomBounds.height - self.height / 2) {
self.y = roomBounds.y + roomBounds.height - self.height / 2;
self.vy *= -1;
}
};
// Update hearts for new health
self.hearts = [];
var heartSize = 30;
var heartSpacing = 35;
var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize;
var startX = -totalHeartsWidth / 2;
for (var h = 0; h < self.maxHealth; h++) {
var heart = LK.getAsset('trap', {
width: heartSize,
height: heartSize,
anchorX: 0.5,
anchorY: 0.5
});
heart.tint = 0xFF1744;
heart.x = startX + h * heartSpacing;
heart.y = -demonSprite.height / 2 - 40;
self.addChild(heart);
self.hearts.push(heart);
}
self.updateHealthBar();
return self;
});
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
// Attach hero asset (red box)
var heroSprite = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = heroSprite.width;
self.height = heroSprite.height;
// Attach sword to hero
var swordSprite = self.attachAsset('sword', {
anchorX: 0.5,
anchorY: 0.5
});
swordSprite.x = -heroSprite.width * 0.3; // Position sword to the left of hero
swordSprite.y = 0; // Center vertically with hero
swordSprite.rotation = -Math.PI / 4; // Angle the sword pointing left
// Hero stats
self.maxHealth = 3;
self.health = self.maxHealth;
self.invincible = false;
self.invincibleTimer = 0;
// Create health bar above character
// Health bar border (white outline)
self.healthBarBorder = LK.getAsset('trap', {
width: 200,
height: 40,
anchorX: 0.5,
anchorY: 0.5
});
self.healthBarBorder.tint = 0xFFFFFF; // White border
self.healthBarBorder.x = 0;
self.healthBarBorder.y = -heroSprite.height / 2 - 50; // Position above character
self.addChild(self.healthBarBorder);
// Health bar background (dark)
self.healthBarBackground = LK.getAsset('trap', {
width: 180,
height: 24,
anchorX: 0.5,
anchorY: 0.5
});
self.healthBarBackground.tint = 0x222222; // Dark gray background
self.healthBarBackground.x = 0;
self.healthBarBackground.y = -heroSprite.height / 2 - 50; // Position above character
self.addChild(self.healthBarBackground);
// Health bar fill (red color)
self.healthBarFill = LK.getAsset('trap', {
width: 180,
height: 24,
anchorX: 0.0,
anchorY: 0.5
});
self.healthBarFill.tint = 0xFF0000; // Red for health bar
self.healthBarFill.x = -90; // Left-aligned within background
self.healthBarFill.y = -heroSprite.height / 2 - 50; // Position above character
self.addChild(self.healthBarFill);
// Update health bar display
self.updateHealthBar = function () {
var healthPercent = self.health / self.maxHealth;
self.healthBarFill.scaleX = healthPercent;
// Keep health bar red color
self.healthBarFill.tint = 0xFF0000; // Always red
// Add pulsing effect when health is critical
if (healthPercent <= 0.25) {
tween(self.healthBarFill, {
alpha: 0.5
}, {
duration: 500,
loop: true,
pingpong: true
});
} else {
tween.stop(self.healthBarFill, {
alpha: true
});
self.healthBarFill.alpha = 1.0;
}
};
// Initialize health bar
self.updateHealthBar();
// Flash when hit
self.flash = function () {
tween(heroSprite, {
tint: 0xffffff
}, {
duration: 100,
onFinish: function onFinish() {
tween(heroSprite, {
tint: 0xd83318
}, {
duration: 200
});
}
});
};
// Take damage
self.takeDamage = function () {
if (self.invincible) return;
self.health -= 1;
self.flash();
self.invincible = true;
self.invincibleTimer = 60; // 1 second at 60fps
LK.effects.flashObject(self, 0xff0000, 300);
self.updateHealthBar();
// Create blood flow effect
for (var b = 0; b < 8; b++) {
var bloodDrop = LK.getAsset('trap', {
width: 12 + Math.random() * 8,
height: 12 + Math.random() * 8,
anchorX: 0.5,
anchorY: 0.5
});
bloodDrop.tint = 0xAA0000; // Dark red blood color
bloodDrop.x = self.x + (Math.random() - 0.5) * 60; // Random spread around hero
bloodDrop.y = self.y + (Math.random() - 0.5) * 40;
bloodDrop.alpha = 0.8 + Math.random() * 0.2;
game.addChild(bloodDrop);
// Animate blood drop falling and fading
var fallDistance = 80 + Math.random() * 120;
var fallDuration = 800 + Math.random() * 400;
tween(bloodDrop, {
y: bloodDrop.y + fallDistance,
alpha: 0,
scaleX: 0.3,
scaleY: 0.3
}, {
duration: fallDuration,
easing: tween.easeIn,
onFinish: function onFinish() {
bloodDrop.destroy();
}
});
}
if (self.health <= 0) {
LK.effects.flashScreen(0xff0000, 800);
// Create dungeon-themed game over overlay
var dungeonGameOverOverlay = new Container();
dungeonGameOverOverlay.zIndex = 10000; // ensure on top
// Dark background
var background = LK.getAsset('trap', {
width: 2048,
height: 2732,
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
background.tint = 0x000000;
background.alpha = 0.8;
dungeonGameOverOverlay.addChild(background);
// Main message
var gameOverText = new Text2("You couldn't pass the dungeon...", {
size: 120,
fill: 0xFF4444,
font: "Impact, Arial Black, Tahoma"
});
gameOverText.anchor.set(0.5, 0.5);
gameOverText.x = 2048 / 2;
gameOverText.y = 1200;
dungeonGameOverOverlay.addChild(gameOverText);
// Subtitle
var subtitleText = new Text2("The darkness consumed you in Room " + currentRoom, {
size: 80,
fill: 0x888888
});
subtitleText.anchor.set(0.5, 0.5);
subtitleText.x = 2048 / 2;
subtitleText.y = 1400;
dungeonGameOverOverlay.addChild(subtitleText);
// Score display
var finalScoreText = new Text2("Monsters Defeated: " + monstersDefeated, {
size: 70,
fill: 0xFFFF88
});
finalScoreText.anchor.set(0.5, 0.5);
finalScoreText.x = 2048 / 2;
finalScoreText.y = 1600;
dungeonGameOverOverlay.addChild(finalScoreText);
game.addChild(dungeonGameOverOverlay);
// Auto restart after 3 seconds
LK.setTimeout(function () {
LK.showGameOver();
}, 3000);
}
};
// Heal
self.heal = function () {
if (self.health < self.maxHealth) {
self.health += 1;
self.updateHealthBar();
LK.effects.flashObject(self, 0x83de44, 300);
}
};
// Called every tick
self.update = function () {
if (self.invincible) {
self.invincibleTimer--;
if (self.invincibleTimer <= 0) {
self.invincible = false;
}
}
};
return self;
});
/****
* Asset Initialization
****/
// Hero: red box
// Monster: green ellipse
// Trap: yellow box
// Treasure: blue ellipse
// Door: purple box
// Key class
var Key = Container.expand(function () {
var self = Container.call(this);
// Attach key asset (gold ellipse)
var keySprite = self.attachAsset('key', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = keySprite.width;
self.height = keySprite.height;
return self;
});
// Mage Ball projectile class
var MageBall = Container.expand(function () {
var self = Container.call(this);
// Create ball visual using trap asset
var ballSprite = self.attachAsset('trap', {
anchorX: 0.5,
anchorY: 0.5,
width: 60,
height: 60
});
ballSprite.tint = 0x8A2BE2; // Purple magic ball
self.width = ballSprite.width;
self.height = ballSprite.height;
// Ball properties
self.vx = 0;
self.vy = 0;
self.speed = 4;
self.lifetime = 300; // 5 seconds at 60fps
// Set direction toward hero
self.setDirection = function (targetX, targetY) {
var dx = targetX - self.x;
var dy = targetY - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 0) {
self.vx = dx / dist * self.speed;
self.vy = dy / dist * self.speed;
}
};
// Update ball movement
self.update = function () {
self.x += self.vx;
self.y += self.vy;
self.lifetime--;
// Add magical sparkle effect
ballSprite.rotation += 0.2;
// Bounce off room walls
if (self.x < roomBounds.x + self.width / 2) {
self.x = roomBounds.x + self.width / 2;
self.vx *= -1;
}
if (self.x > roomBounds.x + roomBounds.width - self.width / 2) {
self.x = roomBounds.x + roomBounds.width - self.width / 2;
self.vx *= -1;
}
if (self.y < roomBounds.y + self.height / 2) {
self.y = roomBounds.y + self.height / 2;
self.vy *= -1;
}
if (self.y > roomBounds.y + roomBounds.height - self.height / 2) {
self.y = roomBounds.y + roomBounds.height - self.height / 2;
self.vy *= -1;
}
};
return self;
});
// Base Monster class
var Monster = Container.expand(function () {
var self = Container.call(this);
// Attach monster asset (green ellipse)
var monsterSprite = self.attachAsset('monster', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
// Set larger hitbox for easier collision detection
self.width = monsterSprite.width * 0.4;
self.height = monsterSprite.height * 0.4;
// Monster health system
self.maxHealth = 1;
self.health = self.maxHealth;
// Create heart-based health display
self.hearts = [];
var heartSize = 30;
var heartSpacing = 35;
var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize;
var startX = -totalHeartsWidth / 2;
for (var h = 0; h < self.maxHealth; h++) {
var heart = LK.getAsset('trap', {
width: heartSize,
height: heartSize,
anchorX: 0.5,
anchorY: 0.5
});
heart.tint = 0xFF1744; // Red heart color
heart.x = startX + h * heartSpacing;
heart.y = -monsterSprite.height / 2 - 40; // Position above monster
self.addChild(heart);
self.hearts.push(heart);
}
// Update heart display
self.updateHealthBar = function () {
// Update heart visibility based on current health
for (var h = 0; h < self.hearts.length; h++) {
if (h < self.health) {
self.hearts[h].visible = true;
self.hearts[h].tint = 0xFF1744; // Red for full hearts
self.hearts[h].alpha = 1.0;
} else {
self.hearts[h].visible = true;
self.hearts[h].tint = 0x444444; // Dark gray for empty hearts
self.hearts[h].alpha = 0.5;
}
}
};
// Initialize heart display
self.updateHealthBar();
// Take damage function with animation
self.takeDamage = function () {
self.health -= 1;
self.updateHealthBar();
// Flash damage animation
tween(monsterSprite, {
tint: 0xFF0000
}, {
duration: 150,
onFinish: function onFinish() {
tween(monsterSprite, {
tint: 0xFFFFFF
}, {
duration: 200
});
}
});
// Shake animation
var originalX = self.x;
tween(self, {
x: originalX + 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX - 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX
}, {
duration: 50
});
}
});
}
});
};
// Movement direction
self.vx = 0;
self.vy = 0;
self.speed = 0.3 + Math.random() * 0.4; // Reduced speed from 1-2 to 0.3-0.7
// Set random direction
self.setRandomDirection = function () {
var angle = Math.random() * Math.PI * 2;
self.vx = Math.cos(angle) * self.speed;
self.vy = Math.sin(angle) * self.speed;
};
self.setRandomDirection();
// Called every tick
self.update = function () {
// Check if hero is close to this monster FIRST (within encounter distance)
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var distToHero = Math.sqrt(dx * dx + dy * dy);
// If hero is within encounter distance, trigger freeze and stop moving
if (distToHero < 120) {
// Reduced from 200 to 120 for less aggressive encounter
if (!gameFrozen) {
// Trigger freeze effect
gameFrozen = true;
freezeTimer = FREEZE_DURATION;
freezeBuffer = FREEZE_BUFFER_TIME; // Set buffer to prevent immediate damage
console.log("Freeze triggered! Buffer set to:", FREEZE_BUFFER_TIME);
// Apply freeze visual effect to all characters
tween(hero, {
tint: 0x8888ff
}, {
duration: 300
});
tween(self, {
tint: 0x8888ff
}, {
duration: 300
});
for (var m = 0; m < monsters.length; m++) {
if (monsters[m] !== self) {
tween(monsters[m], {
tint: 0x8888ff
}, {
duration: 300
});
}
}
}
// Monster stays still when encountering hero
return;
}
// Don't move if game is frozen
if (gameFrozen) {
return;
}
self.x += self.vx;
self.y += self.vy;
// Bounce off room walls
if (self.x < roomBounds.x + self.width / 2) {
self.x = roomBounds.x + self.width / 2;
self.vx *= -1;
}
if (self.x > roomBounds.x + roomBounds.width - self.width / 2) {
self.x = roomBounds.x + roomBounds.width - self.width / 2;
self.vx *= -1;
}
if (self.y < roomBounds.y + self.height / 2) {
self.y = roomBounds.y + self.height / 2;
self.vy *= -1;
}
if (self.y > roomBounds.y + roomBounds.height - self.height / 2) {
self.y = roomBounds.y + roomBounds.height - self.height / 2;
self.vy *= -1;
}
};
return self;
});
// NPC Wizard class - appears in first room to wish good luck
var NPCWizard = Container.expand(function () {
var self = Container.call(this);
// Attach wizard sprite
var wizardSprite = self.attachAsset('wizard', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
self.width = wizardSprite.width;
self.height = wizardSprite.height;
// Speech bubble properties
self.showingSpeech = false;
self.speechBubble = null;
self.speechText = null;
// Show speech bubble with good luck message
self.showSpeech = function () {
if (self.showingSpeech) return;
self.showingSpeech = true;
// Create speech bubble background
self.speechBubble = LK.getAsset('door', {
width: 400,
height: 180,
anchorX: 0.5,
anchorY: 1.0
});
self.speechBubble.tint = 0xFFFFFF;
self.speechBubble.alpha = 0.9;
self.speechBubble.x = 0;
self.speechBubble.y = -wizardSprite.height / 2 - 20;
self.addChild(self.speechBubble);
// Create speech text
self.speechText = new Text2("Good luck in the dungeon,\nbrave adventurer!", {
size: 45,
fill: 0xFFFFFF,
font: "Impact, Arial Black, Tahoma"
});
self.speechText.anchor.set(0.5, 0.5);
self.speechText.x = 0;
self.speechText.y = -wizardSprite.height / 2 - 110;
self.addChild(self.speechText);
// Auto-hide speech after 4 seconds
LK.setTimeout(function () {
self.hideSpeech();
}, 4000);
};
// Hide speech bubble
self.hideSpeech = function () {
if (!self.showingSpeech) return;
self.showingSpeech = false;
if (self.speechBubble) {
self.speechBubble.destroy();
self.speechBubble = null;
}
if (self.speechText) {
self.speechText.destroy();
self.speechText = null;
}
};
return self;
});
// Orc Warrior - Room 2
var OrcWarrior = Container.expand(function () {
var self = Container.call(this);
// Use orc asset instead of monster asset
var orcSprite = self.attachAsset('orc', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.4,
scaleY: 1.4
});
// Set larger hitbox for easier collision detection
self.width = orcSprite.width * 0.4;
self.height = orcSprite.height * 0.4;
// Monster health system
self.maxHealth = 2;
self.health = self.maxHealth;
self.speed = 0.4;
// Create heart-based health display
self.hearts = [];
var heartSize = 30;
var heartSpacing = 35;
var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize;
var startX = -totalHeartsWidth / 2;
for (var h = 0; h < self.maxHealth; h++) {
var heart = LK.getAsset('trap', {
width: heartSize,
height: heartSize,
anchorX: 0.5,
anchorY: 0.5
});
heart.tint = 0xFF1744;
heart.x = startX + h * heartSpacing;
heart.y = -orcSprite.height / 2 - 40;
self.addChild(heart);
self.hearts.push(heart);
}
// Update heart display
self.updateHealthBar = function () {
// Update heart visibility based on current health
for (var h = 0; h < self.hearts.length; h++) {
if (h < self.health) {
self.hearts[h].visible = true;
self.hearts[h].tint = 0xFF1744; // Red for full hearts
self.hearts[h].alpha = 1.0;
} else {
self.hearts[h].visible = true;
self.hearts[h].tint = 0x444444; // Dark gray for empty hearts
self.hearts[h].alpha = 0.5;
}
}
};
// Take damage function with animation
self.takeDamage = function () {
self.health -= 1;
self.updateHealthBar();
// Flash damage animation
tween(orcSprite, {
tint: 0xFF0000
}, {
duration: 150,
onFinish: function onFinish() {
tween(orcSprite, {
tint: 0xFFFFFF
}, {
duration: 200
});
}
});
// Shake animation
var originalX = self.x;
tween(self, {
x: originalX + 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX - 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX
}, {
duration: 50
});
}
});
}
});
};
// Movement direction
self.vx = 0;
self.vy = 0;
// Set random direction
self.setRandomDirection = function () {
var angle = Math.random() * Math.PI * 2;
self.vx = Math.cos(angle) * self.speed;
self.vy = Math.sin(angle) * self.speed;
};
self.setRandomDirection();
// Called every tick
self.update = function () {
// Check if hero is close to this monster FIRST (within encounter distance)
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var distToHero = Math.sqrt(dx * dx + dy * dy);
// If hero is within encounter distance, trigger freeze and stop moving
if (distToHero < 120) {
// Reduced from 200 to 120 for less aggressive encounter
if (!gameFrozen) {
// Trigger freeze effect
gameFrozen = true;
freezeTimer = FREEZE_DURATION;
freezeBuffer = FREEZE_BUFFER_TIME; // Set buffer to prevent immediate damage
console.log("Freeze triggered! Buffer set to:", FREEZE_BUFFER_TIME);
// Apply freeze visual effect to all characters
tween(hero, {
tint: 0x8888ff
}, {
duration: 300
});
tween(self, {
tint: 0x8888ff
}, {
duration: 300
});
for (var m = 0; m < monsters.length; m++) {
if (monsters[m] !== self) {
tween(monsters[m], {
tint: 0x8888ff
}, {
duration: 300
});
}
}
}
// Monster stays still when encountering hero
return;
}
// Don't move if game is frozen
if (gameFrozen) {
return;
}
self.x += self.vx;
self.y += self.vy;
// Bounce off room walls
if (self.x < roomBounds.x + self.width / 2) {
self.x = roomBounds.x + self.width / 2;
self.vx *= -1;
}
if (self.x > roomBounds.x + roomBounds.width - self.width / 2) {
self.x = roomBounds.x + roomBounds.width - self.width / 2;
self.vx *= -1;
}
if (self.y < roomBounds.y + self.height / 2) {
self.y = roomBounds.y + self.height / 2;
self.vy *= -1;
}
if (self.y > roomBounds.y + roomBounds.height - self.height / 2) {
self.y = roomBounds.y + roomBounds.height - self.height / 2;
self.vy *= -1;
}
};
// Update hearts for new health
self.hearts = [];
var heartSize = 30;
var heartSpacing = 35;
var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize;
var startX = -totalHeartsWidth / 2;
for (var h = 0; h < self.maxHealth; h++) {
var heart = LK.getAsset('trap', {
width: heartSize,
height: heartSize,
anchorX: 0.5,
anchorY: 0.5
});
heart.tint = 0xFF1744;
heart.x = startX + h * heartSpacing;
heart.y = -orcSprite.height / 2 - 40;
self.addChild(heart);
self.hearts.push(heart);
}
self.updateHealthBar();
return self;
});
// Skeleton Boss - Room 1
var SkeletonBoss = Container.expand(function () {
var self = Container.call(this);
// Use skeleton asset instead of monster asset
var skeletonSprite = self.attachAsset('skeleton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
// Set larger hitbox for easier collision detection
self.width = skeletonSprite.width * 0.4;
self.height = skeletonSprite.height * 0.4;
// Monster health system
self.maxHealth = 1;
self.health = self.maxHealth;
self.speed = 0.5;
// Create heart-based health display
self.hearts = [];
var heartSize = 30;
var heartSpacing = 35;
var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize;
var startX = -totalHeartsWidth / 2;
for (var h = 0; h < self.maxHealth; h++) {
var heart = LK.getAsset('trap', {
width: heartSize,
height: heartSize,
anchorX: 0.5,
anchorY: 0.5
});
heart.tint = 0xFF1744;
heart.x = startX + h * heartSpacing;
heart.y = -skeletonSprite.height / 2 - 40;
self.addChild(heart);
self.hearts.push(heart);
}
// Update heart display
self.updateHealthBar = function () {
// Update heart visibility based on current health
for (var h = 0; h < self.hearts.length; h++) {
if (h < self.health) {
self.hearts[h].visible = true;
self.hearts[h].tint = 0xFF1744; // Red for full hearts
self.hearts[h].alpha = 1.0;
} else {
self.hearts[h].visible = true;
self.hearts[h].tint = 0x444444; // Dark gray for empty hearts
self.hearts[h].alpha = 0.5;
}
}
};
// Take damage function with animation
self.takeDamage = function () {
self.health -= 1;
self.updateHealthBar();
// Flash damage animation
tween(skeletonSprite, {
tint: 0xFF0000
}, {
duration: 150,
onFinish: function onFinish() {
tween(skeletonSprite, {
tint: 0xFFFFFF
}, {
duration: 200
});
}
});
// Shake animation
var originalX = self.x;
tween(self, {
x: originalX + 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX - 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX
}, {
duration: 50
});
}
});
}
});
};
// Movement direction
self.vx = 0;
self.vy = 0;
// Set random direction
self.setRandomDirection = function () {
var angle = Math.random() * Math.PI * 2;
self.vx = Math.cos(angle) * self.speed;
self.vy = Math.sin(angle) * self.speed;
};
self.setRandomDirection();
// Called every tick
self.update = function () {
// Check if hero is close to this monster FIRST (within encounter distance)
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var distToHero = Math.sqrt(dx * dx + dy * dy);
// If hero is within encounter distance, trigger freeze and stop moving
if (distToHero < 120) {
// Reduced from 200 to 120 for less aggressive encounter
if (!gameFrozen) {
// Trigger freeze effect
gameFrozen = true;
freezeTimer = FREEZE_DURATION;
freezeBuffer = FREEZE_BUFFER_TIME; // Set buffer to prevent immediate damage
console.log("Freeze triggered! Buffer set to:", FREEZE_BUFFER_TIME);
// Apply freeze visual effect to all characters
tween(hero, {
tint: 0x8888ff
}, {
duration: 300
});
tween(self, {
tint: 0x8888ff
}, {
duration: 300
});
for (var m = 0; m < monsters.length; m++) {
if (monsters[m] !== self) {
tween(monsters[m], {
tint: 0x8888ff
}, {
duration: 300
});
}
}
}
// Monster stays still when encountering hero
return;
}
// Don't move if game is frozen
if (gameFrozen) {
return;
}
self.x += self.vx;
self.y += self.vy;
// Bounce off room walls
if (self.x < roomBounds.x + self.width / 2) {
self.x = roomBounds.x + self.width / 2;
self.vx *= -1;
}
if (self.x > roomBounds.x + roomBounds.width - self.width / 2) {
self.x = roomBounds.x + roomBounds.width - self.width / 2;
self.vx *= -1;
}
if (self.y < roomBounds.y + self.height / 2) {
self.y = roomBounds.y + self.height / 2;
self.vy *= -1;
}
if (self.y > roomBounds.y + roomBounds.height - self.height / 2) {
self.y = roomBounds.y + roomBounds.height - self.height / 2;
self.vy *= -1;
}
};
// Skeleton stats
self.maxHealth = 1;
self.health = self.maxHealth;
self.speed = 0.5;
// Update hearts for new health
self.hearts = [];
var heartSize = 30;
var heartSpacing = 35;
var totalHeartsWidth = (self.maxHealth - 1) * heartSpacing + heartSize;
var startX = -totalHeartsWidth / 2;
for (var h = 0; h < self.maxHealth; h++) {
var heart = LK.getAsset('trap', {
width: heartSize,
height: heartSize,
anchorX: 0.5,
anchorY: 0.5
});
heart.tint = 0xFF1744;
heart.x = startX + h * heartSpacing;
heart.y = -skeletonSprite.height / 2 - 40;
self.addChild(heart);
self.hearts.push(heart);
}
self.updateHealthBar();
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2C1810
});
/****
* Game Code
****/
// Create dungeon floor texture with pixel-by-pixel stone pattern
var dungeonFloor = new Container();
var stoneColors = [0x4A4A4A, 0x3A3A3A, 0x5A5A5A, 0x2A2A2A, 0x6A6A6A]; // Various gray stone colors
var mossColors = [0x2D4A2D, 0x1F3A1F, 0x3D5A3D]; // Mossy accents
var dirtColors = [0x4A3A2A, 0x5A4A3A, 0x3A2A1A]; // Dirt between stones
// Create pixelated stone floor
for (var row = 0; row < 68; row++) {
// Cover full height (2732/40 = ~68 rows)
for (var col = 0; col < 52; col++) {
// Cover full width (2048/40 = ~52 cols)
var pixelSize = 40;
var x = col * pixelSize;
var y = row * pixelSize;
// Determine pixel type based on position for realistic stone pattern
var isStone = (row + col) % 3 !== 0; // Most pixels are stone
var isMoss = Math.random() < 0.05; // 5% chance for moss
var isDirt = Math.random() < 0.08; // 8% chance for dirt
var color;
if (isMoss) {
color = mossColors[Math.floor(Math.random() * mossColors.length)];
} else if (isDirt) {
color = dirtColors[Math.floor(Math.random() * dirtColors.length)];
} else {
color = stoneColors[Math.floor(Math.random() * stoneColors.length)];
}
var pixel = LK.getAsset('trap', {
width: pixelSize,
height: pixelSize,
anchorX: 0,
anchorY: 0,
x: x,
y: y
});
pixel.tint = color;
dungeonFloor.addChild(pixel);
}
}
// Add dungeon floor as background layer
game.addChildAt(dungeonFloor, 0); // Add at bottom layer
// Tween plugin for animations
// --- Start Screen Overlay ---
var startScreenOverlay = new Container();
startScreenOverlay.zIndex = 10000; // ensure on top
// Dark background for better text readability
var startBackground = LK.getAsset('trap', {
width: 2048,
height: 2732,
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
startBackground.tint = 0x000000;
startBackground.alpha = 0.85;
startScreenOverlay.addChild(startBackground);
// Welcome message
var welcomeText = new Text2("Welcome, Hero!", {
size: 120,
fill: 0xFFD700,
font: "Impact, Arial Black, Tahoma"
});
welcomeText.anchor.set(0.5, 0.5);
welcomeText.x = 2048 / 2;
welcomeText.y = 600;
startScreenOverlay.addChild(welcomeText);
// Title
var titleText = new Text2("Brave Adventurer", {
size: 180,
fill: "#fff",
font: "Impact, Arial Black, Tahoma"
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 800;
startScreenOverlay.addChild(titleText);
// Story introduction
var storyText = new Text2("Enter the dark dungeon and face legendary monsters.\nDefeat bosses, collect treasures, and prove your courage!", {
size: 60,
fill: 0xCCCCCC,
font: "Impact, Arial Black, Tahoma"
});
storyText.anchor.set(0.5, 0.5);
storyText.x = 2048 / 2;
storyText.y = 1000;
startScreenOverlay.addChild(storyText);
// Subtitle
var subtitleText = new Text2("Tap to move and attack. Collect keys from chests to proceed!", {
size: 70,
fill: 0xB8B031
});
subtitleText.anchor.set(0.5, 0.5);
subtitleText.x = 2048 / 2;
subtitleText.y = 1200;
startScreenOverlay.addChild(subtitleText);
// Play Button
var playBtnWidth = 600;
var playBtnHeight = 180;
var playBtn = LK.getAsset('door', {
width: playBtnWidth,
height: playBtnHeight,
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 1600
});
playBtn.tint = 0x4A8B3B; // Green tint for play button
startScreenOverlay.addChild(playBtn);
var playBtnText = new Text2("START ADVENTURE", {
size: 90,
fill: "#fff",
font: "Impact, Arial Black, Tahoma"
});
playBtnText.anchor.set(0.5, 0.5);
playBtnText.x = 2048 / 2;
playBtnText.y = 1600;
startScreenOverlay.addChild(playBtnText);
// Add pulsing animation to play button
tween(playBtn, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 800,
loop: true,
pingpong: true
});
tween(playBtnText, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 800,
loop: true,
pingpong: true
});
// Instructions text
var instructionsText = new Text2("Tap the button above to begin your quest", {
size: 50,
fill: 0x888888,
font: "Impact, Arial Black, Tahoma"
});
instructionsText.anchor.set(0.5, 0.5);
instructionsText.x = 2048 / 2;
instructionsText.y = 1800;
startScreenOverlay.addChild(instructionsText);
// Add overlay to game
game.addChild(startScreenOverlay);
// Block game input until started
var gameStarted = false;
// Start game handler
function startGame() {
if (gameStarted) return;
gameStarted = true;
// Fade out start screen with smooth transition
tween(startScreenOverlay, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
startScreenOverlay.visible = false;
startScreenOverlay.alpha = 1; // Reset for potential restart
}
});
// Flash screen to indicate game start
LK.effects.flashScreen(0x4A8B3B, 300);
}
// Listen for tap/click on play button
startScreenOverlay.down = function (x, y, obj) {
// Check if tap is inside play button
var local = playBtn.toLocal(startScreenOverlay.toGlobal({
x: x,
y: y
}));
if (local.x > -playBtnWidth / 2 && local.x < playBtnWidth / 2 && local.y > -playBtnHeight / 2 && local.y < playBtnHeight / 2) {
startGame();
}
};
// Intercept all input until game started
var oldGameDown = game.down;
game.down = function (x, y, obj) {
if (!gameStarted) {
if (typeof startScreenOverlay.down === "function") startScreenOverlay.down(x, y, obj);
return;
}
if (typeof oldGameDown === "function") oldGameDown(x, y, obj);
};
var oldGameMove = game.move;
game.move = function (x, y, obj) {
if (!gameStarted) return;
if (typeof oldGameMove === "function") oldGameMove(x, y, obj);
};
var oldGameUp = game.up;
game.up = function (x, y, obj) {
if (!gameStarted) return;
if (typeof oldGameUp === "function") oldGameUp(x, y, obj);
};
// Room bounds (centered, with margin)
var roomMargin = 120;
var roomBounds = {
x: roomMargin,
y: roomMargin + 100,
// leave top 100px for menu
width: 2048 - roomMargin * 2,
height: 2732 - roomMargin * 2 - 100
};
// Game state
var hero;
var monsters = [];
var mageBalls = []; // Track mage projectiles
var door;
var keys = [];
var chests = [];
var hasKey = false;
var draggingHero = false;
var lastMoveX = 0,
lastMoveY = 0;
var currentRoom = 1;
var maxRooms = 5;
var monstersDefeated = 0;
var roomCleared = false;
var gameFrozen = false;
var freezeTimer = 0;
var FREEZE_DURATION = 120; // 2 seconds at 60fps
var freezeBuffer = 0; // Buffer to prevent immediate damage after freeze
var FREEZE_BUFFER_TIME = 30; // 30 frames buffer after freeze starts (0.5 seconds)
var healUsesRemaining = 3; // Player can use heal 3 times total
// GUI elements
var scoreTxt = new Text2('Score: 0', {
size: 90,
fill: "#fff"
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.y = 20;
LK.gui.top.addChild(scoreTxt);
// Room indicator
var roomTxt = new Text2('Room 1', {
size: 80,
fill: 0xFFD700
});
roomTxt.anchor.set(0, 0);
roomTxt.x = 120;
roomTxt.y = 20;
LK.gui.topLeft.addChild(roomTxt);
// Health indicator text
var healthTxt = new Text2('Health: Full', {
size: 70,
fill: 0xFF4444
});
healthTxt.anchor.set(1, 0);
healthTxt.x = -20;
healthTxt.y = 20;
LK.gui.topRight.addChild(healthTxt);
// Helper to update health display - now updates the health bar on the character
function updateHealthDisplay() {
// This will be handled by the health bar on the character
}
// Helper to update score display
function updateScoreDisplay() {
var score = monstersDefeated * 5;
scoreTxt.setText('Score: ' + score);
}
// Helper to update room display
function updateRoomDisplay() {
roomTxt.setText('Room ' + currentRoom);
}
// Helper to update health display
// Helper to clear room
function clearRoom() {
for (var i = 0; i < monsters.length; i++) monsters[i].destroy();
for (var i = 0; i < keys.length; i++) keys[i].destroy();
for (var i = 0; i < chests.length; i++) chests[i].destroy();
for (var i = 0; i < mageBalls.length; i++) mageBalls[i].destroy();
monsters = [];
keys = [];
chests = [];
mageBalls = [];
if (door) {
door.destroy();
door = null;
}
// Clear NPC reference if it exists
if (game.npcWizard) {
game.npcWizard.destroy();
game.npcWizard = null;
}
roomCleared = false;
hasKey = false;
}
// Helper to generate a room
function generateRoom(roomNum) {
clearRoom();
// Place hero at entrance (bottom center)
hero.x = roomBounds.x + roomBounds.width / 2;
hero.y = roomBounds.y + roomBounds.height - hero.height;
// Helper function to check if position is safe from hero spawn area
function isPositionSafeFromHeroSpawn(x, y, heroStartX, heroStartY, safeDistance) {
var dx = x - heroStartX;
var dy = y - heroStartY;
var dist = Math.sqrt(dx * dx + dy * dy);
return dist > safeDistance;
}
// Place monsters - exactly 1 boss monster per room based on room number
var monsterCount = 1;
var heroStartX = roomBounds.x + roomBounds.width / 2;
var heroStartY = roomBounds.y + roomBounds.height - hero.height;
var heroSafeDistance = 400; // Increased safe distance around hero spawn
for (var i = 0; i < monsterCount; i++) {
var m;
// Create different boss types based on room number
if (roomNum === 1) {
m = new SkeletonBoss();
} else if (roomNum === 2) {
m = new OrcWarrior();
} else if (roomNum === 3) {
m = new DarkMage();
} else if (roomNum === 4) {
m = new FireDemon();
} else if (roomNum === 5) {
m = new DragonLord();
} else {
// Fallback for any additional rooms
m = new Monster();
}
var validPosition = false;
var attempts = 0;
// Try to find a position that's not too close to hero spawn
while (!validPosition && attempts < 50) {
m.x = roomBounds.x + 100 + Math.random() * (roomBounds.width - 200);
m.y = roomBounds.y + 200 + Math.random() * (roomBounds.height - 400);
if (isPositionSafeFromHeroSpawn(m.x, m.y, heroStartX, heroStartY, heroSafeDistance)) {
validPosition = true;
}
attempts++;
}
monsters.push(m);
game.addChild(m);
}
// Key will come from chest after killing all monsters, so don't place it randomly
// Place chest (always one per room)
var c = new Chest();
var validPosition = false;
var attempts = 0;
while (!validPosition && attempts < 50) {
c.x = roomBounds.x + 100 + Math.random() * (roomBounds.width - 200);
c.y = roomBounds.y + 200 + Math.random() * (roomBounds.height - 400);
if (isPositionSafeFromHeroSpawn(c.x, c.y, heroStartX, heroStartY, heroSafeDistance)) {
validPosition = true;
}
attempts++;
}
chests.push(c);
game.addChild(c);
// Place door (top center)
door = new Door();
door.x = roomBounds.x + roomBounds.width / 2;
door.y = roomBounds.y + door.height / 2;
game.addChild(door);
door.visible = false; // Only show when room is cleared
// Place NPC wizard only in first room
if (roomNum === 1) {
var npcWizard = new NPCWizard();
npcWizard.x = roomBounds.x + 200; // Position near left wall
npcWizard.y = roomBounds.y + roomBounds.height / 2; // Center vertically
game.addChild(npcWizard);
// Store reference for proximity check
game.npcWizard = npcWizard;
}
roomCleared = false;
updateRoomDisplay();
updateHealthDisplay();
}
// Create hero
hero = new Hero();
game.addChild(hero);
// Start first room
generateRoom(currentRoom);
updateScoreDisplay();
// Dragging logic
game.down = function (x, y, obj) {
// Only start drag if touch is on hero
var local = hero.toLocal(game.toGlobal({
x: x,
y: y
}));
if (local.x > -hero.width / 2 && local.x < hero.width / 2 && local.y > -hero.height / 2 && local.y < hero.height / 2) {
draggingHero = true;
lastMoveX = x;
lastMoveY = y;
}
};
game.up = function (x, y, obj) {
draggingHero = false;
};
function clamp(val, min, max) {
return Math.max(min, Math.min(max, val));
}
// Walk-to destination variables
var walkToActive = false;
var walkToX = 0;
var walkToY = 0;
var walkToSpeed = 22;
// Attack button for attacking monsters - round dungeon-themed button
var killButton = LK.getAsset('monster', {
width: 280,
height: 280,
anchorX: 0.5,
anchorY: 0.5,
x: 2048 - 160,
y: 2732 - 160
});
killButton.tint = 0x4A4A4A; // Dark steel gray for shield-like appearance
killButton.alpha = 0.9; // Slightly transparent for better integration
game.addChild(killButton);
var killButtonText = new Text2("ATTACK", {
size: 60,
fill: 0xFFD700,
font: "Impact, Arial Black, Tahoma"
});
killButtonText.anchor.set(0.5, 0.5);
killButtonText.x = 2048 - 160;
killButtonText.y = 2732 - 160;
game.addChild(killButtonText);
// Heal pot button next to attack button
var healButton = LK.getAsset('chest', {
width: 280,
height: 280,
anchorX: 0.5,
anchorY: 0.5,
x: 2048 - 460,
// Position to the left of attack button
y: 2732 - 160
});
healButton.tint = 0xFF4444; // Red tint for health potion
healButton.alpha = 0.9;
game.addChild(healButton);
var healButtonText = new Text2("HEAL", {
size: 60,
fill: 0xFFD700,
font: "Impact, Arial Black, Tahoma"
});
healButtonText.anchor.set(0.5, 0.5);
healButtonText.x = 2048 - 460;
healButtonText.y = 2732 - 160;
game.addChild(healButtonText);
// Open chest text
var openChestText = new Text2("OPEN CHEST", {
size: 80,
fill: 0xFFD700,
font: "Impact, Arial Black, Tahoma"
});
openChestText.anchor.set(0.5, 0.5);
openChestText.x = 2048 / 2;
openChestText.y = 2732 - 200;
openChestText.visible = false;
game.addChild(openChestText);
// Sword swing state management
var swordSwinging = false;
var swordCooldown = 0;
var SWORD_COOLDOWN_TIME = 15; // frames (0.25 seconds at 60fps)
// Move handler
game.move = function (x, y, obj) {
if (draggingHero) {
// Clamp hero inside room bounds
var hx = clamp(x, roomBounds.x + hero.width / 2, roomBounds.x + roomBounds.width - hero.width / 2);
var hy = clamp(y, roomBounds.y + hero.height / 2, roomBounds.y + roomBounds.height - hero.height / 2);
hero.x = hx;
hero.y = hy;
walkToActive = false; // Cancel walk-to if dragging
}
};
// Tap-to-walk logic: on down, if not on hero, set walk-to destination
var oldGameDown = game.down;
game.down = function (x, y, obj) {
// Only start drag if touch is on hero
var local = hero.toLocal(game.toGlobal({
x: x,
y: y
}));
// Check if heal button was tapped
var healButtonLocal = healButton.toLocal(game.toGlobal({
x: x,
y: y
}));
if (healButtonLocal.x > -healButton.width / 2 && healButtonLocal.x < healButton.width / 2 && healButtonLocal.y > -healButton.height / 2 && healButtonLocal.y < healButton.height / 2) {
// Check if we have heal uses remaining
if (healUsesRemaining > 0) {
// Use heal function from hero
hero.heal();
healUsesRemaining--;
}
return; // Don't process other touch logic
}
// Check if kill button was tapped
var killButtonLocal = killButton.toLocal(game.toGlobal({
x: x,
y: y
}));
if (killButtonLocal.x > -killButton.width / 2 && killButtonLocal.x < killButton.width / 2 && killButtonLocal.y > -killButton.height / 2 && killButtonLocal.y < killButton.height / 2) {
// Check if sword is available (not swinging and cooldown expired)
if (!swordSwinging && swordCooldown <= 0) {
// Get sword sprite from hero for animation
var swordSprite = hero.children[1]; // Sword is the second child (index 1)
// Stop any existing tweens on the sword
tween.stop(swordSprite, {
rotation: true
});
// Set swinging state
swordSwinging = true;
swordCooldown = SWORD_COOLDOWN_TIME;
// Create sword swing effect
var originalRotation = swordSprite.rotation;
tween(swordSprite, {
rotation: originalRotation + Math.PI / 2
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(swordSprite, {
rotation: originalRotation
}, {
duration: 200,
easing: tween.easeIn,
onFinish: function onFinish() {
swordSwinging = false;
}
});
}
});
// Kill button tapped - damage all monsters within 350px of hero
for (var i = monsters.length - 1; i >= 0; i--) {
var m = monsters[i];
var dx = hero.x - m.x;
var dy = hero.y - m.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 500) {
// Deal damage to monster
m.takeDamage();
// Optional: flash hero for feedback
LK.effects.flashObject(hero, 0xffffff, 120);
// Check if monster is dead
if (m.health <= 0) {
// Remove monster
m.destroy();
monsters.splice(i, 1);
monstersDefeated++;
updateScoreDisplay();
}
// Unfreeze game when monster dies
if (gameFrozen) {
gameFrozen = false;
freezeTimer = 0;
// Remove freeze visual effects
tween(hero, {
tint: 0xffffff
}, {
duration: 300
});
for (var j = 0; j < monsters.length; j++) {
tween(monsters[j], {
tint: 0xffffff
}, {
duration: 300
});
}
}
}
}
}
return; // Don't process other touch logic
}
if (local.x > -hero.width / 2 && local.x < hero.width / 2 && local.y > -hero.height / 2 && local.y < hero.height / 2) {
draggingHero = true;
lastMoveX = x;
lastMoveY = y;
walkToActive = false;
} else {
// Set walk-to destination if tap is inside room
var hx = clamp(x, roomBounds.x + hero.width / 2, roomBounds.x + roomBounds.width - hero.width / 2);
var hy = clamp(y, roomBounds.y + hero.height / 2, roomBounds.y + roomBounds.height - hero.height / 2);
walkToX = hx;
walkToY = hy;
walkToActive = true;
}
if (typeof oldGameDown === "function") oldGameDown(x, y, obj);
};
// In update, move hero toward walk-to destination if active
var oldGameUpdate = game.update;
game.update = function () {
// Walk-to logic
if (walkToActive && !draggingHero) {
var dx = walkToX - hero.x;
var dy = walkToY - hero.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > walkToSpeed) {
hero.x += dx / dist * walkToSpeed;
hero.y += dy / dist * walkToSpeed;
} else {
hero.x = walkToX;
hero.y = walkToY;
walkToActive = false;
}
}
if (typeof oldGameUpdate === "function") oldGameUpdate();
};
// Main update loop
game.update = function () {
if (!gameStarted) return;
// Handle freeze timer
if (gameFrozen) {
freezeTimer--;
if (freezeTimer <= 0) {
// Unfreeze game
gameFrozen = false;
// Remove freeze visual effects
tween(hero, {
tint: 0xffffff
}, {
duration: 300
});
for (var m = 0; m < monsters.length; m++) {
tween(monsters[m], {
tint: 0xffffff
}, {
duration: 300
});
}
}
}
// Update sword cooldown
if (swordCooldown > 0) {
swordCooldown--;
}
// Update freeze buffer
if (freezeBuffer > 0) {
freezeBuffer--;
}
// Update hero (only if not frozen)
if (!gameFrozen) {
hero.update();
}
// Update monsters
for (var i = 0; i < monsters.length; i++) {
monsters[i].update();
}
// Update mage balls
for (var i = mageBalls.length - 1; i >= 0; i--) {
var ball = mageBalls[i];
ball.update();
// Remove ball if lifetime expired
if (ball.lifetime <= 0) {
ball.destroy();
mageBalls.splice(i, 1);
continue;
}
// Check collision with hero (only when not invincible and no freeze buffer)
if (!hero.invincible && freezeBuffer <= 0 && hero.intersects(ball)) {
hero.takeDamage();
// Destroy ball on hit
ball.destroy();
mageBalls.splice(i, 1);
// Create impact effect
LK.effects.flashObject(hero, 0x8A2BE2, 200);
}
}
// Attack button is always visible
killButton.visible = true;
killButtonText.visible = true;
// Heal button visibility and text update based on remaining uses
if (healUsesRemaining > 0) {
healButton.visible = true;
healButtonText.visible = true;
healButton.alpha = 0.9;
healButtonText.setText("HEAL (" + healUsesRemaining + ")");
} else {
healButton.visible = true;
healButtonText.visible = true;
healButton.alpha = 0.3; // Make button appear disabled
healButtonText.setText("NO HEALS");
}
// Check if hero is close to chest and all monsters are defeated
var nearChest = false;
if (monsters.length === 0) {
for (var i = 0; i < chests.length; i++) {
var c = chests[i];
if (!c.opened) {
var dx = hero.x - c.x;
var dy = hero.y - c.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 200) {
nearChest = true;
break;
}
}
}
}
// Show/hide open chest text based on proximity and game state
openChestText.visible = nearChest;
// Check collisions: hero vs monsters (only when game is not frozen, no freeze buffer, and hero is not invincible)
if (!gameFrozen && freezeBuffer <= 0 && !hero.invincible) {
for (var i = monsters.length - 1; i >= 0; i--) {
var m = monsters[i];
if (hero.intersects(m)) {
hero.takeDamage();
// No knockback - hero stays in place when touching monsters
// Hero can only kill monsters with the kill button, not by collision
}
}
}
// Check collisions: hero vs keys
for (var i = keys.length - 1; i >= 0; i--) {
var k = keys[i];
if (hero.intersects(k)) {
k.destroy();
keys.splice(i, 1);
hasKey = true;
LK.effects.flashObject(hero, 0xFFD700, 300);
}
}
// Check collisions: hero vs chests
for (var i = 0; i < chests.length; i++) {
var c = chests[i];
if (hero.intersects(c) && monsters.length === 0 && !c.opened) {
c.opened = true;
LK.effects.flashObject(c, 0x83de44, 600);
updateScoreDisplay();
// Spawn key from chest after all monsters are defeated
var k = new Key();
k.x = c.x;
k.y = c.y;
keys.push(k);
game.addChild(k);
}
}
// Room clear check - need to defeat all monsters first, then open chest, then collect key
if (!roomCleared && monsters.length === 0 && chests.length > 0 && chests[0].opened && hasKey) {
roomCleared = true;
door.visible = true;
LK.effects.flashObject(door, 0x83de44, 600);
}
// Check if hero is near NPC wizard in first room
if (currentRoom === 1 && game.npcWizard && !game.npcWizard.showingSpeech) {
var dx = hero.x - game.npcWizard.x;
var dy = hero.y - game.npcWizard.y;
var distToNPC = Math.sqrt(dx * dx + dy * dy);
if (distToNPC < 250) {
// Show speech when hero gets close
game.npcWizard.showSpeech();
}
}
// Check hero at door to next room
if (roomCleared && door && hero.intersects(door)) {
if (currentRoom < maxRooms) {
currentRoom++;
generateRoom(currentRoom);
} else {
// Win!
LK.setScore(monstersDefeated * 5);
LK.showYouWin();
}
}
};
dungeon door. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
png
dungeon hero sword. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
dungeon key. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
dungeon chest. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
dungeon demon. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
dungeon wizard. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
a mage who throws fireballs. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
big dungeon snake. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
a spider. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat