User prompt
Add the memes that's supposed to be in level one
User prompt
Add the memes to dodge ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add meme
Code edit (1 edits merged)
Please save this source code
User prompt
Meme Survival Challenge
Initial prompt
Meme games meme games is the squid games
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 0;
self.active = true;
self.update = function () {
if (self.active) {
self.x += self.speed;
// If obstacle goes off-screen, reset
if (self.x < -100 || self.x > 2148) {
self.active = false;
}
}
};
self.reset = function (x, y, speed) {
self.x = x;
self.y = y;
self.speed = speed;
self.active = true;
};
return self;
});
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 0;
self.active = true;
self.update = function () {
if (self.active) {
self.x += self.speed;
// If platform goes off-screen, reset
if (self.x < -250 || self.x > 2298) {
self.active = false;
}
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('playerCircle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocity = {
x: 0,
y: 0
};
self.isJumping = false;
self.isDraggable = false;
self.jump = function () {
if (!self.isJumping) {
self.velocity.y = -20;
self.isJumping = true;
LK.getSound('jump').play();
}
};
self.reset = function (x, y) {
self.x = x;
self.y = y;
self.velocity = {
x: 0,
y: 0
};
self.isJumping = false;
};
self.down = function (x, y, obj) {
if (self.isDraggable) {
draggedObject = self;
}
};
return self;
});
var ProgressBar = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('progressBar', {
anchorX: 0,
anchorY: 0.5
});
var fill = self.attachAsset('progressFill', {
anchorX: 0,
anchorY: 0.5
});
self.setProgress = function (percent) {
fill.width = Math.min(1800 * (percent / 100), 1800);
};
return self;
});
var Target = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5
});
self.active = true;
self.pulse = function () {
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.easeIn
});
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x34495e
});
/****
* Game Code
****/
var GRAVITY = 0.8;
var GROUND_Y = 2400;
var gameState = "title"; // "title", "playing", "gameOver"
var currentLevel = 1;
var maxLevels = 5;
var levelDuration = 20000; // 20 seconds per level
var levelStartTime = 0;
var draggedObject = null;
var player;
var obstacles = [];
var platforms = [];
var targets = [];
var progressBar;
var scoreText;
var levelText;
var timerText;
var titleText;
var instructionText;
var gameOverText;
var countdownText;
var countdownValue = 3;
var levelDescriptions = ["Dodge the memes!", "Cross the platforms!", "Hit the targets!", "Stay in bounds!", "Survive them all!"];
// Initialize game UI
function initializeUI() {
// Progress bar
progressBar = new ProgressBar();
progressBar.x = 124;
progressBar.y = 100;
LK.gui.addChild(progressBar);
// Score
scoreText = new Text2("Score: 0", {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreText);
// Level
levelText = new Text2("Level: 1", {
size: 60,
fill: 0xFFFFFF
});
levelText.anchor.set(0, 0);
levelText.x = 124;
LK.gui.topLeft.addChild(levelText);
levelText.y = 150;
// Timer
timerText = new Text2("20", {
size: 60,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0);
LK.gui.top.addChild(timerText);
// Title
titleText = new Text2("MEME SURVIVAL\nCHALLENGE", {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.visible = true;
LK.gui.center.addChild(titleText);
// Instruction
instructionText = new Text2("Tap to Start", {
size: 60,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0.5);
instructionText.y = 200;
instructionText.visible = true;
LK.gui.center.addChild(instructionText);
// Countdown
countdownText = new Text2("3", {
size: 200,
fill: 0xFFFFFF
});
countdownText.anchor.set(0.5, 0.5);
countdownText.visible = false;
LK.gui.center.addChild(countdownText);
// Level description
gameOverText = new Text2("", {
size: 60,
fill: 0xFFFFFF
});
gameOverText.anchor.set(0.5, 0.5);
gameOverText.y = 300;
gameOverText.visible = false;
LK.gui.center.addChild(gameOverText);
}
// Initialize player
function initializePlayer() {
player = new Player();
player.reset(1024, 1366);
game.addChild(player);
}
// Initialize obstacles based on level
function initializeLevel(level) {
// Clear any existing objects
clearLevel();
// Update UI
levelText.setText("Level: " + level);
gameOverText.setText(levelDescriptions[level - 1]);
gameOverText.visible = true;
// Set timer
levelStartTime = Date.now();
// Configure level
switch (level) {
case 1:
// Dodge memes level
setupDodgeLevel();
break;
case 2:
// Platform level
setupPlatformLevel();
break;
case 3:
// Target level
setupTargetLevel();
break;
case 4:
// Boundary level
setupBoundaryLevel();
break;
case 5:
// Final level - combination
setupFinalLevel();
break;
}
}
function setupDodgeLevel() {
player.isDraggable = true;
player.reset(1024, 1366);
// Create obstacles
for (var i = 0; i < 10; i++) {
var obstacle = new Obstacle();
obstacle.reset(2300, 400 + Math.random() * 1700, -5 - Math.random() * 5);
obstacles.push(obstacle);
game.addChild(obstacle);
}
}
function setupPlatformLevel() {
player.isDraggable = false;
player.reset(200, 1000);
// Create platforms
for (var i = 0; i < 8; i++) {
var platform = new Platform();
platform.x = 300 + i * 250;
platform.y = 1300 + Math.random() * 800;
platform.speed = 0;
platform.active = true;
platforms.push(platform);
game.addChild(platform);
}
// Add winning platform
var winPlatform = new Platform();
winPlatform.x = 2000;
winPlatform.y = 1500;
winPlatform.speed = 0;
winPlatform.active = true;
platforms.push(winPlatform);
game.addChild(winPlatform);
}
function setupTargetLevel() {
player.isDraggable = true;
player.reset(1024, 1366);
// Create targets
for (var i = 0; i < 5; i++) {
var target = new Target();
target.x = 300 + Math.random() * 1500;
target.y = 400 + Math.random() * 1700;
target.pulse();
targets.push(target);
game.addChild(target);
}
}
function setupBoundaryLevel() {
player.isDraggable = true;
player.reset(1024, 1366);
// Create moving boundaries
var leftBoundary = LK.getAsset('boundary', {
anchorX: 0.5,
anchorY: 0.5
});
leftBoundary.x = 500;
leftBoundary.y = 1366;
game.addChild(leftBoundary);
var rightBoundary = LK.getAsset('boundary', {
anchorX: 0.5,
anchorY: 0.5
});
rightBoundary.x = 1548;
rightBoundary.y = 1366;
game.addChild(rightBoundary);
// Add movement to boundaries
LK.setInterval(function () {
tween(leftBoundary, {
x: 300 + Math.random() * 400
}, {
duration: 1500,
easing: tween.easeInOut
});
tween(rightBoundary, {
x: 1348 + Math.random() * 400
}, {
duration: 1500,
easing: tween.easeInOut
});
}, 2000);
}
function setupFinalLevel() {
player.isDraggable = true;
player.reset(1024, 1366);
// Mix of obstacles, platforms and targets
// Create obstacles
for (var i = 0; i < 5; i++) {
var obstacle = new Obstacle();
obstacle.reset(2300, 400 + Math.random() * 1700, -5 - Math.random() * 5);
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Create platforms
for (var i = 0; i < 3; i++) {
var platform = new Platform();
platform.x = 300 + i * 600;
platform.y = 1300 + Math.random() * 800;
platform.speed = -2;
platform.active = true;
platforms.push(platform);
game.addChild(platform);
}
// Create targets
for (var i = 0; i < 3; i++) {
var target = new Target();
target.x = 300 + Math.random() * 1500;
target.y = 400 + Math.random() * 1700;
target.pulse();
targets.push(target);
game.addChild(target);
}
}
function clearLevel() {
// Remove all obstacles
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
// Remove all platforms
for (var i = 0; i < platforms.length; i++) {
platforms[i].destroy();
}
platforms = [];
// Remove all targets
for (var i = 0; i < targets.length; i++) {
targets[i].destroy();
}
targets = [];
}
function startGame() {
gameState = "countdown";
titleText.visible = false;
instructionText.visible = false;
countdownText.visible = true;
countdownValue = 3;
countdownText.setText(countdownValue.toString());
LK.getSound('countdown').play();
// Start countdown
var countdownTimer = LK.setInterval(function () {
countdownValue--;
if (countdownValue > 0) {
countdownText.setText(countdownValue.toString());
LK.getSound('countdown').play();
} else {
LK.clearInterval(countdownTimer);
countdownText.visible = false;
gameOverText.visible = false;
// Start actual game
gameState = "playing";
currentLevel = 1;
LK.setScore(0);
scoreText.setText("Score: 0");
initializeLevel(currentLevel);
// Play game music
LK.playMusic('gameMusic');
}
}, 1000);
}
function updateLevel() {
// Update timer
var timeLeft = Math.max(0, Math.floor((levelDuration - (Date.now() - levelStartTime)) / 1000));
timerText.setText(timeLeft.toString());
// Update progress bar
var progress = (Date.now() - levelStartTime) / levelDuration * 100;
progressBar.setProgress(progress);
// Check if level time is up
if (Date.now() - levelStartTime >= levelDuration) {
completeLevel();
}
// Level-specific logic
switch (currentLevel) {
case 1:
// Dodge level
updateDodgeLevel();
break;
case 2:
// Platform level
updatePlatformLevel();
break;
case 3:
// Target level
updateTargetLevel();
break;
case 4:
// Boundary level
updateBoundaryLevel();
break;
case 5:
// Final level
updateFinalLevel();
break;
}
}
function updateDodgeLevel() {
// Check collisions with obstacles
for (var i = 0; i < obstacles.length; i++) {
if (obstacles[i].active && player.intersects(obstacles[i])) {
// Player hit an obstacle
LK.getSound('fail').play();
LK.effects.flashScreen(0xff0000, 500);
LK.showGameOver();
return;
}
// Replace obstacles that went off-screen
if (!obstacles[i].active) {
obstacles[i].reset(2300, 400 + Math.random() * 1700, -5 - Math.random() * 5);
}
}
// Add score over time
if (LK.ticks % 30 === 0) {
LK.setScore(LK.getScore() + 1);
scoreText.setText("Score: " + LK.getScore());
}
}
function updatePlatformLevel() {
// Apply gravity
player.velocity.y += GRAVITY;
player.y += player.velocity.y;
// Check if player is standing on a platform
var onPlatform = false;
for (var i = 0; i < platforms.length; i++) {
if (player.y + 60 >= platforms[i].y - 20 && player.y + 60 <= platforms[i].y + 20 && player.x >= platforms[i].x - 200 && player.x <= platforms[i].x + 200) {
player.y = platforms[i].y - 60;
player.velocity.y = 0;
player.isJumping = false;
onPlatform = true;
// Check if player reached the end platform
if (i === platforms.length - 1) {
completeLevel();
return;
}
}
}
// Check if player fell off
if (player.y > GROUND_Y) {
LK.getSound('fail').play();
LK.effects.flashScreen(0xff0000, 500);
LK.showGameOver();
return;
}
}
function updateTargetLevel() {
// Check collisions with targets
for (var i = targets.length - 1; i >= 0; i--) {
if (targets[i].active && player.intersects(targets[i])) {
// Player hit a target
LK.getSound('success').play();
targets[i].destroy();
targets.splice(i, 1);
// Add score
LK.setScore(LK.getScore() + 10);
scoreText.setText("Score: " + LK.getScore());
// Check if all targets are hit
if (targets.length === 0) {
completeLevel();
return;
}
}
}
}
function updateBoundaryLevel() {
// For this level, we check if player is out of bounds (using the existing child objects)
var children = game.children;
for (var i = 0; i < children.length; i++) {
// Find the boundary objects created in setupBoundaryLevel
if (children[i].width === 150 && children[i].height === 2732) {
if (player.intersects(children[i])) {
LK.getSound('fail').play();
LK.effects.flashScreen(0xff0000, 500);
LK.showGameOver();
return;
}
}
}
// Add score over time
if (LK.ticks % 30 === 0) {
LK.setScore(LK.getScore() + 1);
scoreText.setText("Score: " + LK.getScore());
}
}
function updateFinalLevel() {
// Mix of all previous levels' logic
// Check collisions with obstacles
for (var i = 0; i < obstacles.length; i++) {
if (obstacles[i].active && player.intersects(obstacles[i])) {
// Player hit an obstacle
LK.getSound('fail').play();
LK.effects.flashScreen(0xff0000, 500);
LK.showGameOver();
return;
}
// Replace obstacles that went off-screen
if (!obstacles[i].active) {
obstacles[i].reset(2300, 400 + Math.random() * 1700, -5 - Math.random() * 5);
}
}
// Check collisions with targets
for (var i = targets.length - 1; i >= 0; i--) {
if (targets[i].active && player.intersects(targets[i])) {
// Player hit a target
LK.getSound('success').play();
targets[i].destroy();
targets.splice(i, 1);
// Add score
LK.setScore(LK.getScore() + 10);
scoreText.setText("Score: " + LK.getScore());
}
}
// Add score over time
if (LK.ticks % 30 === 0) {
LK.setScore(LK.getScore() + 1);
scoreText.setText("Score: " + LK.getScore());
}
// Check if all targets are hit
if (targets.length === 0) {
completeLevel();
return;
}
}
function completeLevel() {
LK.getSound('levelComplete').play();
currentLevel++;
// Check if all levels are complete
if (currentLevel > maxLevels) {
LK.showYouWin();
} else {
// Start next level
initializeLevel(currentLevel);
}
}
// Input handlers
game.down = function (x, y, obj) {
if (gameState === "title") {
startGame();
} else if (gameState === "playing") {
if (currentLevel === 2) {
// Jump for platform level
player.jump();
} else if (draggedObject === null && player.isDraggable) {
// Start dragging player
var localPoint = player.toLocal({
x: x,
y: y
});
if (Math.sqrt(localPoint.x * localPoint.x + localPoint.y * localPoint.y) < 60) {
draggedObject = player;
}
}
}
};
game.up = function (x, y, obj) {
draggedObject = null;
};
game.move = function (x, y, obj) {
if (draggedObject) {
draggedObject.x = x;
draggedObject.y = y;
}
};
// Initialize game
initializeUI();
initializePlayer();
// Game loop
game.update = function () {
if (gameState === "playing") {
updateLevel();
}
};
// Start with title screen
gameState = "title"; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,637 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var Obstacle = Container.expand(function () {
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 0;
+ self.active = true;
+ self.update = function () {
+ if (self.active) {
+ self.x += self.speed;
+ // If obstacle goes off-screen, reset
+ if (self.x < -100 || self.x > 2148) {
+ self.active = false;
+ }
+ }
+ };
+ self.reset = function (x, y, speed) {
+ self.x = x;
+ self.y = y;
+ self.speed = speed;
+ self.active = true;
+ };
+ return self;
+});
+var Platform = Container.expand(function () {
+ var self = Container.call(this);
+ var platformGraphics = self.attachAsset('platform', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 0;
+ self.active = true;
+ self.update = function () {
+ if (self.active) {
+ self.x += self.speed;
+ // If platform goes off-screen, reset
+ if (self.x < -250 || self.x > 2298) {
+ self.active = false;
+ }
+ }
+ };
+ return self;
+});
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('playerCircle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocity = {
+ x: 0,
+ y: 0
+ };
+ self.isJumping = false;
+ self.isDraggable = false;
+ self.jump = function () {
+ if (!self.isJumping) {
+ self.velocity.y = -20;
+ self.isJumping = true;
+ LK.getSound('jump').play();
+ }
+ };
+ self.reset = function (x, y) {
+ self.x = x;
+ self.y = y;
+ self.velocity = {
+ x: 0,
+ y: 0
+ };
+ self.isJumping = false;
+ };
+ self.down = function (x, y, obj) {
+ if (self.isDraggable) {
+ draggedObject = self;
+ }
+ };
+ return self;
+});
+var ProgressBar = Container.expand(function () {
+ var self = Container.call(this);
+ var background = self.attachAsset('progressBar', {
+ anchorX: 0,
+ anchorY: 0.5
+ });
+ var fill = self.attachAsset('progressFill', {
+ anchorX: 0,
+ anchorY: 0.5
+ });
+ self.setProgress = function (percent) {
+ fill.width = Math.min(1800 * (percent / 100), 1800);
+ };
+ return self;
+});
+var Target = Container.expand(function () {
+ var self = Container.call(this);
+ var targetGraphics = self.attachAsset('target', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.active = true;
+ self.pulse = function () {
+ tween(self, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 500,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(self, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 500,
+ easing: tween.easeIn
+ });
+ }
+ });
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x34495e
+});
+
+/****
+* Game Code
+****/
+var GRAVITY = 0.8;
+var GROUND_Y = 2400;
+var gameState = "title"; // "title", "playing", "gameOver"
+var currentLevel = 1;
+var maxLevels = 5;
+var levelDuration = 20000; // 20 seconds per level
+var levelStartTime = 0;
+var draggedObject = null;
+var player;
+var obstacles = [];
+var platforms = [];
+var targets = [];
+var progressBar;
+var scoreText;
+var levelText;
+var timerText;
+var titleText;
+var instructionText;
+var gameOverText;
+var countdownText;
+var countdownValue = 3;
+var levelDescriptions = ["Dodge the memes!", "Cross the platforms!", "Hit the targets!", "Stay in bounds!", "Survive them all!"];
+// Initialize game UI
+function initializeUI() {
+ // Progress bar
+ progressBar = new ProgressBar();
+ progressBar.x = 124;
+ progressBar.y = 100;
+ LK.gui.addChild(progressBar);
+ // Score
+ scoreText = new Text2("Score: 0", {
+ size: 60,
+ fill: 0xFFFFFF
+ });
+ scoreText.anchor.set(1, 0);
+ LK.gui.topRight.addChild(scoreText);
+ // Level
+ levelText = new Text2("Level: 1", {
+ size: 60,
+ fill: 0xFFFFFF
+ });
+ levelText.anchor.set(0, 0);
+ levelText.x = 124;
+ LK.gui.topLeft.addChild(levelText);
+ levelText.y = 150;
+ // Timer
+ timerText = new Text2("20", {
+ size: 60,
+ fill: 0xFFFFFF
+ });
+ timerText.anchor.set(0.5, 0);
+ LK.gui.top.addChild(timerText);
+ // Title
+ titleText = new Text2("MEME SURVIVAL\nCHALLENGE", {
+ size: 120,
+ fill: 0xFFFFFF
+ });
+ titleText.anchor.set(0.5, 0.5);
+ titleText.visible = true;
+ LK.gui.center.addChild(titleText);
+ // Instruction
+ instructionText = new Text2("Tap to Start", {
+ size: 60,
+ fill: 0xFFFFFF
+ });
+ instructionText.anchor.set(0.5, 0.5);
+ instructionText.y = 200;
+ instructionText.visible = true;
+ LK.gui.center.addChild(instructionText);
+ // Countdown
+ countdownText = new Text2("3", {
+ size: 200,
+ fill: 0xFFFFFF
+ });
+ countdownText.anchor.set(0.5, 0.5);
+ countdownText.visible = false;
+ LK.gui.center.addChild(countdownText);
+ // Level description
+ gameOverText = new Text2("", {
+ size: 60,
+ fill: 0xFFFFFF
+ });
+ gameOverText.anchor.set(0.5, 0.5);
+ gameOverText.y = 300;
+ gameOverText.visible = false;
+ LK.gui.center.addChild(gameOverText);
+}
+// Initialize player
+function initializePlayer() {
+ player = new Player();
+ player.reset(1024, 1366);
+ game.addChild(player);
+}
+// Initialize obstacles based on level
+function initializeLevel(level) {
+ // Clear any existing objects
+ clearLevel();
+ // Update UI
+ levelText.setText("Level: " + level);
+ gameOverText.setText(levelDescriptions[level - 1]);
+ gameOverText.visible = true;
+ // Set timer
+ levelStartTime = Date.now();
+ // Configure level
+ switch (level) {
+ case 1:
+ // Dodge memes level
+ setupDodgeLevel();
+ break;
+ case 2:
+ // Platform level
+ setupPlatformLevel();
+ break;
+ case 3:
+ // Target level
+ setupTargetLevel();
+ break;
+ case 4:
+ // Boundary level
+ setupBoundaryLevel();
+ break;
+ case 5:
+ // Final level - combination
+ setupFinalLevel();
+ break;
+ }
+}
+function setupDodgeLevel() {
+ player.isDraggable = true;
+ player.reset(1024, 1366);
+ // Create obstacles
+ for (var i = 0; i < 10; i++) {
+ var obstacle = new Obstacle();
+ obstacle.reset(2300, 400 + Math.random() * 1700, -5 - Math.random() * 5);
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
+ }
+}
+function setupPlatformLevel() {
+ player.isDraggable = false;
+ player.reset(200, 1000);
+ // Create platforms
+ for (var i = 0; i < 8; i++) {
+ var platform = new Platform();
+ platform.x = 300 + i * 250;
+ platform.y = 1300 + Math.random() * 800;
+ platform.speed = 0;
+ platform.active = true;
+ platforms.push(platform);
+ game.addChild(platform);
+ }
+ // Add winning platform
+ var winPlatform = new Platform();
+ winPlatform.x = 2000;
+ winPlatform.y = 1500;
+ winPlatform.speed = 0;
+ winPlatform.active = true;
+ platforms.push(winPlatform);
+ game.addChild(winPlatform);
+}
+function setupTargetLevel() {
+ player.isDraggable = true;
+ player.reset(1024, 1366);
+ // Create targets
+ for (var i = 0; i < 5; i++) {
+ var target = new Target();
+ target.x = 300 + Math.random() * 1500;
+ target.y = 400 + Math.random() * 1700;
+ target.pulse();
+ targets.push(target);
+ game.addChild(target);
+ }
+}
+function setupBoundaryLevel() {
+ player.isDraggable = true;
+ player.reset(1024, 1366);
+ // Create moving boundaries
+ var leftBoundary = LK.getAsset('boundary', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ leftBoundary.x = 500;
+ leftBoundary.y = 1366;
+ game.addChild(leftBoundary);
+ var rightBoundary = LK.getAsset('boundary', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ rightBoundary.x = 1548;
+ rightBoundary.y = 1366;
+ game.addChild(rightBoundary);
+ // Add movement to boundaries
+ LK.setInterval(function () {
+ tween(leftBoundary, {
+ x: 300 + Math.random() * 400
+ }, {
+ duration: 1500,
+ easing: tween.easeInOut
+ });
+ tween(rightBoundary, {
+ x: 1348 + Math.random() * 400
+ }, {
+ duration: 1500,
+ easing: tween.easeInOut
+ });
+ }, 2000);
+}
+function setupFinalLevel() {
+ player.isDraggable = true;
+ player.reset(1024, 1366);
+ // Mix of obstacles, platforms and targets
+ // Create obstacles
+ for (var i = 0; i < 5; i++) {
+ var obstacle = new Obstacle();
+ obstacle.reset(2300, 400 + Math.random() * 1700, -5 - Math.random() * 5);
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
+ }
+ // Create platforms
+ for (var i = 0; i < 3; i++) {
+ var platform = new Platform();
+ platform.x = 300 + i * 600;
+ platform.y = 1300 + Math.random() * 800;
+ platform.speed = -2;
+ platform.active = true;
+ platforms.push(platform);
+ game.addChild(platform);
+ }
+ // Create targets
+ for (var i = 0; i < 3; i++) {
+ var target = new Target();
+ target.x = 300 + Math.random() * 1500;
+ target.y = 400 + Math.random() * 1700;
+ target.pulse();
+ targets.push(target);
+ game.addChild(target);
+ }
+}
+function clearLevel() {
+ // Remove all obstacles
+ for (var i = 0; i < obstacles.length; i++) {
+ obstacles[i].destroy();
+ }
+ obstacles = [];
+ // Remove all platforms
+ for (var i = 0; i < platforms.length; i++) {
+ platforms[i].destroy();
+ }
+ platforms = [];
+ // Remove all targets
+ for (var i = 0; i < targets.length; i++) {
+ targets[i].destroy();
+ }
+ targets = [];
+}
+function startGame() {
+ gameState = "countdown";
+ titleText.visible = false;
+ instructionText.visible = false;
+ countdownText.visible = true;
+ countdownValue = 3;
+ countdownText.setText(countdownValue.toString());
+ LK.getSound('countdown').play();
+ // Start countdown
+ var countdownTimer = LK.setInterval(function () {
+ countdownValue--;
+ if (countdownValue > 0) {
+ countdownText.setText(countdownValue.toString());
+ LK.getSound('countdown').play();
+ } else {
+ LK.clearInterval(countdownTimer);
+ countdownText.visible = false;
+ gameOverText.visible = false;
+ // Start actual game
+ gameState = "playing";
+ currentLevel = 1;
+ LK.setScore(0);
+ scoreText.setText("Score: 0");
+ initializeLevel(currentLevel);
+ // Play game music
+ LK.playMusic('gameMusic');
+ }
+ }, 1000);
+}
+function updateLevel() {
+ // Update timer
+ var timeLeft = Math.max(0, Math.floor((levelDuration - (Date.now() - levelStartTime)) / 1000));
+ timerText.setText(timeLeft.toString());
+ // Update progress bar
+ var progress = (Date.now() - levelStartTime) / levelDuration * 100;
+ progressBar.setProgress(progress);
+ // Check if level time is up
+ if (Date.now() - levelStartTime >= levelDuration) {
+ completeLevel();
+ }
+ // Level-specific logic
+ switch (currentLevel) {
+ case 1:
+ // Dodge level
+ updateDodgeLevel();
+ break;
+ case 2:
+ // Platform level
+ updatePlatformLevel();
+ break;
+ case 3:
+ // Target level
+ updateTargetLevel();
+ break;
+ case 4:
+ // Boundary level
+ updateBoundaryLevel();
+ break;
+ case 5:
+ // Final level
+ updateFinalLevel();
+ break;
+ }
+}
+function updateDodgeLevel() {
+ // Check collisions with obstacles
+ for (var i = 0; i < obstacles.length; i++) {
+ if (obstacles[i].active && player.intersects(obstacles[i])) {
+ // Player hit an obstacle
+ LK.getSound('fail').play();
+ LK.effects.flashScreen(0xff0000, 500);
+ LK.showGameOver();
+ return;
+ }
+ // Replace obstacles that went off-screen
+ if (!obstacles[i].active) {
+ obstacles[i].reset(2300, 400 + Math.random() * 1700, -5 - Math.random() * 5);
+ }
+ }
+ // Add score over time
+ if (LK.ticks % 30 === 0) {
+ LK.setScore(LK.getScore() + 1);
+ scoreText.setText("Score: " + LK.getScore());
+ }
+}
+function updatePlatformLevel() {
+ // Apply gravity
+ player.velocity.y += GRAVITY;
+ player.y += player.velocity.y;
+ // Check if player is standing on a platform
+ var onPlatform = false;
+ for (var i = 0; i < platforms.length; i++) {
+ if (player.y + 60 >= platforms[i].y - 20 && player.y + 60 <= platforms[i].y + 20 && player.x >= platforms[i].x - 200 && player.x <= platforms[i].x + 200) {
+ player.y = platforms[i].y - 60;
+ player.velocity.y = 0;
+ player.isJumping = false;
+ onPlatform = true;
+ // Check if player reached the end platform
+ if (i === platforms.length - 1) {
+ completeLevel();
+ return;
+ }
+ }
+ }
+ // Check if player fell off
+ if (player.y > GROUND_Y) {
+ LK.getSound('fail').play();
+ LK.effects.flashScreen(0xff0000, 500);
+ LK.showGameOver();
+ return;
+ }
+}
+function updateTargetLevel() {
+ // Check collisions with targets
+ for (var i = targets.length - 1; i >= 0; i--) {
+ if (targets[i].active && player.intersects(targets[i])) {
+ // Player hit a target
+ LK.getSound('success').play();
+ targets[i].destroy();
+ targets.splice(i, 1);
+ // Add score
+ LK.setScore(LK.getScore() + 10);
+ scoreText.setText("Score: " + LK.getScore());
+ // Check if all targets are hit
+ if (targets.length === 0) {
+ completeLevel();
+ return;
+ }
+ }
+ }
+}
+function updateBoundaryLevel() {
+ // For this level, we check if player is out of bounds (using the existing child objects)
+ var children = game.children;
+ for (var i = 0; i < children.length; i++) {
+ // Find the boundary objects created in setupBoundaryLevel
+ if (children[i].width === 150 && children[i].height === 2732) {
+ if (player.intersects(children[i])) {
+ LK.getSound('fail').play();
+ LK.effects.flashScreen(0xff0000, 500);
+ LK.showGameOver();
+ return;
+ }
+ }
+ }
+ // Add score over time
+ if (LK.ticks % 30 === 0) {
+ LK.setScore(LK.getScore() + 1);
+ scoreText.setText("Score: " + LK.getScore());
+ }
+}
+function updateFinalLevel() {
+ // Mix of all previous levels' logic
+ // Check collisions with obstacles
+ for (var i = 0; i < obstacles.length; i++) {
+ if (obstacles[i].active && player.intersects(obstacles[i])) {
+ // Player hit an obstacle
+ LK.getSound('fail').play();
+ LK.effects.flashScreen(0xff0000, 500);
+ LK.showGameOver();
+ return;
+ }
+ // Replace obstacles that went off-screen
+ if (!obstacles[i].active) {
+ obstacles[i].reset(2300, 400 + Math.random() * 1700, -5 - Math.random() * 5);
+ }
+ }
+ // Check collisions with targets
+ for (var i = targets.length - 1; i >= 0; i--) {
+ if (targets[i].active && player.intersects(targets[i])) {
+ // Player hit a target
+ LK.getSound('success').play();
+ targets[i].destroy();
+ targets.splice(i, 1);
+ // Add score
+ LK.setScore(LK.getScore() + 10);
+ scoreText.setText("Score: " + LK.getScore());
+ }
+ }
+ // Add score over time
+ if (LK.ticks % 30 === 0) {
+ LK.setScore(LK.getScore() + 1);
+ scoreText.setText("Score: " + LK.getScore());
+ }
+ // Check if all targets are hit
+ if (targets.length === 0) {
+ completeLevel();
+ return;
+ }
+}
+function completeLevel() {
+ LK.getSound('levelComplete').play();
+ currentLevel++;
+ // Check if all levels are complete
+ if (currentLevel > maxLevels) {
+ LK.showYouWin();
+ } else {
+ // Start next level
+ initializeLevel(currentLevel);
+ }
+}
+// Input handlers
+game.down = function (x, y, obj) {
+ if (gameState === "title") {
+ startGame();
+ } else if (gameState === "playing") {
+ if (currentLevel === 2) {
+ // Jump for platform level
+ player.jump();
+ } else if (draggedObject === null && player.isDraggable) {
+ // Start dragging player
+ var localPoint = player.toLocal({
+ x: x,
+ y: y
+ });
+ if (Math.sqrt(localPoint.x * localPoint.x + localPoint.y * localPoint.y) < 60) {
+ draggedObject = player;
+ }
+ }
+ }
+};
+game.up = function (x, y, obj) {
+ draggedObject = null;
+};
+game.move = function (x, y, obj) {
+ if (draggedObject) {
+ draggedObject.x = x;
+ draggedObject.y = y;
+ }
+};
+// Initialize game
+initializeUI();
+initializePlayer();
+// Game loop
+game.update = function () {
+ if (gameState === "playing") {
+ updateLevel();
+ }
+};
+// Start with title screen
+gameState = "title";
\ No newline at end of file