/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0 }); /**** * Classes ****/ var Cloud = Container.expand(function () { var self = Container.call(this); var cloudGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5, alpha: 0.7 + Math.random() * 0.3 // Varied transparency }); self.speed = 0.5 + Math.random() * 1.5; // Varied speed self.update = function () { self.x -= self.speed; // Reset cloud position when it goes off screen if (self.x < -cloudGraphics.width) { self.x = 2048 + cloudGraphics.width; self.y = 200 + Math.random() * 300; } }; return self; }); var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 0; self.type = 'coin'; // Bobbing animation tween(coinGraphics, { y: 10 }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { tween(coinGraphics, { y: -10 }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { // Reset position and restart animation coinGraphics.y = 0; self.update(); } }); } }); self.update = function () { self.x -= self.speed; }; return self; }); 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.type = 'obstacle'; self.update = function () { self.x -= self.speed; }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.velocity = 0; self.gravity = 0.8; self.jumpForce = -18; self.isJumping = false; self.isInvincible = false; self.update = function () { // Apply gravity self.velocity += self.gravity; self.y += self.velocity; // Ground collision if (self.y > GROUND_LEVEL - playerGraphics.height / 2) { self.y = GROUND_LEVEL - playerGraphics.height / 2; self.velocity = 0; self.isJumping = false; } }; self.jump = function () { if (!self.isJumping) { self.velocity = self.jumpForce; self.isJumping = true; LK.getSound('jump').play(); } }; self.makeInvincible = function (duration) { if (self.invincibleTimeout) { LK.clearTimeout(self.invincibleTimeout); } self.isInvincible = true; // Flash effect var flashInterval = LK.setInterval(function () { playerGraphics.alpha = playerGraphics.alpha === 1 ? 0.4 : 1; }, 150); self.invincibleTimeout = LK.setTimeout(function () { self.isInvincible = false; playerGraphics.alpha = 1; LK.clearInterval(flashInterval); }, duration); }; return self; }); var PowerUp = Container.expand(function () { var self = Container.call(this); var powerupGraphics = self.attachAsset('powerup', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 0; self.type = 'powerup'; // Rotate animation self.rotationSpeed = 0.02; self.update = function () { self.x -= self.speed; powerupGraphics.rotation += self.rotationSpeed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Constants var GROUND_LEVEL = 2500; var BASE_SPEED = 8; var SCORE_MULTIPLIER = 0.1; var DIFFICULTY_INCREASE_RATE = 0.0001; // Game variables var player; var ground; var obstacles = []; var coins = []; var powerups = []; var clouds = []; var gameSpeed = BASE_SPEED; var distanceCounter = 0; var lastObstacleSpawn = 0; var lastCoinSpawn = 0; var lastPowerupSpawn = 0; var obstacleSpawnDistance = 300; var isGameActive = true; var highScore = storage.highScore || 0; // Setup UI var scoreTxt = new Text2('0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var highScoreTxt = new Text2('HIGH: 0', { size: 60, fill: 0xFFFFFF }); highScoreTxt.anchor.set(0.5, 0); highScoreTxt.y = 110; LK.gui.top.addChild(highScoreTxt); highScoreTxt.setText('HIGH: ' + highScore); // Initialize ground ground = LK.getAsset('ground', { anchorX: 0, anchorY: 0, x: 0, y: GROUND_LEVEL }); game.addChild(ground); // Initialize player player = new Player(); player.x = 300; player.y = GROUND_LEVEL - 100; game.addChild(player); // Initialize clouds function createInitialClouds() { for (var i = 0; i < 5; i++) { var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = 200 + Math.random() * 300; clouds.push(cloud); game.addChild(cloud); } } createInitialClouds(); // Game mechanics functions function spawnObstacle() { var obstacle = new Obstacle(); obstacle.x = 2100; obstacle.y = GROUND_LEVEL - obstacle.height / 2; obstacle.speed = gameSpeed; obstacles.push(obstacle); game.addChild(obstacle); } function spawnCoin() { var coin = new Coin(); coin.x = 2100; coin.y = GROUND_LEVEL - 150 - Math.random() * 200; // Random height coin.speed = gameSpeed; coins.push(coin); game.addChild(coin); } function spawnPowerUp() { var powerup = new PowerUp(); powerup.x = 2100; powerup.y = GROUND_LEVEL - 150 - Math.random() * 100; powerup.speed = gameSpeed; powerups.push(powerup); game.addChild(powerup); } function checkCollisions() { // Check obstacle collisions for (var i = obstacles.length - 1; i >= 0; i--) { if (player.intersects(obstacles[i]) && !player.isInvincible) { LK.getSound('hit').play(); LK.effects.flashScreen(0xff0000, 500); // Game over handling if (LK.getScore() > highScore) { highScore = LK.getScore(); storage.highScore = highScore; highScoreTxt.setText('HIGH: ' + Math.floor(highScore)); } LK.showGameOver(); isGameActive = false; return; } } // Check coin collisions for (var j = coins.length - 1; j >= 0; j--) { if (player.intersects(coins[j])) { LK.getSound('collect').play(); LK.setScore(LK.getScore() + 10); scoreTxt.setText(Math.floor(LK.getScore())); // Remove coin coins[j].destroy(); coins.splice(j, 1); } } // Check powerup collisions for (var k = powerups.length - 1; k >= 0; k--) { if (player.intersects(powerups[k])) { LK.getSound('powerup').play(); // Apply powerup effect (invincibility) player.makeInvincible(5000); // Remove powerup powerups[k].destroy(); powerups.splice(k, 1); } } } function updateObjects() { // Update game elements for (var i = obstacles.length - 1; i >= 0; i--) { obstacles[i].speed = gameSpeed; if (obstacles[i].x < -obstacles[i].width) { obstacles[i].destroy(); obstacles.splice(i, 1); } } for (var j = coins.length - 1; j >= 0; j--) { coins[j].speed = gameSpeed; if (coins[j].x < -coins[j].width) { coins[j].destroy(); coins.splice(j, 1); } } for (var k = powerups.length - 1; k >= 0; k--) { powerups[k].speed = gameSpeed; if (powerups[k].x < -powerups[k].width) { powerups[k].destroy(); powerups.splice(k, 1); } } } // Input handlers game.down = function (x, y, obj) { player.jump(); }; // Main game loop game.update = function () { if (!isGameActive) return; // Update distance and score distanceCounter += gameSpeed; LK.setScore(LK.getScore() + SCORE_MULTIPLIER); if (LK.ticks % 10 === 0) { scoreTxt.setText(Math.floor(LK.getScore())); } // Increase difficulty gameSpeed = BASE_SPEED + distanceCounter * DIFFICULTY_INCREASE_RATE; // Spawn obstacles if (distanceCounter - lastObstacleSpawn > obstacleSpawnDistance) { spawnObstacle(); lastObstacleSpawn = distanceCounter; // Make obstacles appear more frequently as game progresses obstacleSpawnDistance = 300 - Math.min(150, Math.floor(distanceCounter / 500)); } // Spawn coins if (distanceCounter - lastCoinSpawn > 500) { spawnCoin(); lastCoinSpawn = distanceCounter; } // Spawn powerups (less frequently) if (distanceCounter - lastPowerupSpawn > 2000) { spawnPowerUp(); lastPowerupSpawn = distanceCounter; } // Update all game objects updateObjects(); // Check for collisions checkCollisions(); }; // Start background music LK.playMusic('bgmusic', { fade: { start: 0, end: 0.4, duration: 1000 } });
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,341 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1", {
+ highScore: 0
+});
+
+/****
+* Classes
+****/
+var Cloud = Container.expand(function () {
+ var self = Container.call(this);
+ var cloudGraphics = self.attachAsset('cloud', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.7 + Math.random() * 0.3 // Varied transparency
+ });
+ self.speed = 0.5 + Math.random() * 1.5; // Varied speed
+ self.update = function () {
+ self.x -= self.speed;
+ // Reset cloud position when it goes off screen
+ if (self.x < -cloudGraphics.width) {
+ self.x = 2048 + cloudGraphics.width;
+ self.y = 200 + Math.random() * 300;
+ }
+ };
+ return self;
+});
+var Coin = Container.expand(function () {
+ var self = Container.call(this);
+ var coinGraphics = self.attachAsset('coin', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 0;
+ self.type = 'coin';
+ // Bobbing animation
+ tween(coinGraphics, {
+ y: 10
+ }, {
+ duration: 800,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(coinGraphics, {
+ y: -10
+ }, {
+ duration: 800,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ // Reset position and restart animation
+ coinGraphics.y = 0;
+ self.update();
+ }
+ });
+ }
+ });
+ self.update = function () {
+ self.x -= self.speed;
+ };
+ return self;
+});
+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.type = 'obstacle';
+ self.update = function () {
+ self.x -= self.speed;
+ };
+ return self;
+});
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocity = 0;
+ self.gravity = 0.8;
+ self.jumpForce = -18;
+ self.isJumping = false;
+ self.isInvincible = false;
+ self.update = function () {
+ // Apply gravity
+ self.velocity += self.gravity;
+ self.y += self.velocity;
+ // Ground collision
+ if (self.y > GROUND_LEVEL - playerGraphics.height / 2) {
+ self.y = GROUND_LEVEL - playerGraphics.height / 2;
+ self.velocity = 0;
+ self.isJumping = false;
+ }
+ };
+ self.jump = function () {
+ if (!self.isJumping) {
+ self.velocity = self.jumpForce;
+ self.isJumping = true;
+ LK.getSound('jump').play();
+ }
+ };
+ self.makeInvincible = function (duration) {
+ if (self.invincibleTimeout) {
+ LK.clearTimeout(self.invincibleTimeout);
+ }
+ self.isInvincible = true;
+ // Flash effect
+ var flashInterval = LK.setInterval(function () {
+ playerGraphics.alpha = playerGraphics.alpha === 1 ? 0.4 : 1;
+ }, 150);
+ self.invincibleTimeout = LK.setTimeout(function () {
+ self.isInvincible = false;
+ playerGraphics.alpha = 1;
+ LK.clearInterval(flashInterval);
+ }, duration);
+ };
+ return self;
+});
+var PowerUp = Container.expand(function () {
+ var self = Container.call(this);
+ var powerupGraphics = self.attachAsset('powerup', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 0;
+ self.type = 'powerup';
+ // Rotate animation
+ self.rotationSpeed = 0.02;
+ self.update = function () {
+ self.x -= self.speed;
+ powerupGraphics.rotation += self.rotationSpeed;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+// Constants
+var GROUND_LEVEL = 2500;
+var BASE_SPEED = 8;
+var SCORE_MULTIPLIER = 0.1;
+var DIFFICULTY_INCREASE_RATE = 0.0001;
+// Game variables
+var player;
+var ground;
+var obstacles = [];
+var coins = [];
+var powerups = [];
+var clouds = [];
+var gameSpeed = BASE_SPEED;
+var distanceCounter = 0;
+var lastObstacleSpawn = 0;
+var lastCoinSpawn = 0;
+var lastPowerupSpawn = 0;
+var obstacleSpawnDistance = 300;
+var isGameActive = true;
+var highScore = storage.highScore || 0;
+// Setup UI
+var scoreTxt = new Text2('0', {
+ size: 100,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var highScoreTxt = new Text2('HIGH: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+highScoreTxt.anchor.set(0.5, 0);
+highScoreTxt.y = 110;
+LK.gui.top.addChild(highScoreTxt);
+highScoreTxt.setText('HIGH: ' + highScore);
+// Initialize ground
+ground = LK.getAsset('ground', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: GROUND_LEVEL
+});
+game.addChild(ground);
+// Initialize player
+player = new Player();
+player.x = 300;
+player.y = GROUND_LEVEL - 100;
+game.addChild(player);
+// Initialize clouds
+function createInitialClouds() {
+ for (var i = 0; i < 5; i++) {
+ var cloud = new Cloud();
+ cloud.x = Math.random() * 2048;
+ cloud.y = 200 + Math.random() * 300;
+ clouds.push(cloud);
+ game.addChild(cloud);
+ }
+}
+createInitialClouds();
+// Game mechanics functions
+function spawnObstacle() {
+ var obstacle = new Obstacle();
+ obstacle.x = 2100;
+ obstacle.y = GROUND_LEVEL - obstacle.height / 2;
+ obstacle.speed = gameSpeed;
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
+}
+function spawnCoin() {
+ var coin = new Coin();
+ coin.x = 2100;
+ coin.y = GROUND_LEVEL - 150 - Math.random() * 200; // Random height
+ coin.speed = gameSpeed;
+ coins.push(coin);
+ game.addChild(coin);
+}
+function spawnPowerUp() {
+ var powerup = new PowerUp();
+ powerup.x = 2100;
+ powerup.y = GROUND_LEVEL - 150 - Math.random() * 100;
+ powerup.speed = gameSpeed;
+ powerups.push(powerup);
+ game.addChild(powerup);
+}
+function checkCollisions() {
+ // Check obstacle collisions
+ for (var i = obstacles.length - 1; i >= 0; i--) {
+ if (player.intersects(obstacles[i]) && !player.isInvincible) {
+ LK.getSound('hit').play();
+ LK.effects.flashScreen(0xff0000, 500);
+ // Game over handling
+ if (LK.getScore() > highScore) {
+ highScore = LK.getScore();
+ storage.highScore = highScore;
+ highScoreTxt.setText('HIGH: ' + Math.floor(highScore));
+ }
+ LK.showGameOver();
+ isGameActive = false;
+ return;
+ }
+ }
+ // Check coin collisions
+ for (var j = coins.length - 1; j >= 0; j--) {
+ if (player.intersects(coins[j])) {
+ LK.getSound('collect').play();
+ LK.setScore(LK.getScore() + 10);
+ scoreTxt.setText(Math.floor(LK.getScore()));
+ // Remove coin
+ coins[j].destroy();
+ coins.splice(j, 1);
+ }
+ }
+ // Check powerup collisions
+ for (var k = powerups.length - 1; k >= 0; k--) {
+ if (player.intersects(powerups[k])) {
+ LK.getSound('powerup').play();
+ // Apply powerup effect (invincibility)
+ player.makeInvincible(5000);
+ // Remove powerup
+ powerups[k].destroy();
+ powerups.splice(k, 1);
+ }
+ }
+}
+function updateObjects() {
+ // Update game elements
+ for (var i = obstacles.length - 1; i >= 0; i--) {
+ obstacles[i].speed = gameSpeed;
+ if (obstacles[i].x < -obstacles[i].width) {
+ obstacles[i].destroy();
+ obstacles.splice(i, 1);
+ }
+ }
+ for (var j = coins.length - 1; j >= 0; j--) {
+ coins[j].speed = gameSpeed;
+ if (coins[j].x < -coins[j].width) {
+ coins[j].destroy();
+ coins.splice(j, 1);
+ }
+ }
+ for (var k = powerups.length - 1; k >= 0; k--) {
+ powerups[k].speed = gameSpeed;
+ if (powerups[k].x < -powerups[k].width) {
+ powerups[k].destroy();
+ powerups.splice(k, 1);
+ }
+ }
+}
+// Input handlers
+game.down = function (x, y, obj) {
+ player.jump();
+};
+// Main game loop
+game.update = function () {
+ if (!isGameActive) return;
+ // Update distance and score
+ distanceCounter += gameSpeed;
+ LK.setScore(LK.getScore() + SCORE_MULTIPLIER);
+ if (LK.ticks % 10 === 0) {
+ scoreTxt.setText(Math.floor(LK.getScore()));
+ }
+ // Increase difficulty
+ gameSpeed = BASE_SPEED + distanceCounter * DIFFICULTY_INCREASE_RATE;
+ // Spawn obstacles
+ if (distanceCounter - lastObstacleSpawn > obstacleSpawnDistance) {
+ spawnObstacle();
+ lastObstacleSpawn = distanceCounter;
+ // Make obstacles appear more frequently as game progresses
+ obstacleSpawnDistance = 300 - Math.min(150, Math.floor(distanceCounter / 500));
+ }
+ // Spawn coins
+ if (distanceCounter - lastCoinSpawn > 500) {
+ spawnCoin();
+ lastCoinSpawn = distanceCounter;
+ }
+ // Spawn powerups (less frequently)
+ if (distanceCounter - lastPowerupSpawn > 2000) {
+ spawnPowerUp();
+ lastPowerupSpawn = distanceCounter;
+ }
+ // Update all game objects
+ updateObjects();
+ // Check for collisions
+ checkCollisions();
+};
+// Start background music
+LK.playMusic('bgmusic', {
+ fade: {
+ start: 0,
+ end: 0.4,
+ duration: 1000
+ }
});
\ No newline at end of file