/****
* Plugins
****/
var tween = LK.import("@upit/tween.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 = 10;
self.lastY = self.y;
self.update = function () {
self.lastY = self.y;
self.y += 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.speed = 0;
self.targetX = 1024;
self.laneWidth = 400;
self.moveSpeed = 15;
self.update = function () {
// Smooth movement toward target X
if (self.x < self.targetX - 5) {
self.x += self.moveSpeed;
} else if (self.x > self.targetX + 5) {
self.x -= self.moveSpeed;
} else {
self.x = self.targetX;
}
};
self.setTargetLane = function (laneIndex) {
var lanes = [512, 1024, 1536];
if (laneIndex >= 0 && laneIndex < lanes.length) {
self.targetX = lanes[laneIndex];
}
};
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 = 8;
self.type = 'multiplier'; // 'multiplier' or 'invincibility'
self.lastY = self.y;
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
// Slight bobbing animation
self.x += Math.sin(LK.ticks * 0.05) * 0.3;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var player = game.addChild(new Player());
player.x = 1024;
player.y = 2400;
var obstacles = [];
var powerups = [];
var currentLane = 1; // 0 = left, 1 = center, 2 = right
var score = 0;
var distanceTraveled = 0;
var gameSpeed = 10;
var baseGameSpeed = 10;
var multiplier = 1;
var invincibilityActive = false;
var invincibilityTime = 0;
var obstaclSpawnRate = 30;
var powerupSpawnRate = 150;
var difficultyTimer = 0;
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var distanceTxt = new Text2('0m', {
size: 80,
fill: 0xFFFFFF
});
distanceTxt.anchor.set(0.5, 0);
distanceTxt.x = 100;
LK.gui.topRight.addChild(distanceTxt);
var speedTxt = new Text2('Speed: 1.0x', {
size: 70,
fill: 0xFFFFFF
});
speedTxt.anchor.set(0, 0);
LK.gui.bottomLeft.addChild(speedTxt);
function updateScore() {
var displayScore = Math.floor(score);
scoreTxt.setText(displayScore);
}
function updateDistance() {
var displayDistance = Math.floor(distanceTraveled / 100);
distanceTxt.setText(displayDistance + 'm');
}
function updateSpeed() {
var speedMultiplier = (baseGameSpeed / 10).toFixed(1);
speedTxt.setText('Speed: ' + speedMultiplier + 'x');
}
function spawnObstacle() {
var lanes = [512, 1024, 1536];
var randomLane = Math.floor(Math.random() * lanes.length);
var obstacle = new Obstacle();
obstacle.x = lanes[randomLane];
obstacle.y = -100;
obstacle.speed = baseGameSpeed;
obstacle.lastY = obstacle.y;
game.addChild(obstacle);
obstacles.push(obstacle);
}
function spawnPowerUp() {
var lanes = [512, 1024, 1536];
var randomLane = Math.floor(Math.random() * lanes.length);
var powerupType = Math.random() > 0.5 ? 'multiplier' : 'invincibility';
var powerup = new PowerUp();
powerup.x = lanes[randomLane];
powerup.y = -100;
powerup.speed = baseGameSpeed * 0.8;
powerup.type = powerupType;
powerup.lastY = powerup.y;
game.addChild(powerup);
powerups.push(powerup);
}
function activatePowerUp(type) {
if (type === 'multiplier') {
multiplier = 2;
tween(scoreTxt, {
scale: 1.2
}, {
duration: 300,
easing: tween.easeOut
});
LK.setTimeout(function () {
multiplier = 1;
}, 5000);
} else if (type === 'invincibility') {
invincibilityActive = true;
invincibilityTime = 300; // 5 seconds at 60fps
player.alpha = 0.7;
tween(player, {
alpha: 1
}, {
duration: 300
});
}
LK.getSound('powerup').play();
}
function endGame() {
LK.effects.flashScreen(0xff0000, 500);
LK.getSound('collision').play();
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
}
game.down = function (x, y, obj) {
// Determine which lane to move to based on tap position
if (x < 682) {
currentLane = 0; // Left lane
player.setTargetLane(0);
} else if (x > 1365) {
currentLane = 2; // Right lane
player.setTargetLane(2);
} else {
currentLane = 1; // Center lane
player.setTargetLane(1);
}
};
game.update = function () {
// Update player
player.update();
// Increase distance and score based on survival
distanceTraveled += baseGameSpeed;
score += baseGameSpeed * multiplier * 0.1;
updateScore();
updateDistance();
// Difficulty progression
difficultyTimer++;
if (difficultyTimer > 600) {
// Every 10 seconds
difficultyTimer = 0;
baseGameSpeed += 0.5;
obstaclSpawnRate = Math.max(15, obstaclSpawnRate - 1);
updateSpeed();
}
// Handle invincibility
if (invincibilityActive) {
invincibilityTime--;
if (invincibilityTime <= 0) {
invincibilityActive = false;
player.alpha = 1;
}
}
// Spawn obstacles
if (LK.ticks % obstaclSpawnRate === 0) {
spawnObstacle();
}
// Spawn power-ups
if (LK.ticks % powerupSpawnRate === 0) {
spawnPowerUp();
}
// Update and check obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
obstacle.update();
// Remove off-screen obstacles
if (obstacle.lastY >= -100 && obstacle.y > 2800) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
// Check collision with player
if (obstacle.intersects(player) && !invincibilityActive) {
endGame();
return;
}
}
// Update and check power-ups
for (var j = powerups.length - 1; j >= 0; j--) {
var powerup = powerups[j];
powerup.update();
// Remove off-screen power-ups
if (powerup.lastY >= -100 && powerup.y > 2800) {
powerup.destroy();
powerups.splice(j, 1);
continue;
}
// Check collision with player
if (powerup.intersects(player)) {
activatePowerUp(powerup.type);
powerup.destroy();
powerups.splice(j, 1);
score += 500 * multiplier;
updateScore();
}
}
};
LK.playMusic('bgmusic', {
loop: true
}); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,265 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.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 = 10;
+ self.lastY = self.y;
+ self.update = function () {
+ self.lastY = self.y;
+ self.y += 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.speed = 0;
+ self.targetX = 1024;
+ self.laneWidth = 400;
+ self.moveSpeed = 15;
+ self.update = function () {
+ // Smooth movement toward target X
+ if (self.x < self.targetX - 5) {
+ self.x += self.moveSpeed;
+ } else if (self.x > self.targetX + 5) {
+ self.x -= self.moveSpeed;
+ } else {
+ self.x = self.targetX;
+ }
+ };
+ self.setTargetLane = function (laneIndex) {
+ var lanes = [512, 1024, 1536];
+ if (laneIndex >= 0 && laneIndex < lanes.length) {
+ self.targetX = lanes[laneIndex];
+ }
+ };
+ 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 = 8;
+ self.type = 'multiplier'; // 'multiplier' or 'invincibility'
+ self.lastY = self.y;
+ self.update = function () {
+ self.lastY = self.y;
+ self.y += self.speed;
+ // Slight bobbing animation
+ self.x += Math.sin(LK.ticks * 0.05) * 0.3;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
+ backgroundColor: 0x1a1a2e
+});
+
+/****
+* Game Code
+****/
+var player = game.addChild(new Player());
+player.x = 1024;
+player.y = 2400;
+var obstacles = [];
+var powerups = [];
+var currentLane = 1; // 0 = left, 1 = center, 2 = right
+var score = 0;
+var distanceTraveled = 0;
+var gameSpeed = 10;
+var baseGameSpeed = 10;
+var multiplier = 1;
+var invincibilityActive = false;
+var invincibilityTime = 0;
+var obstaclSpawnRate = 30;
+var powerupSpawnRate = 150;
+var difficultyTimer = 0;
+var scoreTxt = new Text2('0', {
+ size: 120,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var distanceTxt = new Text2('0m', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+distanceTxt.anchor.set(0.5, 0);
+distanceTxt.x = 100;
+LK.gui.topRight.addChild(distanceTxt);
+var speedTxt = new Text2('Speed: 1.0x', {
+ size: 70,
+ fill: 0xFFFFFF
+});
+speedTxt.anchor.set(0, 0);
+LK.gui.bottomLeft.addChild(speedTxt);
+function updateScore() {
+ var displayScore = Math.floor(score);
+ scoreTxt.setText(displayScore);
+}
+function updateDistance() {
+ var displayDistance = Math.floor(distanceTraveled / 100);
+ distanceTxt.setText(displayDistance + 'm');
+}
+function updateSpeed() {
+ var speedMultiplier = (baseGameSpeed / 10).toFixed(1);
+ speedTxt.setText('Speed: ' + speedMultiplier + 'x');
+}
+function spawnObstacle() {
+ var lanes = [512, 1024, 1536];
+ var randomLane = Math.floor(Math.random() * lanes.length);
+ var obstacle = new Obstacle();
+ obstacle.x = lanes[randomLane];
+ obstacle.y = -100;
+ obstacle.speed = baseGameSpeed;
+ obstacle.lastY = obstacle.y;
+ game.addChild(obstacle);
+ obstacles.push(obstacle);
+}
+function spawnPowerUp() {
+ var lanes = [512, 1024, 1536];
+ var randomLane = Math.floor(Math.random() * lanes.length);
+ var powerupType = Math.random() > 0.5 ? 'multiplier' : 'invincibility';
+ var powerup = new PowerUp();
+ powerup.x = lanes[randomLane];
+ powerup.y = -100;
+ powerup.speed = baseGameSpeed * 0.8;
+ powerup.type = powerupType;
+ powerup.lastY = powerup.y;
+ game.addChild(powerup);
+ powerups.push(powerup);
+}
+function activatePowerUp(type) {
+ if (type === 'multiplier') {
+ multiplier = 2;
+ tween(scoreTxt, {
+ scale: 1.2
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ LK.setTimeout(function () {
+ multiplier = 1;
+ }, 5000);
+ } else if (type === 'invincibility') {
+ invincibilityActive = true;
+ invincibilityTime = 300; // 5 seconds at 60fps
+ player.alpha = 0.7;
+ tween(player, {
+ alpha: 1
+ }, {
+ duration: 300
+ });
+ }
+ LK.getSound('powerup').play();
+}
+function endGame() {
+ LK.effects.flashScreen(0xff0000, 500);
+ LK.getSound('collision').play();
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 500);
+}
+game.down = function (x, y, obj) {
+ // Determine which lane to move to based on tap position
+ if (x < 682) {
+ currentLane = 0; // Left lane
+ player.setTargetLane(0);
+ } else if (x > 1365) {
+ currentLane = 2; // Right lane
+ player.setTargetLane(2);
+ } else {
+ currentLane = 1; // Center lane
+ player.setTargetLane(1);
+ }
+};
+game.update = function () {
+ // Update player
+ player.update();
+ // Increase distance and score based on survival
+ distanceTraveled += baseGameSpeed;
+ score += baseGameSpeed * multiplier * 0.1;
+ updateScore();
+ updateDistance();
+ // Difficulty progression
+ difficultyTimer++;
+ if (difficultyTimer > 600) {
+ // Every 10 seconds
+ difficultyTimer = 0;
+ baseGameSpeed += 0.5;
+ obstaclSpawnRate = Math.max(15, obstaclSpawnRate - 1);
+ updateSpeed();
+ }
+ // Handle invincibility
+ if (invincibilityActive) {
+ invincibilityTime--;
+ if (invincibilityTime <= 0) {
+ invincibilityActive = false;
+ player.alpha = 1;
+ }
+ }
+ // Spawn obstacles
+ if (LK.ticks % obstaclSpawnRate === 0) {
+ spawnObstacle();
+ }
+ // Spawn power-ups
+ if (LK.ticks % powerupSpawnRate === 0) {
+ spawnPowerUp();
+ }
+ // Update and check obstacles
+ for (var i = obstacles.length - 1; i >= 0; i--) {
+ var obstacle = obstacles[i];
+ obstacle.update();
+ // Remove off-screen obstacles
+ if (obstacle.lastY >= -100 && obstacle.y > 2800) {
+ obstacle.destroy();
+ obstacles.splice(i, 1);
+ continue;
+ }
+ // Check collision with player
+ if (obstacle.intersects(player) && !invincibilityActive) {
+ endGame();
+ return;
+ }
+ }
+ // Update and check power-ups
+ for (var j = powerups.length - 1; j >= 0; j--) {
+ var powerup = powerups[j];
+ powerup.update();
+ // Remove off-screen power-ups
+ if (powerup.lastY >= -100 && powerup.y > 2800) {
+ powerup.destroy();
+ powerups.splice(j, 1);
+ continue;
+ }
+ // Check collision with player
+ if (powerup.intersects(player)) {
+ activatePowerUp(powerup.type);
+ powerup.destroy();
+ powerups.splice(j, 1);
+ score += 500 * multiplier;
+ updateScore();
+ }
+ }
+};
+LK.playMusic('bgmusic', {
+ loop: true
});
\ No newline at end of file