User prompt
Affiche le boutton reset qui permet au joueur de reĢinitialiser sa progression a partir du niveau 1 quand il le veut, quelque part a l'eĢcran, le joueur peut alors appuyer dessus pour reĢinitialiser sa progression
User prompt
Ajoute aussi un boutton reset, accessible a l'eĢcran qui permet au joueur de reset sa progression a partir du niveau 1 quand il le veut
User prompt
Fait en sorte que l'abeille reĢcupeĢre 20 % de ses points de vie seulement si elle a deĢjaĢ vaincu un certain nombre d'araigneĢes dans le niveau : 3 dans le niveau 1 et 2, 6 dans entre les niveaux 3 et 7, Et 10 pour les niveaux supeĢrieurs a 7. Ajoute aussi un boutton reset, accessible a l'eĢcran qui permet au joueur de reset sa progression a partir du niveau 1 quand il le veut, Et eĢlargit le jeu : deĢsormais le jeu posseĢde 60 niveaux, Le nombre d'araigneĢes a vaincre pour monter au niveau supeĢrieur, doit doubler par rapport au niveau infeĢrieur
User prompt
Fait en sorte que l'abeille reĢcupeĢre 20 % de ses points de vie seulement si elle a deĢjaĢ vaincu un certain nombre d'araigneĢes dans le niveau : 3 dans le niveau 1 et 2, 6 dans entre les niveaux 3 et 7, Et 10 pour les niveaux supeĢrieurs a 7. Ajoute aussi un boutton reset, accessible a l'eĢcran qui permet au joueur de reset sa progression a partir du niveau 1 quand il le veut, Et eĢlargit le jeu : deĢsormais le jeu posseĢde 60 niveaux, Le nombre d'araigneĢes a vaincre pour monter au niveau supeĢrieur, doit doubler par rapport au niveau infeĢrieur
User prompt
Fait en sorte que le joueur ne saute pas des niveaux, que apreĢs avoir eut 5 araigneĢe au niveau 1, le joueur passe au niveau 2, doit vaincre 10 nouvelles araigneĢe pour passer au niveau 3, puis 15 Nouvelles araigneĢe pour passer au niveau 4, 20 nouvelles araigneĢe pour passer niveau 5, et ainsi de suite, mais sans sauter de plusieurs niveaux en meĢme temps
User prompt
Fait en sorte de reĢgler les probleĢmes de bug d'affichage
User prompt
Fait en sorte que pour monte au niveau supeĢrieur, a chaque fois faut vaincre de nouvelles araigneĢe, c'est a dire qu'aĢ chaque niveau le nombre d'araigneĢes vaincu est reĢinitialiser, et faut vaincre de toutes nouvelles araigneĢe a chaque niveau
User prompt
Fait en sorte que l'abeille perde un nombre aleĢatoire de points compris entre 1 et 20 a chaque coup de l'araigneĢe, et que l'abeille puisse reĢcupeĢrer 20% de ses points lorsqu'elle est veĢcu, si elle a vaincu au moins 3 araigneĢe avant
User prompt
Fait en sorte que le joueur monte d'un seul niveau en meĢme temps, et qu'une seule araigneĢe vaincu a la fois soient comptabiliseĢs
User prompt
AmeĢliore le jeu, en particulier les affichages des textes, afin de les mettres a jour correctement et qu'ils soient visibles et lisibles : quand le joueur monte en niveau, le texte affichant son niveau doit se mettre a jour correctement, l'affichage du niveau d'avant se retirant pour laisser place a l'affichage du niveau actuel
User prompt
Fait en sorte qu'une seule araigneĢe soit vaincu a la fois
User prompt
Fait en sorte que le jeu ne compte que les araigneĢes vaincus manuellement par le joueur comme araigneĢe vaincu
User prompt
Fait en sorte que la limite de points de l'araigneĢe monte de 20 points a chaque nouveau niveau du joueur, et que le joueur ne gagne des araigneĢes vaincus seulement quand il les a rencontreĢ et vaincus tour a tour
User prompt
Le jeu doit est reset au niveau 1 avec le message de compleĢtion deĢs que le joueur atteint le niveau 10, et si le joueur a un niveau supeĢrieur a 10, le jeu se reset des que le joueur a vaincu 15 araigneĢe
User prompt
Fait en sorte que le message de compleĢtion s'affiche deĢs que le joueur finis ou deĢpasse le niveau 10, et le jeu est alors reset au niveau 1
User prompt
Ajoute la musique Du jeu en loop quand le joueur joue au jeu
User prompt
Le jeu doit recommencer depuis le niveau 1 quand le joueur appuie sur ok lors du message de compleĢtion
User prompt
Fait en sorte que le jeu soit reset au niveau 1 quand le joueur appuie sur ok lors du message de compleĢtion
User prompt
Affiche le bouton pour que le joueur puisse reset sa progression a tout moment, en haut a droite de l'eĢcran et fait en sorte que le message de compleĢtion du jeu s'affiche lorsque l'utilisateur atteint 15 araigneĢe au niveau 10
User prompt
Fait en sorte que le message "feĢlicitations vous avez compleĢteĢ Bee Wars ! A bientoĢt pour de nouveaux jeu de clem27games " s'affiche en gros en rose a l'eĢcran quand le joueur atteint le niveau 10, et que le jeu soit reset au niveau 1 depuis le deĢbut quand le joueur appuie sur ok (le joueur peut reset sa progression a tout moment en appuyant sur un boutton reset en haut du jeu)
User prompt
Faire en sorte que l'abeille est une limite de 50 points de vie suppleĢmentaires a chaque nouveaux niveaux, et que le jeu reĢmarre au niveau 1 depuis le deĢbut en cas de deĢfaites de l'abeille
User prompt
Please fix the bug: 'Timeout.tick error: spidersDefeatedText is not defined' in or related to this line: 'spidersDefeatedText.setText("Spiders: " + spidersDefeated);' Line Number: 656
User prompt
Please fix the bug: 'Timeout.tick error: spidersDefeated is not defined' in or related to this line: 'spidersDefeated++;' Line Number: 655
User prompt
Faire en sorte que le joueur monte au niveau 2 au bout de 5 araigneĢe vaincus, au niveau 3 au bout de 8 araigneĢe vaincus, au niveau 4 au bout de 9 araigneĢe vaincus, au niveau 5 au bout de 10 araigneĢe vaincus, au niveau 6 au bout de 11 araigneĢe vaincus, au niveau 7 (12 araigneĢe) , niveau 8 (13 araigneĢe), niveau 9 (14 araigneĢes) et niveau 10 (15 araigneĢe), qu'aĢ chaque nouveau niveau atteint, les points de vie de l'abeille reviennent , et que lorsque le joueur atteint le niveau 10, le jeu affiche en grand en rose "Merci d'avoir joueĢ a Bee Wars! FeĢlicitations tu as compleĢter le jeu! A bientoĢt pour de futures jeux de clem27games !", fait aussi en sorte que le combat se deĢclanche pour toutes les araigneĢes
User prompt
Faire en sorte que le jeu de plateforme continue une fois que l'abeille est seul sur la plateforme, en avançant la plateforme et en geĢneĢrant les autres araigneĢes a vaincre pour le niveau , et la ligne d'arriveĢe a la fin āŖš” Consider importing and using the following plugins: @upit/tween.v1
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { currentLevel: 1 }); /**** * Classes ****/ var BattleUI = Container.expand(function () { var self = Container.call(this); var panel = self.attachAsset('battlePanel', { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 }); var attackBtn = self.attachAsset('attackButton', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 200 }); self.beeHealthBar = self.attachAsset('healthBar', { anchorX: 0, anchorY: 0.5, x: -300, y: -150 }); self.spiderHealthBar = self.attachAsset('healthBar', { anchorX: 0, anchorY: 0.5, x: 0, y: -150 }); var beeHealthText = new Text2("Bee: 100/100", { size: 40, fill: 0xFFFFFF }); beeHealthText.anchor.set(0, 0.5); beeHealthText.x = -300; beeHealthText.y = -200; self.addChild(beeHealthText); var spiderHealthText = new Text2("Spider: 50/50", { size: 40, fill: 0xFFFFFF }); spiderHealthText.anchor.set(0, 0.5); spiderHealthText.x = 0; spiderHealthText.y = -200; self.addChild(spiderHealthText); var turnText = new Text2("Your Turn", { size: 60, fill: 0xFFFFFF }); turnText.anchor.set(0.5, 0.5); turnText.y = -300; self.addChild(turnText); var attackText = new Text2("Attack", { size: 50, fill: 0xFFFFFF }); attackText.anchor.set(0.5, 0.5); attackText.x = 0; attackText.y = 200; self.addChild(attackText); self.updateHealth = function (beeHealth, beeMaxHealth, spiderHealth, spiderMaxHealth) { // Update health bars self.beeHealthBar.scale.x = beeHealth / beeMaxHealth; self.spiderHealthBar.scale.x = spiderHealth / spiderMaxHealth; // Update text beeHealthText.setText("Bee: " + beeHealth + "/" + beeMaxHealth); spiderHealthText.setText("Spider: " + spiderHealth + "/" + spiderMaxHealth); }; self.setTurnText = function (isPlayerTurn) { turnText.setText(isPlayerTurn ? "Your Turn" : "Spider's Turn"); }; self.down = function (x, y, obj) { // Check if attack button was pressed if (x >= attackBtn.x - attackBtn.width / 2 && x <= attackBtn.x + attackBtn.width / 2 && y >= attackBtn.y - attackBtn.height / 2 && y <= attackBtn.y + attackBtn.height / 2) { if (self.onAttackPressed && game.battleState.isPlayerTurn) { self.onAttackPressed(); } } }; return self; }); var Bee = Container.expand(function () { var self = Container.call(this); var beeGraphic = self.attachAsset('bee', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.speed = 8; self.jumpForce = -20; self.gravity = 1; self.onGround = false; self.health = 100; self.maxHealth = 100; self.isJumping = false; self.fallingInVoid = false; self.update = function () { // Apply gravity if (!self.onGround) { self.velocityY += self.gravity; } // Update position self.x += self.velocityX; self.y += self.velocityY; // Reset onGround flag for next frame collision detection self.onGround = false; }; self.moveUp = function () { // Only allow moving up when not jumping if (!self.isJumping) { self.velocityY = -self.speed * 0.8; // Slower than horizontal movement } }; self.jump = function () { if (self.onGround) { self.velocityY = self.jumpForce; self.onGround = false; self.isJumping = true; LK.getSound('jump').play(); } }; self.moveLeft = function () { self.velocityX = -self.speed; }; self.moveRight = function () { self.velocityX = self.speed; }; self.stopMoving = function () { self.velocityX = 0; }; self.takeDamage = function (amount) { self.health -= amount; if (self.health < 0) { self.health = 0; } LK.getSound('hurt').play(); }; self.heal = function (amount) { self.health += amount; if (self.health > self.maxHealth) { self.health = self.maxHealth; } }; return self; }); var ControlsUI = Container.expand(function () { var self = Container.call(this); // Left button var leftBtn = self.attachAsset('attackButton', { anchorX: 0.5, anchorY: 0.5, x: -800, y: 0, tint: 0x0000FF }); var leftText = new Text2("<", { size: 80, fill: 0xFFFFFF }); leftText.anchor.set(0.5, 0.5); leftText.x = -800; self.addChild(leftText); // Right button var rightBtn = self.attachAsset('attackButton', { anchorX: 0.5, anchorY: 0.5, x: -400, y: 0, tint: 0x0000FF }); var rightText = new Text2(">", { size: 80, fill: 0xFFFFFF }); rightText.anchor.set(0.5, 0.5); rightText.x = -400; self.addChild(rightText); // Jump button var jumpBtn = self.attachAsset('attackButton', { anchorX: 0.5, anchorY: 0.5, x: 800, y: 0, tint: 0x00FF00 }); var jumpText = new Text2("Jump", { size: 50, fill: 0xFFFFFF }); jumpText.anchor.set(0.5, 0.5); jumpText.x = 800; self.addChild(jumpText); // Up button var upBtn = self.attachAsset('attackButton', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -80, tint: 0x0099FF }); var upText = new Text2("Up", { size: 50, fill: 0xFFFFFF }); upText.anchor.set(0.5, 0.5); upText.x = 0; upText.y = -80; self.addChild(upText); self.down = function (x, y, obj) { // Check if left button was pressed if (x >= leftBtn.x - leftBtn.width / 2 && x <= leftBtn.x + leftBtn.width / 2 && y >= leftBtn.y - leftBtn.height / 2 && y <= leftBtn.y + leftBtn.height / 2) { if (self.onLeftPressed) { self.onLeftPressed(); } } // Check if right button was pressed if (x >= rightBtn.x - rightBtn.width / 2 && x <= rightBtn.x + rightBtn.width / 2 && y >= rightBtn.y - rightBtn.height / 2 && y <= rightBtn.y + rightBtn.height / 2) { if (self.onRightPressed) { self.onRightPressed(); } } // Check if jump button was pressed if (x >= jumpBtn.x - jumpBtn.width / 2 && x <= jumpBtn.x + jumpBtn.width / 2 && y >= jumpBtn.y - jumpBtn.height / 2 && y <= jumpBtn.y + jumpBtn.height / 2) { if (self.onJumpPressed) { self.onJumpPressed(); } } // Check if up button was pressed if (x >= upBtn.x - upBtn.width / 2 && x <= upBtn.x + upBtn.width / 2 && y >= upBtn.y - upBtn.height / 2 && y <= upBtn.y + upBtn.height / 2) { if (self.onUpPressed) { self.onUpPressed(); } } }; self.up = function (x, y, obj) { // When buttons are released, stop movement if (self.onControlsReleased) { self.onControlsReleased(); } }; return self; }); var FinishLine = Container.expand(function () { var self = Container.call(this); var finishLineGraphic = self.attachAsset('finishLine', { anchorX: 0.5, anchorY: 0.5 }); self.width = finishLineGraphic.width; self.height = finishLineGraphic.height; return self; }); var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphic = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5 }); self.width = platformGraphic.width; self.height = platformGraphic.height; // Handle touch on platform self.down = function (x, y, obj) { if (gameState === "platform" && !dragTarget) { // Move bee to this platform self.moveBeeToThisPlatform(); } }; // Function to move the bee to this platform self.moveBeeToThisPlatform = function () { // Stop current movement bee.velocityX = 0; bee.velocityY = 0; // Play jump sound LK.getSound('jump').play(); // Calculate target position on top of platform var targetX = self.x; var targetY = self.y - self.height / 2 - bee.height / 2; // Create a tween animation for bee to jump to the platform tween(bee, { x: targetX, y: targetY }, { duration: 800, easing: tween.easeOutQuad, onFinish: function onFinish() { bee.onGround = true; bee.isJumping = false; bee.fallingInVoid = false; // Ensure the bee stays on this platform by locking position bee.x = targetX; bee.y = targetY; // Make sure velocity is zero so it doesn't start moving/falling bee.velocityX = 0; bee.velocityY = 0; // Check if there's a spider on this platform and make it move away for (var i = 0; i < spiders.length; i++) { var spider = spiders[i]; if (!spider.defeated && spider.currentPlatform === self) { spider.moveAwayFromBee(bee); } } } }); }; return self; }); var Spider = Container.expand(function () { var self = Container.call(this); var spiderGraphic = self.attachAsset('spider', { anchorX: 0.5, anchorY: 0.5 }); self.health = 50; self.maxHealth = 50; self.attackDamage = 15; self.defeated = false; self.currentPlatform = null; self.moving = false; self.moveAwayFromBee = function (bee) { if (self.moving || self.defeated) { return; } self.moving = true; // Store bee's original position to ensure it doesn't fall var originalBeeY = bee.y; var originalBeeX = bee.x; var isOnSamePlatform = bee.onGround && Math.abs(bee.x - self.x) < self.currentPlatform.width * 0.8; var keepBeeOnPlatform = isOnSamePlatform; // Find nearby platforms to move to var nearbyPlatforms = []; for (var i = 0; i < platforms.length; i++) { // Don't include current platform or platforms too far away if (platforms[i] !== self.currentPlatform && Math.abs(platforms[i].x - self.x) < 800) { nearbyPlatforms.push(platforms[i]); } } // If no nearby platforms, just return if (nearbyPlatforms.length === 0) { self.moving = false; return; } // Sort platforms by distance from bee nearbyPlatforms.sort(function (a, b) { var distA = Math.abs(a.x - bee.x); var distB = Math.abs(b.x - bee.x); return distB - distA; // Further platforms first }); // Get target platform (furthest from bee) var targetPlatform = nearbyPlatforms[0]; var targetX = targetPlatform.x; var targetY = targetPlatform.y - targetPlatform.height / 2 - self.height / 2; // Animate spider moving to new platform tween(self, { x: targetX, y: targetY }, { duration: 500, easing: tween.easeOutQuad, onFinish: function onFinish() { self.currentPlatform = targetPlatform; self.moving = false; // Ensure bee stays on platform if it was on the same platform as spider if (keepBeeOnPlatform) { bee.x = originalBeeX; bee.y = originalBeeY; bee.onGround = true; bee.velocityY = 0; bee.isJumping = false; } } }); }; self.takeDamage = function (amount) { self.health -= amount; if (self.health <= 0) { self.health = 0; self.defeated = true; } }; self.attack = function () { return self.attackDamage; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Game state variables // Initialize bee asset // Initialize spider assets // Initialize platform assets // Initialize finish line // Initialize battle UI elements // Initialize sounds // Initialize music var currentLevel = storage.currentLevel || 1; var maxLevels = 10; var gameState = "platform"; // "platform" or "battle" var platforms = []; var spiders = []; var finishLine; var bee; var battleUI; var controlsUI; var levelText; var dragTarget = null; // Track if the bee is being dragged var levelScrolling = false; // Whether the platforms are moving var scrollSpeed = -3; // Horizontal scroll speed for platforms var platformGenerationTimer = null; // Timer for platform generation var spiderGenerationTimer = null; // Timer for spider generation var lastPlatformX = 0; // Track last platform position for generation // Battle state game.battleState = { currentSpider: null, isPlayerTurn: true, turnDelay: 1000 // ms }; // Initialize level function initLevel(level) { // Reset level scrolling levelScrolling = false; if (platformGenerationTimer) { LK.clearInterval(platformGenerationTimer); platformGenerationTimer = null; } if (spiderGenerationTimer) { LK.clearInterval(spiderGenerationTimer); spiderGenerationTimer = null; } // Clear existing elements platforms = []; spiders = []; // Remove old elements from game while (game.children.length > 0) { game.removeChild(game.children[0]); } // Create bee bee = new Bee(); bee.x = 150; // Create first platform to ensure bee starts on a platform var firstPlatform = new Platform(); firstPlatform.x = 200; firstPlatform.y = 2732 / 2 + 100; platforms.push(firstPlatform); game.addChild(firstPlatform); // Position bee on first platform bee.x = firstPlatform.x; bee.y = firstPlatform.y - firstPlatform.height / 2 - bee.height / 2; bee.onGround = true; game.addChild(bee); // Create platforms based on level var platformCount = 5 + level; var platformWidth = 400; var platformHeight = 30; var minPlatformY = 500; var maxPlatformY = 2732 - 500; var platformSpacing = 2048 / platformCount; for (var i = 0; i < platformCount; i++) { var platform = new Platform(); platform.x = i * platformSpacing + platformSpacing / 2; platform.y = minPlatformY + Math.random() * (maxPlatformY - minPlatformY); platforms.push(platform); game.addChild(platform); } // Create spiders based on level var spiderCount = level; for (var i = 0; i < spiderCount; i++) { var spider = new Spider(); // Position spiders on platforms, starting from the second platform var platformIndex = Math.floor((i + 1) * (platformCount - 1) / spiderCount); spider.x = platforms[platformIndex].x; spider.y = platforms[platformIndex].y - platforms[platformIndex].height / 2 - spider.height / 2; spider.currentPlatform = platforms[platformIndex]; spiders.push(spider); game.addChild(spider); } // Create finish line finishLine = new FinishLine(); finishLine.x = 2048 - 100; finishLine.y = platforms[platformCount - 1].y - platforms[platformCount - 1].height / 2 - finishLine.height / 2; game.addChild(finishLine); // Create controls UI controlsUI = new ControlsUI(); controlsUI.x = 2048 / 2; controlsUI.y = 2732 - 150; LK.gui.addChild(controlsUI); // Set up controls controlsUI.onLeftPressed = function () { bee.moveLeft(); }; controlsUI.onRightPressed = function () { bee.moveRight(); }; controlsUI.onJumpPressed = function () { bee.jump(); }; controlsUI.onUpPressed = function () { bee.moveUp(); }; controlsUI.onControlsReleased = function () { bee.stopMoving(); }; // Create level display text levelText = new Text2("Level: " + currentLevel + "/" + maxLevels, { size: 60, fill: 0xFFFFFF }); levelText.anchor.set(0.5, 0); LK.gui.top.addChild(levelText); // Create score display scoreText = new Text2("Score: " + LK.getScore(), { size: 60, fill: 0xFFFFFF }); scoreText.anchor.set(1, 0); scoreText.x = -50; LK.gui.topRight.addChild(scoreText); // Set game state gameState = "platform"; // Play background music LK.playMusic('gameMusic'); } // Start battle with a spider function startBattle(spider) { // Store bee's position and ground state before battle var originalBeeX = bee.x; var originalBeeY = bee.y; var originalOnGround = bee.onGround; gameState = "battle"; game.battleState.currentSpider = spider; game.battleState.isPlayerTurn = true; // Keep bee in place by setting velocities to zero bee.velocityX = 0; bee.velocityY = 0; // Create battle UI battleUI = new BattleUI(); battleUI.x = 2048 / 2; battleUI.y = 2732 / 2; battleUI.updateHealth(bee.health, bee.maxHealth, spider.health, spider.maxHealth); battleUI.setTurnText(true); game.addChild(battleUI); // Set up attack button handler battleUI.onAttackPressed = function () { if (game.battleState.isPlayerTurn) { playerAttack(); } }; // Store original position and state in battle state for recovery after battle game.battleState.originalBeeX = originalBeeX; game.battleState.originalBeeY = originalBeeY; game.battleState.originalOnGround = originalOnGround; } // Player attacks in battle function playerAttack() { var damage = 20 + Math.floor(Math.random() * 10); // 20-29 damage game.battleState.currentSpider.takeDamage(damage); LK.getSound('attack').play(); // Update battle UI battleUI.updateHealth(bee.health, bee.maxHealth, game.battleState.currentSpider.health, game.battleState.currentSpider.maxHealth); // Flash effect on spider LK.effects.flashObject(game.battleState.currentSpider, 0xFF0000, 300); // Check if spider is defeated if (game.battleState.currentSpider.defeated) { LK.setTimeout(function () { endBattle(true); }, 1000); return; } // Switch turns game.battleState.isPlayerTurn = false; battleUI.setTurnText(false); // Spider attacks after delay LK.setTimeout(function () { spiderAttack(); }, game.battleState.turnDelay); } // Spider attacks in battle function spiderAttack() { var damage = game.battleState.currentSpider.attack(); bee.takeDamage(damage); LK.getSound('hurt').play(); // Update battle UI battleUI.updateHealth(bee.health, bee.maxHealth, game.battleState.currentSpider.health, game.battleState.currentSpider.maxHealth); // Flash effect on bee LK.effects.flashObject(bee, 0xFF0000, 300); // Check if bee is defeated if (bee.health <= 0) { LK.setTimeout(function () { endBattle(false); }, 1000); return; } // Switch turns game.battleState.isPlayerTurn = true; battleUI.setTurnText(true); } // End battle function endBattle(playerWon) { // Remove battle UI game.removeChild(battleUI); if (playerWon) { // Mark spider as defeated game.battleState.currentSpider.defeated = true; // Make spider invisible game.battleState.currentSpider.alpha = 0; // Increase score LK.setScore(LK.getScore() + 100); scoreText.setText("Score: " + LK.getScore()); } else { // Game over if player lost LK.showGameOver(); return; } // Restore bee's position and state from before the battle bee.x = game.battleState.originalBeeX; bee.y = game.battleState.originalBeeY; bee.onGround = game.battleState.originalOnGround; // Ensure bee doesn't fall by zeroing velocities bee.velocityX = 0; bee.velocityY = 0; // Return to platform mode gameState = "platform"; } // Start level scrolling function startLevelScrolling() { levelScrolling = true; lastPlatformX = platforms[platforms.length - 1].x; // Start platform generation timer platformGenerationTimer = LK.setInterval(function () { generateNewPlatform(); }, 2000); // Start spider generation timer spiderGenerationTimer = LK.setInterval(function () { generateNewSpider(); }, 5000); // Move finish line further ahead tween(finishLine, { x: 2048 + 3000 }, { duration: 1000, easing: tween.linear }); } // Generate a new platform ahead function generateNewPlatform() { if (!levelScrolling) { return; } var platform = new Platform(); // Position new platform off screen to the right platform.x = 2048 + platform.width / 2; // Randomize y position within screen bounds var minPlatformY = 500; var maxPlatformY = 2732 - 500; platform.y = minPlatformY + Math.random() * (maxPlatformY - minPlatformY); // Add platform to game platforms.push(platform); game.addChild(platform); // Update last platform x position lastPlatformX = platform.x; } // Generate a new spider on a platform function generateNewSpider() { if (!levelScrolling) { return; } // Find suitable platform for new spider (one that's just entered the screen) var suitablePlatforms = []; for (var i = 0; i < platforms.length; i++) { if (platforms[i].x > 1500 && platforms[i].x < 2500) { suitablePlatforms.push(platforms[i]); } } if (suitablePlatforms.length === 0) { return; } // Choose a random platform var platform = suitablePlatforms[Math.floor(Math.random() * suitablePlatforms.length)]; // Create new spider var spider = new Spider(); spider.x = platform.x; spider.y = platform.y - platform.height / 2 - spider.height / 2; spider.currentPlatform = platform; // Add spider to game spiders.push(spider); game.addChild(spider); } // Stop level scrolling function stopLevelScrolling() { levelScrolling = false; // Clear timers if (platformGenerationTimer) { LK.clearInterval(platformGenerationTimer); platformGenerationTimer = null; } if (spiderGenerationTimer) { LK.clearInterval(spiderGenerationTimer); spiderGenerationTimer = null; } } // Complete level function completeLevel() { LK.getSound('levelComplete').play(); // Stop level scrolling stopLevelScrolling(); // Increase level currentLevel++; storage.currentLevel = currentLevel; // Check if all levels completed if (currentLevel > maxLevels) { LK.showYouWin(); return; } // Initialize next level LK.setTimeout(function () { initLevel(currentLevel); }, 1000); } // Check collision between bee and platform function checkPlatformCollision(bee, platform) { // Simple rectangle collision var beeLeft = bee.x - bee.width / 2; var beeRight = bee.x + bee.width / 2; var beeTop = bee.y - bee.height / 2; var beeBottom = bee.y + bee.height / 2; var platformLeft = platform.x - platform.width / 2; var platformRight = platform.x + platform.width / 2; var platformTop = platform.y - platform.height / 2; var platformBottom = platform.y + platform.height / 2; // Check for collision if (beeRight > platformLeft && beeLeft < platformRight && beeBottom > platformTop && beeTop < platformBottom) { // Check if landing on top of platform if (beeBottom > platformTop && bee.velocityY > 0 && beeTop < platformTop) { bee.y = platformTop - bee.height / 2; bee.velocityY = 0; bee.onGround = true; bee.isJumping = false; return true; } } return false; } // Find and jump to the nearest platform function findAndJumpToNearestPlatform() { var nearestPlatform = null; var shortestDistance = Infinity; // Find the nearest platform for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; var horizontalDistance = Math.abs(platform.x - bee.x); // Only consider platforms that are reasonably within reach horizontally if (horizontalDistance < 500) { var verticalDistance = platform.y - platform.height / 2 - bee.y; // Prefer platforms slightly above the bee or at the same level var distance = horizontalDistance + (verticalDistance > 0 ? verticalDistance * 2 : Math.abs(verticalDistance) * 0.5); if (distance < shortestDistance) { shortestDistance = distance; nearestPlatform = platform; } } } // If we found a platform, animate jumping to it if (nearestPlatform) { // Stop current movement bee.velocityX = 0; bee.velocityY = 0; // Play jump sound LK.getSound('jump').play(); // Tween to the platform position with a nice arc var targetX = nearestPlatform.x; var targetY = nearestPlatform.y - nearestPlatform.height / 2 - bee.height / 2; // Create an animation that looks like a jump tween(bee, { x: targetX, y: targetY }, { duration: 800, easing: tween.easeOutQuad, onFinish: function onFinish() { bee.onGround = true; bee.isJumping = false; } }); } } // Handle bee dragging - mouse/touch down game.down = function (x, y, obj) { if (gameState === "platform") { // Check if tap is on the bee var beeLeft = bee.x - bee.width / 2; var beeRight = bee.x + bee.width / 2; var beeTop = bee.y - bee.height / 2; var beeBottom = bee.y + bee.height / 2; if (x >= beeLeft && x <= beeRight && y >= beeTop && y <= beeBottom) { dragTarget = bee; // Stop current movement when starting to drag bee.velocityX = 0; bee.velocityY = 0; } } }; // Handle game movement game.move = function (x, y, obj) { // Only process movement in platform mode if (gameState === "platform") { // If dragging the bee, update its position if (dragTarget) { dragTarget.x = x; dragTarget.y = y; // Reset falling flags when manually dragging bee.fallingInVoid = false; return; } // Check if bee is falling in void and rescue it with any tap if (bee.fallingInVoid) { findAndJumpToNearestPlatform(); return; } // If tap is on the top fifth of the screen, jump if (y < 2732 / 5) { bee.jump(); } // If tap is in the top-mid section of the screen, move up else if (y < 2732 / 3) { bee.moveUp(); } // If tap is on the right half of the screen, move right else if (x > 2048 / 2) { bee.moveRight(); } // If tap is on the left half of the screen, move left else { bee.moveLeft(); } } }; // Initialize first level initLevel(currentLevel); // Handle touch release to stop bee movement or place bee on platform when dragging game.up = function (x, y, obj) { if (gameState === "platform") { if (dragTarget) { // Check if bee is over a platform to place it properly var platformFound = false; for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; var platformLeft = platform.x - platform.width / 2; var platformRight = platform.x + platform.width / 2; var platformTop = platform.y - platform.height / 2; // If bee is above platform horizontally, place it on the platform if (bee.x >= platformLeft && bee.x <= platformRight) { bee.y = platformTop - bee.height / 2; bee.velocityY = 0; bee.onGround = true; bee.isJumping = false; platformFound = true; break; } } // If no platform found beneath the bee, it starts falling if (!platformFound) { bee.onGround = false; bee.velocityY = 1; // Start falling gently } // Release drag target dragTarget = null; } else { bee.stopMoving(); } } }; // Game update loop game.update = function () { // Skip update if in battle mode if (gameState === "battle") { return; } // Only update bee physics if not being dragged if (!dragTarget) { // Update bee bee.update(); } // Add visual indication when bee is falling in void if (bee.fallingInVoid) { // Flash the bee to indicate it can be rescued if (LK.ticks % 10 < 5) { bee.alpha = 0.5; } else { bee.alpha = 1.0; } } else { bee.alpha = 1.0; } // Check for platform collisions if bee is not being dragged if (!dragTarget) { // Check for platform collisions for (var i = 0; i < platforms.length; i++) { checkPlatformCollision(bee, platforms[i]); } } // Check for screen boundaries if (bee.x < bee.width / 2) { bee.x = bee.width / 2; } else if (bee.x > 2048 - bee.width / 2) { bee.x = 2048 - bee.width / 2; } // Check if bee is falling with no platform below if (bee.y > 2732 - 400 && bee.velocityY > 0 && !bee.onGround) { // Set a flag that bee is falling in void to allow rescue by tap bee.fallingInVoid = true; } else if (bee.y > 2732 + bee.height) { // Fell off the screen LK.showGameOver(); return; } else { // Reset falling flag when not in danger zone bee.fallingInVoid = false; } // Check for spiders on the same platform as bee for (var i = 0; i < spiders.length; i++) { var spider = spiders[i]; if (!spider.defeated) { // Check if bee and spider are on the same platform if (spider.currentPlatform) { var onSamePlatform = Math.abs(bee.x - spider.x) < spider.currentPlatform.width * 0.8 && Math.abs(bee.y - spider.y) < 20; if (onSamePlatform && !spider.moving) { // Spider should move away spider.moveAwayFromBee(bee); } } // Check for collision to start battle if (bee.intersects(spider)) { startBattle(spider); return; } } } // Check if all spiders on screen are defeated to start scrolling var visibleSpiders = false; for (var i = 0; i < spiders.length; i++) { if (!spiders[i].defeated && spiders[i].x < 2048) { visibleSpiders = true; break; } } // Start level scrolling if all visible spiders are defeated and not already scrolling if (!visibleSpiders && !levelScrolling && bee.onGround) { startLevelScrolling(); } // Handle platform and object movement when scrolling if (levelScrolling) { // Move platforms for (var i = 0; i < platforms.length; i++) { platforms[i].x += scrollSpeed; // Remove platforms that have gone off screen if (platforms[i].x < -platforms[i].width) { game.removeChild(platforms[i]); platforms.splice(i, 1); i--; } } // Move spiders with their platforms for (var i = 0; i < spiders.length; i++) { if (spiders[i].currentPlatform) { spiders[i].x = spiders[i].currentPlatform.x; } } // Move finish line finishLine.x += scrollSpeed; // If bee is on a platform, move it with the platform if (bee.onGround) { bee.x += scrollSpeed; } } // Check for finish line collision if (bee.intersects(finishLine)) { // Check if all spiders are defeated var allSpidersDefeated = true; for (var i = 0; i < spiders.length; i++) { if (!spiders[i].defeated) { allSpidersDefeated = false; break; } } if (allSpidersDefeated) { completeLevel(); } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
currentLevel: 1
});
/****
* Classes
****/
var BattleUI = Container.expand(function () {
var self = Container.call(this);
var panel = self.attachAsset('battlePanel', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8
});
var attackBtn = self.attachAsset('attackButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 200
});
self.beeHealthBar = self.attachAsset('healthBar', {
anchorX: 0,
anchorY: 0.5,
x: -300,
y: -150
});
self.spiderHealthBar = self.attachAsset('healthBar', {
anchorX: 0,
anchorY: 0.5,
x: 0,
y: -150
});
var beeHealthText = new Text2("Bee: 100/100", {
size: 40,
fill: 0xFFFFFF
});
beeHealthText.anchor.set(0, 0.5);
beeHealthText.x = -300;
beeHealthText.y = -200;
self.addChild(beeHealthText);
var spiderHealthText = new Text2("Spider: 50/50", {
size: 40,
fill: 0xFFFFFF
});
spiderHealthText.anchor.set(0, 0.5);
spiderHealthText.x = 0;
spiderHealthText.y = -200;
self.addChild(spiderHealthText);
var turnText = new Text2("Your Turn", {
size: 60,
fill: 0xFFFFFF
});
turnText.anchor.set(0.5, 0.5);
turnText.y = -300;
self.addChild(turnText);
var attackText = new Text2("Attack", {
size: 50,
fill: 0xFFFFFF
});
attackText.anchor.set(0.5, 0.5);
attackText.x = 0;
attackText.y = 200;
self.addChild(attackText);
self.updateHealth = function (beeHealth, beeMaxHealth, spiderHealth, spiderMaxHealth) {
// Update health bars
self.beeHealthBar.scale.x = beeHealth / beeMaxHealth;
self.spiderHealthBar.scale.x = spiderHealth / spiderMaxHealth;
// Update text
beeHealthText.setText("Bee: " + beeHealth + "/" + beeMaxHealth);
spiderHealthText.setText("Spider: " + spiderHealth + "/" + spiderMaxHealth);
};
self.setTurnText = function (isPlayerTurn) {
turnText.setText(isPlayerTurn ? "Your Turn" : "Spider's Turn");
};
self.down = function (x, y, obj) {
// Check if attack button was pressed
if (x >= attackBtn.x - attackBtn.width / 2 && x <= attackBtn.x + attackBtn.width / 2 && y >= attackBtn.y - attackBtn.height / 2 && y <= attackBtn.y + attackBtn.height / 2) {
if (self.onAttackPressed && game.battleState.isPlayerTurn) {
self.onAttackPressed();
}
}
};
return self;
});
var Bee = Container.expand(function () {
var self = Container.call(this);
var beeGraphic = self.attachAsset('bee', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.speed = 8;
self.jumpForce = -20;
self.gravity = 1;
self.onGround = false;
self.health = 100;
self.maxHealth = 100;
self.isJumping = false;
self.fallingInVoid = false;
self.update = function () {
// Apply gravity
if (!self.onGround) {
self.velocityY += self.gravity;
}
// Update position
self.x += self.velocityX;
self.y += self.velocityY;
// Reset onGround flag for next frame collision detection
self.onGround = false;
};
self.moveUp = function () {
// Only allow moving up when not jumping
if (!self.isJumping) {
self.velocityY = -self.speed * 0.8; // Slower than horizontal movement
}
};
self.jump = function () {
if (self.onGround) {
self.velocityY = self.jumpForce;
self.onGround = false;
self.isJumping = true;
LK.getSound('jump').play();
}
};
self.moveLeft = function () {
self.velocityX = -self.speed;
};
self.moveRight = function () {
self.velocityX = self.speed;
};
self.stopMoving = function () {
self.velocityX = 0;
};
self.takeDamage = function (amount) {
self.health -= amount;
if (self.health < 0) {
self.health = 0;
}
LK.getSound('hurt').play();
};
self.heal = function (amount) {
self.health += amount;
if (self.health > self.maxHealth) {
self.health = self.maxHealth;
}
};
return self;
});
var ControlsUI = Container.expand(function () {
var self = Container.call(this);
// Left button
var leftBtn = self.attachAsset('attackButton', {
anchorX: 0.5,
anchorY: 0.5,
x: -800,
y: 0,
tint: 0x0000FF
});
var leftText = new Text2("<", {
size: 80,
fill: 0xFFFFFF
});
leftText.anchor.set(0.5, 0.5);
leftText.x = -800;
self.addChild(leftText);
// Right button
var rightBtn = self.attachAsset('attackButton', {
anchorX: 0.5,
anchorY: 0.5,
x: -400,
y: 0,
tint: 0x0000FF
});
var rightText = new Text2(">", {
size: 80,
fill: 0xFFFFFF
});
rightText.anchor.set(0.5, 0.5);
rightText.x = -400;
self.addChild(rightText);
// Jump button
var jumpBtn = self.attachAsset('attackButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 800,
y: 0,
tint: 0x00FF00
});
var jumpText = new Text2("Jump", {
size: 50,
fill: 0xFFFFFF
});
jumpText.anchor.set(0.5, 0.5);
jumpText.x = 800;
self.addChild(jumpText);
// Up button
var upBtn = self.attachAsset('attackButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -80,
tint: 0x0099FF
});
var upText = new Text2("Up", {
size: 50,
fill: 0xFFFFFF
});
upText.anchor.set(0.5, 0.5);
upText.x = 0;
upText.y = -80;
self.addChild(upText);
self.down = function (x, y, obj) {
// Check if left button was pressed
if (x >= leftBtn.x - leftBtn.width / 2 && x <= leftBtn.x + leftBtn.width / 2 && y >= leftBtn.y - leftBtn.height / 2 && y <= leftBtn.y + leftBtn.height / 2) {
if (self.onLeftPressed) {
self.onLeftPressed();
}
}
// Check if right button was pressed
if (x >= rightBtn.x - rightBtn.width / 2 && x <= rightBtn.x + rightBtn.width / 2 && y >= rightBtn.y - rightBtn.height / 2 && y <= rightBtn.y + rightBtn.height / 2) {
if (self.onRightPressed) {
self.onRightPressed();
}
}
// Check if jump button was pressed
if (x >= jumpBtn.x - jumpBtn.width / 2 && x <= jumpBtn.x + jumpBtn.width / 2 && y >= jumpBtn.y - jumpBtn.height / 2 && y <= jumpBtn.y + jumpBtn.height / 2) {
if (self.onJumpPressed) {
self.onJumpPressed();
}
}
// Check if up button was pressed
if (x >= upBtn.x - upBtn.width / 2 && x <= upBtn.x + upBtn.width / 2 && y >= upBtn.y - upBtn.height / 2 && y <= upBtn.y + upBtn.height / 2) {
if (self.onUpPressed) {
self.onUpPressed();
}
}
};
self.up = function (x, y, obj) {
// When buttons are released, stop movement
if (self.onControlsReleased) {
self.onControlsReleased();
}
};
return self;
});
var FinishLine = Container.expand(function () {
var self = Container.call(this);
var finishLineGraphic = self.attachAsset('finishLine', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = finishLineGraphic.width;
self.height = finishLineGraphic.height;
return self;
});
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphic = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = platformGraphic.width;
self.height = platformGraphic.height;
// Handle touch on platform
self.down = function (x, y, obj) {
if (gameState === "platform" && !dragTarget) {
// Move bee to this platform
self.moveBeeToThisPlatform();
}
};
// Function to move the bee to this platform
self.moveBeeToThisPlatform = function () {
// Stop current movement
bee.velocityX = 0;
bee.velocityY = 0;
// Play jump sound
LK.getSound('jump').play();
// Calculate target position on top of platform
var targetX = self.x;
var targetY = self.y - self.height / 2 - bee.height / 2;
// Create a tween animation for bee to jump to the platform
tween(bee, {
x: targetX,
y: targetY
}, {
duration: 800,
easing: tween.easeOutQuad,
onFinish: function onFinish() {
bee.onGround = true;
bee.isJumping = false;
bee.fallingInVoid = false;
// Ensure the bee stays on this platform by locking position
bee.x = targetX;
bee.y = targetY;
// Make sure velocity is zero so it doesn't start moving/falling
bee.velocityX = 0;
bee.velocityY = 0;
// Check if there's a spider on this platform and make it move away
for (var i = 0; i < spiders.length; i++) {
var spider = spiders[i];
if (!spider.defeated && spider.currentPlatform === self) {
spider.moveAwayFromBee(bee);
}
}
}
});
};
return self;
});
var Spider = Container.expand(function () {
var self = Container.call(this);
var spiderGraphic = self.attachAsset('spider', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 50;
self.maxHealth = 50;
self.attackDamage = 15;
self.defeated = false;
self.currentPlatform = null;
self.moving = false;
self.moveAwayFromBee = function (bee) {
if (self.moving || self.defeated) {
return;
}
self.moving = true;
// Store bee's original position to ensure it doesn't fall
var originalBeeY = bee.y;
var originalBeeX = bee.x;
var isOnSamePlatform = bee.onGround && Math.abs(bee.x - self.x) < self.currentPlatform.width * 0.8;
var keepBeeOnPlatform = isOnSamePlatform;
// Find nearby platforms to move to
var nearbyPlatforms = [];
for (var i = 0; i < platforms.length; i++) {
// Don't include current platform or platforms too far away
if (platforms[i] !== self.currentPlatform && Math.abs(platforms[i].x - self.x) < 800) {
nearbyPlatforms.push(platforms[i]);
}
}
// If no nearby platforms, just return
if (nearbyPlatforms.length === 0) {
self.moving = false;
return;
}
// Sort platforms by distance from bee
nearbyPlatforms.sort(function (a, b) {
var distA = Math.abs(a.x - bee.x);
var distB = Math.abs(b.x - bee.x);
return distB - distA; // Further platforms first
});
// Get target platform (furthest from bee)
var targetPlatform = nearbyPlatforms[0];
var targetX = targetPlatform.x;
var targetY = targetPlatform.y - targetPlatform.height / 2 - self.height / 2;
// Animate spider moving to new platform
tween(self, {
x: targetX,
y: targetY
}, {
duration: 500,
easing: tween.easeOutQuad,
onFinish: function onFinish() {
self.currentPlatform = targetPlatform;
self.moving = false;
// Ensure bee stays on platform if it was on the same platform as spider
if (keepBeeOnPlatform) {
bee.x = originalBeeX;
bee.y = originalBeeY;
bee.onGround = true;
bee.velocityY = 0;
bee.isJumping = false;
}
}
});
};
self.takeDamage = function (amount) {
self.health -= amount;
if (self.health <= 0) {
self.health = 0;
self.defeated = true;
}
};
self.attack = function () {
return self.attackDamage;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Game state variables
// Initialize bee asset
// Initialize spider assets
// Initialize platform assets
// Initialize finish line
// Initialize battle UI elements
// Initialize sounds
// Initialize music
var currentLevel = storage.currentLevel || 1;
var maxLevels = 10;
var gameState = "platform"; // "platform" or "battle"
var platforms = [];
var spiders = [];
var finishLine;
var bee;
var battleUI;
var controlsUI;
var levelText;
var dragTarget = null; // Track if the bee is being dragged
var levelScrolling = false; // Whether the platforms are moving
var scrollSpeed = -3; // Horizontal scroll speed for platforms
var platformGenerationTimer = null; // Timer for platform generation
var spiderGenerationTimer = null; // Timer for spider generation
var lastPlatformX = 0; // Track last platform position for generation
// Battle state
game.battleState = {
currentSpider: null,
isPlayerTurn: true,
turnDelay: 1000 // ms
};
// Initialize level
function initLevel(level) {
// Reset level scrolling
levelScrolling = false;
if (platformGenerationTimer) {
LK.clearInterval(platformGenerationTimer);
platformGenerationTimer = null;
}
if (spiderGenerationTimer) {
LK.clearInterval(spiderGenerationTimer);
spiderGenerationTimer = null;
}
// Clear existing elements
platforms = [];
spiders = [];
// Remove old elements from game
while (game.children.length > 0) {
game.removeChild(game.children[0]);
}
// Create bee
bee = new Bee();
bee.x = 150;
// Create first platform to ensure bee starts on a platform
var firstPlatform = new Platform();
firstPlatform.x = 200;
firstPlatform.y = 2732 / 2 + 100;
platforms.push(firstPlatform);
game.addChild(firstPlatform);
// Position bee on first platform
bee.x = firstPlatform.x;
bee.y = firstPlatform.y - firstPlatform.height / 2 - bee.height / 2;
bee.onGround = true;
game.addChild(bee);
// Create platforms based on level
var platformCount = 5 + level;
var platformWidth = 400;
var platformHeight = 30;
var minPlatformY = 500;
var maxPlatformY = 2732 - 500;
var platformSpacing = 2048 / platformCount;
for (var i = 0; i < platformCount; i++) {
var platform = new Platform();
platform.x = i * platformSpacing + platformSpacing / 2;
platform.y = minPlatformY + Math.random() * (maxPlatformY - minPlatformY);
platforms.push(platform);
game.addChild(platform);
}
// Create spiders based on level
var spiderCount = level;
for (var i = 0; i < spiderCount; i++) {
var spider = new Spider();
// Position spiders on platforms, starting from the second platform
var platformIndex = Math.floor((i + 1) * (platformCount - 1) / spiderCount);
spider.x = platforms[platformIndex].x;
spider.y = platforms[platformIndex].y - platforms[platformIndex].height / 2 - spider.height / 2;
spider.currentPlatform = platforms[platformIndex];
spiders.push(spider);
game.addChild(spider);
}
// Create finish line
finishLine = new FinishLine();
finishLine.x = 2048 - 100;
finishLine.y = platforms[platformCount - 1].y - platforms[platformCount - 1].height / 2 - finishLine.height / 2;
game.addChild(finishLine);
// Create controls UI
controlsUI = new ControlsUI();
controlsUI.x = 2048 / 2;
controlsUI.y = 2732 - 150;
LK.gui.addChild(controlsUI);
// Set up controls
controlsUI.onLeftPressed = function () {
bee.moveLeft();
};
controlsUI.onRightPressed = function () {
bee.moveRight();
};
controlsUI.onJumpPressed = function () {
bee.jump();
};
controlsUI.onUpPressed = function () {
bee.moveUp();
};
controlsUI.onControlsReleased = function () {
bee.stopMoving();
};
// Create level display text
levelText = new Text2("Level: " + currentLevel + "/" + maxLevels, {
size: 60,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
// Create score display
scoreText = new Text2("Score: " + LK.getScore(), {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(1, 0);
scoreText.x = -50;
LK.gui.topRight.addChild(scoreText);
// Set game state
gameState = "platform";
// Play background music
LK.playMusic('gameMusic');
}
// Start battle with a spider
function startBattle(spider) {
// Store bee's position and ground state before battle
var originalBeeX = bee.x;
var originalBeeY = bee.y;
var originalOnGround = bee.onGround;
gameState = "battle";
game.battleState.currentSpider = spider;
game.battleState.isPlayerTurn = true;
// Keep bee in place by setting velocities to zero
bee.velocityX = 0;
bee.velocityY = 0;
// Create battle UI
battleUI = new BattleUI();
battleUI.x = 2048 / 2;
battleUI.y = 2732 / 2;
battleUI.updateHealth(bee.health, bee.maxHealth, spider.health, spider.maxHealth);
battleUI.setTurnText(true);
game.addChild(battleUI);
// Set up attack button handler
battleUI.onAttackPressed = function () {
if (game.battleState.isPlayerTurn) {
playerAttack();
}
};
// Store original position and state in battle state for recovery after battle
game.battleState.originalBeeX = originalBeeX;
game.battleState.originalBeeY = originalBeeY;
game.battleState.originalOnGround = originalOnGround;
}
// Player attacks in battle
function playerAttack() {
var damage = 20 + Math.floor(Math.random() * 10); // 20-29 damage
game.battleState.currentSpider.takeDamage(damage);
LK.getSound('attack').play();
// Update battle UI
battleUI.updateHealth(bee.health, bee.maxHealth, game.battleState.currentSpider.health, game.battleState.currentSpider.maxHealth);
// Flash effect on spider
LK.effects.flashObject(game.battleState.currentSpider, 0xFF0000, 300);
// Check if spider is defeated
if (game.battleState.currentSpider.defeated) {
LK.setTimeout(function () {
endBattle(true);
}, 1000);
return;
}
// Switch turns
game.battleState.isPlayerTurn = false;
battleUI.setTurnText(false);
// Spider attacks after delay
LK.setTimeout(function () {
spiderAttack();
}, game.battleState.turnDelay);
}
// Spider attacks in battle
function spiderAttack() {
var damage = game.battleState.currentSpider.attack();
bee.takeDamage(damage);
LK.getSound('hurt').play();
// Update battle UI
battleUI.updateHealth(bee.health, bee.maxHealth, game.battleState.currentSpider.health, game.battleState.currentSpider.maxHealth);
// Flash effect on bee
LK.effects.flashObject(bee, 0xFF0000, 300);
// Check if bee is defeated
if (bee.health <= 0) {
LK.setTimeout(function () {
endBattle(false);
}, 1000);
return;
}
// Switch turns
game.battleState.isPlayerTurn = true;
battleUI.setTurnText(true);
}
// End battle
function endBattle(playerWon) {
// Remove battle UI
game.removeChild(battleUI);
if (playerWon) {
// Mark spider as defeated
game.battleState.currentSpider.defeated = true;
// Make spider invisible
game.battleState.currentSpider.alpha = 0;
// Increase score
LK.setScore(LK.getScore() + 100);
scoreText.setText("Score: " + LK.getScore());
} else {
// Game over if player lost
LK.showGameOver();
return;
}
// Restore bee's position and state from before the battle
bee.x = game.battleState.originalBeeX;
bee.y = game.battleState.originalBeeY;
bee.onGround = game.battleState.originalOnGround;
// Ensure bee doesn't fall by zeroing velocities
bee.velocityX = 0;
bee.velocityY = 0;
// Return to platform mode
gameState = "platform";
}
// Start level scrolling
function startLevelScrolling() {
levelScrolling = true;
lastPlatformX = platforms[platforms.length - 1].x;
// Start platform generation timer
platformGenerationTimer = LK.setInterval(function () {
generateNewPlatform();
}, 2000);
// Start spider generation timer
spiderGenerationTimer = LK.setInterval(function () {
generateNewSpider();
}, 5000);
// Move finish line further ahead
tween(finishLine, {
x: 2048 + 3000
}, {
duration: 1000,
easing: tween.linear
});
}
// Generate a new platform ahead
function generateNewPlatform() {
if (!levelScrolling) {
return;
}
var platform = new Platform();
// Position new platform off screen to the right
platform.x = 2048 + platform.width / 2;
// Randomize y position within screen bounds
var minPlatformY = 500;
var maxPlatformY = 2732 - 500;
platform.y = minPlatformY + Math.random() * (maxPlatformY - minPlatformY);
// Add platform to game
platforms.push(platform);
game.addChild(platform);
// Update last platform x position
lastPlatformX = platform.x;
}
// Generate a new spider on a platform
function generateNewSpider() {
if (!levelScrolling) {
return;
}
// Find suitable platform for new spider (one that's just entered the screen)
var suitablePlatforms = [];
for (var i = 0; i < platforms.length; i++) {
if (platforms[i].x > 1500 && platforms[i].x < 2500) {
suitablePlatforms.push(platforms[i]);
}
}
if (suitablePlatforms.length === 0) {
return;
}
// Choose a random platform
var platform = suitablePlatforms[Math.floor(Math.random() * suitablePlatforms.length)];
// Create new spider
var spider = new Spider();
spider.x = platform.x;
spider.y = platform.y - platform.height / 2 - spider.height / 2;
spider.currentPlatform = platform;
// Add spider to game
spiders.push(spider);
game.addChild(spider);
}
// Stop level scrolling
function stopLevelScrolling() {
levelScrolling = false;
// Clear timers
if (platformGenerationTimer) {
LK.clearInterval(platformGenerationTimer);
platformGenerationTimer = null;
}
if (spiderGenerationTimer) {
LK.clearInterval(spiderGenerationTimer);
spiderGenerationTimer = null;
}
}
// Complete level
function completeLevel() {
LK.getSound('levelComplete').play();
// Stop level scrolling
stopLevelScrolling();
// Increase level
currentLevel++;
storage.currentLevel = currentLevel;
// Check if all levels completed
if (currentLevel > maxLevels) {
LK.showYouWin();
return;
}
// Initialize next level
LK.setTimeout(function () {
initLevel(currentLevel);
}, 1000);
}
// Check collision between bee and platform
function checkPlatformCollision(bee, platform) {
// Simple rectangle collision
var beeLeft = bee.x - bee.width / 2;
var beeRight = bee.x + bee.width / 2;
var beeTop = bee.y - bee.height / 2;
var beeBottom = bee.y + bee.height / 2;
var platformLeft = platform.x - platform.width / 2;
var platformRight = platform.x + platform.width / 2;
var platformTop = platform.y - platform.height / 2;
var platformBottom = platform.y + platform.height / 2;
// Check for collision
if (beeRight > platformLeft && beeLeft < platformRight && beeBottom > platformTop && beeTop < platformBottom) {
// Check if landing on top of platform
if (beeBottom > platformTop && bee.velocityY > 0 && beeTop < platformTop) {
bee.y = platformTop - bee.height / 2;
bee.velocityY = 0;
bee.onGround = true;
bee.isJumping = false;
return true;
}
}
return false;
}
// Find and jump to the nearest platform
function findAndJumpToNearestPlatform() {
var nearestPlatform = null;
var shortestDistance = Infinity;
// Find the nearest platform
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
var horizontalDistance = Math.abs(platform.x - bee.x);
// Only consider platforms that are reasonably within reach horizontally
if (horizontalDistance < 500) {
var verticalDistance = platform.y - platform.height / 2 - bee.y;
// Prefer platforms slightly above the bee or at the same level
var distance = horizontalDistance + (verticalDistance > 0 ? verticalDistance * 2 : Math.abs(verticalDistance) * 0.5);
if (distance < shortestDistance) {
shortestDistance = distance;
nearestPlatform = platform;
}
}
}
// If we found a platform, animate jumping to it
if (nearestPlatform) {
// Stop current movement
bee.velocityX = 0;
bee.velocityY = 0;
// Play jump sound
LK.getSound('jump').play();
// Tween to the platform position with a nice arc
var targetX = nearestPlatform.x;
var targetY = nearestPlatform.y - nearestPlatform.height / 2 - bee.height / 2;
// Create an animation that looks like a jump
tween(bee, {
x: targetX,
y: targetY
}, {
duration: 800,
easing: tween.easeOutQuad,
onFinish: function onFinish() {
bee.onGround = true;
bee.isJumping = false;
}
});
}
}
// Handle bee dragging - mouse/touch down
game.down = function (x, y, obj) {
if (gameState === "platform") {
// Check if tap is on the bee
var beeLeft = bee.x - bee.width / 2;
var beeRight = bee.x + bee.width / 2;
var beeTop = bee.y - bee.height / 2;
var beeBottom = bee.y + bee.height / 2;
if (x >= beeLeft && x <= beeRight && y >= beeTop && y <= beeBottom) {
dragTarget = bee;
// Stop current movement when starting to drag
bee.velocityX = 0;
bee.velocityY = 0;
}
}
};
// Handle game movement
game.move = function (x, y, obj) {
// Only process movement in platform mode
if (gameState === "platform") {
// If dragging the bee, update its position
if (dragTarget) {
dragTarget.x = x;
dragTarget.y = y;
// Reset falling flags when manually dragging
bee.fallingInVoid = false;
return;
}
// Check if bee is falling in void and rescue it with any tap
if (bee.fallingInVoid) {
findAndJumpToNearestPlatform();
return;
}
// If tap is on the top fifth of the screen, jump
if (y < 2732 / 5) {
bee.jump();
}
// If tap is in the top-mid section of the screen, move up
else if (y < 2732 / 3) {
bee.moveUp();
}
// If tap is on the right half of the screen, move right
else if (x > 2048 / 2) {
bee.moveRight();
}
// If tap is on the left half of the screen, move left
else {
bee.moveLeft();
}
}
};
// Initialize first level
initLevel(currentLevel);
// Handle touch release to stop bee movement or place bee on platform when dragging
game.up = function (x, y, obj) {
if (gameState === "platform") {
if (dragTarget) {
// Check if bee is over a platform to place it properly
var platformFound = false;
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
var platformLeft = platform.x - platform.width / 2;
var platformRight = platform.x + platform.width / 2;
var platformTop = platform.y - platform.height / 2;
// If bee is above platform horizontally, place it on the platform
if (bee.x >= platformLeft && bee.x <= platformRight) {
bee.y = platformTop - bee.height / 2;
bee.velocityY = 0;
bee.onGround = true;
bee.isJumping = false;
platformFound = true;
break;
}
}
// If no platform found beneath the bee, it starts falling
if (!platformFound) {
bee.onGround = false;
bee.velocityY = 1; // Start falling gently
}
// Release drag target
dragTarget = null;
} else {
bee.stopMoving();
}
}
};
// Game update loop
game.update = function () {
// Skip update if in battle mode
if (gameState === "battle") {
return;
}
// Only update bee physics if not being dragged
if (!dragTarget) {
// Update bee
bee.update();
}
// Add visual indication when bee is falling in void
if (bee.fallingInVoid) {
// Flash the bee to indicate it can be rescued
if (LK.ticks % 10 < 5) {
bee.alpha = 0.5;
} else {
bee.alpha = 1.0;
}
} else {
bee.alpha = 1.0;
}
// Check for platform collisions if bee is not being dragged
if (!dragTarget) {
// Check for platform collisions
for (var i = 0; i < platforms.length; i++) {
checkPlatformCollision(bee, platforms[i]);
}
}
// Check for screen boundaries
if (bee.x < bee.width / 2) {
bee.x = bee.width / 2;
} else if (bee.x > 2048 - bee.width / 2) {
bee.x = 2048 - bee.width / 2;
}
// Check if bee is falling with no platform below
if (bee.y > 2732 - 400 && bee.velocityY > 0 && !bee.onGround) {
// Set a flag that bee is falling in void to allow rescue by tap
bee.fallingInVoid = true;
} else if (bee.y > 2732 + bee.height) {
// Fell off the screen
LK.showGameOver();
return;
} else {
// Reset falling flag when not in danger zone
bee.fallingInVoid = false;
}
// Check for spiders on the same platform as bee
for (var i = 0; i < spiders.length; i++) {
var spider = spiders[i];
if (!spider.defeated) {
// Check if bee and spider are on the same platform
if (spider.currentPlatform) {
var onSamePlatform = Math.abs(bee.x - spider.x) < spider.currentPlatform.width * 0.8 && Math.abs(bee.y - spider.y) < 20;
if (onSamePlatform && !spider.moving) {
// Spider should move away
spider.moveAwayFromBee(bee);
}
}
// Check for collision to start battle
if (bee.intersects(spider)) {
startBattle(spider);
return;
}
}
}
// Check if all spiders on screen are defeated to start scrolling
var visibleSpiders = false;
for (var i = 0; i < spiders.length; i++) {
if (!spiders[i].defeated && spiders[i].x < 2048) {
visibleSpiders = true;
break;
}
}
// Start level scrolling if all visible spiders are defeated and not already scrolling
if (!visibleSpiders && !levelScrolling && bee.onGround) {
startLevelScrolling();
}
// Handle platform and object movement when scrolling
if (levelScrolling) {
// Move platforms
for (var i = 0; i < platforms.length; i++) {
platforms[i].x += scrollSpeed;
// Remove platforms that have gone off screen
if (platforms[i].x < -platforms[i].width) {
game.removeChild(platforms[i]);
platforms.splice(i, 1);
i--;
}
}
// Move spiders with their platforms
for (var i = 0; i < spiders.length; i++) {
if (spiders[i].currentPlatform) {
spiders[i].x = spiders[i].currentPlatform.x;
}
}
// Move finish line
finishLine.x += scrollSpeed;
// If bee is on a platform, move it with the platform
if (bee.onGround) {
bee.x += scrollSpeed;
}
}
// Check for finish line collision
if (bee.intersects(finishLine)) {
// Check if all spiders are defeated
var allSpidersDefeated = true;
for (var i = 0; i < spiders.length; i++) {
if (!spiders[i].defeated) {
allSpidersDefeated = false;
break;
}
}
if (allSpidersDefeated) {
completeLevel();
}
}
};
tron d'arbre mignon de plateforme. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Abeille. In-Game asset. 2d. High contrast. No shadows
AraigneĢe. In-Game asset. 2d. High contrast. No shadows
Fond d'eĢcran ruche. In-Game asset. 2d. High contrast. No shadows
Fond d'eĢcran maiĢs. In-Game asset. 2d. High contrast. No shadows
Fond d'eĢcran roche. In-Game asset. 2d. High contrast. No shadows
Fond d'eĢcran campagne. In-Game asset. 2d. High contrast. No shadows
Fond d'eĢcran nid des araigneĢes. In-Game asset. 2d. High contrast. No shadows
Fond d'eĢcran foreĢt enchanteĢe. In-Game asset. 2d. High contrast. No shadows
Fond d'eĢcran muguet. In-Game asset. 2d. High contrast. No shadows
Fond d'eĢcran roses epineuses. In-Game asset. 2d. High contrast. No shadows
Fond d'eĢcran prairie manga. In-Game asset. 2d. High contrast. No shadows
Fond d'eĢcran ortis. In-Game asset. 2d. High contrast. No shadows
Frelon. In-Game asset. 2d. High contrast. No shadows
GueĢpe. In-Game asset. 2d. High contrast. No shadows
Libellule. In-Game asset. 2d. High contrast. No shadows
Oiseau. In-Game asset. 2d. High contrast. No shadows