/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = 2;
self.direction = 1;
self.patrolDistance = 200;
self.startX = 0;
self.setPatrol = function (startX, distance) {
self.startX = startX;
self.patrolDistance = distance;
};
self.update = function () {
self.x += self.speed * self.direction;
if (self.x > self.startX + self.patrolDistance || self.x < self.startX) {
self.direction *= -1;
enemyGraphics.scaleX = self.direction;
}
};
return self;
});
var Goal = Container.expand(function () {
var self = Container.call(this);
var goalGraphics = self.attachAsset('goal', {
anchorX: 0.5,
anchorY: 1.0
});
// Animate goal with gentle pulsing
tween(goalGraphics, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(goalGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Restart animation
tween(goalGraphics, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut
});
}
});
}
});
return self;
});
var Platform = Container.expand(function (width, height) {
var self = Container.call(this);
var platformGraphics = self.attachAsset('ground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: width / 200,
scaleY: height / 40
});
self.width = width;
self.height = height;
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityX = 0;
self.velocityY = 0;
self.speed = 8;
self.jumpPower = -20;
self.gravity = 1.2;
self.onGround = false;
self.facing = 1; // 1 for right, -1 for left
self.jump = function () {
if (self.onGround) {
self.velocityY = self.jumpPower;
self.onGround = false;
LK.getSound('jump').play();
}
};
self.moveLeft = function () {
self.velocityX = -self.speed;
self.facing = -1;
playerGraphics.scaleX = -1;
};
self.moveRight = function () {
self.velocityX = self.speed;
self.facing = 1;
playerGraphics.scaleX = 1;
};
self.stop = function () {
self.velocityX = 0;
};
self.update = function () {
// Apply gravity
self.velocityY += self.gravity;
// Apply velocity
self.x += self.velocityX;
self.y += self.velocityY;
// Check ground collision
self.onGround = false;
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
if (self.intersects(platform) && self.velocityY >= 0) {
self.y = platform.y - platform.height / 2;
self.velocityY = 0;
self.onGround = true;
break;
}
}
// Check boundaries
if (self.y > 2732) {
restartLevel();
}
// Apply friction when on ground
if (self.onGround) {
self.velocityX *= 0.8;
}
};
return self;
});
var Spike = Container.expand(function () {
var self = Container.call(this);
var spikeGraphics = self.attachAsset('spike', {
anchorX: 0.5,
anchorY: 1.0
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var player;
var platforms = [];
var enemies = [];
var spikes = [];
var goal;
var gameStarted = false;
var levelStartTime = 0;
var currentLevel = 1;
var maxLevel = storage.maxLevel || 1;
// UI Elements
var levelText = new Text2('Level 1', {
size: 80,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
levelText.y = 50;
var instructionText = new Text2('Tap sides to move, top to jump', {
size: 60,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(instructionText);
function createLevel(levelNum) {
// Clear existing level
for (var i = platforms.length - 1; i >= 0; i--) {
platforms[i].destroy();
}
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].destroy();
}
for (var i = spikes.length - 1; i >= 0; i--) {
spikes[i].destroy();
}
if (goal) {
goal.destroy();
}
platforms = [];
enemies = [];
spikes = [];
// Level 1 - Simple introduction
if (levelNum === 1) {
// Ground platforms
var platform1 = game.addChild(new Platform(400, 60));
platform1.x = 200;
platform1.y = 2500;
platforms.push(platform1);
var platform2 = game.addChild(new Platform(300, 60));
platform2.x = 700;
platform2.y = 2400;
platforms.push(platform2);
var platform3 = game.addChild(new Platform(300, 60));
platform3.x = 1100;
platform3.y = 2300;
platforms.push(platform3);
var platform4 = game.addChild(new Platform(400, 60));
platform4.x = 1600;
platform4.y = 2200;
platforms.push(platform4);
// Simple enemy
var enemy1 = game.addChild(new Enemy());
enemy1.x = 700;
enemy1.y = 2400;
enemy1.setPatrol(600, 200);
enemies.push(enemy1);
// Goal
goal = game.addChild(new Goal());
goal.x = 1600;
goal.y = 2200;
}
// Level 2 - More complex
else if (levelNum === 2) {
var platform1 = game.addChild(new Platform(300, 60));
platform1.x = 150;
platform1.y = 2500;
platforms.push(platform1);
var platform2 = game.addChild(new Platform(200, 60));
platform2.x = 500;
platform2.y = 2400;
platforms.push(platform2);
var platform3 = game.addChild(new Platform(200, 60));
platform3.x = 800;
platform3.y = 2300;
platforms.push(platform3);
var platform4 = game.addChild(new Platform(300, 60));
platform4.x = 1200;
platform4.y = 2400;
platforms.push(platform4);
var platform5 = game.addChild(new Platform(400, 60));
platform5.x = 1700;
platform5.y = 2200;
platforms.push(platform5);
// Enemies
var enemy1 = game.addChild(new Enemy());
enemy1.x = 500;
enemy1.y = 2400;
enemy1.setPatrol(450, 100);
enemies.push(enemy1);
var enemy2 = game.addChild(new Enemy());
enemy2.x = 1200;
enemy2.y = 2400;
enemy2.setPatrol(1100, 200);
enemies.push(enemy2);
// Spikes
var spike1 = game.addChild(new Spike());
spike1.x = 800;
spike1.y = 2300;
spikes.push(spike1);
goal = game.addChild(new Goal());
goal.x = 1700;
goal.y = 2200;
}
// Level 3 - Advanced
else {
var platform1 = game.addChild(new Platform(250, 60));
platform1.x = 125;
platform1.y = 2500;
platforms.push(platform1);
var platform2 = game.addChild(new Platform(150, 60));
platform2.x = 400;
platform2.y = 2350;
platforms.push(platform2);
var platform3 = game.addChild(new Platform(150, 60));
platform3.x = 650;
platform3.y = 2200;
platforms.push(platform3);
var platform4 = game.addChild(new Platform(200, 60));
platform4.x = 950;
platform4.y = 2350;
platforms.push(platform4);
var platform5 = game.addChild(new Platform(200, 60));
platform5.x = 1300;
platform5.y = 2250;
platforms.push(platform5);
var platform6 = game.addChild(new Platform(300, 60));
platform6.x = 1650;
platform6.y = 2150;
platforms.push(platform6);
// Multiple enemies
var enemy1 = game.addChild(new Enemy());
enemy1.x = 400;
enemy1.y = 2350;
enemy1.setPatrol(350, 100);
enemies.push(enemy1);
var enemy2 = game.addChild(new Enemy());
enemy2.x = 950;
enemy2.y = 2350;
enemy2.setPatrol(900, 100);
enemies.push(enemy2);
var enemy3 = game.addChild(new Enemy());
enemy3.x = 1300;
enemy3.y = 2250;
enemy3.setPatrol(1250, 100);
enemies.push(enemy3);
// More spikes
var spike1 = game.addChild(new Spike());
spike1.x = 650;
spike1.y = 2200;
spikes.push(spike1);
var spike2 = game.addChild(new Spike());
spike2.x = 1300;
spike2.y = 2250;
spikes.push(spike2);
goal = game.addChild(new Goal());
goal.x = 1650;
goal.y = 2150;
}
}
function startGame() {
if (gameStarted) return;
gameStarted = true;
levelStartTime = Date.now();
instructionText.visible = false;
// Create player
player = game.addChild(new Player());
player.x = 200;
player.y = 2400;
// Create level
createLevel(currentLevel);
levelText.setText('Level ' + currentLevel);
}
function restartLevel() {
LK.getSound('hit').play();
LK.effects.flashScreen(0xFF0000, 500);
if (player) {
player.destroy();
}
// Reset player
player = game.addChild(new Player());
player.x = 200;
player.y = 2400;
levelStartTime = Date.now();
}
function nextLevel() {
currentLevel++;
if (currentLevel > maxLevel) {
maxLevel = currentLevel;
storage.maxLevel = maxLevel;
}
if (currentLevel > 3) {
// Game completed
LK.showYouWin();
return;
}
// Destroy current player
if (player) {
player.destroy();
}
// Create new level
createLevel(currentLevel);
levelText.setText('Level ' + currentLevel);
// Reset player
player = game.addChild(new Player());
player.x = 200;
player.y = 2400;
levelStartTime = Date.now();
}
// Touch controls
var leftPressed = false;
var rightPressed = false;
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
return;
}
// Jump area (upper third of screen)
if (y < 2732 / 3) {
if (player) {
player.jump();
}
}
// Movement areas
else {
if (x < 2048 / 2) {
leftPressed = true;
} else {
rightPressed = true;
}
}
};
game.up = function (x, y, obj) {
leftPressed = false;
rightPressed = false;
if (player) {
player.stop();
}
};
game.update = function () {
if (!gameStarted || !player) return;
// Handle continuous movement
if (leftPressed && !rightPressed) {
player.moveLeft();
} else if (rightPressed && !leftPressed) {
player.moveRight();
} else if (!leftPressed && !rightPressed) {
player.stop();
}
// Check enemy collisions
for (var i = 0; i < enemies.length; i++) {
if (player.intersects(enemies[i])) {
restartLevel();
return;
}
}
// Check spike collisions
for (var i = 0; i < spikes.length; i++) {
if (player.intersects(spikes[i])) {
restartLevel();
return;
}
}
// Check goal collision
if (goal && player.intersects(goal)) {
LK.getSound('collect').play();
var completionTime = Math.floor((Date.now() - levelStartTime) / 1000);
LK.setScore(LK.getScore() + Math.max(100 - completionTime, 10));
nextLevel();
}
// Camera follow player
var targetX = Math.max(0, Math.min(player.x - 1024, 2048));
game.x += (targetX - game.x) * 0.1;
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,441 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var Enemy = Container.expand(function () {
+ var self = Container.call(this);
+ var enemyGraphics = self.attachAsset('enemy', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ self.speed = 2;
+ self.direction = 1;
+ self.patrolDistance = 200;
+ self.startX = 0;
+ self.setPatrol = function (startX, distance) {
+ self.startX = startX;
+ self.patrolDistance = distance;
+ };
+ self.update = function () {
+ self.x += self.speed * self.direction;
+ if (self.x > self.startX + self.patrolDistance || self.x < self.startX) {
+ self.direction *= -1;
+ enemyGraphics.scaleX = self.direction;
+ }
+ };
+ return self;
+});
+var Goal = Container.expand(function () {
+ var self = Container.call(this);
+ var goalGraphics = self.attachAsset('goal', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ // Animate goal with gentle pulsing
+ tween(goalGraphics, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(goalGraphics, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ // Restart animation
+ tween(goalGraphics, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut
+ });
+ }
+ });
+ }
+ });
+ return self;
+});
+var Platform = Container.expand(function (width, height) {
+ var self = Container.call(this);
+ var platformGraphics = self.attachAsset('ground', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: width / 200,
+ scaleY: height / 40
+ });
+ self.width = width;
+ self.height = height;
+ return self;
+});
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ self.velocityX = 0;
+ self.velocityY = 0;
+ self.speed = 8;
+ self.jumpPower = -20;
+ self.gravity = 1.2;
+ self.onGround = false;
+ self.facing = 1; // 1 for right, -1 for left
+ self.jump = function () {
+ if (self.onGround) {
+ self.velocityY = self.jumpPower;
+ self.onGround = false;
+ LK.getSound('jump').play();
+ }
+ };
+ self.moveLeft = function () {
+ self.velocityX = -self.speed;
+ self.facing = -1;
+ playerGraphics.scaleX = -1;
+ };
+ self.moveRight = function () {
+ self.velocityX = self.speed;
+ self.facing = 1;
+ playerGraphics.scaleX = 1;
+ };
+ self.stop = function () {
+ self.velocityX = 0;
+ };
+ self.update = function () {
+ // Apply gravity
+ self.velocityY += self.gravity;
+ // Apply velocity
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ // Check ground collision
+ self.onGround = false;
+ for (var i = 0; i < platforms.length; i++) {
+ var platform = platforms[i];
+ if (self.intersects(platform) && self.velocityY >= 0) {
+ self.y = platform.y - platform.height / 2;
+ self.velocityY = 0;
+ self.onGround = true;
+ break;
+ }
+ }
+ // Check boundaries
+ if (self.y > 2732) {
+ restartLevel();
+ }
+ // Apply friction when on ground
+ if (self.onGround) {
+ self.velocityX *= 0.8;
+ }
+ };
+ return self;
+});
+var Spike = Container.expand(function () {
+ var self = Container.call(this);
+ var spikeGraphics = self.attachAsset('spike', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+var player;
+var platforms = [];
+var enemies = [];
+var spikes = [];
+var goal;
+var gameStarted = false;
+var levelStartTime = 0;
+var currentLevel = 1;
+var maxLevel = storage.maxLevel || 1;
+// UI Elements
+var levelText = new Text2('Level 1', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+levelText.anchor.set(0.5, 0);
+LK.gui.top.addChild(levelText);
+levelText.y = 50;
+var instructionText = new Text2('Tap sides to move, top to jump', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 0.5);
+LK.gui.center.addChild(instructionText);
+function createLevel(levelNum) {
+ // Clear existing level
+ for (var i = platforms.length - 1; i >= 0; i--) {
+ platforms[i].destroy();
+ }
+ for (var i = enemies.length - 1; i >= 0; i--) {
+ enemies[i].destroy();
+ }
+ for (var i = spikes.length - 1; i >= 0; i--) {
+ spikes[i].destroy();
+ }
+ if (goal) {
+ goal.destroy();
+ }
+ platforms = [];
+ enemies = [];
+ spikes = [];
+ // Level 1 - Simple introduction
+ if (levelNum === 1) {
+ // Ground platforms
+ var platform1 = game.addChild(new Platform(400, 60));
+ platform1.x = 200;
+ platform1.y = 2500;
+ platforms.push(platform1);
+ var platform2 = game.addChild(new Platform(300, 60));
+ platform2.x = 700;
+ platform2.y = 2400;
+ platforms.push(platform2);
+ var platform3 = game.addChild(new Platform(300, 60));
+ platform3.x = 1100;
+ platform3.y = 2300;
+ platforms.push(platform3);
+ var platform4 = game.addChild(new Platform(400, 60));
+ platform4.x = 1600;
+ platform4.y = 2200;
+ platforms.push(platform4);
+ // Simple enemy
+ var enemy1 = game.addChild(new Enemy());
+ enemy1.x = 700;
+ enemy1.y = 2400;
+ enemy1.setPatrol(600, 200);
+ enemies.push(enemy1);
+ // Goal
+ goal = game.addChild(new Goal());
+ goal.x = 1600;
+ goal.y = 2200;
+ }
+ // Level 2 - More complex
+ else if (levelNum === 2) {
+ var platform1 = game.addChild(new Platform(300, 60));
+ platform1.x = 150;
+ platform1.y = 2500;
+ platforms.push(platform1);
+ var platform2 = game.addChild(new Platform(200, 60));
+ platform2.x = 500;
+ platform2.y = 2400;
+ platforms.push(platform2);
+ var platform3 = game.addChild(new Platform(200, 60));
+ platform3.x = 800;
+ platform3.y = 2300;
+ platforms.push(platform3);
+ var platform4 = game.addChild(new Platform(300, 60));
+ platform4.x = 1200;
+ platform4.y = 2400;
+ platforms.push(platform4);
+ var platform5 = game.addChild(new Platform(400, 60));
+ platform5.x = 1700;
+ platform5.y = 2200;
+ platforms.push(platform5);
+ // Enemies
+ var enemy1 = game.addChild(new Enemy());
+ enemy1.x = 500;
+ enemy1.y = 2400;
+ enemy1.setPatrol(450, 100);
+ enemies.push(enemy1);
+ var enemy2 = game.addChild(new Enemy());
+ enemy2.x = 1200;
+ enemy2.y = 2400;
+ enemy2.setPatrol(1100, 200);
+ enemies.push(enemy2);
+ // Spikes
+ var spike1 = game.addChild(new Spike());
+ spike1.x = 800;
+ spike1.y = 2300;
+ spikes.push(spike1);
+ goal = game.addChild(new Goal());
+ goal.x = 1700;
+ goal.y = 2200;
+ }
+ // Level 3 - Advanced
+ else {
+ var platform1 = game.addChild(new Platform(250, 60));
+ platform1.x = 125;
+ platform1.y = 2500;
+ platforms.push(platform1);
+ var platform2 = game.addChild(new Platform(150, 60));
+ platform2.x = 400;
+ platform2.y = 2350;
+ platforms.push(platform2);
+ var platform3 = game.addChild(new Platform(150, 60));
+ platform3.x = 650;
+ platform3.y = 2200;
+ platforms.push(platform3);
+ var platform4 = game.addChild(new Platform(200, 60));
+ platform4.x = 950;
+ platform4.y = 2350;
+ platforms.push(platform4);
+ var platform5 = game.addChild(new Platform(200, 60));
+ platform5.x = 1300;
+ platform5.y = 2250;
+ platforms.push(platform5);
+ var platform6 = game.addChild(new Platform(300, 60));
+ platform6.x = 1650;
+ platform6.y = 2150;
+ platforms.push(platform6);
+ // Multiple enemies
+ var enemy1 = game.addChild(new Enemy());
+ enemy1.x = 400;
+ enemy1.y = 2350;
+ enemy1.setPatrol(350, 100);
+ enemies.push(enemy1);
+ var enemy2 = game.addChild(new Enemy());
+ enemy2.x = 950;
+ enemy2.y = 2350;
+ enemy2.setPatrol(900, 100);
+ enemies.push(enemy2);
+ var enemy3 = game.addChild(new Enemy());
+ enemy3.x = 1300;
+ enemy3.y = 2250;
+ enemy3.setPatrol(1250, 100);
+ enemies.push(enemy3);
+ // More spikes
+ var spike1 = game.addChild(new Spike());
+ spike1.x = 650;
+ spike1.y = 2200;
+ spikes.push(spike1);
+ var spike2 = game.addChild(new Spike());
+ spike2.x = 1300;
+ spike2.y = 2250;
+ spikes.push(spike2);
+ goal = game.addChild(new Goal());
+ goal.x = 1650;
+ goal.y = 2150;
+ }
+}
+function startGame() {
+ if (gameStarted) return;
+ gameStarted = true;
+ levelStartTime = Date.now();
+ instructionText.visible = false;
+ // Create player
+ player = game.addChild(new Player());
+ player.x = 200;
+ player.y = 2400;
+ // Create level
+ createLevel(currentLevel);
+ levelText.setText('Level ' + currentLevel);
+}
+function restartLevel() {
+ LK.getSound('hit').play();
+ LK.effects.flashScreen(0xFF0000, 500);
+ if (player) {
+ player.destroy();
+ }
+ // Reset player
+ player = game.addChild(new Player());
+ player.x = 200;
+ player.y = 2400;
+ levelStartTime = Date.now();
+}
+function nextLevel() {
+ currentLevel++;
+ if (currentLevel > maxLevel) {
+ maxLevel = currentLevel;
+ storage.maxLevel = maxLevel;
+ }
+ if (currentLevel > 3) {
+ // Game completed
+ LK.showYouWin();
+ return;
+ }
+ // Destroy current player
+ if (player) {
+ player.destroy();
+ }
+ // Create new level
+ createLevel(currentLevel);
+ levelText.setText('Level ' + currentLevel);
+ // Reset player
+ player = game.addChild(new Player());
+ player.x = 200;
+ player.y = 2400;
+ levelStartTime = Date.now();
+}
+// Touch controls
+var leftPressed = false;
+var rightPressed = false;
+game.down = function (x, y, obj) {
+ if (!gameStarted) {
+ startGame();
+ return;
+ }
+ // Jump area (upper third of screen)
+ if (y < 2732 / 3) {
+ if (player) {
+ player.jump();
+ }
+ }
+ // Movement areas
+ else {
+ if (x < 2048 / 2) {
+ leftPressed = true;
+ } else {
+ rightPressed = true;
+ }
+ }
+};
+game.up = function (x, y, obj) {
+ leftPressed = false;
+ rightPressed = false;
+ if (player) {
+ player.stop();
+ }
+};
+game.update = function () {
+ if (!gameStarted || !player) return;
+ // Handle continuous movement
+ if (leftPressed && !rightPressed) {
+ player.moveLeft();
+ } else if (rightPressed && !leftPressed) {
+ player.moveRight();
+ } else if (!leftPressed && !rightPressed) {
+ player.stop();
+ }
+ // Check enemy collisions
+ for (var i = 0; i < enemies.length; i++) {
+ if (player.intersects(enemies[i])) {
+ restartLevel();
+ return;
+ }
+ }
+ // Check spike collisions
+ for (var i = 0; i < spikes.length; i++) {
+ if (player.intersects(spikes[i])) {
+ restartLevel();
+ return;
+ }
+ }
+ // Check goal collision
+ if (goal && player.intersects(goal)) {
+ LK.getSound('collect').play();
+ var completionTime = Math.floor((Date.now() - levelStartTime) / 1000);
+ LK.setScore(LK.getScore() + Math.max(100 - completionTime, 10));
+ nextLevel();
+ }
+ // Camera follow player
+ var targetX = Math.max(0, Math.min(player.x - 1024, 2048));
+ game.x += (targetX - game.x) * 0.1;
+};
\ No newline at end of file