User prompt
dikey olsun yollar ve arasında boşluk olmasın, sağa veya sola kaydırdığında daha hızlı hareket etsin , yukarı kaydırdığında üzerinden atlayabileceği daha küçük otobüsler de olsun
User prompt
yol sabit kalsın otobüsler ilerlesin
User prompt
otobüsler birbirinin üzerine çıkmasın aynı anda otobüslerin hızı aynı olsun zaman ilerledikçe tüm otobüsler yavaş yavaş hızlansın
User prompt
otobüsler oyuncuyu ezsin oyuncu otobüslerin üzerinden geçemesin oyuncu yandığında mavi parça bölünerek küçük parçalara ayrılsın sanki parçalanmış gibi ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
oyun ekranı 4 eş parçaya bölünsün gri zemin üzerinde her 4S parçada beyaz şeritler olsun yol gibi görünsün binalar olmasın otobüsler olsun
User prompt
paralar dışında hiç bir şey başka bir şeyin üzerine gelmesin
Code edit (1 edits merged)
Please save this source code
User prompt
Urban Dash
User prompt
subway surf oyunun aynısını yap
Initial prompt
önce bi subway surf ün aynısını yap
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0
});
/****
* Classes
****/
var Bus = Container.expand(function () {
var self = Container.call(this);
var busSprite = self.attachAsset('bus', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = busSprite.width;
self.height = busSprite.height;
self.speed = 1; // All buses have the same base speed
self.lane = 0; // 0-3 for the four road lanes
self.update = function () {
self.lastX = self.x;
// Move vertically from top to bottom
self.y += gameSpeed * self.speed;
if (self.y > 2732 + self.height) {
self.resetPosition();
}
};
self.resetPosition = function () {
// Reset to top of screen
self.y = -self.height - Math.random() * 300;
// Randomly assign to a lane
self.lane = Math.floor(Math.random() * 4);
self.x = roadPositions[self.lane];
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinSprite = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = coinSprite.width;
self.height = coinSprite.height;
self.lane = 1;
// Coin animation (rotate)
LK.setInterval(function () {
tween(coinSprite, {
rotation: coinSprite.rotation + Math.PI * 2
}, {
duration: 1000
});
}, 1000);
self.update = function () {
self.y += gameSpeed;
if (self.y > 2732 + self.height) {
self.destroy();
}
};
return self;
});
var MiniBus = Container.expand(function () {
var self = Container.call(this);
var busSprite = self.attachAsset('bus', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
// Smaller than regular buses
scaleY: 0.6
});
self.width = busSprite.width * 0.6;
self.height = busSprite.height * 0.6;
self.speed = 1.2; // Slightly faster than regular buses
self.lane = 0; // 0-3 for the four road lanes
busSprite.tint = 0x99CC99; // Different color to distinguish from regular buses
self.update = function () {
self.lastX = self.x;
// Move vertically from top to bottom
self.y += gameSpeed * self.speed;
if (self.y > 2732 + self.height) {
self.resetPosition();
}
};
self.resetPosition = function () {
// Reset to top of screen
self.y = -self.height - Math.random() * 300;
// Randomly assign to a lane
self.lane = Math.floor(Math.random() * 4);
self.x = roadPositions[self.lane];
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleSprite = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = obstacleSprite.width;
self.height = obstacleSprite.height;
self.lane = 1;
self.type = "normal"; // normal, low, high
self.setType = function (newType) {
self.type = newType;
if (newType === "low") {
obstacleSprite.scaleY = 0.5;
obstacleSprite.y = obstacleSprite.height / 4;
} else if (newType === "high") {
obstacleSprite.scaleY = 0.7;
obstacleSprite.y = -obstacleSprite.height / 4;
}
};
self.update = function () {
self.y += gameSpeed;
if (self.y > 2732 + self.height) {
self.destroy();
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerSprite = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = playerSprite.width;
self.height = playerSprite.height;
self.lane = 1; // 0=left, 1=center, 2=right
self.isJumping = false;
self.isSliding = false;
self.hasShield = false;
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
var startY = self.y;
LK.getSound('jump').play();
tween(self, {
y: startY - 300
}, {
duration: 400,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
y: startY
}, {
duration: 400,
easing: tween.easeIn,
onFinish: function onFinish() {
self.isJumping = false;
}
});
}
});
}
};
self.slide = function () {
if (!self.isSliding && !self.isJumping) {
self.isSliding = true;
var originalHeight = playerSprite.height;
tween(playerSprite, {
scaleY: 0.5
}, {
duration: 300,
onFinish: function onFinish() {
LK.setTimeout(function () {
tween(playerSprite, {
scaleY: 1
}, {
duration: 300,
onFinish: function onFinish() {
self.isSliding = false;
}
});
}, 300);
}
});
}
};
self.moveLane = function (targetLane) {
if (targetLane >= 0 && targetLane <= 3) {
self.lane = targetLane;
tween(self, {
x: roadPositions[targetLane]
}, {
duration: 200,
easing: tween.easeOut
});
}
};
self.activateShield = function () {
self.hasShield = true;
playerSprite.tint = 0x00FFFF;
LK.setTimeout(function () {
self.hasShield = false;
playerSprite.tint = 0xFFFFFF;
}, 5000);
};
self.update = function () {
// Player logic updated in game update
};
return self;
});
var PlayerParticle = Container.expand(function () {
var self = Container.call(this);
var particleSprite = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2 + Math.random() * 0.2,
scaleY: 0.2 + Math.random() * 0.2
});
self.vx = 0;
self.vy = 0;
self.gravity = 0.2;
self.friction = 0.98;
self.lifespan = 1000;
self.birthTime = Date.now();
self.update = function () {
// Apply physics
self.vy += self.gravity;
self.vx *= self.friction;
self.vy *= self.friction;
self.x += self.vx;
self.y += self.vy;
// Fade out based on lifespan
var age = Date.now() - self.birthTime;
var lifePercent = 1 - age / self.lifespan;
if (lifePercent <= 0) {
self.destroy();
return;
}
particleSprite.alpha = lifePercent;
};
return self;
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerupSprite = self.attachAsset('powerup', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = powerupSprite.width;
self.height = powerupSprite.height;
self.lane = 1;
self.type = "shield"; // shield, magnet, slowdown
// Pulsate animation
function pulsate() {
tween(powerupSprite, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 500,
onFinish: function onFinish() {
tween(powerupSprite, {
scaleX: 1,
scaleY: 1
}, {
duration: 500,
onFinish: pulsate
});
}
});
}
pulsate();
self.setType = function (newType) {
self.type = newType;
if (newType === "shield") {
powerupSprite.tint = 0x00FFFF;
} else if (newType === "magnet") {
powerupSprite.tint = 0xFF00FF;
} else if (newType === "slowdown") {
powerupSprite.tint = 0x00FF00;
}
};
self.update = function () {
self.y += gameSpeed;
if (self.y > 2732 + self.height) {
self.destroy();
}
};
return self;
});
var RoadLine = Container.expand(function () {
var self = Container.call(this);
var lineSprite = self.attachAsset('road_line', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = lineSprite.width;
self.height = lineSprite.height;
self.lane = 0; // 0-3 for the four road lanes
self.update = function () {
// Road lines remain stationary
};
self.resetPosition = function () {
// No reset needed as lines are now stationary
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x777777 // Gray background
});
/****
* Game Code
****/
// Game variables
var player;
var obstacles = [];
var coins = [];
var powerups = [];
var buses = [];
var roadLines = [];
var ground;
var gameSpeed = 5;
var initialGameSpeed = 5;
var maxGameSpeed = 15;
var speedIncreaseInterval;
var gameStarted = false;
var distanceTraveled = 0;
var score = 0;
var coinValue = 10;
var highScore = storage.highScore || 0;
var hasMagnet = false;
var magnetRange = 200;
// Define the 4 road positions (vertical lanes)
var roadWidth = 2048 / 4;
var roadPositions = [roadWidth * 0.5, roadWidth * 1.5, roadWidth * 2.5, roadWidth * 3.5];
// Lane positions for player, obstacles and collectibles
var laneX = [roadPositions[0], roadPositions[1], roadPositions[2], roadPositions[3]];
// UI elements
var scoreTxt = new Text2('SCORE: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreTxt);
scoreTxt.x = -scoreTxt.width - 20;
scoreTxt.y = 20;
var distanceTxt = new Text2('DISTANCE: 0m', {
size: 60,
fill: 0xFFFFFF
});
distanceTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(distanceTxt);
distanceTxt.x = -distanceTxt.width - 20;
distanceTxt.y = 90;
var highScoreTxt = new Text2('BEST: ' + highScore, {
size: 50,
fill: 0xFFFFFF
});
highScoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(highScoreTxt);
highScoreTxt.x = -highScoreTxt.width - 20;
highScoreTxt.y = 160;
var startTxt = new Text2('SWIPE TO START', {
size: 100,
fill: 0xFFFFFF
});
startTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(startTxt);
// Game initialization functions
function initializeGame() {
// Create gray ground/background
game.setBackgroundColor(0x777777);
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5
}));
ground.x = 2048 / 2;
ground.y = 2732 / 2;
// Create 4 vertical roads with no gaps between them
var roadWidth = 2048 / 4; // Divide screen width into 4 equal parts
for (var i = 0; i < 4; i++) {
var road = game.addChild(LK.getAsset('road', {
anchorX: 0.5,
anchorY: 0.5,
width: roadWidth,
// Set width to exactly 1/4 of screen
height: 2732 // Full screen height
}));
road.x = roadWidth * i + roadWidth / 2; // Position roads side by side with no gaps
road.y = 2732 / 2;
}
// Create road lines as vertical marks down the roads
var roadWidth = 2048 / 4; // Width of each road
for (var i = 0; i < 4; i++) {
for (var j = 0; j < 15; j++) {
var roadLine = new RoadLine();
roadLine.lane = i;
roadLine.x = roadWidth * i + roadWidth / 2; // Center in each road
roadLine.y = j * 200; // Distribute lines vertically
roadLines.push(roadLine);
game.addChild(roadLine);
}
}
// Create player
player = game.addChild(new Player());
player.lane = 1; // Start in second lane
player.x = roadPositions[player.lane]; // Position player horizontally on the road
player.y = 2732 - 300; // Position player near bottom of screen
// Create regular buses
for (var i = 0; i < 6; i++) {
var bus = new Bus();
bus.lane = Math.floor(Math.random() * 4);
bus.x = roadPositions[bus.lane];
// Position buses with enough space between them vertically
var offset = i * (bus.height + 300);
bus.y = -offset - bus.height;
// Make sure buses in the same lane don't overlap
for (var j = 0; j < buses.length; j++) {
if (bus.lane === buses[j].lane && Math.abs(bus.y - buses[j].y) < bus.height + buses[j].height) {
// Move this bus further up to avoid overlap
bus.y = buses[j].y - (bus.height + 300);
}
}
buses.push(bus);
game.addChild(bus);
}
// Create mini buses (that can be jumped over)
var miniBuses = [];
for (var i = 0; i < 4; i++) {
var miniBus = new MiniBus();
miniBus.lane = Math.floor(Math.random() * 4);
miniBus.x = roadPositions[miniBus.lane];
// Position mini buses with enough space
var offset = i * (miniBus.height + 400);
miniBus.y = -offset - miniBus.height - 500;
// Make sure mini buses don't overlap with regular buses
for (var j = 0; j < buses.length; j++) {
if (miniBus.lane === buses[j].lane && Math.abs(miniBus.y - buses[j].y) < miniBus.height + buses[j].height) {
miniBus.y = buses[j].y - (miniBus.height + 400);
}
}
miniBuses.push(miniBus);
buses.push(miniBus); // Add to main buses array for updates
game.addChild(miniBus);
}
// Initialize variables
obstacles = [];
coins = [];
powerups = [];
gameSpeed = initialGameSpeed;
distanceTraveled = 0;
score = 0;
updateUI();
}
function startGame() {
gameStarted = true;
LK.setScore(0);
startTxt.visible = false;
// Start increasing game speed over time
speedIncreaseInterval = LK.setInterval(function () {
if (gameSpeed < maxGameSpeed) {
gameSpeed += 0.5;
// Update all buses to have the same speed when game speed changes
for (var i = 0; i < buses.length; i++) {
buses[i].speed = 1; // Keep all buses at same speed when the game speeds up
}
}
}, 10000);
// Start spawning obstacles, coins, and powerups
spawnObstacles();
spawnCoins();
spawnPowerups();
// Play background music
LK.playMusic('bgmusic');
}
function updateUI() {
scoreTxt.setText('SCORE: ' + score);
scoreTxt.x = -scoreTxt.width - 20;
var distance = Math.floor(distanceTraveled / 10);
distanceTxt.setText('DISTANCE: ' + distance + 'm');
distanceTxt.x = -distanceTxt.width - 20;
highScoreTxt.setText('BEST: ' + highScore);
highScoreTxt.x = -highScoreTxt.width - 20;
}
// Object spawning functions
function spawnObstacles() {
var obstacleTimer = LK.setInterval(function () {
if (!gameStarted) return;
var obstacle = new Obstacle();
obstacle.lane = Math.floor(Math.random() * 4); // Random lane (4 lanes)
// Check if there's already an obstacle in this lane near spawn point
var canSpawn = true;
for (var i = 0; i < obstacles.length; i++) {
if (obstacles[i].lane === obstacle.lane && obstacles[i].y < 0) {
canSpawn = false;
break;
}
}
if (!canSpawn) return;
obstacle.x = roadPositions[obstacle.lane];
obstacle.y = -obstacle.height;
// Randomize obstacle type
var types = ["normal", "low", "high"];
var randomType = types[Math.floor(Math.random() * types.length)];
obstacle.setType(randomType);
obstacles.push(obstacle);
game.addChild(obstacle);
}, 2000 - Math.min(gameSpeed * 50, 1500)); // Spawn faster as game speed increases
}
function spawnCoins() {
var coinTimer = LK.setInterval(function () {
if (!gameStarted) return;
// Random coin pattern
var pattern = Math.floor(Math.random() * 4);
if (pattern === 0) {
// Single coin
var lane = Math.floor(Math.random() * 4);
spawnCoin(lane);
} else if (pattern === 1) {
// Vertical line of coins
var lane = Math.floor(Math.random() * 4);
for (var i = 0; i < 3; i++) {
var coin = new Coin();
coin.lane = lane;
coin.x = roadPositions[lane];
coin.y = -coin.height - i * 120;
coins.push(coin);
game.addChild(coin);
}
} else if (pattern === 2) {
// Horizontal line of coins
for (var i = 0; i < 4; i++) {
spawnCoin(i);
}
} else {
// Diagonal line of coins
for (var i = 0; i < 4; i++) {
var coin = new Coin();
coin.lane = i;
coin.x = roadPositions[i];
coin.y = -coin.height - i * 120;
coins.push(coin);
game.addChild(coin);
}
}
}, 3000);
}
function spawnCoin(lane) {
var coin = new Coin();
coin.lane = lane;
coin.x = roadPositions[lane];
coin.y = -coin.height;
coins.push(coin);
game.addChild(coin);
}
function spawnPowerups() {
var powerupTimer = LK.setInterval(function () {
if (!gameStarted) return;
var powerup = new PowerUp();
powerup.lane = Math.floor(Math.random() * 4);
// Check if there's already an obstacle or powerup in this lane near spawn point
var canSpawn = true;
for (var i = 0; i < obstacles.length; i++) {
if (obstacles[i].lane === powerup.lane && obstacles[i].y < 0) {
canSpawn = false;
break;
}
}
for (var i = 0; i < powerups.length; i++) {
if (powerups[i].lane === powerup.lane && powerups[i].y < 0) {
canSpawn = false;
break;
}
}
if (!canSpawn) return;
powerup.x = roadPositions[powerup.lane];
powerup.y = -powerup.height;
// Randomize powerup type
var types = ["shield", "magnet", "slowdown"];
var randomType = types[Math.floor(Math.random() * types.length)];
powerup.setType(randomType);
powerups.push(powerup);
game.addChild(powerup);
}, 15000); // Powerups appear less frequently
}
// Game mechanics functions
function checkCollisions() {
// Check obstacle collisions
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
// Check if obstacle is about to overlap with any other obstacle
for (var j = 0; j < obstacles.length; j++) {
if (i !== j && obstacle.lane === obstacles[j].lane && Math.abs(obstacle.y - obstacles[j].y) < (obstacle.height + obstacles[j].height) / 2) {
// Remove the obstacle that's about to overlap
obstacles.splice(i, 1);
obstacle.destroy();
i--;
break;
}
}
if (i < 0 || !obstacles[i]) continue;
obstacle = obstacles[i];
// Check player collision
if (player.lane === obstacle.lane && !player.isJumping && player.y - player.height / 2 < obstacle.y + obstacle.height / 2 && player.y + player.height / 2 > obstacle.y - obstacle.height / 2) {
// Check if player can avoid by sliding under high obstacle
if (obstacle.type === "high" && player.isSliding) {
continue;
}
// Check if player can avoid by jumping over low obstacle
if (obstacle.type === "low" && player.isJumping) {
continue;
}
// Check if player has shield
if (player.hasShield) {
player.hasShield = false;
player.tint = 0xFFFFFF;
obstacles.splice(i, 1);
obstacle.destroy();
continue;
}
// Collision occurred
createPlayerParticles();
gameOver();
break;
}
}
// Check bus collisions
for (var i = buses.length - 1; i >= 0; i--) {
var bus = buses[i];
// Check for bus-to-bus collisions
for (var j = 0; j < buses.length; j++) {
if (i !== j && bus.lane === buses[j].lane && Math.abs(bus.y - buses[j].y) < (bus.height + buses[j].height) * 0.8) {
// Prevent overlap by repositioning this bus
bus.y = buses[j].y - (bus.height + buses[j].height);
if (bus.y > 2732 + bus.height) {
bus.resetPosition();
}
}
}
// Check player collision with bus
if (player.lane === bus.lane && Math.abs(player.y - bus.y) < (player.height + bus.height) / 2) {
// Check if it's a mini bus that can be jumped over
if (bus instanceof MiniBus && player.isJumping) {
continue; // Player successfully jumped over the mini bus
}
// Check if player has shield
if (player.hasShield) {
player.hasShield = false;
player.tint = 0xFFFFFF;
continue;
}
// Collision occurred
createPlayerParticles();
gameOver();
break;
}
}
// Check coin collections
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
// Regular collection
if (player.lane === coin.lane && Math.abs(player.x - coin.x) < (player.width + coin.width) / 2) {
collectCoin(coin, i);
}
// Magnet effect collection
else if (hasMagnet && Math.sqrt(Math.pow(player.x - coin.x, 2) + Math.pow(player.y - coin.y, 2)) < magnetRange) {
tween(coin, {
x: player.x,
y: player.y
}, {
duration: 200,
onFinish: function onFinish() {
collectCoin(coin, i);
}
});
}
}
// Check powerup collections
for (var i = powerups.length - 1; i >= 0; i--) {
var powerup = powerups[i];
// Check if powerup is about to overlap with obstacles
for (var j = 0; j < obstacles.length; j++) {
if (powerup.lane === obstacles[j].lane && Math.abs(powerup.y - obstacles[j].y) < (powerup.height + obstacles[j].height) / 2) {
// Remove powerup to prevent overlap
powerups.splice(i, 1);
powerup.destroy();
i--;
break;
}
}
// Check if powerup is about to overlap with other powerups
if (i >= 0 && powerups[i]) {
for (var j = 0; j < powerups.length; j++) {
if (i !== j && powerup.lane === powerups[j].lane && Math.abs(powerup.y - powerups[j].y) < (powerup.height + powerups[j].height) / 2) {
// Remove this powerup to prevent overlap
powerups.splice(i, 1);
powerup.destroy();
i--;
break;
}
}
}
if (i < 0 || !powerups[i]) continue;
powerup = powerups[i];
if (player.lane === powerup.lane && Math.abs(player.x - powerup.x) < (player.width + powerup.width) / 2) {
// Apply powerup effect
if (powerup.type === "shield") {
player.activateShield();
} else if (powerup.type === "magnet") {
activateMagnet();
} else if (powerup.type === "slowdown") {
slowDownGame();
}
LK.getSound('powerup_collect').play();
score += 30;
LK.setScore(score);
updateUI();
powerups.splice(i, 1);
powerup.destroy();
}
}
}
function collectCoin(coin, index) {
LK.getSound('coin_collect').play();
score += coinValue;
LK.setScore(score);
if (coins[index]) {
coins.splice(index, 1);
coin.destroy();
}
updateUI();
}
function activateMagnet() {
hasMagnet = true;
LK.setTimeout(function () {
hasMagnet = false;
}, 10000);
}
function slowDownGame() {
var originalSpeed = gameSpeed;
gameSpeed = gameSpeed / 2;
LK.setTimeout(function () {
gameSpeed = originalSpeed;
}, 5000);
}
function createPlayerParticles() {
// Create particle explosion effect at player position
var particleCount = 20;
var particles = [];
for (var i = 0; i < particleCount; i++) {
var particle = new PlayerParticle();
game.addChild(particle);
particle.x = player.x;
particle.y = player.y;
// Random direction
var angle = Math.random() * Math.PI * 2;
var speed = 2 + Math.random() * 5;
particle.vx = Math.cos(angle) * speed;
particle.vy = Math.sin(angle) * speed;
// Random rotation and scale for variety
particle.rotation = Math.random() * Math.PI * 2;
// Set random lifespan
particle.lifespan = 800 + Math.random() * 1200;
particle.birthTime = Date.now();
// Add to particles array for tracking
particles.push(particle);
}
// Hide the original player
player.visible = false;
}
function gameOver() {
LK.getSound('crash').play();
LK.effects.flashScreen(0xFF0000, 500);
// Update high score if needed
if (score > highScore) {
highScore = score;
storage.highScore = highScore;
}
// Clear intervals
LK.clearInterval(speedIncreaseInterval);
// Show game over screen
LK.setTimeout(function () {
LK.showGameOver();
}, 1000); // Delay game over screen to see particles
}
// Touch/swipe controls
var startY, startX;
var MIN_SWIPE_DISTANCE = 50;
game.down = function (x, y) {
startX = x;
startY = y;
};
game.up = function (x, y) {
if (!startX || !startY) return;
var deltaX = x - startX;
var deltaY = y - startY;
var absDeltaX = Math.abs(deltaX);
var absDeltaY = Math.abs(deltaY);
// Start game on any swipe if not started
if (!gameStarted) {
startGame();
return;
}
// Detect swipe direction
if (absDeltaX > MIN_SWIPE_DISTANCE || absDeltaY > MIN_SWIPE_DISTANCE) {
// Horizontal swipe detection (left/right) - faster movement
if (absDeltaX > absDeltaY) {
if (deltaX > 0) {
// Swipe right - move faster with stronger swipe
var newLane = Math.min(player.lane + 1 + Math.floor(absDeltaX / 150), 3);
player.moveLane(newLane);
tween.killTweensOf(player); // Kill any existing movement tweens
tween(player, {
x: roadPositions[newLane]
}, {
duration: 150,
// Faster movement
easing: tween.easeOut
});
} else {
// Swipe left - move faster with stronger swipe
var newLane = Math.max(player.lane - 1 - Math.floor(absDeltaX / 150), 0);
player.moveLane(newLane);
tween.killTweensOf(player);
tween(player, {
x: roadPositions[newLane]
}, {
duration: 150,
// Faster movement
easing: tween.easeOut
});
}
}
// Vertical swipe detection (up/down)
else {
if (deltaY < 0) {
// Swipe up (jump)
player.jump();
} else {
// Swipe down (slide)
player.slide();
}
}
}
};
// Initialize the game
initializeGame();
// Game update loop
game.update = function () {
if (!gameStarted) return;
// Update distance traveled
distanceTraveled += gameSpeed;
updateUI();
// Check for collisions
checkCollisions();
// Update game objects (only buses move now)
for (var i = obstacles.length - 1; i >= 0; i--) {
if (obstacles[i]) obstacles[i].update();
}
for (var i = coins.length - 1; i >= 0; i--) {
if (coins[i]) coins[i].update();
}
for (var i = powerups.length - 1; i >= 0; i--) {
if (powerups[i]) powerups[i].update();
}
for (var i = buses.length - 1; i >= 0; i--) {
if (buses[i]) buses[i].update();
}
// Road lines are now stationary
// Update all PlayerParticle instances that might be in the scene
var particles = game.children.filter(function (child) {
return child instanceof PlayerParticle;
});
for (var i = 0; i < particles.length; i++) {
particles[i].update();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -19,20 +19,21 @@
self.height = busSprite.height;
self.speed = 1; // All buses have the same base speed
self.lane = 0; // 0-3 for the four road lanes
self.update = function () {
- // Move horizontally instead of vertically
- self.x += gameSpeed * self.speed;
- if (self.x > 2048 + self.width) {
+ self.lastX = self.x;
+ // Move vertically from top to bottom
+ self.y += gameSpeed * self.speed;
+ if (self.y > 2732 + self.height) {
self.resetPosition();
}
};
self.resetPosition = function () {
- // Reset to left of screen
- self.x = -self.width - Math.random() * 300;
- // Keep bus on the same lane (road)
+ // Reset to top of screen
+ self.y = -self.height - Math.random() * 300;
+ // Randomly assign to a lane
self.lane = Math.floor(Math.random() * 4);
- self.y = roadPositions[self.lane];
+ self.x = roadPositions[self.lane];
};
return self;
});
var Coin = Container.expand(function () {
@@ -59,8 +60,39 @@
}
};
return self;
});
+var MiniBus = Container.expand(function () {
+ var self = Container.call(this);
+ var busSprite = self.attachAsset('bus', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.6,
+ // Smaller than regular buses
+ scaleY: 0.6
+ });
+ self.width = busSprite.width * 0.6;
+ self.height = busSprite.height * 0.6;
+ self.speed = 1.2; // Slightly faster than regular buses
+ self.lane = 0; // 0-3 for the four road lanes
+ busSprite.tint = 0x99CC99; // Different color to distinguish from regular buses
+ self.update = function () {
+ self.lastX = self.x;
+ // Move vertically from top to bottom
+ self.y += gameSpeed * self.speed;
+ if (self.y > 2732 + self.height) {
+ self.resetPosition();
+ }
+ };
+ self.resetPosition = function () {
+ // Reset to top of screen
+ self.y = -self.height - Math.random() * 300;
+ // Randomly assign to a lane
+ self.lane = Math.floor(Math.random() * 4);
+ self.x = roadPositions[self.lane];
+ };
+ return self;
+});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleSprite = self.attachAsset('obstacle', {
anchorX: 0.5,
@@ -150,9 +182,9 @@
self.moveLane = function (targetLane) {
if (targetLane >= 0 && targetLane <= 3) {
self.lane = targetLane;
tween(self, {
- y: roadPositions[targetLane]
+ x: roadPositions[targetLane]
}, {
duration: 200,
easing: tween.easeOut
});
@@ -296,12 +328,13 @@
var coinValue = 10;
var highScore = storage.highScore || 0;
var hasMagnet = false;
var magnetRange = 200;
-// Define the 4 road positions (horizontal lanes)
-var roadPositions = [2732 * 0.125, 2732 * 0.375, 2732 * 0.625, 2732 * 0.875];
+// Define the 4 road positions (vertical lanes)
+var roadWidth = 2048 / 4;
+var roadPositions = [roadWidth * 0.5, roadWidth * 1.5, roadWidth * 2.5, roadWidth * 3.5];
// Lane positions for player, obstacles and collectibles
-var laneY = [roadPositions[0], roadPositions[1], roadPositions[2], roadPositions[3]];
+var laneX = [roadPositions[0], roadPositions[1], roadPositions[2], roadPositions[3]];
// UI elements
var scoreTxt = new Text2('SCORE: 0', {
size: 60,
fill: 0xFFFFFF
@@ -341,53 +374,75 @@
anchorY: 0.5
}));
ground.x = 2048 / 2;
ground.y = 2732 / 2;
- // Create 4 horizontal roads
+ // Create 4 vertical roads with no gaps between them
+ var roadWidth = 2048 / 4; // Divide screen width into 4 equal parts
for (var i = 0; i < 4; i++) {
var road = game.addChild(LK.getAsset('road', {
anchorX: 0.5,
anchorY: 0.5,
- rotation: Math.PI / 2 // Rotate roads 90 degrees to make them horizontal
+ width: roadWidth,
+ // Set width to exactly 1/4 of screen
+ height: 2732 // Full screen height
}));
- road.x = 2048 / 2;
- road.y = roadPositions[i]; // Position roads horizontally
+ road.x = roadWidth * i + roadWidth / 2; // Position roads side by side with no gaps
+ road.y = 2732 / 2;
}
- // Create road lines as horizontal marks across roads
+ // Create road lines as vertical marks down the roads
+ var roadWidth = 2048 / 4; // Width of each road
for (var i = 0; i < 4; i++) {
- for (var j = 0; j < 10; j++) {
+ for (var j = 0; j < 15; j++) {
var roadLine = new RoadLine();
roadLine.lane = i;
- roadLine.y = roadPositions[i];
- roadLine.x = j * 300; // Distribute lines horizontally
- roadLine.rotation = Math.PI / 2; // Rotate lines 90 degrees
+ roadLine.x = roadWidth * i + roadWidth / 2; // Center in each road
+ roadLine.y = j * 200; // Distribute lines vertically
roadLines.push(roadLine);
game.addChild(roadLine);
}
}
// Create player
player = game.addChild(new Player());
player.lane = 1; // Start in second lane
- player.y = roadPositions[player.lane];
- player.x = 300; // Position player on left side of screen
- // Create buses
- for (var i = 0; i < 8; i++) {
+ player.x = roadPositions[player.lane]; // Position player horizontally on the road
+ player.y = 2732 - 300; // Position player near bottom of screen
+ // Create regular buses
+ for (var i = 0; i < 6; i++) {
var bus = new Bus();
bus.lane = Math.floor(Math.random() * 4);
- bus.y = roadPositions[bus.lane];
- // Position buses with enough space between them horizontally
- var offset = i * (bus.width + 300);
- bus.x = -offset - bus.width;
+ bus.x = roadPositions[bus.lane];
+ // Position buses with enough space between them vertically
+ var offset = i * (bus.height + 300);
+ bus.y = -offset - bus.height;
// Make sure buses in the same lane don't overlap
for (var j = 0; j < buses.length; j++) {
- if (bus.lane === buses[j].lane && Math.abs(bus.x - buses[j].x) < bus.width + buses[j].width) {
- // Move this bus further left to avoid overlap
- bus.x = buses[j].x - (bus.width + 300);
+ if (bus.lane === buses[j].lane && Math.abs(bus.y - buses[j].y) < bus.height + buses[j].height) {
+ // Move this bus further up to avoid overlap
+ bus.y = buses[j].y - (bus.height + 300);
}
}
buses.push(bus);
game.addChild(bus);
}
+ // Create mini buses (that can be jumped over)
+ var miniBuses = [];
+ for (var i = 0; i < 4; i++) {
+ var miniBus = new MiniBus();
+ miniBus.lane = Math.floor(Math.random() * 4);
+ miniBus.x = roadPositions[miniBus.lane];
+ // Position mini buses with enough space
+ var offset = i * (miniBus.height + 400);
+ miniBus.y = -offset - miniBus.height - 500;
+ // Make sure mini buses don't overlap with regular buses
+ for (var j = 0; j < buses.length; j++) {
+ if (miniBus.lane === buses[j].lane && Math.abs(miniBus.y - buses[j].y) < miniBus.height + buses[j].height) {
+ miniBus.y = buses[j].y - (miniBus.height + 400);
+ }
+ }
+ miniBuses.push(miniBus);
+ buses.push(miniBus); // Add to main buses array for updates
+ game.addChild(miniBus);
+ }
// Initialize variables
obstacles = [];
coins = [];
powerups = [];
@@ -581,10 +636,13 @@
}
}
}
// Check player collision with bus
- if (player.lane === bus.lane && Math.abs(player.x - bus.x) < (player.width + bus.width) / 2) {
- // Buses can't be jumped over or slid under
+ if (player.lane === bus.lane && Math.abs(player.y - bus.y) < (player.height + bus.height) / 2) {
+ // Check if it's a mini bus that can be jumped over
+ if (bus instanceof MiniBus && player.isJumping) {
+ continue; // Player successfully jumped over the mini bus
+ }
// Check if player has shield
if (player.hasShield) {
player.hasShield = false;
player.tint = 0xFFFFFF;
@@ -743,16 +801,34 @@
return;
}
// Detect swipe direction
if (absDeltaX > MIN_SWIPE_DISTANCE || absDeltaY > MIN_SWIPE_DISTANCE) {
- // Horizontal swipe detection (left/right)
+ // Horizontal swipe detection (left/right) - faster movement
if (absDeltaX > absDeltaY) {
if (deltaX > 0) {
- // Swipe right
- player.moveLane(Math.min(player.lane + 1, 3));
+ // Swipe right - move faster with stronger swipe
+ var newLane = Math.min(player.lane + 1 + Math.floor(absDeltaX / 150), 3);
+ player.moveLane(newLane);
+ tween.killTweensOf(player); // Kill any existing movement tweens
+ tween(player, {
+ x: roadPositions[newLane]
+ }, {
+ duration: 150,
+ // Faster movement
+ easing: tween.easeOut
+ });
} else {
- // Swipe left
- player.moveLane(Math.max(player.lane - 1, 0));
+ // Swipe left - move faster with stronger swipe
+ var newLane = Math.max(player.lane - 1 - Math.floor(absDeltaX / 150), 0);
+ player.moveLane(newLane);
+ tween.killTweensOf(player);
+ tween(player, {
+ x: roadPositions[newLane]
+ }, {
+ duration: 150,
+ // Faster movement
+ easing: tween.easeOut
+ });
}
}
// Vertical swipe detection (up/down)
else {