User prompt
create a new sound named Enemy_Death and play it when an enemy dies
User prompt
instead of playing the Upgrade sound wgen the player selects an upgrade, move it from there and instead play it when an enemy dies
User prompt
move the platform 50 pixels higher
User prompt
there's a duplicate of the platform on the screen, one you just move 100 pixels higher and another in the center of the screen. remove the duplicate in the center of the screen
User prompt
move the platform 100 pixels higher
User prompt
the '+1 HP when you pass GO' should increment the healing for the feature that handles GO. when the peons moves through go, so when it moves from cell 8 to cell 1, then upgrade the GO feature by adding +1 to it.s value. so since the starting value for when the peon moves through go is to restore 1hp, moving on now it will restore +2 hp. each ulterior upgrade adds +1 to this value
User prompt
Update the UpgradeManager to Exclusively Handle the New Variable a. Adjust the applyUpgrade Method: Handle "Pass GO" Upgrade: When the "Pass GO" upgrade is selected, only increment passGoHealIncrement. Do Not Modify: Avoid changing other healing variables like healBoost or healBoostCount. b. Example Modification: Before: javascript Copy code if (selectedUpgrade.description.includes('random')) { // Existing logic modifying heal cells } After: javascript Copy code case 'passGoHeal': upgradeState.global.passGoHealIncrement += selectedUpgrade.value; console.log("Pass GO Heal Increment is now", upgradeState.global.passGoHealIncrement); break; c. Maintain Clear Separation: Single Responsibility: Ensure that each upgrade type only modifies its corresponding variables. Prevent any overlap where one upgrade affects multiple unrelated variables.
User prompt
Example Flow in Rotation: Peon Completes Rotation: Detect currentPosition == 0. Calculate Heal Amount: healAmount = baseHeal + upgradeState.global.passGoHealIncrement; Apply Heal: self.playerHP.updateHP(healAmount); Display Heal Text: Show "+healAmount HP" to the player.
User prompt
Remove Unintended Increments: Eliminate Incrementing in Rotation Logic: Ensure that the rotation logic only reads from passGoHealIncrement and does not modify it. Example: Remove any lines like upgradeState.categorical.healBoostCount += 1; from the rotation logic.
User prompt
Display the Correct Heal Text: Ensure that the heal text dynamically reflects the healAmount (e.g., "+2 HP" if healAmount is 2). Avoid Hardcoding: Do not hardcode the heal text to a fixed value.
User prompt
Apply the Heal Appropriately: Update Player's HP: Use the calculated healAmount to update the player's HP. Example: self.playerHP.updateHP(healAmount);
User prompt
Calculate the Heal Amount Correctly: Base Heal Amount: Determine if there's a base HP restoration (e.g., always +1 HP). Total Heal Amount: Sum the base heal with passGoHealIncrement. Formula: healAmount = baseHeal + upgradeState.global.passGoHealIncrement;
User prompt
Refactor the Peon's Rotation Logic a. Update the spin Method in the Peon Class: Objective: Ensure that the HP restoration upon passing GO uses the newly introduced passGoHealIncrement.
User prompt
Prevent Overlapping Effects: Ensure Isolation: Confirm that applying the "Pass GO" upgrade does not influence other healing upgrades. Example Flow: Upgrade Applied: Player selects "+1 HP when you pass GO". Action: Only passGoHealIncrement is incremented by +1.
User prompt
Modify the Upgrade Application Logic a. Distinguish the "Pass GO" Upgrade: Ensure Unique Identification: Assign a unique type or description to the "Pass GO" upgrade. Example: javascript Copy code { type: 'passGoHeal', value: 1, description: '+1 HP when you pass GO' } b. Update the UpgradeManager Class: Handle the "Pass GO" Upgrade Separately: In the applyUpgrade method, detect when the "Pass GO" upgrade is selected. Increment Only passGoHealIncrement: When the "Pass GO" upgrade is applied, only increment upgradeState.global.passGoHealIncrement by the upgrade's value (e.g., +1). Do Not Modify: Avoid altering healBoost, healBoostCount, or any other healing-related variables.
User prompt
Introduce a Dedicated Variable for "Pass GO" Healing a. Define a New Variable: Purpose: This variable will specifically track the additional HP restored each time the peon completes a full rotation (passes GO). Suggested Name: passGoHealIncrement or goHealBonus. b. Initialize the Variable: Location: Within your centralized upgradeState object. Initial Value: Set it to 0, indicating no bonus HP restoration before any upgrades. Example Structure: javascript Copy code var upgradeState = { global: { totalDamageBoost: 0, passGoHealIncrement: 0 // Dedicated variable for "Pass GO" healing }, categorical: { minorDamageBoost: 0, majorDamageBoost: 0, criticalDamageBoost: 0, healBoost: 0, // Existing heal-related upgrades healBoostCount: 0 }, individual: { specificCellBoosts: {} } };
User prompt
the ui shows the enemy damage as Damage:11-17. the starting damage of the enemy at round 1 should be 10-15, esnure this error is corrected
User prompt
Please fix the bug: 'EnemyDamage is not a constructor' in or related to this line: 'var enemyDamage = new EnemyDamage(); // Initialize enemyDamage instance' Line Number: 802
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'minDamage')' in or related to this line: 'var enemyDamageText = new Text2('Damage: ' + enemyDamage.minDamage + '-' + enemyDamage.maxDamage, {' Line Number: 803
User prompt
place a text in the game's HUI showing the enemy's current damage. show it in this format "Damage: 10-15" where 10 is min damage and 15 is max damage. update these values after each round when the enemy damage crows
User prompt
Please fix the bug: 'Timeout.tick error: maxDamage is not defined' in or related to this line: 'var damage = Math.floor(Math.random() * (maxDamage - minDamage + 1)) + minDamage;' Line Number: 393
User prompt
refactor and reconsolidate the damage dealing system of the enemy into a single class. at round one, the enemy's damage starts with a ranage between the minimum damage of 10 and maximum damage of 15. after every round when a new enemy is spawned, increase the enemy damage. increase minmimum damage by 1 and max by 2
User prompt
the damage taken by the player is not correctly shown in the console. the game correctly applies the right damage to the player, but the value shown in the console is wrong
User prompt
the damage taken by the player is not correctly shown in the console
User prompt
player_damage sound doesnt play when hp is deducted from the player's HP. make sure when damage is applied to the player, the sound plays. the damage has a delay to it, ensure that doesn't affect this
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // BackgroundContainer class var BackgroundContainer = Container.expand(function () { var self = Container.call(this); }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Enemy class to handle enemy logic var Enemy = Container.expand(function (assetType) { var self = Container.call(this); if (!assetType) { console.error("Asset type is undefined"); return; } var enemyGraphics = cachedEnemyAssets[assetType]; // Reuse cached asset enemyGraphics.anchor.set(0.5, 0.5); // Set anchor to center self.addChild(enemyGraphics); // Attach the cached asset to the enemy self.init = function (initialHP) { self.x = 2048 / 2; self.y = 2732 / 2 - 500; // Initialize the enemy's HP self.hp = initialHP; // Add a text to display the enemy's HP self.hpText = new Text2("", { size: 150, fill: 0x000000 }); self.hpText.anchor.set(0.5, 0.5); self.hpText.y = -700; // Move the text higher self.addChild(self.hpText); // Update the enemy's HP text if (self.hpText) { self.hpText.setText("HP: " + self.hp); } }; // self.init(); // Ensure init is called during construction }); // ForegroundContainer class var ForegroundContainer = Container.expand(function () { var self = Container.call(this); }); // MidgroundContainer class var MidgroundContainer = Container.expand(function () { var self = Container.call(this); }); // Peon class to represent the player character var Peon = Container.expand(function () { var self = Container.call(this); // Attach the 'peon' asset to the Peon var peonGraphics = self.attachAsset('peon', { anchorX: 0.5, anchorY: 0.5 }); // Initialize the Peon's position on the wheel self.init = function (wheel) { self.x = wheel.x; self.y = wheel.y; self.currentPosition = Math.floor(Math.random() * 8); // Peon's current position on the wheel self.playerHP = new PlayerHP(); self.x += self.currentPosition * 250; // Position Peon on the random cell }; // Spin the Peon around the wheel self.spin = function (wheel, steps) { self.steps = steps; // Use the passed steps parameter instead of random assignment var _spinStep = function spinStep() { self.currentPosition = (self.currentPosition + 1) % 8; self.x = wheel.x + self.currentPosition * 250; if (self.currentPosition == 0) { self.x = wheel.x; // Add +1 to the full rotation variable when moving from the last 8th cell back to the first cell upgradeState.categorical.healBoostCount += 1; var healText = new Text2('+1', { size: 150, fill: 0x00FF00 // Green color for heal }); healText.anchor.set(0.5, 0.5); healText.x = self.playerHP.hpText.x + 250; healText.y = self.playerHP.hpText.y; LK.gui.top.addChild(healText); tween(healText, { alpha: 0, y: healText.y - 50 }, { duration: 1000, easing: tween.easeOut, onFinish: function onFinish() { healText.destroy(); } }); // Display Pass_GO asset in the center of the screen var passGoAsset = LK.getAsset('Pass_GO', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2 + 880, y: 2732 / 2 + 950, alpha: 0 }); midgroundContainer.addChild(passGoAsset); tween(passGoAsset, { alpha: 1 }, { duration: 300, onFinish: function onFinish() { LK.setTimeout(function () { tween(passGoAsset, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { passGoAsset.destroy(); } }); }, 500); } }); } self.steps--; if (self.steps <= 0) { self.x = wheel.x + self.currentPosition * 250; var cell = wheel.cells[self.currentPosition]; if (cell.actionType === 'heal') { var healAmount = cell.damage; // Use the updated damage value from the cell self.playerHP.updateHP(healAmount); LK.getSound('Heal').play(); // Play the 'Heal' sound var healText = new Text2('+' + healAmount, { size: 150, fill: 0x00FF00 }); healText.anchor.set(0.5, 0.5); healText.x = self.playerHP.hpText.x + 250; healText.y = self.playerHP.hpText.y; LK.gui.top.addChild(healText); tween(healText, { alpha: 0, y: healText.y - 50 }, { duration: 1000, easing: tween.easeOut, onFinish: function onFinish() { healText.destroy(); } }); } else { var projectile = projectilePool.getProjectile(); projectile.init(self.x, self.y, enemy.x, enemy.y, 10, cell.damage, self.currentPosition); if (!projectile.parent) { game.addChild(projectile); } } wheel.isSpinning = false; var _deductHp = function deductHp() { if (cell.actionType !== 'heal') { var damage = Math.floor(Math.random() * (maxDamage - minDamage + 1)) + minDamage; self.playerHP.updateHP(-damage); } }; // Removed instant damage application to player's health } else { LK.setTimeout(_spinStep, currentInterval * 10); // Increase interval to slow down peon speed } }; _spinStep(); }; }); // Current interval for the spin // Player class to handle player logic var Player = Container.expand(function () { var self = Container.call(this); // Attach the 'peon' asset to the Player var playerGraphics = self.attachAsset('peon', { anchorX: 0.5, anchorY: 0.5 }); // Initialize the Player's position on the wheel self.init = function (wheel) { self.x = wheel.x; self.y = wheel.y; self.currentPosition = Math.floor(Math.random() * 8); // Player's current position on the wheel self.hp = 200; // Player's HP self.hpText = new Text2('Player: ' + self.hp, { size: 150, fill: 0xFFFFFF //Optional (this is the default string) }); self.hpText.anchor.set(0.5, 0); // Sets anchor to the center of the top edge of the text. self.hpText.y += 1000; // Move the text 1000 pixels lower LK.gui.top.addChild(self.hpText); self.x += self.currentPosition * 250; // Position Player on the random cell }; // Spin the Player around the wheel self.spin = function (wheel) { // Generate a random integer between 10 and 15 self.steps = Math.floor(Math.random() * (maxTiles - startingMovingTiles + 1)) + startingMovingTiles; var _spinStep = function spinStep() { self.currentPosition = (self.currentPosition + 1) % 8; // Update Player's current position self.x = wheel.x + self.currentPosition * 250; // Move Player one cell to the right if (self.currentPosition == 0) { // If Player reaches Cell 8, loop back to Cell 1 self.x = wheel.x; } self.steps--; currentInterval *= multiplier; // Increase the interval by the multiplier if (self.steps <= 0) { // Player lands on the final cell self.x = wheel.x + self.currentPosition * 250; // Check the action type of the landed cell var cell = wheel.cells[self.currentPosition]; if (cell.actionType === 'heal') { self.hp += cell.damage; if (self.hp > 200) { self.hp = 200; } self.hpText.setText('Player: ' + self.hp); LK.getSound('Heal').play(); // Play the 'Heal' sound // Create and display heal amount text var healText = new Text2('+' + cell.damage, { size: 150, fill: 0x00FF00 // Green color for heal }); healText.anchor.set(0.5, 0.5); healText.x = self.hpText.x + 250; healText.y = self.hpText.y; // Position it directly over the player's HP text LK.gui.top.addChild(healText); // Tween animation for heal text tween(healText, { alpha: 0, y: healText.y - 50 // Move slightly up during fade out }, { duration: 1000, // 1 second duration easing: tween.easeOut, onFinish: function onFinish() { healText.destroy(); } }); } else { var projectile = projectilePool.getProjectile(); projectile.init(self.x, self.y, enemy.x, enemy.y, 10, cell.damage, self.currentPosition); if (!projectile.parent) { game.addChild(projectile); } } wheel.isSpinning = false; // Set isSpinning to false after the spin is complete // Deduct damage from player's HP after player stops var _deductHp = function deductHp() { if (cell.actionType !== 'heal') { var damage = Math.floor(Math.random() * (maxDamage - minDamage + 1)) + minDamage; self.hp -= damage; if (self.hp < 0) { self.hp = 0; } self.hpText.setText('Player: ' + self.hp); LK.getSound('Player_Damage').play(); // Play sound immediately when HP is deducted if (self.hp === 0) { LK.showGameOver(); } } }; _deductHp(); currentInterval = startingInterval; // Reset the interval to the starting interval } else { LK.setTimeout(_spinStep, currentInterval); // Schedule the next step } }; _spinStep(); // Start the spin }; }); // Projectile class to represent the projectiles shot by the cells var Projectile = Container.expand(function () { var self = Container.call(this); // Attach the 'projectile' asset to the Projectile var projectileGraphics = self.attachAsset('projectile', { anchorX: 0.5, anchorY: 0.5, alpha: 0 // Set the projectile to be invisible }); // Initialize the Projectile's position and target self.init = function (startX, startY, targetX, targetY, speed, damage, cellIndex) { self.x = startX; self.y = startY; self.targetX = targetX; self.targetY = targetY; self.speed = speed * 10; // Further increase the bullet speed var cell = wheel.cells[cellIndex]; var baseDamage = 0; if (cell) { baseDamage = cell.damage; // Use the latest damage value from the cell } var totalDamageBoost = upgradeState.global.totalDamageBoost; var specificCellBoost = upgradeState.individual.specificCellBoosts[self.cellIndex] || 0; var categoricalBoost = 0; if (cell && cell.type === 'minor') { categoricalBoost = upgradeState.categorical.minorDamageBoost; } else if (cell && cell.type === 'major') { categoricalBoost = upgradeState.categorical.majorDamageBoost; } else if (cell && cell.type === 'critical') { categoricalBoost = upgradeState.categorical.criticalDamageBoost; } self.cellIndex = cellIndex; self.damage = cell.damage + totalDamageBoost + specificCellBoost + categoricalBoost; self.active = true; // Mark projectile as active }; // Move the Projectile towards its target self.update = function () { if (!self.active) { return; } // Skip update if not active var dx = self.targetX - self.x; var dy = self.targetY - self.y; var dist = calculateDistance(self.x, self.y, self.targetX, self.targetY); if (dist < self.speed) { self.x = self.targetX; self.y = self.targetY; self.deactivate(); // Deactivate when reaching target } else { self.x += dx * self.speed / dist; self.y += dy * self.speed / dist; // Check if the projectile has intersected with the enemy if (self.intersects(enemy)) { // Deal damage to the enemy enemy.hp -= self.damage; // Heal the player based on the vampiric ability if (upgradeState.global.vampiricAbility) { peon.playerHP.updateHP(upgradeState.global.vampiricAbility); var healText = new Text2('+' + upgradeState.global.vampiricAbility, { //{2R.1} size: 150, //{2R.2} fill: 0x00FF00 //{2R.3} }); //{2R.4} healText.anchor.set(0.5, 0.5); //{2R.5} healText.x = peon.playerHP.hpText.x + 250; //{2R.6} healText.y = peon.playerHP.hpText.y; //{2R.7} LK.gui.top.addChild(healText); //{2R.8} tween(healText, { //{2R.9} alpha: 0, //{2R.10} y: healText.y - 50 //{2R.11} }, { //{2R.12} duration: 1000, //{2R.13} easing: tween.easeOut, //{2R.14} onFinish: function onFinish() { //{2R.15} healText.destroy(); //{2R.16} } //{2R.17} }); //{2R.18} } // Delay the damage application to the player's health LK.setTimeout(function () { console.log("Player received damage: " + self.damage); // Log the damage received by the player if (enemy.hp <= 0) { enemy.destroy(); upgradeManager.refreshCellDamage(); // Refresh cell damage before entering upgrade mode gameState = "upgradeMode"; pauseGame(); upgradeManager.enterUpgradeMode(); } else { var damage = Math.floor(Math.random() * (maxDamage - minDamage + 1)) + minDamage; peon.playerHP.updateHP(-damage); } }, 500); // Delay of 500ms // Display damage text on enemy var damagePanel = LK.getAsset('Damage_Panel', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0, scaleX: 1, // Ensure the panel is at its original size scaleY: 1 // Ensure the panel is at its original size }); var damageText = new Text2(self.damage.toString(), { size: 150, fill: 0xFF0000, stroke: 0x000000, strokeThickness: 10 }); damageText.stroke = 0x000000; damageText.strokeThickness = 10; damageText.anchor.set(0.5, 0.5); damageText.x = 2048 / 2; // Center horizontally damageText.y = 2732 / 2 - 1000; // Move 600 pixels higher damagePanel.x = damageText.x; damagePanel.y = damageText.y + 50; foregroundContainer.addChild(damageText); midgroundContainer.addChild(damagePanel); // Attach the panel to the midground container // Tween animation for appearance and fade out tween(damageText, { // Apply tween to the damage text alpha: 0, y: damageText.y - 100 // Move slightly up during fade out }, { duration: 800, easing: tween.easeIn, onFinish: function onFinish() { damageText.destroy(); // Destroy the text after animation damagePanel.destroy(); // Destroy the panel after animation } }); tween(damagePanel, { // Apply tween to the panel alpha: 0, y: damagePanel.y - 100 // Move slightly up during fade out }, { duration: 800, easing: tween.easeIn, onFinish: function onFinish() { // No need to destroy here as it's handled in damageText's onFinish } }); // Update the enemy's HP text if (enemy) { if (enemy.hpText) { if (enemy.hpText) { enemy.hpText.setText("HP: " + enemy.hp); // Update the enemy's HP text } } } self.deactivate(); // Deactivate the projectile // Add shake animation to the enemy var shake = 20; var shakeSpeed = 15; var originalEnemyX = enemy.x; // Save the original position of the enemy var shakeInterval = LK.setInterval(function () { shake *= -1; enemy.x += shake; shakeSpeed--; if (shakeSpeed <= 0) { LK.clearInterval(shakeInterval); enemy.x = originalEnemyX; // Reset the enemy's position after the shake animation ends } }, shakeSpeed); // If enemy's HP reaches 0, destroy the enemy and play explosion animation if (enemy.hp <= 0) { enemy.destroy(); upgradeManager.refreshCellDamage(); // Refresh cell damage before entering upgrade mode gameState = "upgradeMode"; pauseGame(); upgradeManager.enterUpgradeMode(); // Create a custom explosion animation if (enemy.assetType) { var explosion = self.attachAsset(enemy.assetType, { anchorX: 0.5, anchorY: 0.5 }); explosion.x = enemy.x; explosion.y = enemy.y; explosion.scaleX = 2; explosion.scaleY = 2; explosion.alpha = 0.5; game.addChild(explosion); var _fadeOut = function fadeOut() { explosion.alpha -= 0.05; if (explosion.alpha <= 0) { explosion.destroy(); } else { LK.setTimeout(_fadeOut, 50); } }; _fadeOut(); } // Enemy creation moved to after upgrade selection } } } }; // Deactivate the projectile and return it to the pool self.deactivate = function () { self.active = false; self.x = -1000; // Move off-screen self.y = -1000; // Move off-screen }; }); // SpinningWheel class to handle spinning mechanics var SpinningWheel = Container.expand(function () { var self = Container.call(this); self.cells = []; self.isSpinning = false; // Initialize the wheel with cells self.init = function () { self.cells = []; var cellTypes = [{ type: 'critical', baseDamage: 100, actionType: 'damage' }, { type: 'major', baseDamage: 25, actionType: 'damage' }, { type: 'minor', baseDamage: 10, actionType: 'damage' }, { type: 'heal', baseDamage: 15, actionType: 'heal' }, { type: 'minor', baseDamage: 10, actionType: 'damage' }, { type: 'major', baseDamage: 25, actionType: 'damage' }, { type: 'minor', baseDamage: 10, actionType: 'damage' }, { type: 'heal', baseDamage: 15, actionType: 'heal' }]; for (var i = 0; i < cellTypes.length; i++) { var cell = new Tile(cellTypes[i].type, cellTypes[i].baseDamage, cellTypes[i].actionType); self.cells.push(cell); } for (var i = 0; i < self.cells.length; i++) { var assetType = 'tile'; if (self.cells[i].type === 'minor') { assetType = 'Tile_1'; } else if (self.cells[i].type === 'major') { assetType = 'Tile_2'; } else if (self.cells[i].actionType === 'heal') { assetType = 'Tile_3'; } self.cells[i].initDisplay(assetType, i * 250, 100); self.addChild(self.cells[i].display); } }; // Spin the Player around the wheel self.spin = function (player) { if (!self.isSpinning) { self.isSpinning = true; player.spin(self); } }; }); // Initialize UpgradeManager var UpgradeManager = Container.expand(function (wheel) { var self = Container.call(this); self.wheel = wheel; // Store the wheel instance self.availableUpgrades = upgradeOptions; self.generateUpgradeOptions = function () { return getRandomUpgrades(); }; self.applyUpgrade = function (selectedUpgrade) { switch (selectedUpgrade.type) { case 'increaseDamage': // Update upgradeState based on the upgrade description if (selectedUpgrade.description.includes('all damage')) { upgradeState.global.totalDamageBoost = Math.min(upgradeState.global.totalDamageBoost + selectedUpgrade.value, 1000); } else if (selectedUpgrade.description.includes('minor damage')) { upgradeState.categorical.minorDamageBoost = Math.min(upgradeState.categorical.minorDamageBoost + selectedUpgrade.value, 500); } else if (selectedUpgrade.description.includes('major damage')) { upgradeState.categorical.majorDamageBoost += selectedUpgrade.value; } else if (selectedUpgrade.description.includes('critical')) { upgradeState.categorical.criticalDamageBoost += selectedUpgrade.value; } else if (selectedUpgrade.description.includes('random')) { var damageCells = self.wheel.cells.filter(function (cell) { //{3B.1} return cell.actionType === 'damage'; //{3B.2} }); //{3B.3} if (damageCells.length > 0) { //{3B.4} var randomIndex = Math.floor(Math.random() * damageCells.length); //{3B.5} var randomCell = damageCells[randomIndex]; //{3B.6} var cellIndex = self.wheel.cells.indexOf(randomCell); //{3B.7} if (!upgradeState.individual.specificCellBoosts[cellIndex]) { upgradeState.individual.specificCellBoosts[cellIndex] = 0; //{3C.1} } //{3C.2} upgradeState.individual.specificCellBoosts[cellIndex] = Math.min(upgradeState.individual.specificCellBoosts[cellIndex] + 100, 200); //{3C.3} console.log("Added +100 to cell index:", cellIndex); //{3C.4} } } self.refreshCellDamage(); // Refresh cell damage after applying upgrade console.log("Updated upgradeState:", upgradeState); console.log("Global Boost:", upgradeState.global.totalDamageBoost); console.log("Categorical Boosts:", upgradeState.categorical); console.log("Specific Cell Boosts:", upgradeState.individual.specificCellBoosts); break; case 'heal': if (selectedUpgrade.description === 'Heal +50 HP') { peon.playerHP.updateHP(selectedUpgrade.value); LK.getSound('Heal').play(); // Play the 'Heal' sound when the upgrade is selected } else { // Increase the damage value of heal cells for (var i = 0; i < self.wheel.cells.length; i++) { if (self.wheel.cells[i].actionType === 'heal') { self.wheel.cells[i].damage += selectedUpgrade.value; console.log("Increased heal cell damage for cell", i, "to", self.wheel.cells[i].damage); } } upgradeState.categorical.healBoost += selectedUpgrade.value; // Increment healBoost console.log("Total heal boost is now", upgradeState.categorical.healBoost); // Log total heal boost LK.getSound('Upgrade').play(); // Play the 'Upgrade' sound } self.refreshCellDamage(); // Refresh cell damage after applying upgrade break; case 'increaseHP': peon.playerHP.updateHP(selectedUpgrade.value); break; case 'increaseSpeed': if (target && typeof target.speed !== 'undefined') { target.speed += selectedUpgrade.value; } else { console.error('Target is undefined or does not have a speed property'); } break; case 'increaseVampiric': // Increase the vampiric ability of projectiles upgradeState.global.vampiricAbility = (upgradeState.global.vampiricAbility || 0) + selectedUpgrade.value; console.log("Vampiric Ability increased to:", upgradeState.global.vampiricAbility); break; case 'increaseHealIncrement': //{3R.1} // Increase the health increment by 1 for full rotation upgradeState.categorical.healBoost += selectedUpgrade.value; //{3R.2} upgradeState.categorical.healBoostCount = (upgradeState.categorical.healBoostCount || 0) + 1; // Track number of upgrades console.log("Health increment increased by 1 for full rotation. Total heal boost is now", upgradeState.categorical.healBoost); //{3R.3} console.log("New HP restoration value per full rotation:", 1 + upgradeState.categorical.healBoostCount); self.refreshCellDamage(); // Refresh cell damage after applying upgrade break; //{3R.4} default: console.error('Unknown upgrade type'); } }; self.refreshCellDamage = function () { console.log("refreshCellDamage called"); // Log function call if (!self.wheel || !self.wheel.cells) { console.error("Wheel or its cells are not initialized."); // Only return if critical initialization issues exist return; } for (var i = 0; i < self.wheel.cells.length; i++) { var cell = self.wheel.cells[i]; var totalDamageBoost = upgradeState.global.totalDamageBoost; var specificCellBoost = upgradeState.individual.specificCellBoosts[i] || 0; var categoricalBoost = 0; if (cell.type === 'minor') { categoricalBoost = upgradeState.categorical.minorDamageBoost; } else if (cell.type === 'major') { categoricalBoost = upgradeState.categorical.majorDamageBoost; } else if (cell.type === 'critical') { categoricalBoost = upgradeState.categorical.criticalDamageBoost; } var healBoost = upgradeState.categorical.healBoost || 0; var effectiveDamage = cell.baseDamage + totalDamageBoost + specificCellBoost + categoricalBoost; if (cell.actionType === 'heal') { effectiveDamage += healBoost; } console.log("Cell ".concat(i, " (").concat(cell.type, ") new damage: ").concat(effectiveDamage)); cell.damage = effectiveDamage; var displayText = cell.actionType === 'heal' ? '+' + effectiveDamage : effectiveDamage.toString(); // Remove existing damageText if present if (cell.display) { var existingDamageText = cell.display.children.find(function (child) { return child.name === 'damageText'; }); if (existingDamageText) { existingDamageText.destroy(); } // Create a new damageText instance var damageText = new Text2(displayText, { size: 50, fill: cell.actionType === 'heal' ? 0x00FF00 : 0xFFFFFF }); damageText.name = 'damageText'; // Assign unique name damageText.anchor.set(0.5, 0.5); cell.display.addChild(damageText); } } }; self.enterUpgradeMode = function () { if (self.upgradeScreenOpen) { return; } // Check if upgrade screen is already open self.upgradeScreenOpen = true; // Set flag to indicate upgrade screen is open var options = getRandomUpgrades(); // Directly call getRandomUpgrades to ensure fresh selection var upgradeUI = new UpgradeUI(); upgradeUI.init(options); game.addChild(upgradeUI); }; }); // UpgradeUI class to handle upgrade selection interface var UpgradeUI = Container.expand(function () { var self = Container.call(this); self.upgradeOptions = []; // Initialize the UI with two upgrade options self.init = function (options) { self.upgradeOptions = options; self.displayOptions(); }; // Display the upgrade options self.displayOptions = function () { for (var i = 0; i < 2; i++) { var optionContainer = new Container(); // Create a container for each option optionContainer.x = 1024; // Center horizontally optionContainer.y = 1700 + i * 250; // Move options 800 pixels lower var optionText = new Text2(self.upgradeOptions[i].description, { size: 150, fill: 0x800080 }); optionText.anchor.set(0.5, 0.5); optionContainer.addChild(optionText); // Add text to the container optionContainer.interactive = true; // Make the container interactive optionContainer.on('down', function (selectedUpgrade, optionContainer) { // Use closure to capture the correct upgrade return function () { console.log("Upgrade option clicked:", selectedUpgrade.description); // Log the click event // Add tween animation to simulate pressing effect tween(optionContainer.scale, { x: 0.9, y: 0.9 }, { duration: 75, easing: tween.easeInOut, onFinish: function onFinish() { tween(optionContainer.scale, { x: 1, y: 1 }, { duration: 75, easing: tween.easeInOut, onFinish: function onFinish() { self.selectUpgrade(selectedUpgrade); } }); } }); }; }(self.upgradeOptions[i], optionContainer)); // Pass the correct upgrade option and container self.addChild(optionContainer); // Add the container to the UI } }; // Handle upgrade selection self.selectUpgrade = function (selectedUpgrade) { console.log("Selected upgrade:", selectedUpgrade.description); // Log the selected upgrade upgradeManager.applyUpgrade(selectedUpgrade); if (selectedUpgrade.description !== 'Heal +50 HP') { LK.getSound('Upgrade').play(); // Play the 'Upgrade' sound } upgradeManager.refreshCellDamage(); // Ensure cell damage is updated after applying upgrade self.destroy(); // Close the UI gameState = "playing"; // Resume the game resumeGame(); // Restore game interactivity enemy = createNewEnemy(); // Create a new enemy after upgrade selection game.addChild(enemy); upgradeManager.upgradeScreenOpen = false; // Reset flag after upgrade selection }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xFFFFFF, //Init game with black background interaction: true // Enable interaction manager }); /**** * Game Code ****/ // Initialize the 'Heal' sound // InputHandler class to manage player input disabling var InputHandler = function InputHandler() { this.holdTimer = null; this.isInputDisabled = false; // Method to start the hold timer this.startHoldTimer = function () { var self = this; this.holdTimer = LK.setTimeout(function () { self.disableInput(); }, 2000); // Disable input after 2 seconds }; // Method to disable player input this.disableInput = function () { this.isInputDisabled = true; game.interaction = false; // Disable interaction console.log("Input disabled due to prolonged hold"); // Simulate finger release to release the peon if (chargeTimer) { LK.clearInterval(chargeTimer); chargeTimer = null; if (chargeCount >= 1) { LK.getSound('Roll').play(); // Play the 'Roll' sound peon.spin(wheel, chargeCount); } chargeCount = 0; currentInterval = startingInterval; multiplier = 0.5; tween.stop(peon, { x: true }); inputHandler.reset(); // Reset the input handler //{6L.8} LK.getSound('Charge').stop(); // Stop the 'Charge' sound } }; // Method to reset the input handler this.reset = function () { if (this.holdTimer) { LK.clearTimeout(this.holdTimer); this.holdTimer = null; } this.isInputDisabled = false; game.interaction = true; // Re-enable interaction }; }; var inputHandler = new InputHandler(); // PlayerHP class to manage player's health and display LK.on('damageReceived', function (damageAmount) { peon.playerHP.updateHP(-damageAmount); }); LK.on('healingReceived', function (healAmount) { peon.playerHP.updateHP(healAmount); }); // Tile class to represent different types of tiles on the wheel // PlayerHP class to manage player's health and display var PlayerHP = function PlayerHP() { this.hp = 200; this.maxHP = 200; this.hpText = new Text2('Player: ' + this.hp, { size: 150, fill: 0x000000 }); this.hpText.anchor.set(0.5, 0); this.hpText.y += 1500; LK.gui.top.addChild(this.hpText); }; PlayerHP.prototype.updateHP = function (amount) { this.hp += amount; if (this.hp > this.maxHP) { this.hp = this.maxHP; } else if (this.hp < 0) { this.hp = 0; } this.hpText.setText('Player: ' + this.hp); if (amount < 0) { LK.getSound('Player_Damage').play(); // Ensure sound plays when HP is deducted console.log("Player took damage: " + amount); // Log the damage amount } if (this.hp === 0) { LK.showGameOver(); } }; PlayerHP.prototype.setMaxHP = function (newMaxHP) { this.maxHP = newMaxHP; if (this.hp > this.maxHP) { this.hp = this.maxHP; } this.hpText.setText('Player: ' + this.hp); }; PlayerHP.prototype.getCurrentHP = function () { return this.hp; }; PlayerHP.prototype.getMaxHP = function () { return this.maxHP; }; PlayerHP.prototype.resetHP = function () { this.hp = this.maxHP; this.hpText.setText('Player: ' + this.hp); }; var Tile = function Tile(type, baseDamage, actionType) { this.type = type; this.baseDamage = baseDamage; this.damage = baseDamage; this.actionType = actionType; this.display = null; }; // Method to initialize the display for the tile Tile.prototype.initDisplay = function (assetType, x, y) { this.display = LK.getAsset(assetType, { anchorX: 0.5, anchorY: 0.5, x: x, y: y }); this.display.name = "tile_".concat(x, "_").concat(y); // Assign a unique name based on position }; // Method to update the tile's damage value Tile.prototype.updateDamage = function (newDamage) { this.damage = newDamage; }; function startPeonShake() { tween(peon, { x: peon.x + 5 }, { duration: 50, easing: tween.easeInOut, onFinish: function onFinish() { tween(peon, { x: peon.x - 5 }, { duration: 50, easing: tween.easeInOut, onFinish: function onFinish() { if (chargeTimer) { startPeonShake(); // Continue shaking } } }); } }); } var midgroundContainer = new MidgroundContainer(); game.addChild(midgroundContainer); var platform = LK.getAsset('Platform', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); midgroundContainer.addChild(platform); // Centralized state for tracking upgrades // PlayerHP class to manage player's health and display // PlayerHP class to manage player's health and display var PlayerHP = function PlayerHP() { this.hp = 200; this.maxHP = 200; this.hpText = new Text2('Player: ' + this.hp, { size: 150, fill: 0x000000 }); this.hpText.anchor.set(0.5, 0); this.hpText.y += 1500; LK.gui.top.addChild(this.hpText); }; PlayerHP.prototype.updateHP = function (amount) { this.hp += amount; if (this.hp > this.maxHP) { this.hp = this.maxHP; } else if (this.hp < 0) { this.hp = 0; } this.hpText.setText('Player: ' + this.hp); if (this.hp === 0) { LK.showGameOver(); } }; PlayerHP.prototype.setMaxHP = function (newMaxHP) { this.maxHP = newMaxHP; if (this.hp > this.maxHP) { this.hp = this.maxHP; } this.hpText.setText('Player: ' + this.hp); }; PlayerHP.prototype.getCurrentHP = function () { return this.hp; }; PlayerHP.prototype.getMaxHP = function () { return this.maxHP; }; PlayerHP.prototype.resetHP = function () { this.hp = this.maxHP; this.hpText.setText('Player: ' + this.hp); }; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) { return t; } var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) { return i; } throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var enemySpawnCount = 0; var upgradeState = { global: { totalDamageBoost: 0 }, categorical: { minorDamageBoost: 0, majorDamageBoost: 0, criticalDamageBoost: 0, healBoost: 0, // New property to track heal boosts healBoostCount: 0 // Track number of heal increment upgrades }, individual: { specificCellBoosts: {} } }; // Initialize gameState to manage game states // UpgradeManager class to handle upgrades var gameState = "playing"; // Possible states: playing, paused, upgradeMode // Centralized data structure for upgrade options var upgradeOptions = [{ type: 'increaseDamage', value: 5, description: '+5 to all damage' }, { type: 'increaseDamage', value: 100, description: '+100 to one random tile' }, { type: 'increaseDamage', value: 10, description: '+10 to minor damage' }, { type: 'increaseDamage', value: 25, description: '+25 to major damage' }, { type: 'heal', value: 50, description: 'Heal +50 HP' }, { type: 'increaseVampiric', value: 1, description: '+1 HP Lifesteal' }, { type: 'heal', value: 5, description: '+5 to Heal ability' }, { type: 'increaseHealIncrement', value: 1, description: '+1 HP when you pass GO' }]; function shuffleArray(array) { for (var i = array.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var _ref = [array[j], array[i]]; array[i] = _ref[0]; array[j] = _ref[1]; } } function getRandomUpgrades() { shuffleArray(upgradeOptions); return upgradeOptions.slice(0, 2); } var wheel = new SpinningWheel(); var upgradeManager = new UpgradeManager(wheel); if (midgroundContainer) { midgroundContainer.addChild(wheel); } else { console.error("midgroundContainer is not initialized."); } wheel.init(); wheel.x = 150; // Initial x position wheel.y = 2500; // Space cells horizontally game.addChild(wheel); upgradeManager.wheel = wheel; // Assign wheel reference to UpgradeManager upgradeManager.enterUpgradeMode = upgradeManager.enterUpgradeMode.bind(upgradeManager); // Function to pause the game function pauseGame() { // Logic to pause animations, input, and timers console.log("Game paused"); } // Function to trigger the upgrade system UI function triggerUpgradeUI(options) { // Logic to display upgrade options to the player console.log("Upgrade UI triggered with options:", options); // Display options in a UI for the player to select // This is a placeholder for the actual UI implementation } // Function to resume the game function resumeGame() { // Logic to resume animations, input, and timers console.log("Game resumed"); } // Example usage: Generate upgrade options and apply one to the Peon // ProjectilePool class to manage projectile instances // Helper function to calculate distance between two points // Cache enemy assets for reuse // ProjectilePool class to manage projectile instances var CELL_ACTIONS = { DAMAGE_10: { damage: 10, actionType: 'damage' }, DAMAGE_25: { damage: 25, actionType: 'damage' }, DAMAGE_100: { damage: 100, actionType: 'damage' }, HEAL_25: { damage: 25, actionType: 'heal' } }; function calculateDistance(x1, y1, x2, y2) { return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)); } var cachedEnemyAssets = { enemy: LK.getAsset('enemy', {}), enemy_2: LK.getAsset('enemy_2', {}), enemy_3: LK.getAsset('enemy_3', {}) }; var ProjectilePool = function ProjectilePool() { this.pool = []; this.getProjectile = function () { for (var i = 0; i < this.pool.length; i++) { if (!this.pool[i].active) { return this.pool[i]; } } if (this.pool.length < this.maxPoolSize) { var newProjectile = new Projectile(); this.pool.push(newProjectile); return newProjectile; } return null; // Return null if pool is full }; this.releaseProjectile = function (projectile) { projectile.deactivate(); }; }; var projectilePool = new ProjectilePool(); projectilePool.maxPoolSize = 10; // Set maximum pool size // ProjectilePool class to manage projectile instances // Global timing variables // Initialize spinning wheel var startingInterval = 2; // Starting interval for the spin var multiplier = 0.5; // Multiplier for the interval increase var currentInterval = startingInterval; var startingMovingTiles = 11; // Starting moving tiles var maxTiles = 17; // Maximum number of tiles var minDamage = 10; // Minimum damage var maxDamage = 15; // Maximum damage var backgroundContainer = new BackgroundContainer(); game.addChild(backgroundContainer); var midgroundContainer = new MidgroundContainer(); game.addChild(midgroundContainer); var platform = LK.getAsset('Platform', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); midgroundContainer.addChild(platform); var foregroundContainer = new ForegroundContainer(); game.addChild(foregroundContainer); var wheel = new SpinningWheel(); midgroundContainer.addChild(wheel); wheel.init(); wheel.x = 150; // Initial x position wheel.y = 2500; // Space cells horizontally game.addChild(wheel); // Initialize the Peon and add it to the game var peon = new Peon(); peon.init(wheel); game.addChild(peon); // Function to create a new enemy function createNewEnemy() { // Define available enemy types var enemyTypes = [{ asset: 'enemy' }, { asset: 'enemy_2' }, { asset: 'enemy_3' }]; // Select a random enemy type var randomIndex = Math.floor(Math.random() * enemyTypes.length); var selectedEnemy = enemyTypes[randomIndex]; // Increment the spawn count enemySpawnCount += 1; minDamage += 1; // Increase minimum damage by 1 maxDamage += 2; // Increase maximum damage by 2 // Calculate HP: 50 * spawn count var enemyHP = 50 * enemySpawnCount; // Instantiate the enemy with required parameters var newEnemy = new Enemy(selectedEnemy.asset); newEnemy.init(enemyHP); backgroundContainer.addChild(newEnemy); updateLevelText(); return newEnemy; } // Initialize level text var levelText = new Text2('Level: 1', { size: 50, fill: 0x000000 }); levelText.anchor.set(0.5, 0); levelText.y = 10; // Position it at the top of the screen LK.gui.top.addChild(levelText); // Initialize the first enemy var enemy = createNewEnemy(); // Function to update level text function updateLevelText() { levelText.setText('Level: ' + enemySpawnCount); } // Add a text to display the player's HP var playerHPState = { currentHP: peon.playerHP.getCurrentHP(), maxHP: peon.playerHP.getMaxHP() }; // Restore player HP state when game resumes function restorePlayerHPState() { peon.playerHP.hp = playerHPState.currentHP; peon.playerHP.maxHP = playerHPState.maxHP; peon.playerHP.hpText.setText('Player: ' + peon.playerHP.hp); } // Add a down event to the game to spin the Peon when the screen is tapped var chargeCount = 0; var chargeTimer = null; game.down = function (x, y, obj) { if (gameState !== "upgradeMode" && !wheel.isSpinning && !chargeTimer && !inputHandler.isInputDisabled) { //{6J.1} //{6J.1} chargeCount = Math.floor(Math.random() * 2) + 1; // Randomly set chargeCount between 1 and 2 //{6J.2} chargeTimer = LK.setInterval(function () { //{6J.3} chargeCount++; //{6J.4} }, 150); //{6J.5} // Start peon shake effect startPeonShake(); inputHandler.startHoldTimer(); // Start the hold timer //{6J.6} LK.getSound('Charge').play(); // Play the 'Charge' sound } //{6J.6} }; game.up = function (x, y, obj) { if (chargeTimer) { game.interaction = false; // Disable interaction LK.setTimeout(function () { game.interaction = true; // Re-enable interaction after 200ms }, 400); //{6L.1} //{6L.1} LK.clearInterval(chargeTimer); //{6L.2} chargeTimer = null; //{6L.3} if (chargeCount >= 1) { //{6L.4} //{6L.4} LK.getSound('Roll').play(); // Play the 'Roll' sound peon.spin(wheel, chargeCount); //{6L.5} } //{6L.6} chargeCount = 0; // Reset chargeCount after spin //{6L.7} currentInterval = startingInterval; // Reset the interval to the starting interval multiplier = 0.5; // Reset the multiplier to its initial value // Stop peon shake effect tween.stop(peon, { x: true }); inputHandler.reset(); // Reset the input handler } //{6L.8} };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// BackgroundContainer class
var BackgroundContainer = Container.expand(function () {
var self = Container.call(this);
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Enemy class to handle enemy logic
var Enemy = Container.expand(function (assetType) {
var self = Container.call(this);
if (!assetType) {
console.error("Asset type is undefined");
return;
}
var enemyGraphics = cachedEnemyAssets[assetType]; // Reuse cached asset
enemyGraphics.anchor.set(0.5, 0.5); // Set anchor to center
self.addChild(enemyGraphics); // Attach the cached asset to the enemy
self.init = function (initialHP) {
self.x = 2048 / 2;
self.y = 2732 / 2 - 500;
// Initialize the enemy's HP
self.hp = initialHP;
// Add a text to display the enemy's HP
self.hpText = new Text2("", {
size: 150,
fill: 0x000000
});
self.hpText.anchor.set(0.5, 0.5);
self.hpText.y = -700; // Move the text higher
self.addChild(self.hpText);
// Update the enemy's HP text
if (self.hpText) {
self.hpText.setText("HP: " + self.hp);
}
};
// self.init(); // Ensure init is called during construction
});
// ForegroundContainer class
var ForegroundContainer = Container.expand(function () {
var self = Container.call(this);
});
// MidgroundContainer class
var MidgroundContainer = Container.expand(function () {
var self = Container.call(this);
});
// Peon class to represent the player character
var Peon = Container.expand(function () {
var self = Container.call(this);
// Attach the 'peon' asset to the Peon
var peonGraphics = self.attachAsset('peon', {
anchorX: 0.5,
anchorY: 0.5
});
// Initialize the Peon's position on the wheel
self.init = function (wheel) {
self.x = wheel.x;
self.y = wheel.y;
self.currentPosition = Math.floor(Math.random() * 8); // Peon's current position on the wheel
self.playerHP = new PlayerHP();
self.x += self.currentPosition * 250; // Position Peon on the random cell
};
// Spin the Peon around the wheel
self.spin = function (wheel, steps) {
self.steps = steps; // Use the passed steps parameter instead of random assignment
var _spinStep = function spinStep() {
self.currentPosition = (self.currentPosition + 1) % 8;
self.x = wheel.x + self.currentPosition * 250;
if (self.currentPosition == 0) {
self.x = wheel.x;
// Add +1 to the full rotation variable when moving from the last 8th cell back to the first cell
upgradeState.categorical.healBoostCount += 1;
var healText = new Text2('+1', {
size: 150,
fill: 0x00FF00 // Green color for heal
});
healText.anchor.set(0.5, 0.5);
healText.x = self.playerHP.hpText.x + 250;
healText.y = self.playerHP.hpText.y;
LK.gui.top.addChild(healText);
tween(healText, {
alpha: 0,
y: healText.y - 50
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
healText.destroy();
}
});
// Display Pass_GO asset in the center of the screen
var passGoAsset = LK.getAsset('Pass_GO', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2 + 880,
y: 2732 / 2 + 950,
alpha: 0
});
midgroundContainer.addChild(passGoAsset);
tween(passGoAsset, {
alpha: 1
}, {
duration: 300,
onFinish: function onFinish() {
LK.setTimeout(function () {
tween(passGoAsset, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
passGoAsset.destroy();
}
});
}, 500);
}
});
}
self.steps--;
if (self.steps <= 0) {
self.x = wheel.x + self.currentPosition * 250;
var cell = wheel.cells[self.currentPosition];
if (cell.actionType === 'heal') {
var healAmount = cell.damage; // Use the updated damage value from the cell
self.playerHP.updateHP(healAmount);
LK.getSound('Heal').play(); // Play the 'Heal' sound
var healText = new Text2('+' + healAmount, {
size: 150,
fill: 0x00FF00
});
healText.anchor.set(0.5, 0.5);
healText.x = self.playerHP.hpText.x + 250;
healText.y = self.playerHP.hpText.y;
LK.gui.top.addChild(healText);
tween(healText, {
alpha: 0,
y: healText.y - 50
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
healText.destroy();
}
});
} else {
var projectile = projectilePool.getProjectile();
projectile.init(self.x, self.y, enemy.x, enemy.y, 10, cell.damage, self.currentPosition);
if (!projectile.parent) {
game.addChild(projectile);
}
}
wheel.isSpinning = false;
var _deductHp = function deductHp() {
if (cell.actionType !== 'heal') {
var damage = Math.floor(Math.random() * (maxDamage - minDamage + 1)) + minDamage;
self.playerHP.updateHP(-damage);
}
};
// Removed instant damage application to player's health
} else {
LK.setTimeout(_spinStep, currentInterval * 10); // Increase interval to slow down peon speed
}
};
_spinStep();
};
});
// Current interval for the spin
// Player class to handle player logic
var Player = Container.expand(function () {
var self = Container.call(this);
// Attach the 'peon' asset to the Player
var playerGraphics = self.attachAsset('peon', {
anchorX: 0.5,
anchorY: 0.5
});
// Initialize the Player's position on the wheel
self.init = function (wheel) {
self.x = wheel.x;
self.y = wheel.y;
self.currentPosition = Math.floor(Math.random() * 8); // Player's current position on the wheel
self.hp = 200; // Player's HP
self.hpText = new Text2('Player: ' + self.hp, {
size: 150,
fill: 0xFFFFFF //Optional (this is the default string)
});
self.hpText.anchor.set(0.5, 0); // Sets anchor to the center of the top edge of the text.
self.hpText.y += 1000; // Move the text 1000 pixels lower
LK.gui.top.addChild(self.hpText);
self.x += self.currentPosition * 250; // Position Player on the random cell
};
// Spin the Player around the wheel
self.spin = function (wheel) {
// Generate a random integer between 10 and 15
self.steps = Math.floor(Math.random() * (maxTiles - startingMovingTiles + 1)) + startingMovingTiles;
var _spinStep = function spinStep() {
self.currentPosition = (self.currentPosition + 1) % 8; // Update Player's current position
self.x = wheel.x + self.currentPosition * 250; // Move Player one cell to the right
if (self.currentPosition == 0) {
// If Player reaches Cell 8, loop back to Cell 1
self.x = wheel.x;
}
self.steps--;
currentInterval *= multiplier; // Increase the interval by the multiplier
if (self.steps <= 0) {
// Player lands on the final cell
self.x = wheel.x + self.currentPosition * 250;
// Check the action type of the landed cell
var cell = wheel.cells[self.currentPosition];
if (cell.actionType === 'heal') {
self.hp += cell.damage;
if (self.hp > 200) {
self.hp = 200;
}
self.hpText.setText('Player: ' + self.hp);
LK.getSound('Heal').play(); // Play the 'Heal' sound
// Create and display heal amount text
var healText = new Text2('+' + cell.damage, {
size: 150,
fill: 0x00FF00 // Green color for heal
});
healText.anchor.set(0.5, 0.5);
healText.x = self.hpText.x + 250;
healText.y = self.hpText.y; // Position it directly over the player's HP text
LK.gui.top.addChild(healText);
// Tween animation for heal text
tween(healText, {
alpha: 0,
y: healText.y - 50 // Move slightly up during fade out
}, {
duration: 1000,
// 1 second duration
easing: tween.easeOut,
onFinish: function onFinish() {
healText.destroy();
}
});
} else {
var projectile = projectilePool.getProjectile();
projectile.init(self.x, self.y, enemy.x, enemy.y, 10, cell.damage, self.currentPosition);
if (!projectile.parent) {
game.addChild(projectile);
}
}
wheel.isSpinning = false; // Set isSpinning to false after the spin is complete
// Deduct damage from player's HP after player stops
var _deductHp = function deductHp() {
if (cell.actionType !== 'heal') {
var damage = Math.floor(Math.random() * (maxDamage - minDamage + 1)) + minDamage;
self.hp -= damage;
if (self.hp < 0) {
self.hp = 0;
}
self.hpText.setText('Player: ' + self.hp);
LK.getSound('Player_Damage').play(); // Play sound immediately when HP is deducted
if (self.hp === 0) {
LK.showGameOver();
}
}
};
_deductHp();
currentInterval = startingInterval; // Reset the interval to the starting interval
} else {
LK.setTimeout(_spinStep, currentInterval); // Schedule the next step
}
};
_spinStep(); // Start the spin
};
});
// Projectile class to represent the projectiles shot by the cells
var Projectile = Container.expand(function () {
var self = Container.call(this);
// Attach the 'projectile' asset to the Projectile
var projectileGraphics = self.attachAsset('projectile', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0 // Set the projectile to be invisible
});
// Initialize the Projectile's position and target
self.init = function (startX, startY, targetX, targetY, speed, damage, cellIndex) {
self.x = startX;
self.y = startY;
self.targetX = targetX;
self.targetY = targetY;
self.speed = speed * 10; // Further increase the bullet speed
var cell = wheel.cells[cellIndex];
var baseDamage = 0;
if (cell) {
baseDamage = cell.damage; // Use the latest damage value from the cell
}
var totalDamageBoost = upgradeState.global.totalDamageBoost;
var specificCellBoost = upgradeState.individual.specificCellBoosts[self.cellIndex] || 0;
var categoricalBoost = 0;
if (cell && cell.type === 'minor') {
categoricalBoost = upgradeState.categorical.minorDamageBoost;
} else if (cell && cell.type === 'major') {
categoricalBoost = upgradeState.categorical.majorDamageBoost;
} else if (cell && cell.type === 'critical') {
categoricalBoost = upgradeState.categorical.criticalDamageBoost;
}
self.cellIndex = cellIndex;
self.damage = cell.damage + totalDamageBoost + specificCellBoost + categoricalBoost;
self.active = true; // Mark projectile as active
};
// Move the Projectile towards its target
self.update = function () {
if (!self.active) {
return;
} // Skip update if not active
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var dist = calculateDistance(self.x, self.y, self.targetX, self.targetY);
if (dist < self.speed) {
self.x = self.targetX;
self.y = self.targetY;
self.deactivate(); // Deactivate when reaching target
} else {
self.x += dx * self.speed / dist;
self.y += dy * self.speed / dist;
// Check if the projectile has intersected with the enemy
if (self.intersects(enemy)) {
// Deal damage to the enemy
enemy.hp -= self.damage;
// Heal the player based on the vampiric ability
if (upgradeState.global.vampiricAbility) {
peon.playerHP.updateHP(upgradeState.global.vampiricAbility);
var healText = new Text2('+' + upgradeState.global.vampiricAbility, {
//{2R.1}
size: 150,
//{2R.2}
fill: 0x00FF00 //{2R.3}
}); //{2R.4}
healText.anchor.set(0.5, 0.5); //{2R.5}
healText.x = peon.playerHP.hpText.x + 250; //{2R.6}
healText.y = peon.playerHP.hpText.y; //{2R.7}
LK.gui.top.addChild(healText); //{2R.8}
tween(healText, {
//{2R.9}
alpha: 0,
//{2R.10}
y: healText.y - 50 //{2R.11}
}, {
//{2R.12}
duration: 1000,
//{2R.13}
easing: tween.easeOut,
//{2R.14}
onFinish: function onFinish() {
//{2R.15}
healText.destroy(); //{2R.16}
} //{2R.17}
}); //{2R.18}
}
// Delay the damage application to the player's health
LK.setTimeout(function () {
console.log("Player received damage: " + self.damage); // Log the damage received by the player
if (enemy.hp <= 0) {
enemy.destroy();
upgradeManager.refreshCellDamage(); // Refresh cell damage before entering upgrade mode
gameState = "upgradeMode";
pauseGame();
upgradeManager.enterUpgradeMode();
} else {
var damage = Math.floor(Math.random() * (maxDamage - minDamage + 1)) + minDamage;
peon.playerHP.updateHP(-damage);
}
}, 500); // Delay of 500ms
// Display damage text on enemy
var damagePanel = LK.getAsset('Damage_Panel', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0,
scaleX: 1,
// Ensure the panel is at its original size
scaleY: 1 // Ensure the panel is at its original size
});
var damageText = new Text2(self.damage.toString(), {
size: 150,
fill: 0xFF0000,
stroke: 0x000000,
strokeThickness: 10
});
damageText.stroke = 0x000000;
damageText.strokeThickness = 10;
damageText.anchor.set(0.5, 0.5);
damageText.x = 2048 / 2; // Center horizontally
damageText.y = 2732 / 2 - 1000; // Move 600 pixels higher
damagePanel.x = damageText.x;
damagePanel.y = damageText.y + 50;
foregroundContainer.addChild(damageText);
midgroundContainer.addChild(damagePanel); // Attach the panel to the midground container
// Tween animation for appearance and fade out
tween(damageText, {
// Apply tween to the damage text
alpha: 0,
y: damageText.y - 100 // Move slightly up during fade out
}, {
duration: 800,
easing: tween.easeIn,
onFinish: function onFinish() {
damageText.destroy(); // Destroy the text after animation
damagePanel.destroy(); // Destroy the panel after animation
}
});
tween(damagePanel, {
// Apply tween to the panel
alpha: 0,
y: damagePanel.y - 100 // Move slightly up during fade out
}, {
duration: 800,
easing: tween.easeIn,
onFinish: function onFinish() {
// No need to destroy here as it's handled in damageText's onFinish
}
});
// Update the enemy's HP text
if (enemy) {
if (enemy.hpText) {
if (enemy.hpText) {
enemy.hpText.setText("HP: " + enemy.hp); // Update the enemy's HP text
}
}
}
self.deactivate(); // Deactivate the projectile
// Add shake animation to the enemy
var shake = 20;
var shakeSpeed = 15;
var originalEnemyX = enemy.x; // Save the original position of the enemy
var shakeInterval = LK.setInterval(function () {
shake *= -1;
enemy.x += shake;
shakeSpeed--;
if (shakeSpeed <= 0) {
LK.clearInterval(shakeInterval);
enemy.x = originalEnemyX; // Reset the enemy's position after the shake animation ends
}
}, shakeSpeed);
// If enemy's HP reaches 0, destroy the enemy and play explosion animation
if (enemy.hp <= 0) {
enemy.destroy();
upgradeManager.refreshCellDamage(); // Refresh cell damage before entering upgrade mode
gameState = "upgradeMode";
pauseGame();
upgradeManager.enterUpgradeMode();
// Create a custom explosion animation
if (enemy.assetType) {
var explosion = self.attachAsset(enemy.assetType, {
anchorX: 0.5,
anchorY: 0.5
});
explosion.x = enemy.x;
explosion.y = enemy.y;
explosion.scaleX = 2;
explosion.scaleY = 2;
explosion.alpha = 0.5;
game.addChild(explosion);
var _fadeOut = function fadeOut() {
explosion.alpha -= 0.05;
if (explosion.alpha <= 0) {
explosion.destroy();
} else {
LK.setTimeout(_fadeOut, 50);
}
};
_fadeOut();
}
// Enemy creation moved to after upgrade selection
}
}
}
};
// Deactivate the projectile and return it to the pool
self.deactivate = function () {
self.active = false;
self.x = -1000; // Move off-screen
self.y = -1000; // Move off-screen
};
});
// SpinningWheel class to handle spinning mechanics
var SpinningWheel = Container.expand(function () {
var self = Container.call(this);
self.cells = [];
self.isSpinning = false;
// Initialize the wheel with cells
self.init = function () {
self.cells = [];
var cellTypes = [{
type: 'critical',
baseDamage: 100,
actionType: 'damage'
}, {
type: 'major',
baseDamage: 25,
actionType: 'damage'
}, {
type: 'minor',
baseDamage: 10,
actionType: 'damage'
}, {
type: 'heal',
baseDamage: 15,
actionType: 'heal'
}, {
type: 'minor',
baseDamage: 10,
actionType: 'damage'
}, {
type: 'major',
baseDamage: 25,
actionType: 'damage'
}, {
type: 'minor',
baseDamage: 10,
actionType: 'damage'
}, {
type: 'heal',
baseDamage: 15,
actionType: 'heal'
}];
for (var i = 0; i < cellTypes.length; i++) {
var cell = new Tile(cellTypes[i].type, cellTypes[i].baseDamage, cellTypes[i].actionType);
self.cells.push(cell);
}
for (var i = 0; i < self.cells.length; i++) {
var assetType = 'tile';
if (self.cells[i].type === 'minor') {
assetType = 'Tile_1';
} else if (self.cells[i].type === 'major') {
assetType = 'Tile_2';
} else if (self.cells[i].actionType === 'heal') {
assetType = 'Tile_3';
}
self.cells[i].initDisplay(assetType, i * 250, 100);
self.addChild(self.cells[i].display);
}
};
// Spin the Player around the wheel
self.spin = function (player) {
if (!self.isSpinning) {
self.isSpinning = true;
player.spin(self);
}
};
});
// Initialize UpgradeManager
var UpgradeManager = Container.expand(function (wheel) {
var self = Container.call(this);
self.wheel = wheel; // Store the wheel instance
self.availableUpgrades = upgradeOptions;
self.generateUpgradeOptions = function () {
return getRandomUpgrades();
};
self.applyUpgrade = function (selectedUpgrade) {
switch (selectedUpgrade.type) {
case 'increaseDamage':
// Update upgradeState based on the upgrade description
if (selectedUpgrade.description.includes('all damage')) {
upgradeState.global.totalDamageBoost = Math.min(upgradeState.global.totalDamageBoost + selectedUpgrade.value, 1000);
} else if (selectedUpgrade.description.includes('minor damage')) {
upgradeState.categorical.minorDamageBoost = Math.min(upgradeState.categorical.minorDamageBoost + selectedUpgrade.value, 500);
} else if (selectedUpgrade.description.includes('major damage')) {
upgradeState.categorical.majorDamageBoost += selectedUpgrade.value;
} else if (selectedUpgrade.description.includes('critical')) {
upgradeState.categorical.criticalDamageBoost += selectedUpgrade.value;
} else if (selectedUpgrade.description.includes('random')) {
var damageCells = self.wheel.cells.filter(function (cell) {
//{3B.1}
return cell.actionType === 'damage'; //{3B.2}
}); //{3B.3}
if (damageCells.length > 0) {
//{3B.4}
var randomIndex = Math.floor(Math.random() * damageCells.length); //{3B.5}
var randomCell = damageCells[randomIndex]; //{3B.6}
var cellIndex = self.wheel.cells.indexOf(randomCell); //{3B.7}
if (!upgradeState.individual.specificCellBoosts[cellIndex]) {
upgradeState.individual.specificCellBoosts[cellIndex] = 0; //{3C.1}
} //{3C.2}
upgradeState.individual.specificCellBoosts[cellIndex] = Math.min(upgradeState.individual.specificCellBoosts[cellIndex] + 100, 200); //{3C.3}
console.log("Added +100 to cell index:", cellIndex); //{3C.4}
}
}
self.refreshCellDamage(); // Refresh cell damage after applying upgrade
console.log("Updated upgradeState:", upgradeState);
console.log("Global Boost:", upgradeState.global.totalDamageBoost);
console.log("Categorical Boosts:", upgradeState.categorical);
console.log("Specific Cell Boosts:", upgradeState.individual.specificCellBoosts);
break;
case 'heal':
if (selectedUpgrade.description === 'Heal +50 HP') {
peon.playerHP.updateHP(selectedUpgrade.value);
LK.getSound('Heal').play(); // Play the 'Heal' sound when the upgrade is selected
} else {
// Increase the damage value of heal cells
for (var i = 0; i < self.wheel.cells.length; i++) {
if (self.wheel.cells[i].actionType === 'heal') {
self.wheel.cells[i].damage += selectedUpgrade.value;
console.log("Increased heal cell damage for cell", i, "to", self.wheel.cells[i].damage);
}
}
upgradeState.categorical.healBoost += selectedUpgrade.value; // Increment healBoost
console.log("Total heal boost is now", upgradeState.categorical.healBoost); // Log total heal boost
LK.getSound('Upgrade').play(); // Play the 'Upgrade' sound
}
self.refreshCellDamage(); // Refresh cell damage after applying upgrade
break;
case 'increaseHP':
peon.playerHP.updateHP(selectedUpgrade.value);
break;
case 'increaseSpeed':
if (target && typeof target.speed !== 'undefined') {
target.speed += selectedUpgrade.value;
} else {
console.error('Target is undefined or does not have a speed property');
}
break;
case 'increaseVampiric':
// Increase the vampiric ability of projectiles
upgradeState.global.vampiricAbility = (upgradeState.global.vampiricAbility || 0) + selectedUpgrade.value;
console.log("Vampiric Ability increased to:", upgradeState.global.vampiricAbility);
break;
case 'increaseHealIncrement':
//{3R.1}
// Increase the health increment by 1 for full rotation
upgradeState.categorical.healBoost += selectedUpgrade.value; //{3R.2}
upgradeState.categorical.healBoostCount = (upgradeState.categorical.healBoostCount || 0) + 1; // Track number of upgrades
console.log("Health increment increased by 1 for full rotation. Total heal boost is now", upgradeState.categorical.healBoost); //{3R.3}
console.log("New HP restoration value per full rotation:", 1 + upgradeState.categorical.healBoostCount);
self.refreshCellDamage(); // Refresh cell damage after applying upgrade
break;
//{3R.4}
default:
console.error('Unknown upgrade type');
}
};
self.refreshCellDamage = function () {
console.log("refreshCellDamage called"); // Log function call
if (!self.wheel || !self.wheel.cells) {
console.error("Wheel or its cells are not initialized.");
// Only return if critical initialization issues exist
return;
}
for (var i = 0; i < self.wheel.cells.length; i++) {
var cell = self.wheel.cells[i];
var totalDamageBoost = upgradeState.global.totalDamageBoost;
var specificCellBoost = upgradeState.individual.specificCellBoosts[i] || 0;
var categoricalBoost = 0;
if (cell.type === 'minor') {
categoricalBoost = upgradeState.categorical.minorDamageBoost;
} else if (cell.type === 'major') {
categoricalBoost = upgradeState.categorical.majorDamageBoost;
} else if (cell.type === 'critical') {
categoricalBoost = upgradeState.categorical.criticalDamageBoost;
}
var healBoost = upgradeState.categorical.healBoost || 0;
var effectiveDamage = cell.baseDamage + totalDamageBoost + specificCellBoost + categoricalBoost;
if (cell.actionType === 'heal') {
effectiveDamage += healBoost;
}
console.log("Cell ".concat(i, " (").concat(cell.type, ") new damage: ").concat(effectiveDamage));
cell.damage = effectiveDamage;
var displayText = cell.actionType === 'heal' ? '+' + effectiveDamage : effectiveDamage.toString();
// Remove existing damageText if present
if (cell.display) {
var existingDamageText = cell.display.children.find(function (child) {
return child.name === 'damageText';
});
if (existingDamageText) {
existingDamageText.destroy();
}
// Create a new damageText instance
var damageText = new Text2(displayText, {
size: 50,
fill: cell.actionType === 'heal' ? 0x00FF00 : 0xFFFFFF
});
damageText.name = 'damageText'; // Assign unique name
damageText.anchor.set(0.5, 0.5);
cell.display.addChild(damageText);
}
}
};
self.enterUpgradeMode = function () {
if (self.upgradeScreenOpen) {
return;
} // Check if upgrade screen is already open
self.upgradeScreenOpen = true; // Set flag to indicate upgrade screen is open
var options = getRandomUpgrades(); // Directly call getRandomUpgrades to ensure fresh selection
var upgradeUI = new UpgradeUI();
upgradeUI.init(options);
game.addChild(upgradeUI);
};
});
// UpgradeUI class to handle upgrade selection interface
var UpgradeUI = Container.expand(function () {
var self = Container.call(this);
self.upgradeOptions = [];
// Initialize the UI with two upgrade options
self.init = function (options) {
self.upgradeOptions = options;
self.displayOptions();
};
// Display the upgrade options
self.displayOptions = function () {
for (var i = 0; i < 2; i++) {
var optionContainer = new Container(); // Create a container for each option
optionContainer.x = 1024; // Center horizontally
optionContainer.y = 1700 + i * 250; // Move options 800 pixels lower
var optionText = new Text2(self.upgradeOptions[i].description, {
size: 150,
fill: 0x800080
});
optionText.anchor.set(0.5, 0.5);
optionContainer.addChild(optionText); // Add text to the container
optionContainer.interactive = true; // Make the container interactive
optionContainer.on('down', function (selectedUpgrade, optionContainer) {
// Use closure to capture the correct upgrade
return function () {
console.log("Upgrade option clicked:", selectedUpgrade.description); // Log the click event
// Add tween animation to simulate pressing effect
tween(optionContainer.scale, {
x: 0.9,
y: 0.9
}, {
duration: 75,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(optionContainer.scale, {
x: 1,
y: 1
}, {
duration: 75,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.selectUpgrade(selectedUpgrade);
}
});
}
});
};
}(self.upgradeOptions[i], optionContainer)); // Pass the correct upgrade option and container
self.addChild(optionContainer); // Add the container to the UI
}
};
// Handle upgrade selection
self.selectUpgrade = function (selectedUpgrade) {
console.log("Selected upgrade:", selectedUpgrade.description); // Log the selected upgrade
upgradeManager.applyUpgrade(selectedUpgrade);
if (selectedUpgrade.description !== 'Heal +50 HP') {
LK.getSound('Upgrade').play(); // Play the 'Upgrade' sound
}
upgradeManager.refreshCellDamage(); // Ensure cell damage is updated after applying upgrade
self.destroy(); // Close the UI
gameState = "playing"; // Resume the game
resumeGame(); // Restore game interactivity
enemy = createNewEnemy(); // Create a new enemy after upgrade selection
game.addChild(enemy);
upgradeManager.upgradeScreenOpen = false; // Reset flag after upgrade selection
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFFFFF,
//Init game with black background
interaction: true // Enable interaction manager
});
/****
* Game Code
****/
// Initialize the 'Heal' sound
// InputHandler class to manage player input disabling
var InputHandler = function InputHandler() {
this.holdTimer = null;
this.isInputDisabled = false;
// Method to start the hold timer
this.startHoldTimer = function () {
var self = this;
this.holdTimer = LK.setTimeout(function () {
self.disableInput();
}, 2000); // Disable input after 2 seconds
};
// Method to disable player input
this.disableInput = function () {
this.isInputDisabled = true;
game.interaction = false; // Disable interaction
console.log("Input disabled due to prolonged hold");
// Simulate finger release to release the peon
if (chargeTimer) {
LK.clearInterval(chargeTimer);
chargeTimer = null;
if (chargeCount >= 1) {
LK.getSound('Roll').play(); // Play the 'Roll' sound
peon.spin(wheel, chargeCount);
}
chargeCount = 0;
currentInterval = startingInterval;
multiplier = 0.5;
tween.stop(peon, {
x: true
});
inputHandler.reset(); // Reset the input handler //{6L.8}
LK.getSound('Charge').stop(); // Stop the 'Charge' sound
}
};
// Method to reset the input handler
this.reset = function () {
if (this.holdTimer) {
LK.clearTimeout(this.holdTimer);
this.holdTimer = null;
}
this.isInputDisabled = false;
game.interaction = true; // Re-enable interaction
};
};
var inputHandler = new InputHandler();
// PlayerHP class to manage player's health and display
LK.on('damageReceived', function (damageAmount) {
peon.playerHP.updateHP(-damageAmount);
});
LK.on('healingReceived', function (healAmount) {
peon.playerHP.updateHP(healAmount);
});
// Tile class to represent different types of tiles on the wheel
// PlayerHP class to manage player's health and display
var PlayerHP = function PlayerHP() {
this.hp = 200;
this.maxHP = 200;
this.hpText = new Text2('Player: ' + this.hp, {
size: 150,
fill: 0x000000
});
this.hpText.anchor.set(0.5, 0);
this.hpText.y += 1500;
LK.gui.top.addChild(this.hpText);
};
PlayerHP.prototype.updateHP = function (amount) {
this.hp += amount;
if (this.hp > this.maxHP) {
this.hp = this.maxHP;
} else if (this.hp < 0) {
this.hp = 0;
}
this.hpText.setText('Player: ' + this.hp);
if (amount < 0) {
LK.getSound('Player_Damage').play(); // Ensure sound plays when HP is deducted
console.log("Player took damage: " + amount); // Log the damage amount
}
if (this.hp === 0) {
LK.showGameOver();
}
};
PlayerHP.prototype.setMaxHP = function (newMaxHP) {
this.maxHP = newMaxHP;
if (this.hp > this.maxHP) {
this.hp = this.maxHP;
}
this.hpText.setText('Player: ' + this.hp);
};
PlayerHP.prototype.getCurrentHP = function () {
return this.hp;
};
PlayerHP.prototype.getMaxHP = function () {
return this.maxHP;
};
PlayerHP.prototype.resetHP = function () {
this.hp = this.maxHP;
this.hpText.setText('Player: ' + this.hp);
};
var Tile = function Tile(type, baseDamage, actionType) {
this.type = type;
this.baseDamage = baseDamage;
this.damage = baseDamage;
this.actionType = actionType;
this.display = null;
};
// Method to initialize the display for the tile
Tile.prototype.initDisplay = function (assetType, x, y) {
this.display = LK.getAsset(assetType, {
anchorX: 0.5,
anchorY: 0.5,
x: x,
y: y
});
this.display.name = "tile_".concat(x, "_").concat(y); // Assign a unique name based on position
};
// Method to update the tile's damage value
Tile.prototype.updateDamage = function (newDamage) {
this.damage = newDamage;
};
function startPeonShake() {
tween(peon, {
x: peon.x + 5
}, {
duration: 50,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(peon, {
x: peon.x - 5
}, {
duration: 50,
easing: tween.easeInOut,
onFinish: function onFinish() {
if (chargeTimer) {
startPeonShake(); // Continue shaking
}
}
});
}
});
}
var midgroundContainer = new MidgroundContainer();
game.addChild(midgroundContainer);
var platform = LK.getAsset('Platform', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
midgroundContainer.addChild(platform);
// Centralized state for tracking upgrades
// PlayerHP class to manage player's health and display
// PlayerHP class to manage player's health and display
var PlayerHP = function PlayerHP() {
this.hp = 200;
this.maxHP = 200;
this.hpText = new Text2('Player: ' + this.hp, {
size: 150,
fill: 0x000000
});
this.hpText.anchor.set(0.5, 0);
this.hpText.y += 1500;
LK.gui.top.addChild(this.hpText);
};
PlayerHP.prototype.updateHP = function (amount) {
this.hp += amount;
if (this.hp > this.maxHP) {
this.hp = this.maxHP;
} else if (this.hp < 0) {
this.hp = 0;
}
this.hpText.setText('Player: ' + this.hp);
if (this.hp === 0) {
LK.showGameOver();
}
};
PlayerHP.prototype.setMaxHP = function (newMaxHP) {
this.maxHP = newMaxHP;
if (this.hp > this.maxHP) {
this.hp = this.maxHP;
}
this.hpText.setText('Player: ' + this.hp);
};
PlayerHP.prototype.getCurrentHP = function () {
return this.hp;
};
PlayerHP.prototype.getMaxHP = function () {
return this.maxHP;
};
PlayerHP.prototype.resetHP = function () {
this.hp = this.maxHP;
this.hpText.setText('Player: ' + this.hp);
};
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
if ("object" != _typeof(t) || !t) {
return t;
}
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof(i)) {
return i;
}
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
var enemySpawnCount = 0;
var upgradeState = {
global: {
totalDamageBoost: 0
},
categorical: {
minorDamageBoost: 0,
majorDamageBoost: 0,
criticalDamageBoost: 0,
healBoost: 0,
// New property to track heal boosts
healBoostCount: 0 // Track number of heal increment upgrades
},
individual: {
specificCellBoosts: {}
}
};
// Initialize gameState to manage game states
// UpgradeManager class to handle upgrades
var gameState = "playing"; // Possible states: playing, paused, upgradeMode
// Centralized data structure for upgrade options
var upgradeOptions = [{
type: 'increaseDamage',
value: 5,
description: '+5 to all damage'
}, {
type: 'increaseDamage',
value: 100,
description: '+100 to one random tile'
}, {
type: 'increaseDamage',
value: 10,
description: '+10 to minor damage'
}, {
type: 'increaseDamage',
value: 25,
description: '+25 to major damage'
}, {
type: 'heal',
value: 50,
description: 'Heal +50 HP'
}, {
type: 'increaseVampiric',
value: 1,
description: '+1 HP Lifesteal'
}, {
type: 'heal',
value: 5,
description: '+5 to Heal ability'
}, {
type: 'increaseHealIncrement',
value: 1,
description: '+1 HP when you pass GO'
}];
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var _ref = [array[j], array[i]];
array[i] = _ref[0];
array[j] = _ref[1];
}
}
function getRandomUpgrades() {
shuffleArray(upgradeOptions);
return upgradeOptions.slice(0, 2);
}
var wheel = new SpinningWheel();
var upgradeManager = new UpgradeManager(wheel);
if (midgroundContainer) {
midgroundContainer.addChild(wheel);
} else {
console.error("midgroundContainer is not initialized.");
}
wheel.init();
wheel.x = 150; // Initial x position
wheel.y = 2500; // Space cells horizontally
game.addChild(wheel);
upgradeManager.wheel = wheel; // Assign wheel reference to UpgradeManager
upgradeManager.enterUpgradeMode = upgradeManager.enterUpgradeMode.bind(upgradeManager);
// Function to pause the game
function pauseGame() {
// Logic to pause animations, input, and timers
console.log("Game paused");
}
// Function to trigger the upgrade system UI
function triggerUpgradeUI(options) {
// Logic to display upgrade options to the player
console.log("Upgrade UI triggered with options:", options);
// Display options in a UI for the player to select
// This is a placeholder for the actual UI implementation
}
// Function to resume the game
function resumeGame() {
// Logic to resume animations, input, and timers
console.log("Game resumed");
}
// Example usage: Generate upgrade options and apply one to the Peon
// ProjectilePool class to manage projectile instances
// Helper function to calculate distance between two points
// Cache enemy assets for reuse
// ProjectilePool class to manage projectile instances
var CELL_ACTIONS = {
DAMAGE_10: {
damage: 10,
actionType: 'damage'
},
DAMAGE_25: {
damage: 25,
actionType: 'damage'
},
DAMAGE_100: {
damage: 100,
actionType: 'damage'
},
HEAL_25: {
damage: 25,
actionType: 'heal'
}
};
function calculateDistance(x1, y1, x2, y2) {
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}
var cachedEnemyAssets = {
enemy: LK.getAsset('enemy', {}),
enemy_2: LK.getAsset('enemy_2', {}),
enemy_3: LK.getAsset('enemy_3', {})
};
var ProjectilePool = function ProjectilePool() {
this.pool = [];
this.getProjectile = function () {
for (var i = 0; i < this.pool.length; i++) {
if (!this.pool[i].active) {
return this.pool[i];
}
}
if (this.pool.length < this.maxPoolSize) {
var newProjectile = new Projectile();
this.pool.push(newProjectile);
return newProjectile;
}
return null; // Return null if pool is full
};
this.releaseProjectile = function (projectile) {
projectile.deactivate();
};
};
var projectilePool = new ProjectilePool();
projectilePool.maxPoolSize = 10; // Set maximum pool size
// ProjectilePool class to manage projectile instances
// Global timing variables
// Initialize spinning wheel
var startingInterval = 2; // Starting interval for the spin
var multiplier = 0.5; // Multiplier for the interval increase
var currentInterval = startingInterval;
var startingMovingTiles = 11; // Starting moving tiles
var maxTiles = 17; // Maximum number of tiles
var minDamage = 10; // Minimum damage
var maxDamage = 15; // Maximum damage
var backgroundContainer = new BackgroundContainer();
game.addChild(backgroundContainer);
var midgroundContainer = new MidgroundContainer();
game.addChild(midgroundContainer);
var platform = LK.getAsset('Platform', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
midgroundContainer.addChild(platform);
var foregroundContainer = new ForegroundContainer();
game.addChild(foregroundContainer);
var wheel = new SpinningWheel();
midgroundContainer.addChild(wheel);
wheel.init();
wheel.x = 150; // Initial x position
wheel.y = 2500; // Space cells horizontally
game.addChild(wheel);
// Initialize the Peon and add it to the game
var peon = new Peon();
peon.init(wheel);
game.addChild(peon);
// Function to create a new enemy
function createNewEnemy() {
// Define available enemy types
var enemyTypes = [{
asset: 'enemy'
}, {
asset: 'enemy_2'
}, {
asset: 'enemy_3'
}];
// Select a random enemy type
var randomIndex = Math.floor(Math.random() * enemyTypes.length);
var selectedEnemy = enemyTypes[randomIndex];
// Increment the spawn count
enemySpawnCount += 1;
minDamage += 1; // Increase minimum damage by 1
maxDamage += 2; // Increase maximum damage by 2
// Calculate HP: 50 * spawn count
var enemyHP = 50 * enemySpawnCount;
// Instantiate the enemy with required parameters
var newEnemy = new Enemy(selectedEnemy.asset);
newEnemy.init(enemyHP);
backgroundContainer.addChild(newEnemy);
updateLevelText();
return newEnemy;
}
// Initialize level text
var levelText = new Text2('Level: 1', {
size: 50,
fill: 0x000000
});
levelText.anchor.set(0.5, 0);
levelText.y = 10; // Position it at the top of the screen
LK.gui.top.addChild(levelText);
// Initialize the first enemy
var enemy = createNewEnemy();
// Function to update level text
function updateLevelText() {
levelText.setText('Level: ' + enemySpawnCount);
}
// Add a text to display the player's HP
var playerHPState = {
currentHP: peon.playerHP.getCurrentHP(),
maxHP: peon.playerHP.getMaxHP()
};
// Restore player HP state when game resumes
function restorePlayerHPState() {
peon.playerHP.hp = playerHPState.currentHP;
peon.playerHP.maxHP = playerHPState.maxHP;
peon.playerHP.hpText.setText('Player: ' + peon.playerHP.hp);
}
// Add a down event to the game to spin the Peon when the screen is tapped
var chargeCount = 0;
var chargeTimer = null;
game.down = function (x, y, obj) {
if (gameState !== "upgradeMode" && !wheel.isSpinning && !chargeTimer && !inputHandler.isInputDisabled) {
//{6J.1}
//{6J.1}
chargeCount = Math.floor(Math.random() * 2) + 1; // Randomly set chargeCount between 1 and 2 //{6J.2}
chargeTimer = LK.setInterval(function () {
//{6J.3}
chargeCount++; //{6J.4}
}, 150); //{6J.5}
// Start peon shake effect
startPeonShake();
inputHandler.startHoldTimer(); // Start the hold timer //{6J.6}
LK.getSound('Charge').play(); // Play the 'Charge' sound
} //{6J.6}
};
game.up = function (x, y, obj) {
if (chargeTimer) {
game.interaction = false; // Disable interaction
LK.setTimeout(function () {
game.interaction = true; // Re-enable interaction after 200ms
}, 400); //{6L.1}
//{6L.1}
LK.clearInterval(chargeTimer); //{6L.2}
chargeTimer = null; //{6L.3}
if (chargeCount >= 1) {
//{6L.4}
//{6L.4}
LK.getSound('Roll').play(); // Play the 'Roll' sound
peon.spin(wheel, chargeCount); //{6L.5}
} //{6L.6}
chargeCount = 0; // Reset chargeCount after spin //{6L.7}
currentInterval = startingInterval; // Reset the interval to the starting interval
multiplier = 0.5; // Reset the multiplier to its initial value
// Stop peon shake effect
tween.stop(peon, {
x: true
});
inputHandler.reset(); // Reset the input handler
} //{6L.8}
};
8-bit pixelated triangle pick. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Design a panel for a hyper-casual 2D video game, styled as a clean, white speech bubble. The panel has softly rounded corners and a slight cloud-like shape, with a small, rounded tail pointing downward or to the side. The design is pure and minimal, with no shadows or unnecessary details, ensuring a crisp, modern look. The edges are outlined with a subtle, light-gray stroke to enhance contrast while maintaining a soft and approachable aesthetic. Perfect for displaying text or damage stats in a playful yet functional manner.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Design a 2D UI element for a cute and lively text graphic that says 'GO.' The text should be bold and bubbly, with a soft, rounded font in a bright, cheerful green to indicate life and healing. The background features a large, semi-transparent green plus sign, subtly glowing and radiating a gentle, rejuvenating energy. The 'GO' text is prominently centered, with a slight 3D effect and playful highlights to make it pop, exuding a sense of positivity and vitality. The overall design is clean, minimal, and adorable, perfect for a hyper-casual mobile game.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
video game cute banana Pokémon with Matrix-like black glasses and a trench coat, oversized head occupying most of its body, standing on two tiny chubby feet at the bottom, tiny adorable creature with a cute angry expression, looking straight ahead, facing the camera directly. 2D flat vector illustration. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
video game cute divine grape bunch Pokémon with an angelic halo above its head and a harp beside it, oversized head occupying most of its body, standing on two tiny chubby feet at the bottom, tiny adorable creature with a cute angry expression, looking straight ahead, facing the camera directly. 2D flat vector illustration. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.