/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.lane = 0;
self.speed = 15;
self.rotation = 0;
self.lastY = 0;
self.collected = false;
self.update = function () {
self.y += self.speed;
self.rotation += 0.1;
coinGraphics.rotation = self.rotation;
self.lastY = self.y;
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.lane = 0;
self.speed = 15;
self.lastY = 0;
self.update = function () {
self.y += self.speed;
self.lastY = self.y;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.lane = 1; // 0 = left, 1 = center, 2 = right
self.isJumping = false;
self.jumpVelocity = 0;
self.jumpHeight = 300;
self.jumpPower = -20;
self.gravity = 0.8;
self.baseY = 0;
self.isInvincible = false;
self.invincibilityTimer = 0;
self.update = function () {
// Apply gravity when jumping
if (self.isJumping) {
self.jumpVelocity += self.gravity;
self.y += self.jumpVelocity;
if (self.y >= self.baseY) {
self.y = self.baseY;
self.isJumping = false;
self.jumpVelocity = 0;
}
}
// Update invincibility flash effect
if (self.isInvincible) {
self.invincibilityTimer--;
playerGraphics.alpha = self.invincibilityTimer % 10 < 5 ? 0.5 : 1;
if (self.invincibilityTimer <= 0) {
self.isInvincible = false;
playerGraphics.alpha = 1;
}
}
};
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.jumpVelocity = self.jumpPower;
LK.getSound('jump').play();
}
};
self.moveToLane = function (laneIndex) {
if (laneIndex >= 0 && laneIndex <= 2) {
self.lane = laneIndex;
var lanePositions = [512, 1024, 1536];
tween(self, {
x: lanePositions[laneIndex]
}, {
duration: 150,
easing: tween.easeOut
});
}
};
self.activateInvincibility = function (duration) {
self.isInvincible = true;
self.invincibilityTimer = 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.lane = 0;
self.speed = 15;
self.type = 'invincibility'; // invincibility, speed_boost, magnet
self.lastY = 0;
self.collected = false;
self.pulseScale = 1;
self.pulseDirection = 1;
self.update = function () {
self.y += self.speed;
self.pulseScale += 0.02 * self.pulseDirection;
if (self.pulseScale > 1.15) {
self.pulseDirection = -1;
} else if (self.pulseScale < 0.85) {
self.pulseDirection = 1;
}
powerupGraphics.scaleX = self.pulseScale;
powerupGraphics.scaleY = self.pulseScale;
self.lastY = self.y;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
var player = game.addChild(new Player());
player.baseY = 2300;
player.y = player.baseY;
player.x = 1024;
player.moveToLane(1);
var obstacles = [];
var coins = [];
var powerups = [];
var score = 0;
var distance = 0;
var gameSpeed = 15;
var baseSpeed = 15;
var speedMultiplier = 1;
var spawnTimer = 0;
var speedIncreaseTimer = 0;
var speedIncreaseInterval = 600; // 10 seconds at 60 FPS
var maxHighScore = storage.highScore || 0;
var scoreTxt = new Text2('Score: 0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreTxt);
var distanceTxt = new Text2('Distance: 0', {
size: 100,
fill: 0xFFFFFF
});
distanceTxt.anchor.set(0, 0.5);
LK.gui.left.addChild(distanceTxt);
var multiplierTxt = new Text2('Speed: 1.0x', {
size: 90,
fill: 0xFFD700
});
multiplierTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(multiplierTxt);
var lanePositions = [512, 1024, 1536];
var swipeStartX = null;
var swipeStartY = null;
function spawnObstacle() {
var newObstacle = game.addChild(new Obstacle());
newObstacle.lane = Math.floor(Math.random() * 3);
newObstacle.x = lanePositions[newObstacle.lane];
newObstacle.y = -150;
newObstacle.speed = gameSpeed;
newObstacle.lastY = newObstacle.y;
obstacles.push(newObstacle);
}
function spawnCoin() {
var newCoin = game.addChild(new Coin());
newCoin.lane = Math.floor(Math.random() * 3);
newCoin.x = lanePositions[newCoin.lane];
newCoin.y = -80;
newCoin.speed = gameSpeed;
newCoin.lastY = newCoin.y;
coins.push(newCoin);
}
function spawnPowerUp() {
var newPowerUp = game.addChild(new PowerUp());
newPowerUp.lane = Math.floor(Math.random() * 3);
newPowerUp.x = lanePositions[newPowerUp.lane];
newPowerUp.y = -90;
newPowerUp.speed = gameSpeed;
newPowerUp.lastY = newPowerUp.y;
var powerupTypes = ['invincibility', 'speed_boost', 'magnet'];
newPowerUp.type = powerupTypes[Math.floor(Math.random() * powerupTypes.length)];
powerups.push(newPowerUp);
}
game.down = function (x, y, obj) {
swipeStartX = x;
swipeStartY = y;
};
game.up = function (x, y, obj) {
if (swipeStartX !== null && swipeStartY !== null) {
var deltaX = x - swipeStartX;
var deltaY = y - swipeStartY;
var absDeltaX = Math.abs(deltaX);
var absDeltaY = Math.abs(deltaY);
if (absDeltaY > 100 && absDeltaY > absDeltaX) {
player.jump();
} else if (absDeltaX > 100 && absDeltaX > absDeltaY) {
if (deltaX < 0) {
// Swipe left
player.moveToLane(player.lane - 1);
} else {
// Swipe right
player.moveToLane(player.lane + 1);
}
}
}
swipeStartX = null;
swipeStartY = null;
};
game.update = function () {
// Update game speed
speedIncreaseTimer++;
if (speedIncreaseTimer >= speedIncreaseInterval) {
speedIncreaseTimer = 0;
speedMultiplier += 0.1;
gameSpeed = baseSpeed * speedMultiplier;
}
// Update score and distance
distance += gameSpeed / 15;
score = Math.floor(distance);
scoreTxt.setText('Score: ' + score);
distanceTxt.setText('Distance: ' + Math.floor(distance / 10));
multiplierTxt.setText('Speed: ' + speedMultiplier.toFixed(1) + 'x');
// Spawn obstacles
spawnTimer++;
if (spawnTimer >= Math.max(30, 120 - Math.floor(speedMultiplier * 10))) {
spawnTimer = 0;
spawnObstacle();
}
// Spawn coins
if (spawnTimer % 40 === 0 && Math.random() > 0.5) {
spawnCoin();
}
// Spawn power-ups
if (spawnTimer % 80 === 0 && Math.random() > 0.7) {
spawnPowerUp();
}
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
if (obstacle.lastY <= 2732 && obstacle.y > 2732) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
var wasIntersecting = false;
if (!player.isInvincible) {
wasIntersecting = player.intersects(obstacle);
if (wasIntersecting) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xFF0000, 500);
LK.showGameOver();
}
}
}
// Update coins
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
if (coin.lastY <= 2732 && coin.y > 2732) {
coin.destroy();
coins.splice(i, 1);
continue;
}
if (!coin.collected && player.intersects(coin)) {
coin.collected = true;
score += 10;
LK.getSound('coin_collect').play();
LK.effects.flashObject(coin, 0xFFFFFF, 200);
coin.destroy();
coins.splice(i, 1);
continue;
}
}
// Update power-ups
for (var i = powerups.length - 1; i >= 0; i--) {
var powerup = powerups[i];
if (powerup.lastY <= 2732 && powerup.y > 2732) {
powerup.destroy();
powerups.splice(i, 1);
continue;
}
if (!powerup.collected && player.intersects(powerup)) {
powerup.collected = true;
LK.getSound('powerup_collect').play();
LK.effects.flashObject(powerup, 0x00FF00, 300);
if (powerup.type === 'invincibility') {
player.activateInvincibility(300);
score += 50;
} else if (powerup.type === 'speed_boost') {
speedMultiplier += 0.2;
gameSpeed = baseSpeed * speedMultiplier;
score += 30;
} else if (powerup.type === 'magnet') {
score += 100;
// Attract nearby coins
for (var j = 0; j < coins.length; j++) {
if (coins[j]) {
coins[j].speed += 10;
}
}
}
powerup.destroy();
powerups.splice(i, 1);
continue;
}
}
// Update high score
if (score > maxHighScore) {
maxHighScore = score;
storage.highScore = maxHighScore;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,337 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var Coin = Container.expand(function () {
+ var self = Container.call(this);
+ var coinGraphics = self.attachAsset('coin', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.lane = 0;
+ self.speed = 15;
+ self.rotation = 0;
+ self.lastY = 0;
+ self.collected = false;
+ self.update = function () {
+ self.y += self.speed;
+ self.rotation += 0.1;
+ coinGraphics.rotation = self.rotation;
+ self.lastY = self.y;
+ };
+ return self;
+});
+var Obstacle = Container.expand(function () {
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.lane = 0;
+ self.speed = 15;
+ self.lastY = 0;
+ self.update = function () {
+ self.y += self.speed;
+ self.lastY = self.y;
+ };
+ return self;
+});
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.lane = 1; // 0 = left, 1 = center, 2 = right
+ self.isJumping = false;
+ self.jumpVelocity = 0;
+ self.jumpHeight = 300;
+ self.jumpPower = -20;
+ self.gravity = 0.8;
+ self.baseY = 0;
+ self.isInvincible = false;
+ self.invincibilityTimer = 0;
+ self.update = function () {
+ // Apply gravity when jumping
+ if (self.isJumping) {
+ self.jumpVelocity += self.gravity;
+ self.y += self.jumpVelocity;
+ if (self.y >= self.baseY) {
+ self.y = self.baseY;
+ self.isJumping = false;
+ self.jumpVelocity = 0;
+ }
+ }
+ // Update invincibility flash effect
+ if (self.isInvincible) {
+ self.invincibilityTimer--;
+ playerGraphics.alpha = self.invincibilityTimer % 10 < 5 ? 0.5 : 1;
+ if (self.invincibilityTimer <= 0) {
+ self.isInvincible = false;
+ playerGraphics.alpha = 1;
+ }
+ }
+ };
+ self.jump = function () {
+ if (!self.isJumping) {
+ self.isJumping = true;
+ self.jumpVelocity = self.jumpPower;
+ LK.getSound('jump').play();
+ }
+ };
+ self.moveToLane = function (laneIndex) {
+ if (laneIndex >= 0 && laneIndex <= 2) {
+ self.lane = laneIndex;
+ var lanePositions = [512, 1024, 1536];
+ tween(self, {
+ x: lanePositions[laneIndex]
+ }, {
+ duration: 150,
+ easing: tween.easeOut
+ });
+ }
+ };
+ self.activateInvincibility = function (duration) {
+ self.isInvincible = true;
+ self.invincibilityTimer = 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.lane = 0;
+ self.speed = 15;
+ self.type = 'invincibility'; // invincibility, speed_boost, magnet
+ self.lastY = 0;
+ self.collected = false;
+ self.pulseScale = 1;
+ self.pulseDirection = 1;
+ self.update = function () {
+ self.y += self.speed;
+ self.pulseScale += 0.02 * self.pulseDirection;
+ if (self.pulseScale > 1.15) {
+ self.pulseDirection = -1;
+ } else if (self.pulseScale < 0.85) {
+ self.pulseDirection = 1;
+ }
+ powerupGraphics.scaleX = self.pulseScale;
+ powerupGraphics.scaleY = self.pulseScale;
+ self.lastY = self.y;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1a1a1a
+});
+
+/****
+* Game Code
+****/
+var player = game.addChild(new Player());
+player.baseY = 2300;
+player.y = player.baseY;
+player.x = 1024;
+player.moveToLane(1);
+var obstacles = [];
+var coins = [];
+var powerups = [];
+var score = 0;
+var distance = 0;
+var gameSpeed = 15;
+var baseSpeed = 15;
+var speedMultiplier = 1;
+var spawnTimer = 0;
+var speedIncreaseTimer = 0;
+var speedIncreaseInterval = 600; // 10 seconds at 60 FPS
+var maxHighScore = storage.highScore || 0;
+var scoreTxt = new Text2('Score: 0', {
+ size: 120,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0, 0);
+LK.gui.topRight.addChild(scoreTxt);
+var distanceTxt = new Text2('Distance: 0', {
+ size: 100,
+ fill: 0xFFFFFF
+});
+distanceTxt.anchor.set(0, 0.5);
+LK.gui.left.addChild(distanceTxt);
+var multiplierTxt = new Text2('Speed: 1.0x', {
+ size: 90,
+ fill: 0xFFD700
+});
+multiplierTxt.anchor.set(0, 0);
+LK.gui.topRight.addChild(multiplierTxt);
+var lanePositions = [512, 1024, 1536];
+var swipeStartX = null;
+var swipeStartY = null;
+function spawnObstacle() {
+ var newObstacle = game.addChild(new Obstacle());
+ newObstacle.lane = Math.floor(Math.random() * 3);
+ newObstacle.x = lanePositions[newObstacle.lane];
+ newObstacle.y = -150;
+ newObstacle.speed = gameSpeed;
+ newObstacle.lastY = newObstacle.y;
+ obstacles.push(newObstacle);
+}
+function spawnCoin() {
+ var newCoin = game.addChild(new Coin());
+ newCoin.lane = Math.floor(Math.random() * 3);
+ newCoin.x = lanePositions[newCoin.lane];
+ newCoin.y = -80;
+ newCoin.speed = gameSpeed;
+ newCoin.lastY = newCoin.y;
+ coins.push(newCoin);
+}
+function spawnPowerUp() {
+ var newPowerUp = game.addChild(new PowerUp());
+ newPowerUp.lane = Math.floor(Math.random() * 3);
+ newPowerUp.x = lanePositions[newPowerUp.lane];
+ newPowerUp.y = -90;
+ newPowerUp.speed = gameSpeed;
+ newPowerUp.lastY = newPowerUp.y;
+ var powerupTypes = ['invincibility', 'speed_boost', 'magnet'];
+ newPowerUp.type = powerupTypes[Math.floor(Math.random() * powerupTypes.length)];
+ powerups.push(newPowerUp);
+}
+game.down = function (x, y, obj) {
+ swipeStartX = x;
+ swipeStartY = y;
+};
+game.up = function (x, y, obj) {
+ if (swipeStartX !== null && swipeStartY !== null) {
+ var deltaX = x - swipeStartX;
+ var deltaY = y - swipeStartY;
+ var absDeltaX = Math.abs(deltaX);
+ var absDeltaY = Math.abs(deltaY);
+ if (absDeltaY > 100 && absDeltaY > absDeltaX) {
+ player.jump();
+ } else if (absDeltaX > 100 && absDeltaX > absDeltaY) {
+ if (deltaX < 0) {
+ // Swipe left
+ player.moveToLane(player.lane - 1);
+ } else {
+ // Swipe right
+ player.moveToLane(player.lane + 1);
+ }
+ }
+ }
+ swipeStartX = null;
+ swipeStartY = null;
+};
+game.update = function () {
+ // Update game speed
+ speedIncreaseTimer++;
+ if (speedIncreaseTimer >= speedIncreaseInterval) {
+ speedIncreaseTimer = 0;
+ speedMultiplier += 0.1;
+ gameSpeed = baseSpeed * speedMultiplier;
+ }
+ // Update score and distance
+ distance += gameSpeed / 15;
+ score = Math.floor(distance);
+ scoreTxt.setText('Score: ' + score);
+ distanceTxt.setText('Distance: ' + Math.floor(distance / 10));
+ multiplierTxt.setText('Speed: ' + speedMultiplier.toFixed(1) + 'x');
+ // Spawn obstacles
+ spawnTimer++;
+ if (spawnTimer >= Math.max(30, 120 - Math.floor(speedMultiplier * 10))) {
+ spawnTimer = 0;
+ spawnObstacle();
+ }
+ // Spawn coins
+ if (spawnTimer % 40 === 0 && Math.random() > 0.5) {
+ spawnCoin();
+ }
+ // Spawn power-ups
+ if (spawnTimer % 80 === 0 && Math.random() > 0.7) {
+ spawnPowerUp();
+ }
+ // Update obstacles
+ for (var i = obstacles.length - 1; i >= 0; i--) {
+ var obstacle = obstacles[i];
+ if (obstacle.lastY <= 2732 && obstacle.y > 2732) {
+ obstacle.destroy();
+ obstacles.splice(i, 1);
+ continue;
+ }
+ var wasIntersecting = false;
+ if (!player.isInvincible) {
+ wasIntersecting = player.intersects(obstacle);
+ if (wasIntersecting) {
+ LK.getSound('hit').play();
+ LK.effects.flashScreen(0xFF0000, 500);
+ LK.showGameOver();
+ }
+ }
+ }
+ // Update coins
+ for (var i = coins.length - 1; i >= 0; i--) {
+ var coin = coins[i];
+ if (coin.lastY <= 2732 && coin.y > 2732) {
+ coin.destroy();
+ coins.splice(i, 1);
+ continue;
+ }
+ if (!coin.collected && player.intersects(coin)) {
+ coin.collected = true;
+ score += 10;
+ LK.getSound('coin_collect').play();
+ LK.effects.flashObject(coin, 0xFFFFFF, 200);
+ coin.destroy();
+ coins.splice(i, 1);
+ continue;
+ }
+ }
+ // Update power-ups
+ for (var i = powerups.length - 1; i >= 0; i--) {
+ var powerup = powerups[i];
+ if (powerup.lastY <= 2732 && powerup.y > 2732) {
+ powerup.destroy();
+ powerups.splice(i, 1);
+ continue;
+ }
+ if (!powerup.collected && player.intersects(powerup)) {
+ powerup.collected = true;
+ LK.getSound('powerup_collect').play();
+ LK.effects.flashObject(powerup, 0x00FF00, 300);
+ if (powerup.type === 'invincibility') {
+ player.activateInvincibility(300);
+ score += 50;
+ } else if (powerup.type === 'speed_boost') {
+ speedMultiplier += 0.2;
+ gameSpeed = baseSpeed * speedMultiplier;
+ score += 30;
+ } else if (powerup.type === 'magnet') {
+ score += 100;
+ // Attract nearby coins
+ for (var j = 0; j < coins.length; j++) {
+ if (coins[j]) {
+ coins[j].speed += 10;
+ }
+ }
+ }
+ powerup.destroy();
+ powerups.splice(i, 1);
+ continue;
+ }
+ }
+ // Update high score
+ if (score > maxHighScore) {
+ maxHighScore = score;
+ storage.highScore = maxHighScore;
+ }
+};
\ No newline at end of file
coin. In-Game asset. 2d. High contrast. No shadows
power spray. In-Game asset. 2d. High contrast. No shadows
cute man. In-Game asset. 2d. High contrast. No shadows
duvar. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
lane. In-Game asset. 2d. High contrast. No shadows