/**** * Classes ****/ var TargetingPotion = Container.expand(function () { var self = Container.call(this); var potionGraphics = self.attachAsset('potion', { anchorX: 0.5, anchorY: 0.5 }); self.baseSpeed = 5; self.speedMultiplier = 1; self.move = function () { var targetX = fairy.x; var targetY = fairy.y; var moveX = targetX - self.x; var moveY = targetY - self.y; var distance = Math.sqrt(moveX * moveX + moveY * moveY); self.x += moveX / distance * self.baseSpeed * self.speedMultiplier; self.y += moveY / distance * self.baseSpeed * self.speedMultiplier; if (self.y > 2732 || self.x < 0 || self.x > 2048) { self.destroy(); } }; }); var PixelateEffect = Container.expand(function () { var self = Container.call(this); self.applyTo = function (target) { // Placeholder for pixelation effect logic // This is where you would implement the actual pixelation effect // For now, we'll just log to the console console.log('Applying pixelation effect to', target); // After the effect is applied, destroy the target target.destroy(); }; }); // LivesDisplay class var LivesDisplay = Container.expand(function () { var self = Container.call(this); self.updateLives = function (lives) { self.removeChildren(); // Clear existing heart icons var spacing = 10; // Spacing between hearts for (var i = 0; i < lives; i++) { var heartIcon = self.attachAsset('heart_full', {}); heartIcon.x = i * (heartIcon.width + spacing); // Position hearts horizontally with spacing self.addChild(heartIcon); } for (var j = lives; j < self.maxLives; j++) { var emptyHeartIcon = self.attachAsset('heart_empty', {}); emptyHeartIcon.x = j * (emptyHeartIcon.width + spacing); self.addChild(emptyHeartIcon); } }; }); // Fairy class var Fairy = Container.expand(function () { var self = Container.call(this); var fairyGraphics = self.attachAsset('fairy', { anchorX: 0.5, anchorY: 0.5 }); fairyGraphics.scale.set(1.2); // Slightly reduce the size of the fairy self.lives = 3; self.speed = 10; self.moveLeft = function () { self.x = Math.max(self.width / 2, self.x - self.speed); }; self.moveRight = function () { self.x = Math.min(2048 - self.width / 2, self.x + self.speed); }; self.moveUp = function () { self.y = Math.max(self.height / 2, self.y - self.speed); }; self.moveDown = function () { self.y = Math.min(2732 - self.height / 2, self.y + self.speed); }; }); // Potion class var Potion = Container.expand(function () { var self = Container.call(this); var potionGraphics = self.attachAsset('potion', { anchorX: 0.5, anchorY: 0.5 }); self.baseSpeed = 6; self.speedMultiplier = 1; self.move = function () { self.y += self.baseSpeed * self.speedMultiplier; if (self.y > 2732 + self.height / 2) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // New potion spawn logic // Add background asset var minPotions = 4; var maxPotions = 8; var spawnInterval = 120; // Spawn every 2 seconds (120 ticks at 60FPS) var nextSpawnTick = spawnInterval; LK.on('tick', function () { // Other game logic... // Handle potion spawning if (LK.ticks % spawnInterval === 0) { for (var j = 0; j < maxPotions; j++) { var potion = new Potion(); potion.x = Math.random() * (2048 - potion.width) + potion.width / 2; potion.y = -potion.height / 2; potions.push(potion); game.addChild(potion); } } // Other game logic... }); var background = game.attachAsset('background', {}); background.width = 2048; background.height = 2732; game.addChild(background); // Initialize fairy var fairy = game.addChild(new Fairy()); fairy.x = 1024; // Center horizontally fairy.y = 2732 - 100; // Start near the bottom of the screen // Initialize potions array var potions = []; // Initialize lives display var livesDisplay = game.addChild(new LivesDisplay()); livesDisplay.updateLives(fairy.lives); LK.gui.top.addChild(livesDisplay); // Attach livesDisplay to the top center of the screen. // Handle touch movement and orient fairy horizontally based on movement direction function handleTouchMove(obj) { var touchPos = obj.event.getLocalPosition(game); var previousX = fairy.x; fairy.x = touchPos.x; fairy.y = touchPos.y; // Determine if fairy should face left or right based on movement direction if (touchPos.x < previousX) { fairy.scale.x = -1; // Flip fairy horizontally to face left } else if (touchPos.x > previousX) { fairy.scale.x = 1; // Default orientation to face right } } // Add touch move listener to the game game.on('move', handleTouchMove); // Game tick event LK.on('tick', function () { // Move potions for (var i = potions.length - 1; i >= 0; i--) { potions[i].move(); if (fairy.intersects(potions[i]) && !fairy.isImmortal) { // Decrease fairy's lives when touching a potion and end game if lives are 0 fairy.lives--; // Display 'Holala!' if two lives are lost consecutively if (fairy.previousLifeLossTick && LK.ticks - fairy.previousLifeLossTick <= 1) { var holalaText = new Text2('Holala!', { size: 200, fill: "#ff0000" }); holalaText.anchor.set(0.5, 0.5); holalaText.x = 1024; holalaText.y = 1366; game.addChild(holalaText); LK.setTimeout(function () { holalaText.destroy(); }, 2000); } fairy.previousLifeLossTick = LK.ticks; livesDisplay.updateLives(fairy.lives); LK.effects.flashObject(fairy, 0xff0000, 500); if (fairy.lives <= 0) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } else { fairy.isImmortal = true; fairy.blinkInterval = LK.setInterval(function () { fairy.visible = !fairy.visible; }, 150); LK.setTimeout(function () { fairy.isImmortal = false; LK.clearInterval(fairy.blinkInterval); fairy.visible = true; // Ensure fairy is visible after immortality ends }, 3000); } // Apply effect to the potion before destroying it var effect = new PixelateEffect(); effect.applyTo(potions[i]); potions.splice(i, 1); } } // Change potion behavior after fairy crosses 5 lines var linesCrossedThreshold = 5; // Number of lines the fairy must cross var lineSpacing = 2732 / 5; // Spacing of lines based on screen height if (fairy.y < 2732 - linesCrossedThreshold * lineSpacing) { for (var p = potions.length - 1; p >= 0; p--) { if (!(potions[p] instanceof TargetingPotion)) { var targetingPotion = new TargetingPotion(); targetingPotion.x = potions[p].x; targetingPotion.y = potions[p].y; potions[p].destroy(); potions.splice(p, 1); game.addChild(targetingPotion); potions.push(targetingPotion); } } } });
/****
* Classes
****/
var TargetingPotion = Container.expand(function () {
var self = Container.call(this);
var potionGraphics = self.attachAsset('potion', {
anchorX: 0.5,
anchorY: 0.5
});
self.baseSpeed = 5;
self.speedMultiplier = 1;
self.move = function () {
var targetX = fairy.x;
var targetY = fairy.y;
var moveX = targetX - self.x;
var moveY = targetY - self.y;
var distance = Math.sqrt(moveX * moveX + moveY * moveY);
self.x += moveX / distance * self.baseSpeed * self.speedMultiplier;
self.y += moveY / distance * self.baseSpeed * self.speedMultiplier;
if (self.y > 2732 || self.x < 0 || self.x > 2048) {
self.destroy();
}
};
});
var PixelateEffect = Container.expand(function () {
var self = Container.call(this);
self.applyTo = function (target) {
// Placeholder for pixelation effect logic
// This is where you would implement the actual pixelation effect
// For now, we'll just log to the console
console.log('Applying pixelation effect to', target);
// After the effect is applied, destroy the target
target.destroy();
};
});
// LivesDisplay class
var LivesDisplay = Container.expand(function () {
var self = Container.call(this);
self.updateLives = function (lives) {
self.removeChildren(); // Clear existing heart icons
var spacing = 10; // Spacing between hearts
for (var i = 0; i < lives; i++) {
var heartIcon = self.attachAsset('heart_full', {});
heartIcon.x = i * (heartIcon.width + spacing); // Position hearts horizontally with spacing
self.addChild(heartIcon);
}
for (var j = lives; j < self.maxLives; j++) {
var emptyHeartIcon = self.attachAsset('heart_empty', {});
emptyHeartIcon.x = j * (emptyHeartIcon.width + spacing);
self.addChild(emptyHeartIcon);
}
};
});
// Fairy class
var Fairy = Container.expand(function () {
var self = Container.call(this);
var fairyGraphics = self.attachAsset('fairy', {
anchorX: 0.5,
anchorY: 0.5
});
fairyGraphics.scale.set(1.2); // Slightly reduce the size of the fairy
self.lives = 3;
self.speed = 10;
self.moveLeft = function () {
self.x = Math.max(self.width / 2, self.x - self.speed);
};
self.moveRight = function () {
self.x = Math.min(2048 - self.width / 2, self.x + self.speed);
};
self.moveUp = function () {
self.y = Math.max(self.height / 2, self.y - self.speed);
};
self.moveDown = function () {
self.y = Math.min(2732 - self.height / 2, self.y + self.speed);
};
});
// Potion class
var Potion = Container.expand(function () {
var self = Container.call(this);
var potionGraphics = self.attachAsset('potion', {
anchorX: 0.5,
anchorY: 0.5
});
self.baseSpeed = 6;
self.speedMultiplier = 1;
self.move = function () {
self.y += self.baseSpeed * self.speedMultiplier;
if (self.y > 2732 + self.height / 2) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// New potion spawn logic
// Add background asset
var minPotions = 4;
var maxPotions = 8;
var spawnInterval = 120; // Spawn every 2 seconds (120 ticks at 60FPS)
var nextSpawnTick = spawnInterval;
LK.on('tick', function () {
// Other game logic...
// Handle potion spawning
if (LK.ticks % spawnInterval === 0) {
for (var j = 0; j < maxPotions; j++) {
var potion = new Potion();
potion.x = Math.random() * (2048 - potion.width) + potion.width / 2;
potion.y = -potion.height / 2;
potions.push(potion);
game.addChild(potion);
}
}
// Other game logic...
});
var background = game.attachAsset('background', {});
background.width = 2048;
background.height = 2732;
game.addChild(background);
// Initialize fairy
var fairy = game.addChild(new Fairy());
fairy.x = 1024; // Center horizontally
fairy.y = 2732 - 100; // Start near the bottom of the screen
// Initialize potions array
var potions = [];
// Initialize lives display
var livesDisplay = game.addChild(new LivesDisplay());
livesDisplay.updateLives(fairy.lives);
LK.gui.top.addChild(livesDisplay); // Attach livesDisplay to the top center of the screen.
// Handle touch movement and orient fairy horizontally based on movement direction
function handleTouchMove(obj) {
var touchPos = obj.event.getLocalPosition(game);
var previousX = fairy.x;
fairy.x = touchPos.x;
fairy.y = touchPos.y;
// Determine if fairy should face left or right based on movement direction
if (touchPos.x < previousX) {
fairy.scale.x = -1; // Flip fairy horizontally to face left
} else if (touchPos.x > previousX) {
fairy.scale.x = 1; // Default orientation to face right
}
}
// Add touch move listener to the game
game.on('move', handleTouchMove);
// Game tick event
LK.on('tick', function () {
// Move potions
for (var i = potions.length - 1; i >= 0; i--) {
potions[i].move();
if (fairy.intersects(potions[i]) && !fairy.isImmortal) {
// Decrease fairy's lives when touching a potion and end game if lives are 0
fairy.lives--;
// Display 'Holala!' if two lives are lost consecutively
if (fairy.previousLifeLossTick && LK.ticks - fairy.previousLifeLossTick <= 1) {
var holalaText = new Text2('Holala!', {
size: 200,
fill: "#ff0000"
});
holalaText.anchor.set(0.5, 0.5);
holalaText.x = 1024;
holalaText.y = 1366;
game.addChild(holalaText);
LK.setTimeout(function () {
holalaText.destroy();
}, 2000);
}
fairy.previousLifeLossTick = LK.ticks;
livesDisplay.updateLives(fairy.lives);
LK.effects.flashObject(fairy, 0xff0000, 500);
if (fairy.lives <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
} else {
fairy.isImmortal = true;
fairy.blinkInterval = LK.setInterval(function () {
fairy.visible = !fairy.visible;
}, 150);
LK.setTimeout(function () {
fairy.isImmortal = false;
LK.clearInterval(fairy.blinkInterval);
fairy.visible = true; // Ensure fairy is visible after immortality ends
}, 3000);
}
// Apply effect to the potion before destroying it
var effect = new PixelateEffect();
effect.applyTo(potions[i]);
potions.splice(i, 1);
}
}
// Change potion behavior after fairy crosses 5 lines
var linesCrossedThreshold = 5; // Number of lines the fairy must cross
var lineSpacing = 2732 / 5; // Spacing of lines based on screen height
if (fairy.y < 2732 - linesCrossedThreshold * lineSpacing) {
for (var p = potions.length - 1; p >= 0; p--) {
if (!(potions[p] instanceof TargetingPotion)) {
var targetingPotion = new TargetingPotion();
targetingPotion.x = potions[p].x;
targetingPotion.y = potions[p].y;
potions[p].destroy();
potions.splice(p, 1);
game.addChild(targetingPotion);
potions.push(targetingPotion);
}
}
}
});
nothing
fairy. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
heart. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
un monde féerique. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
enleve ça
le même coeur mais vide