User prompt
Step 1: Define Upgrade Options Create a list of upgrade types. These can affect all damage tiles, specific tiles, or certain tile categories (e.g., minor, major). javascript Copy code const UPGRADE_OPTIONS = [ { description: "Increase all damage tiles by +5", apply: (wheel) => { wheel.cells.forEach(cell => { if (cell.actionType === 'damage') cell.damage += 5; }); }}, { description: "Add +50 to a random tile", apply: (wheel) => { const damageCells = wheel.cells.filter(cell => cell.actionType === 'damage'); if (damageCells.length > 0) { const randomIndex = Math.floor(Math.random() * damageCells.length); damageCells[randomIndex].damage += 50; } }}, { description: "Add +20 to all minor tiles", apply: (wheel) => { wheel.cells.forEach(cell => { if (cell.actionType === 'damage' && cell.damage < 30) cell.damage += 20; }); }}, { description: "Add +30 to all major tiles", apply: (wheel) => { wheel.cells.forEach(cell => { if (cell.actionType === 'damage' && cell.damage >= 30) cell.damage += 30; }); }}, ];
User prompt
Use Containers for Pausable Elements To organize your code and make pausing/resuming easier: Place all game elements that need to pause (e.g., the wheel, enemies, projectiles) into a dedicated container. The container can have a method like pauseAll() or resumeAll() to propagate the pause/resume command to all child elements.
User prompt
Scattered pause/resume logic can create inconsistencies, where some elements respect the pause while others don’t. Solution: Use a centralized method (e.g., pauseGame() and resumeGame()) that: Changes the gameState. Stops all ongoing animations, updates, or input processing. Resumes these elements when called.
User prompt
When the game enters the "paused" state, all elements must stop updating. Key areas to address: Input Handling Ensure no input events (e.g., taps or clicks) are processed when paused. Fix: Check the gameState at the start of input handlers. If the state is "paused", block input logic. Enemy Movement and Spawning Any logic related to enemies (e.g., movement or respawning) must also stop during pause. Fix: Add a guard to prevent spawning or updating enemy actions while the game is paused.
User prompt
Your game is missing a clear, centralized way to track states (e.g., "playing", "paused", "upgrade mode"). Solution: Create a single global gameState variable or similar system to track the current state, e.g.,: gameState = "playing" gameState = "paused" gameState = "upgradeMode"
User prompt
Your game is missing a clear, centralized way to track states (e.g., "playing", "paused", "upgrade mode"). Solution: Create a single global gameState variable or similar system to track the current state, e.g.,: gameState = "playing" gameState = "paused" gameState = "upgradeMode" How it helps: Every game element (like spinning, enemy movement, or input handling) should respect this state. For example: If the state is "paused", no animations, inputs, or updates should occur. Use this state as a guard clause in all major logic (e.g., if gameState === "paused", skip processing).
User prompt
when an enemy hp reaches 0 and dies, go to upgrades menu and pause game
User prompt
Ensure game pauses when an enemy dies by setting isSpinning to false and entering upgrade mode. when it dies not when it takes damage
User prompt
ensure game pauses when enemy dies
User prompt
only pause the game when an enemy dies not when the peon stops. right now you pause the game after the first click, ensure you only pause when enemy dies
User prompt
only pause the game when an enemy dies not when the peon stops
User prompt
only pause the game when an enemy dies not when the peon stops
User prompt
when an enemy dies, you should enter upgrade manager mode and pause the game
User prompt
Please fix the bug: 'TypeError: game.pause is not a function' in or related to this line: 'game.pause(); // Pause the game' Line Number: 593
User prompt
when an enemy dies, you should enter upgrade manager mode and pause the game
User prompt
Phase 1: Core Mechanic Setup Goal: Implement the most basic functionality: pausing after an enemy is defeated and resuming gameplay. Enemy Defeat Detection Set up a mechanism to detect when an enemy’s HP reaches 0. Trigger a simple “pause” state. Use a container or class (e.g., UpgradeManager) to manage this state. The UpgradeManager will track whether the game is in upgrade mode and control what happens during that time.
Code edit (1 edits merged)
Please save this source code
User prompt
start enemy hp with 50
User prompt
Phase 1: Core Mechanic Setup Goal: Implement the most basic functionality: pausing after an enemy is defeated and resuming gameplay. Enemy Defeat Detection Set up a mechanism to detect when an enemy’s HP reaches 0. Trigger a simple “pause” state. Use a container or class (e.g., UpgradeManager) to manage this state. The UpgradeManager will track whether the game is in upgrade mode and control what happens during that time.
User prompt
Please fix the bug: 'TypeError: game.pause is not a function' in or related to this line: 'game.pause();' Line Number: 359
User prompt
Phase 1: Core Mechanic Setup Goal: Implement the most basic functionality: pausing after an enemy is defeated and resuming gameplay. Enemy Defeat Detection Set up a mechanism to detect when an enemy’s HP reaches 0. Trigger a simple “pause” state. Use a container or class (e.g., UpgradeManager) to manage this state. The UpgradeManager will track whether the game is in upgrade mode and control what happens during that time.
User prompt
Trigger Upgrade Mode When an enemy is destroyed, the game pauses. Bring up a new screen or overlay for the player to see the upgrade options. Disable any other input or interaction during this mode to ensure the player’s focus remains on the upgrades.
User prompt
Please fix the bug: 'TypeError: LK.pauseGame is not a function' in or related to this line: 'LK.pauseGame();' Line Number: 450
User prompt
Please fix the bug: 'TypeError: game.pause is not a function' in or related to this line: 'game.pause();' Line Number: 450
User prompt
Please fix the bug: 'TypeError: LK.pauseGame is not a function' in or related to this line: 'LK.pauseGame();' Line Number: 450
/**** * 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, hpIncrement) { 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 () { self.x = 2048 / 2; self.y = 2732 / 2 - 500; // Initialize the enemy's HP self.hpIncrement = hpIncrement; self.hp = 100 + self.hpIncrement; // Add a text to display the enemy's HP self.hpText = new Text2("", { size: 200, fill: 0xFFFFFF }); 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.hp = 200; // Peon's HP self.hpText = new Text2('Peon: ' + self.hp, { size: 150, fill: 0xFFFFFF }); self.hpText.anchor.set(0.5, 0); self.hpText.y += 1000; LK.gui.top.addChild(self.hpText); self.x += self.currentPosition * 250; // Position Peon on the random cell }; // Spin the Peon around the wheel self.spin = function (wheel) { self.steps = Math.floor(Math.random() * (maxTiles - startingMovingTiles + 1)) + startingMovingTiles; 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; } self.steps--; currentInterval *= multiplier; if (self.steps <= 0) { self.x = wheel.x + self.currentPosition * 250; var cell = wheel.cells[self.currentPosition]; if (cell.actionType === 'heal') { self.hp += cell.damage; if (self.hp > 200) { self.hp = 200; } self.hpText.setText('Peon: ' + self.hp); var healText = new Text2('+' + cell.damage, { size: 150, fill: 0x00FF00 }); healText.anchor.set(0.5, 0.5); healText.x = self.hpText.x + 250; healText.y = self.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); 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.hp -= damage; if (self.hp < 0) { self.hp = 0; } self.hpText.setText('Peon: ' + self.hp); if (self.hp === 0) { LK.showGameOver(); } } }; _deductHp(); currentInterval = startingInterval; } else { LK.setTimeout(_spinStep, currentInterval); } }; _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); // 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); 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); 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 }); // Initialize the Projectile's position and target self.init = function (startX, startY, targetX, targetY, speed, damage) { self.x = startX; self.y = startY; self.targetX = targetX; self.targetY = targetY; self.speed = speed * 3; // Increase the bullet speed self.damage = damage; 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; // Display damage text on enemy 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 = 0; damageText.y = -300; LK.gui.center.addChild(damageText); // Tween animation for appearance tween(damageText, { alpha: 1, y: enemy.y - 50 }, { duration: 800, easing: tween.easeOut }); // Tween animation for fade out tween(damageText, { alpha: 0, y: damageText.y - 100 // Move slightly up during fade out }, { duration: 800, easing: tween.easeIn, onFinish: function onFinish() { damageText.destroy(); } }); // Update the enemy's HP text if (enemy) { if (!enemy.hpText) { enemy.hpText = new Text2("", { size: 200, fill: 0xFFFFFF }); enemy.hpText.anchor.set(0.5, 0.5); enemy.hpText.y = -700; enemy.addChild(enemy.hpText); } 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(); pauseGameAndShowUpgrades(); // 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(); } // Create a new enemy enemy = createNewEnemy(); // Properly instantiated if (!enemy.hpText) { enemy.hpText = new Text2("", { size: 200, fill: 0xFFFFFF }); enemy.hpText.anchor.set(0.5, 0.5); enemy.hpText.y = -700; enemy.addChild(enemy.hpText); } enemy.hpText.setText("HP: " + enemy.hp); // Update the enemy's HP text game.addChild(enemy); } } } }; // 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 = [CELL_ACTIONS.DAMAGE_10, CELL_ACTIONS.DAMAGE_25, CELL_ACTIONS.DAMAGE_10, CELL_ACTIONS.DAMAGE_100, CELL_ACTIONS.DAMAGE_10, CELL_ACTIONS.DAMAGE_25, CELL_ACTIONS.DAMAGE_10, CELL_ACTIONS.HEAL_50]; for (var i = 0; i < self.cells.length; i++) { var cell = self.attachAsset('tile', { anchorX: 0.5, anchorY: 0.5, x: i * 250 // Increase space between cells }); self.addChild(cell); // Add text to each cell to display the damage value var damageText = new Text2(self.cells[i].damage.toString(), { size: 50, fill: 0xFFFFFF }); damageText.anchor.set(0.5, 0.5); cell.addChild(damageText); } }; // Spin the Player around the wheel self.spin = function (player) { if (!self.isSpinning) { self.isSpinning = true; player.spin(self); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ function pauseGameAndShowUpgrades() { // Pause the game game.pause(); // Create upgrade options var upgradeOptions = createUpgradeOptions(); // Display upgrade options to the player displayUpgradeOptions(upgradeOptions, function (selectedUpgrade) { // Apply the selected upgrade applyUpgrade(selectedUpgrade); // Resume the game game.resume(); }); } function createUpgradeOptions() { // Generate two random upgrade options var upgrades = [{ type: 'increaseDamage', value: 10 }, { type: 'increaseDamage', value: 25 }]; return upgrades; } function displayUpgradeOptions(upgrades, callback) { // Display the upgrade options to the player // This is a placeholder for the actual UI implementation console.log("Choose an upgrade:", upgrades); // Simulate player selecting an upgrade var selectedUpgrade = upgrades[Math.floor(Math.random() * upgrades.length)]; callback(selectedUpgrade); } function applyUpgrade(upgrade) { // Apply the effects of the selected upgrade to the relevant tiles wheel.cells.forEach(function (cell) { if (cell.actionType === 'damage') { cell.damage += upgrade.value; } }); } // ProjectilePool class to manage projectile instances // Cache enemy assets for reuse // Helper function to calculate distance between two points // 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_50: { damage: 50, 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 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]; } } var newProjectile = new Projectile(); this.pool.push(newProjectile); return newProjectile; }; }; var startingInterval = 2; // Starting interval for the spin var multiplier = 1.3; // 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 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 and their HP increments var enemyTypes = [{ asset: 'enemy', hpIncrement: 0 }, { asset: 'enemy_2', hpIncrement: -50 }, { asset: 'enemy_3', hpIncrement: 100 }]; // Select a random enemy type var randomIndex = Math.floor(Math.random() * enemyTypes.length); var selectedEnemy = enemyTypes[randomIndex]; // Instantiate the enemy with required parameters var newEnemy = new Enemy(selectedEnemy.asset, selectedEnemy.hpIncrement); game.addChild(newEnemy); return newEnemy; } // Initialize the first enemy var enemy = createNewEnemy(); // Add a text to display the player's HP // Add a down event to the game to spin the Peon when the screen is tapped game.down = function (x, y, obj) { if (!wheel.isSpinning) { wheel.spin(peon); } };
/****
* 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, hpIncrement) {
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 () {
self.x = 2048 / 2;
self.y = 2732 / 2 - 500;
// Initialize the enemy's HP
self.hpIncrement = hpIncrement;
self.hp = 100 + self.hpIncrement;
// Add a text to display the enemy's HP
self.hpText = new Text2("", {
size: 200,
fill: 0xFFFFFF
});
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.hp = 200; // Peon's HP
self.hpText = new Text2('Peon: ' + self.hp, {
size: 150,
fill: 0xFFFFFF
});
self.hpText.anchor.set(0.5, 0);
self.hpText.y += 1000;
LK.gui.top.addChild(self.hpText);
self.x += self.currentPosition * 250; // Position Peon on the random cell
};
// Spin the Peon around the wheel
self.spin = function (wheel) {
self.steps = Math.floor(Math.random() * (maxTiles - startingMovingTiles + 1)) + startingMovingTiles;
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;
}
self.steps--;
currentInterval *= multiplier;
if (self.steps <= 0) {
self.x = wheel.x + self.currentPosition * 250;
var cell = wheel.cells[self.currentPosition];
if (cell.actionType === 'heal') {
self.hp += cell.damage;
if (self.hp > 200) {
self.hp = 200;
}
self.hpText.setText('Peon: ' + self.hp);
var healText = new Text2('+' + cell.damage, {
size: 150,
fill: 0x00FF00
});
healText.anchor.set(0.5, 0.5);
healText.x = self.hpText.x + 250;
healText.y = self.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);
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.hp -= damage;
if (self.hp < 0) {
self.hp = 0;
}
self.hpText.setText('Peon: ' + self.hp);
if (self.hp === 0) {
LK.showGameOver();
}
}
};
_deductHp();
currentInterval = startingInterval;
} else {
LK.setTimeout(_spinStep, currentInterval);
}
};
_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);
// 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);
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);
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
});
// Initialize the Projectile's position and target
self.init = function (startX, startY, targetX, targetY, speed, damage) {
self.x = startX;
self.y = startY;
self.targetX = targetX;
self.targetY = targetY;
self.speed = speed * 3; // Increase the bullet speed
self.damage = damage;
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;
// Display damage text on enemy
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 = 0;
damageText.y = -300;
LK.gui.center.addChild(damageText);
// Tween animation for appearance
tween(damageText, {
alpha: 1,
y: enemy.y - 50
}, {
duration: 800,
easing: tween.easeOut
});
// Tween animation for fade out
tween(damageText, {
alpha: 0,
y: damageText.y - 100 // Move slightly up during fade out
}, {
duration: 800,
easing: tween.easeIn,
onFinish: function onFinish() {
damageText.destroy();
}
});
// Update the enemy's HP text
if (enemy) {
if (!enemy.hpText) {
enemy.hpText = new Text2("", {
size: 200,
fill: 0xFFFFFF
});
enemy.hpText.anchor.set(0.5, 0.5);
enemy.hpText.y = -700;
enemy.addChild(enemy.hpText);
}
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();
pauseGameAndShowUpgrades();
// 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();
}
// Create a new enemy
enemy = createNewEnemy(); // Properly instantiated
if (!enemy.hpText) {
enemy.hpText = new Text2("", {
size: 200,
fill: 0xFFFFFF
});
enemy.hpText.anchor.set(0.5, 0.5);
enemy.hpText.y = -700;
enemy.addChild(enemy.hpText);
}
enemy.hpText.setText("HP: " + enemy.hp); // Update the enemy's HP text
game.addChild(enemy);
}
}
}
};
// 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 = [CELL_ACTIONS.DAMAGE_10, CELL_ACTIONS.DAMAGE_25, CELL_ACTIONS.DAMAGE_10, CELL_ACTIONS.DAMAGE_100, CELL_ACTIONS.DAMAGE_10, CELL_ACTIONS.DAMAGE_25, CELL_ACTIONS.DAMAGE_10, CELL_ACTIONS.HEAL_50];
for (var i = 0; i < self.cells.length; i++) {
var cell = self.attachAsset('tile', {
anchorX: 0.5,
anchorY: 0.5,
x: i * 250 // Increase space between cells
});
self.addChild(cell);
// Add text to each cell to display the damage value
var damageText = new Text2(self.cells[i].damage.toString(), {
size: 50,
fill: 0xFFFFFF
});
damageText.anchor.set(0.5, 0.5);
cell.addChild(damageText);
}
};
// Spin the Player around the wheel
self.spin = function (player) {
if (!self.isSpinning) {
self.isSpinning = true;
player.spin(self);
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
function pauseGameAndShowUpgrades() {
// Pause the game
game.pause();
// Create upgrade options
var upgradeOptions = createUpgradeOptions();
// Display upgrade options to the player
displayUpgradeOptions(upgradeOptions, function (selectedUpgrade) {
// Apply the selected upgrade
applyUpgrade(selectedUpgrade);
// Resume the game
game.resume();
});
}
function createUpgradeOptions() {
// Generate two random upgrade options
var upgrades = [{
type: 'increaseDamage',
value: 10
}, {
type: 'increaseDamage',
value: 25
}];
return upgrades;
}
function displayUpgradeOptions(upgrades, callback) {
// Display the upgrade options to the player
// This is a placeholder for the actual UI implementation
console.log("Choose an upgrade:", upgrades);
// Simulate player selecting an upgrade
var selectedUpgrade = upgrades[Math.floor(Math.random() * upgrades.length)];
callback(selectedUpgrade);
}
function applyUpgrade(upgrade) {
// Apply the effects of the selected upgrade to the relevant tiles
wheel.cells.forEach(function (cell) {
if (cell.actionType === 'damage') {
cell.damage += upgrade.value;
}
});
}
// ProjectilePool class to manage projectile instances
// Cache enemy assets for reuse
// Helper function to calculate distance between two points
// 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_50: {
damage: 50,
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 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];
}
}
var newProjectile = new Projectile();
this.pool.push(newProjectile);
return newProjectile;
};
};
var startingInterval = 2; // Starting interval for the spin
var multiplier = 1.3; // 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 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 and their HP increments
var enemyTypes = [{
asset: 'enemy',
hpIncrement: 0
}, {
asset: 'enemy_2',
hpIncrement: -50
}, {
asset: 'enemy_3',
hpIncrement: 100
}];
// Select a random enemy type
var randomIndex = Math.floor(Math.random() * enemyTypes.length);
var selectedEnemy = enemyTypes[randomIndex];
// Instantiate the enemy with required parameters
var newEnemy = new Enemy(selectedEnemy.asset, selectedEnemy.hpIncrement);
game.addChild(newEnemy);
return newEnemy;
}
// Initialize the first enemy
var enemy = createNewEnemy();
// Add a text to display the player's HP
// Add a down event to the game to spin the Peon when the screen is tapped
game.down = function (x, y, obj) {
if (!wheel.isSpinning) {
wheel.spin(peon);
}
};
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.