/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // No background character class needed // Define a class for enemies var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.passed = false; self.update = function () { self.x -= enemySpeed; if (self.x < -50) { self.destroy(); } }; }); // Define a class for enemy miniatures var EnemyMiniature = Container.expand(function () { var self = Container.call(this); var miniatureGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.3, scaleY: 0.3 }); return self; }); //<Assets used in the game will automatically appear here> // Define a class for the player character var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5, tint: 0xFFFFFF // Default tint, will be changed on transformation }); var playerJumpingGraphics = LK.getAsset('player_jumping', { anchorX: 0.5, anchorY: 0.5, tint: 0xFFFFFF // Default tint, will be changed on transformation }); var playerTransformedGraphics = LK.getAsset('player_transformed', { anchorX: 0.5, anchorY: 0.5, tint: 0xFF9900 // Orange tint for transformed state }); var playerDancingGraphics = LK.getAsset('player_dancing', { anchorX: 0.5, anchorY: 0.5, tint: 0xFFFFFF // Default tint for dancing state }); playerJumpingGraphics.visible = false; playerTransformedGraphics.visible = false; playerDancingGraphics.visible = false; self.addChild(playerJumpingGraphics); self.addChild(playerTransformedGraphics); self.addChild(playerDancingGraphics); self.isTransformed = false; self.isDancing = false; self.speed = 5; self.jumpHeight = 40; self.isJumping = false; self.scale.set(1, 1); // Initialize scale for transformation self.velocityY = 0; self.update = function () { if (self.isDancing) { // When in winning state, show dancing character playerGraphics.visible = false; playerJumpingGraphics.visible = false; playerTransformedGraphics.visible = false; playerDancingGraphics.visible = true; // Keep the player stationary self.y = 2732 / 2; return; // Skip regular movement logic when in winning state } // Track if this is the first frame of jumping if (self.isJumping && self.velocityY === -self.jumpHeight) { // Play jump sound exactly when the jump animation begins LK.getSound('Jump').play(); } if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; // Decreased gravity effect by 30% // Show jumping character playerGraphics.visible = false; playerTransformedGraphics.visible = false; playerJumpingGraphics.visible = true; playerDancingGraphics.visible = false; if (self.y >= 2732 / 2) { // Ground level self.y = 2732 / 2; self.isJumping = false; self.velocityY = 0; // Switch back to appropriate character based on transformation state if (self.isTransformed) { playerTransformedGraphics.visible = true; playerGraphics.visible = false; playerJumpingGraphics.visible = false; playerDancingGraphics.visible = false; } else { playerGraphics.visible = true; playerTransformedGraphics.visible = false; playerJumpingGraphics.visible = false; playerDancingGraphics.visible = false; } } } else { // Show appropriate character when not jumping based on transformation state if (self.isTransformed) { playerTransformedGraphics.visible = true; playerGraphics.visible = false; playerJumpingGraphics.visible = false; playerDancingGraphics.visible = false; } else { playerGraphics.visible = true; playerTransformedGraphics.visible = false; playerJumpingGraphics.visible = false; playerDancingGraphics.visible = false; } } }; self.jump = function () { if (!self.isJumping && !self.isDancing && !(self.scale.x >= 2)) { self.isJumping = true; self.velocityY = -self.jumpHeight; // We'll play the sound in the update method when jumping begins } }; self.transform = function (transformed) { self.isTransformed = transformed; if (self.isDancing) { return; } // Don't change appearance if dancing if (transformed) { playerGraphics.visible = false; playerJumpingGraphics.visible = false; playerTransformedGraphics.visible = true; playerDancingGraphics.visible = false; // Keep the original tint when transforming playerTransformedGraphics.tint = playerGraphics.tint; } else { playerGraphics.visible = !self.isJumping; playerJumpingGraphics.visible = self.isJumping; playerTransformedGraphics.visible = false; playerDancingGraphics.visible = false; } }; self.dance = function () { self.isDancing = true; playerGraphics.visible = false; playerJumpingGraphics.visible = false; playerTransformedGraphics.visible = false; playerDancingGraphics.visible = true; // Transform player appearance self.isTransformed = true; // No rotation animation self.rotation = 0; // Apply permanent transformation with larger size var originalY = self.y; tween(self.scale, { x: 2, y: 2 }, { duration: 500, easing: tween.easeOutElastic, onUpdate: function onUpdate() { // Keep the player's feet at the same level by adjusting Y position var heightIncrease = self.height - self.height / self.scale.y; self.y = originalY - heightIncrease / 2; } }); }; self.stopDancing = function () { self.isDancing = false; self.rotation = 0; // Return to normal state if (self.isTransformed) { playerTransformedGraphics.visible = true; playerGraphics.visible = false; playerJumpingGraphics.visible = false; playerDancingGraphics.visible = false; } else { playerGraphics.visible = true; playerTransformedGraphics.visible = false; playerJumpingGraphics.visible = false; playerDancingGraphics.visible = false; } // Reset scale to normal tween(self.scale, { x: 1, y: 1 }, { duration: 300, easing: tween.easeInOutQuad }); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0 })); background.x = 0; background.y = 0; // Play background music LK.playMusic('deneme1'); // Initialize player var player = game.addChild(new Player()); player.x = 200; // Position player on the left side of the screen player.y = 2732 / 2; // Initialize enemies var enemies = []; var enemySpawnInterval = 100; var enemySpawnCounter = 0; var enemySpeed = 5; var speedIncreaseTimer = LK.setInterval(function () { enemySpeed += 1; console.log("Enemy speed increased to: " + enemySpeed); }, 5000); // 5 seconds // Create a new Text2 object to display the score var scoreText = new Text2('0', { size: 100, fill: 0xFFFFFF }); // Create text to display enemy count var enemyCountText = new Text2('Enemies Passed: 0', { size: 60, fill: 0xFFFFFF }); // Add the score text to the game GUI at the top center of the screen LK.gui.top.addChild(scoreText); scoreText.x = 2048 / 2; scoreText.y = 0; // Add enemy count text below score LK.gui.top.addChild(enemyCountText); enemyCountText.x = 2048 / 2; enemyCountText.y = 110; // Initialize enemy passed counter var enemiesPassed = 0; // Variable to track if transformation is in progress var isTransforming = false; // Countdown timer for transformation duration var transformCountdown = 0; // No need for background characters array // Countdown text display var countdownText = new Text2('', { size: 200, fill: 0xFF9900, // Orange color to match transformation stroke: 0x000000, // Black outline strokeThickness: 10, // Make the outline visible bold: true // Make text bold }); countdownText.anchor.set(0.5, 0.5); countdownText.x = 2048 / 2; // Center horizontally countdownText.y = 2732 / 2 - 400; // Position in middle of screen, above player LK.gui.center.addChild(countdownText); // Use center GUI container instead of top countdownText.visible = false; // Hide until needed // Create a container for enemy miniatures var miniatureContainer = new Container(); LK.gui.topRight.addChild(miniatureContainer); miniatureContainer.x = -50; // Offset from right edge miniatureContainer.y = 50; // Array to track miniatures var enemyMiniatures = []; // Handle game updates game.update = function () { player.update(); // Spawn enemies (only if player hasn't won yet) if (enemiesPassed < 15) { enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval) { var enemy = new Enemy(); enemy.x = 2048; enemy.y = 2732 / 2; enemies.push(enemy); game.addChild(enemy); // Randomize the spawn interval for the next enemy enemySpawnInterval = Math.floor(Math.random() * 150) + 50; enemySpawnCounter = 0; } } else { // Remove any remaining enemies when 15 enemies are passed for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].destroy(); enemies.splice(i, 1); } } // Update transformation countdown if active if (transformCountdown > 0) { transformCountdown--; // Update countdown display - show seconds remaining var secondsRemaining = Math.ceil(transformCountdown / 60); // 60 frames per second countdownText.setText(secondsRemaining.toString()); // Make countdown text more visible as it gets lower if (secondsRemaining <= 2) { countdownText.fill = 0xFF0000; // Red for urgency } else { countdownText.fill = 0xFF9900; // Orange for normal countdown } // Hide countdown when it reaches zero if (transformCountdown <= 0) { countdownText.setText(''); } } // No background characters to update // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); // Track last intersection state for clean collision detection if (enemies[j].lastIntersecting === undefined) { enemies[j].lastIntersecting = false; } var currentlyIntersecting = player.intersects(enemies[j]); // Check if player collides with enemy when NOT transformed (player loses) if (!player.isTransformed && currentlyIntersecting && !enemies[j].passed) { // Flash screen red to indicate player has lost LK.effects.flashScreen(0xFF0000, 1000); // Show game over screen LK.showGameOver(); continue; } // Handle collision when player is transformed if (player.isTransformed && currentlyIntersecting && !enemies[j].passed) { // "Eat" the enemy // Create eating animation effect LK.effects.flashObject(enemies[j], 0xFF0000, 300); // Add bonus score for eating enemy LK.setScore(LK.getScore() + 5); scoreText.setText(LK.getScore()); // Create "eaten" text var eatenText = new Text2('+5', { size: 40, fill: 0xFF0000 }); eatenText.anchor.set(0.5, 0.5); eatenText.x = enemies[j].x; eatenText.y = enemies[j].y - 50; game.addChild(eatenText); // Remove eaten text after animation tween(eatenText, { y: eatenText.y - 100, alpha: 0 }, { duration: 800, onFinish: function onFinish() { eatenText.destroy(); } }); // Create explosion effect particles where the enemy was eaten for (var c = 0; c < 10; c++) { var particle = new Container(); var particleGraphic = particle.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.2, scaleY: 0.2 }); // Position particles around where enemy was eaten var angle = Math.random() * Math.PI * 2; var distance = 10 + Math.random() * 30; particle.x = enemies[j].x; particle.y = enemies[j].y; // Random rotation particle.rotation = Math.random() * Math.PI * 2; // Add to game game.addChild(particle); // Animate particles exploding outward and fading tween(particle, { x: enemies[j].x + Math.cos(angle) * distance * 8, y: enemies[j].y + Math.sin(angle) * distance * 8, alpha: 0, rotation: particle.rotation + Math.random() * 3 }, { duration: 500 + Math.random() * 300, easing: tween.easeOutQuad, onFinish: function () { this.destroy(); }.bind(particle) }); } // Remove the enemy enemies[j].destroy(); enemies.splice(j, 1); continue; } // If enemy passes player if (player.x > enemies[j].x && !enemies[j].passed) { enemies[j].passed = true; // Increment both counters LK.setScore(LK.getScore() + 1); enemiesPassed++; // Update both text displays scoreText.setText(LK.getScore()); enemyCountText.setText('Enemies Passed: ' + enemiesPassed); // Flash the enemy count text to highlight change LK.effects.flashObject(enemyCountText, 0x00FF00, 300); // Add a miniature of the passed enemy to the top right corner var miniature = new EnemyMiniature(); enemyMiniatures.push(miniature); miniatureContainer.addChild(miniature); // Arrange miniatures in rows of 5 var rowLength = 5; var miniSize = 40; // Space for each miniature var row = Math.floor((enemyMiniatures.length - 1) / rowLength); var col = (enemyMiniatures.length - 1) % rowLength; miniature.x = -(col * miniSize); miniature.y = row * miniSize; // Check if player has passed 15 enemies to complete the game if (enemiesPassed >= 15) { // Make player start dancing and transform player.dance(); // Create congratulation text before showing you win screen var congratsText = new Text2('Tebrikler!', { size: 120, fill: 0xFFD700 // Gold color }); congratsText.anchor.set(0.5, 0.5); congratsText.x = 2048 / 2; congratsText.y = 2732 / 2 - 200; // Move text up so it doesn't overlap with dancing player game.addChild(congratsText); // Add party effect - colored circles around the dancing player for (var i = 0; i < 10; i++) { var confetti = new Container(); var confettiGraphic = confetti.attachAsset('centerCircle', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.5, scaleY: 0.5 }); // Random colors for confetti var colors = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF]; confettiGraphic.tint = colors[Math.floor(Math.random() * colors.length)]; // Position around the player var angle = Math.random() * Math.PI * 2; var distance = 200 + Math.random() * 100; confetti.x = player.x + Math.cos(angle) * distance; confetti.y = player.y + Math.sin(angle) * distance; game.addChild(confetti); // Animate confetti tween(confetti, { x: confetti.x + Math.random() * 200 - 100, y: confetti.y - 200 - Math.random() * 200, alpha: 0 }, { duration: 1500, onFinish: function () { this.destroy(); }.bind(confetti) }); } // Flash screen with celebratory color LK.effects.flashScreen(0x00FF00, 1000); // No instruction text needed since player can't move // Show win screen after a longer delay to enjoy transformation animation more LK.setTimeout(function () { player.stopDancing(); LK.showYouWin(); }, 6000); // Extended to 6 seconds to show transformation animation longer } // Achievement notification for passing 5 enemies if (enemiesPassed % 5 === 0 && enemiesPassed > 0 && !isTransforming) { // Player transformation isTransforming = true; // Change to transformed character player.transform(true); // Set transformation countdown (5 seconds at 60fps) transformCountdown = 300; // 5 seconds duration countdownText.setText('5'); // Initial value // Position countdown text in the center of the screen countdownText.x = 2048 / 2; countdownText.y = 2732 / 2 - 400; // Position above the player countdownText.visible = true; // Save the player's original position var originalY = player.y; // Double the player size with animation tween(player.scale, { x: 2, y: 2 }, { duration: 500, easing: tween.easeOutElastic, onUpdate: function onUpdate() { // Keep the player's feet at the same level by adjusting Y position // Since the anchor is at 0.5, we need to adjust by half the height difference var heightIncrease = player.height - player.height / player.scale.y; player.y = originalY - heightIncrease / 2; } }); // Flash the player to highlight the achievement LK.effects.flashObject(player, 0xFF9900, 500); // Add text notification about transformation var transformText = new Text2('POWER UP!', { size: 80, fill: 0xFF9900 }); transformText.anchor.set(0.5, 0.5); transformText.x = player.x + 200; transformText.y = player.y - 150; game.addChild(transformText); LK.setTimeout(function () { transformText.destroy(); }, 2000); // Reset player size and appearance after 5 seconds LK.setTimeout(function () { var originalY = 2732 / 2; // Original player Y position (center of screen) tween(player.scale, { x: 1, y: 1 }, { duration: 500, easing: tween.easeInOutQuad, onUpdate: function onUpdate() { // Gradually restore original position as scale decreases var heightIncrease = player.height - player.height / player.scale.y; player.y = originalY - heightIncrease / 2; }, onFinish: function onFinish() { player.y = originalY; // Ensure player is exactly at original position player.transform(false); isTransforming = false; transformCountdown = 0; // Reset countdown countdownText.setText(''); // Clear countdown display countdownText.visible = false; // Hide countdown text completely } }); }, 5000); } } } }; // Handle player jump or control movement when dancing game.down = function (x, y, obj) { if (player.isDancing) { // No movement controls after winning } else { player.jump(); } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// No background character class needed
// Define a class for enemies
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.passed = false;
self.update = function () {
self.x -= enemySpeed;
if (self.x < -50) {
self.destroy();
}
};
});
// Define a class for enemy miniatures
var EnemyMiniature = Container.expand(function () {
var self = Container.call(this);
var miniatureGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.3,
scaleY: 0.3
});
return self;
});
//<Assets used in the game will automatically appear here>
// Define a class for the player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xFFFFFF // Default tint, will be changed on transformation
});
var playerJumpingGraphics = LK.getAsset('player_jumping', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xFFFFFF // Default tint, will be changed on transformation
});
var playerTransformedGraphics = LK.getAsset('player_transformed', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xFF9900 // Orange tint for transformed state
});
var playerDancingGraphics = LK.getAsset('player_dancing', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xFFFFFF // Default tint for dancing state
});
playerJumpingGraphics.visible = false;
playerTransformedGraphics.visible = false;
playerDancingGraphics.visible = false;
self.addChild(playerJumpingGraphics);
self.addChild(playerTransformedGraphics);
self.addChild(playerDancingGraphics);
self.isTransformed = false;
self.isDancing = false;
self.speed = 5;
self.jumpHeight = 40;
self.isJumping = false;
self.scale.set(1, 1); // Initialize scale for transformation
self.velocityY = 0;
self.update = function () {
if (self.isDancing) {
// When in winning state, show dancing character
playerGraphics.visible = false;
playerJumpingGraphics.visible = false;
playerTransformedGraphics.visible = false;
playerDancingGraphics.visible = true;
// Keep the player stationary
self.y = 2732 / 2;
return; // Skip regular movement logic when in winning state
}
// Track if this is the first frame of jumping
if (self.isJumping && self.velocityY === -self.jumpHeight) {
// Play jump sound exactly when the jump animation begins
LK.getSound('Jump').play();
}
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.7; // Decreased gravity effect by 30%
// Show jumping character
playerGraphics.visible = false;
playerTransformedGraphics.visible = false;
playerJumpingGraphics.visible = true;
playerDancingGraphics.visible = false;
if (self.y >= 2732 / 2) {
// Ground level
self.y = 2732 / 2;
self.isJumping = false;
self.velocityY = 0;
// Switch back to appropriate character based on transformation state
if (self.isTransformed) {
playerTransformedGraphics.visible = true;
playerGraphics.visible = false;
playerJumpingGraphics.visible = false;
playerDancingGraphics.visible = false;
} else {
playerGraphics.visible = true;
playerTransformedGraphics.visible = false;
playerJumpingGraphics.visible = false;
playerDancingGraphics.visible = false;
}
}
} else {
// Show appropriate character when not jumping based on transformation state
if (self.isTransformed) {
playerTransformedGraphics.visible = true;
playerGraphics.visible = false;
playerJumpingGraphics.visible = false;
playerDancingGraphics.visible = false;
} else {
playerGraphics.visible = true;
playerTransformedGraphics.visible = false;
playerJumpingGraphics.visible = false;
playerDancingGraphics.visible = false;
}
}
};
self.jump = function () {
if (!self.isJumping && !self.isDancing && !(self.scale.x >= 2)) {
self.isJumping = true;
self.velocityY = -self.jumpHeight;
// We'll play the sound in the update method when jumping begins
}
};
self.transform = function (transformed) {
self.isTransformed = transformed;
if (self.isDancing) {
return;
} // Don't change appearance if dancing
if (transformed) {
playerGraphics.visible = false;
playerJumpingGraphics.visible = false;
playerTransformedGraphics.visible = true;
playerDancingGraphics.visible = false;
// Keep the original tint when transforming
playerTransformedGraphics.tint = playerGraphics.tint;
} else {
playerGraphics.visible = !self.isJumping;
playerJumpingGraphics.visible = self.isJumping;
playerTransformedGraphics.visible = false;
playerDancingGraphics.visible = false;
}
};
self.dance = function () {
self.isDancing = true;
playerGraphics.visible = false;
playerJumpingGraphics.visible = false;
playerTransformedGraphics.visible = false;
playerDancingGraphics.visible = true;
// Transform player appearance
self.isTransformed = true;
// No rotation animation
self.rotation = 0;
// Apply permanent transformation with larger size
var originalY = self.y;
tween(self.scale, {
x: 2,
y: 2
}, {
duration: 500,
easing: tween.easeOutElastic,
onUpdate: function onUpdate() {
// Keep the player's feet at the same level by adjusting Y position
var heightIncrease = self.height - self.height / self.scale.y;
self.y = originalY - heightIncrease / 2;
}
});
};
self.stopDancing = function () {
self.isDancing = false;
self.rotation = 0;
// Return to normal state
if (self.isTransformed) {
playerTransformedGraphics.visible = true;
playerGraphics.visible = false;
playerJumpingGraphics.visible = false;
playerDancingGraphics.visible = false;
} else {
playerGraphics.visible = true;
playerTransformedGraphics.visible = false;
playerJumpingGraphics.visible = false;
playerDancingGraphics.visible = false;
}
// Reset scale to normal
tween(self.scale, {
x: 1,
y: 1
}, {
duration: 300,
easing: tween.easeInOutQuad
});
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
}));
background.x = 0;
background.y = 0;
// Play background music
LK.playMusic('deneme1');
// Initialize player
var player = game.addChild(new Player());
player.x = 200; // Position player on the left side of the screen
player.y = 2732 / 2;
// Initialize enemies
var enemies = [];
var enemySpawnInterval = 100;
var enemySpawnCounter = 0;
var enemySpeed = 5;
var speedIncreaseTimer = LK.setInterval(function () {
enemySpeed += 1;
console.log("Enemy speed increased to: " + enemySpeed);
}, 5000); // 5 seconds
// Create a new Text2 object to display the score
var scoreText = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
// Create text to display enemy count
var enemyCountText = new Text2('Enemies Passed: 0', {
size: 60,
fill: 0xFFFFFF
});
// Add the score text to the game GUI at the top center of the screen
LK.gui.top.addChild(scoreText);
scoreText.x = 2048 / 2;
scoreText.y = 0;
// Add enemy count text below score
LK.gui.top.addChild(enemyCountText);
enemyCountText.x = 2048 / 2;
enemyCountText.y = 110;
// Initialize enemy passed counter
var enemiesPassed = 0;
// Variable to track if transformation is in progress
var isTransforming = false;
// Countdown timer for transformation duration
var transformCountdown = 0;
// No need for background characters array
// Countdown text display
var countdownText = new Text2('', {
size: 200,
fill: 0xFF9900,
// Orange color to match transformation
stroke: 0x000000,
// Black outline
strokeThickness: 10,
// Make the outline visible
bold: true // Make text bold
});
countdownText.anchor.set(0.5, 0.5);
countdownText.x = 2048 / 2; // Center horizontally
countdownText.y = 2732 / 2 - 400; // Position in middle of screen, above player
LK.gui.center.addChild(countdownText); // Use center GUI container instead of top
countdownText.visible = false; // Hide until needed
// Create a container for enemy miniatures
var miniatureContainer = new Container();
LK.gui.topRight.addChild(miniatureContainer);
miniatureContainer.x = -50; // Offset from right edge
miniatureContainer.y = 50;
// Array to track miniatures
var enemyMiniatures = [];
// Handle game updates
game.update = function () {
player.update();
// Spawn enemies (only if player hasn't won yet)
if (enemiesPassed < 15) {
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
var enemy = new Enemy();
enemy.x = 2048;
enemy.y = 2732 / 2;
enemies.push(enemy);
game.addChild(enemy);
// Randomize the spawn interval for the next enemy
enemySpawnInterval = Math.floor(Math.random() * 150) + 50;
enemySpawnCounter = 0;
}
} else {
// Remove any remaining enemies when 15 enemies are passed
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].destroy();
enemies.splice(i, 1);
}
}
// Update transformation countdown if active
if (transformCountdown > 0) {
transformCountdown--;
// Update countdown display - show seconds remaining
var secondsRemaining = Math.ceil(transformCountdown / 60); // 60 frames per second
countdownText.setText(secondsRemaining.toString());
// Make countdown text more visible as it gets lower
if (secondsRemaining <= 2) {
countdownText.fill = 0xFF0000; // Red for urgency
} else {
countdownText.fill = 0xFF9900; // Orange for normal countdown
}
// Hide countdown when it reaches zero
if (transformCountdown <= 0) {
countdownText.setText('');
}
}
// No background characters to update
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
// Track last intersection state for clean collision detection
if (enemies[j].lastIntersecting === undefined) {
enemies[j].lastIntersecting = false;
}
var currentlyIntersecting = player.intersects(enemies[j]);
// Check if player collides with enemy when NOT transformed (player loses)
if (!player.isTransformed && currentlyIntersecting && !enemies[j].passed) {
// Flash screen red to indicate player has lost
LK.effects.flashScreen(0xFF0000, 1000);
// Show game over screen
LK.showGameOver();
continue;
}
// Handle collision when player is transformed
if (player.isTransformed && currentlyIntersecting && !enemies[j].passed) {
// "Eat" the enemy
// Create eating animation effect
LK.effects.flashObject(enemies[j], 0xFF0000, 300);
// Add bonus score for eating enemy
LK.setScore(LK.getScore() + 5);
scoreText.setText(LK.getScore());
// Create "eaten" text
var eatenText = new Text2('+5', {
size: 40,
fill: 0xFF0000
});
eatenText.anchor.set(0.5, 0.5);
eatenText.x = enemies[j].x;
eatenText.y = enemies[j].y - 50;
game.addChild(eatenText);
// Remove eaten text after animation
tween(eatenText, {
y: eatenText.y - 100,
alpha: 0
}, {
duration: 800,
onFinish: function onFinish() {
eatenText.destroy();
}
});
// Create explosion effect particles where the enemy was eaten
for (var c = 0; c < 10; c++) {
var particle = new Container();
var particleGraphic = particle.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.2
});
// Position particles around where enemy was eaten
var angle = Math.random() * Math.PI * 2;
var distance = 10 + Math.random() * 30;
particle.x = enemies[j].x;
particle.y = enemies[j].y;
// Random rotation
particle.rotation = Math.random() * Math.PI * 2;
// Add to game
game.addChild(particle);
// Animate particles exploding outward and fading
tween(particle, {
x: enemies[j].x + Math.cos(angle) * distance * 8,
y: enemies[j].y + Math.sin(angle) * distance * 8,
alpha: 0,
rotation: particle.rotation + Math.random() * 3
}, {
duration: 500 + Math.random() * 300,
easing: tween.easeOutQuad,
onFinish: function () {
this.destroy();
}.bind(particle)
});
}
// Remove the enemy
enemies[j].destroy();
enemies.splice(j, 1);
continue;
}
// If enemy passes player
if (player.x > enemies[j].x && !enemies[j].passed) {
enemies[j].passed = true;
// Increment both counters
LK.setScore(LK.getScore() + 1);
enemiesPassed++;
// Update both text displays
scoreText.setText(LK.getScore());
enemyCountText.setText('Enemies Passed: ' + enemiesPassed);
// Flash the enemy count text to highlight change
LK.effects.flashObject(enemyCountText, 0x00FF00, 300);
// Add a miniature of the passed enemy to the top right corner
var miniature = new EnemyMiniature();
enemyMiniatures.push(miniature);
miniatureContainer.addChild(miniature);
// Arrange miniatures in rows of 5
var rowLength = 5;
var miniSize = 40; // Space for each miniature
var row = Math.floor((enemyMiniatures.length - 1) / rowLength);
var col = (enemyMiniatures.length - 1) % rowLength;
miniature.x = -(col * miniSize);
miniature.y = row * miniSize;
// Check if player has passed 15 enemies to complete the game
if (enemiesPassed >= 15) {
// Make player start dancing and transform
player.dance();
// Create congratulation text before showing you win screen
var congratsText = new Text2('Tebrikler!', {
size: 120,
fill: 0xFFD700 // Gold color
});
congratsText.anchor.set(0.5, 0.5);
congratsText.x = 2048 / 2;
congratsText.y = 2732 / 2 - 200; // Move text up so it doesn't overlap with dancing player
game.addChild(congratsText);
// Add party effect - colored circles around the dancing player
for (var i = 0; i < 10; i++) {
var confetti = new Container();
var confettiGraphic = confetti.attachAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.5,
scaleY: 0.5
});
// Random colors for confetti
var colors = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF];
confettiGraphic.tint = colors[Math.floor(Math.random() * colors.length)];
// Position around the player
var angle = Math.random() * Math.PI * 2;
var distance = 200 + Math.random() * 100;
confetti.x = player.x + Math.cos(angle) * distance;
confetti.y = player.y + Math.sin(angle) * distance;
game.addChild(confetti);
// Animate confetti
tween(confetti, {
x: confetti.x + Math.random() * 200 - 100,
y: confetti.y - 200 - Math.random() * 200,
alpha: 0
}, {
duration: 1500,
onFinish: function () {
this.destroy();
}.bind(confetti)
});
}
// Flash screen with celebratory color
LK.effects.flashScreen(0x00FF00, 1000);
// No instruction text needed since player can't move
// Show win screen after a longer delay to enjoy transformation animation more
LK.setTimeout(function () {
player.stopDancing();
LK.showYouWin();
}, 6000); // Extended to 6 seconds to show transformation animation longer
}
// Achievement notification for passing 5 enemies
if (enemiesPassed % 5 === 0 && enemiesPassed > 0 && !isTransforming) {
// Player transformation
isTransforming = true;
// Change to transformed character
player.transform(true);
// Set transformation countdown (5 seconds at 60fps)
transformCountdown = 300; // 5 seconds duration
countdownText.setText('5'); // Initial value
// Position countdown text in the center of the screen
countdownText.x = 2048 / 2;
countdownText.y = 2732 / 2 - 400; // Position above the player
countdownText.visible = true;
// Save the player's original position
var originalY = player.y;
// Double the player size with animation
tween(player.scale, {
x: 2,
y: 2
}, {
duration: 500,
easing: tween.easeOutElastic,
onUpdate: function onUpdate() {
// Keep the player's feet at the same level by adjusting Y position
// Since the anchor is at 0.5, we need to adjust by half the height difference
var heightIncrease = player.height - player.height / player.scale.y;
player.y = originalY - heightIncrease / 2;
}
});
// Flash the player to highlight the achievement
LK.effects.flashObject(player, 0xFF9900, 500);
// Add text notification about transformation
var transformText = new Text2('POWER UP!', {
size: 80,
fill: 0xFF9900
});
transformText.anchor.set(0.5, 0.5);
transformText.x = player.x + 200;
transformText.y = player.y - 150;
game.addChild(transformText);
LK.setTimeout(function () {
transformText.destroy();
}, 2000);
// Reset player size and appearance after 5 seconds
LK.setTimeout(function () {
var originalY = 2732 / 2; // Original player Y position (center of screen)
tween(player.scale, {
x: 1,
y: 1
}, {
duration: 500,
easing: tween.easeInOutQuad,
onUpdate: function onUpdate() {
// Gradually restore original position as scale decreases
var heightIncrease = player.height - player.height / player.scale.y;
player.y = originalY - heightIncrease / 2;
},
onFinish: function onFinish() {
player.y = originalY; // Ensure player is exactly at original position
player.transform(false);
isTransforming = false;
transformCountdown = 0; // Reset countdown
countdownText.setText(''); // Clear countdown display
countdownText.visible = false; // Hide countdown text completely
}
});
}, 5000);
}
}
}
};
// Handle player jump or control movement when dancing
game.down = function (x, y, obj) {
if (player.isDancing) {
// No movement controls after winning
} else {
player.jump();
}
};