User prompt
L'abeille ne doit pas tomber de la plateforme de l'araignée quand le combat se lance
User prompt
L'abeille ne doit pas tomber de la plateforme de l'araignée quand l'araignée se pousse
User prompt
L'araignée doit se pousser quand l'abeille arrive sur la même plateforme quelle, avant que se lance le combat entre les deux
User prompt
L'abeille ne doit pas tomber lorsqu'elle rejoint la plateforme cliqué (qu'elle soit vers le haut, le bas et même celle de l'araignée)
User prompt
L'abeille doit pouvoir voler vers le haut quand l'utilisateur tape sur une plateforme, l'abeille doit rejoindre la plateforme en question
User prompt
L'abeille doit pouvoir être glisser vers le haut, le bas et sur les plateformes du choix du joueur, et l'abeille doit être sur une plateforme lors du démarrage du jeu , cela lui permettra d'avancer
User prompt
Ajoute une fonctionnalité pour que le joueur puisse déplacer l'abeille vers le haut, et la faire sauter
User prompt
Ajoute une fonctionnalité pour que le joueur puisse déplacer son abeille dans le vide, en appuyant sur l'écran pour la remettre sur une plateforme
User prompt
Ajoute une fonctionnalité pour que l'abeille saute a la plateforme la plus proche lorsqu'elle se retrouve dans le vide ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Le joueur doit pouvoir faire sauter et bouger son abeille sur la plateforme en appuyant sur son écran
User prompt
Ajoute une fonctionnalité pour que le joueur puisse bouger et faire avancer son abeille en appuyant sur l'écran
Code edit (1 edits merged)
Please save this source code
User prompt
Bee vs Spiders: Platform Battle
Initial prompt
Crée ce jeu : --- **Titre** : *Abeille vs Araignées* **Genre** : Jeu de plateforme avec combat au tour par tour **Description** : Dans ce jeu de plateforme, l'objectif est de guider une abeille à travers plusieurs niveaux semés d'araignées. Le joueur doit faire avancer l'abeille jusqu'à la ligne d'arrivée en traversant des plateformes tout en combattant les araignées rencontrées sur le chemin. ### Mécaniques de Jeu : 1. **Déplacement de l'abeille** : - L'abeille se déplace automatiquement sur les plateformes, mais le joueur peut la contrôler à l’aide des flèches directionnelles ou des touches (par exemple, *flèche droite* pour avancer et *flèche gauche* pour reculer). - Si l'abeille touche une araignée, un combat commence. 2. **Combat au tour par tour** : - Lorsqu'une araignée est rencontrée, un combat s'engage entre l'abeille et l'araignée. - **Points de vie** : L'abeille et l'araignée commencent avec 50 points de vie chacun. - **Attaque de l'araignée** : L'araignée attaque automatiquement à chaque tour. - **Attaque de l'abeille** : Le joueur doit appuyer sur un bouton ("Attaquer") pour faire attaquer l'abeille. - Le combat est résolu en alternance : l'araignée attaque, puis le joueur peut faire attaquer l'abeille. Cela continue jusqu'à ce que l'un des deux perde tous ses points de vie. 3. **Conséquences du combat** : - **Si l'abeille gagne** : L'araignée est éliminée, et l'abeille peut continuer à avancer sur la plateforme. - **Si l'araignée gagne** : L'abeille perd et doit recommencer le niveau à partir du début de la plateforme. 4. **Niveaux** : - **Niveau 1** : 5 araignées à affronter avant d'atteindre la ligne d'arrivée. - **Niveaux 2 à 3** : 8 araignées à affronter. - **Niveaux 4 à 5** : 10 araignées à affronter. - **Niveau 6** : 13 araignées à affronter. - **Niveaux 7 à 9** : 15 araignées à affronter. - **Niveau 10** : 20 araignées à affronter. 5. **Objectif** : L'objectif est de faire avancer l'abeille jusqu'à la ligne d'arrivée à la fin de chaque niveau. Chaque niveau devient plus difficile en raison de l'augmentation du nombre d'araignées à combattre. 6. **Progression de Niveau** : - Chaque fois que le joueur finit un niveau, il passe au suivant avec un nombre accru d'araignées. - À la fin du **niveau 10**, un message de félicitations s'affiche : *"Félicitations ! Tu as gagné le jeu ! À bientôt pour d'autres jeux de clem27games."* ### Détails Techniques : - **Graphismes** : L'abeille et les araignées doivent être dessinées dans un style simple et mignon. La plateforme devrait être un environnement naturel (par exemple, des branches, des fleurs, etc.), et les araignées devraient apparaître sur la plateforme à différents endroits. - **Contrôles** : - Flèches directionnelles pour déplacer l'abeille. - Espace ou un bouton spécifique pour faire attaquer l'abeille. - **Combat** : - Chaque personnage (abeille et araignée) aura une barre de vie affichée à l'écran. - Les attaques doivent être simples et visuellement distinctes pour chaque personnage. - Un son ou une animation de frappe peut être ajouté lorsque l’abeille ou l’araignée attaque. - **Écran de Fin** : - Un message s’affiche à la fin du niveau 10 : *"Félicitations ! Tu as gagné le jeu ! À bientôt pour d'autres jeux de clem27games."* - L'écran de victoire pourrait inclure une animation ou un effet visuel pour rendre l’expérience de victoire plus immersive.
/****
* 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
// Battle state
game.battleState = {
currentSpider: null,
isPlayerTurn: true,
turnDelay: 1000 // ms
};
// Initialize level
function initLevel(level) {
// 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";
}
// Complete level
function completeLevel() {
LK.getSound('levelComplete').play();
// 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 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();
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -400,16 +400,16 @@
/****
* Game Code
****/
-// Initialize music
-// Initialize sounds
-// Initialize battle UI elements
-// Initialize finish line
-// Initialize platform assets
-// Initialize spider assets
-// Initialize bee asset
// 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 = [];
@@ -522,11 +522,18 @@
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;
@@ -538,8 +545,12 @@
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
@@ -600,8 +611,15 @@
// 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";
}
// Complete level
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
Araignée. In-Game asset. 2d. High contrast. No shadows
Fond d'écran ruche. In-Game asset. 2d. High contrast. No shadows
Fond d'écran maïs. In-Game asset. 2d. High contrast. No shadows
Fond d'écran roche. In-Game asset. 2d. High contrast. No shadows
Fond d'écran campagne. In-Game asset. 2d. High contrast. No shadows
Fond d'écran nid des araignées. In-Game asset. 2d. High contrast. No shadows
Fond d'écran forêt enchantée. In-Game asset. 2d. High contrast. No shadows
Fond d'écran muguet. In-Game asset. 2d. High contrast. No shadows
Fond d'écran roses epineuses. In-Game asset. 2d. High contrast. No shadows
Fond d'écran prairie manga. In-Game asset. 2d. High contrast. No shadows
Fond d'écran ortis. In-Game asset. 2d. High contrast. No shadows
Frelon. In-Game asset. 2d. High contrast. No shadows
Guê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