User prompt
Oyuncunun arabası saniyede 3 tık hızlansın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Ok tuşları hariç başka bir yere basıldığında araba sağa sola hareket etmesin.
User prompt
Ok tuşları harici başka bir yere dokunduğumuzda sağa sola hareket etme.
User prompt
Gas pedalını oyundan tamamen kaldır.
User prompt
Sağa ok tuşunu 1-2 tık sola, sol ok tuşunu 1-2 tık sağa kaydır.
User prompt
Sağ ve sol ok tuşunu büyüt.
User prompt
Gaz pedalını kaldır, sağ ok düşünü sağ köşeye al, sol ok düşünü de sol köşede bırak.
User prompt
Oyuncunun arabasına Gaz pedalına Bastığında Araba hızlanmaya Başlasın Gaz pedalına Oyuncu gaz pedalına basmıyorsa Araba dursun ama Sağa sola hareket etsin
User prompt
Oyuncunun arabası gaz pedalına basmadan hareket etmesin.
User prompt
Oyuncunu arabası gaz pedalı na basmdan hareket etmesin
User prompt
Oyun aktiviteleri ekle tamamlayalım
User prompt
Kutular dönmesin
User prompt
Oyuncu arabası, oyuncu arabası kutulara değdiğinde oyun bitsin.
User prompt
Yere dökülmüş kutular yap
User prompt
Her 300 metre de 1 tane insan yola atlasın
User prompt
Her 100 metre bir 2 tane insan yola atlasın
User prompt
Yakıtlara oyuncu arabası değdiğinde Kendi etrafında dönsün ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Yere dökülmüş yakıtlar olsun değdiğimizde oyuncu arabası kaysın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Süreyi sağ üst köşeye koy
User prompt
Oyuna süre ekle oyun bitene kadar nekadar süre oynamışız göstersin
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Bush = Container.expand(function () {
var self = Container.call(this);
var bushGraphics = self.attachAsset('bush', {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = 6;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('playerCar', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 0;
self.targetX = 0;
self.lane = 1; // 0=left, 1=center, 2=right
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 = 6;
self.lastY = 0;
self.lastIntersecting = false;
self.update = function () {
self.y += self.speed;
coinGraphics.rotation += 0.1;
};
return self;
});
var EnemyCar = Container.expand(function () {
var self = Container.call(this);
var carTypes = ['enemyCar1', 'enemyCar2', 'enemyCar3'];
var randomType = carTypes[Math.floor(Math.random() * carTypes.length)];
var carGraphics = self.attachAsset(randomType, {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.lastY = 0;
self.lastIntersecting = false;
self.update = function () {
self.y += self.speed;
};
return self;
});
var FuelTank = Container.expand(function () {
var self = Container.call(this);
var fuelTankGraphics = self.attachAsset('fuelTank', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.lastY = 0;
self.lastIntersecting = false;
self.update = function () {
self.y += self.speed;
fuelTankGraphics.rotation += 0.05;
};
return self;
});
var Human = Container.expand(function () {
var self = Container.call(this);
var humanGraphics = self.attachAsset('enemyCar1', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
scaleY: 0.6
});
humanGraphics.tint = 0xFFAAAA; // Make humans pink-ish to distinguish from cars
self.speed = 6;
self.lastY = 0;
self.lastIntersecting = false;
self.update = function () {
self.y += self.speed;
};
return self;
});
var RoadLine = Container.expand(function () {
var self = Container.call(this);
var lineGraphics = self.attachAsset('roadLine', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.update = function () {
self.y += self.speed;
};
return self;
});
var SpilledFuel = Container.expand(function () {
var self = Container.call(this);
var spillGraphics = self.attachAsset('spilledFuel', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.lastY = 0;
self.lastIntersecting = false;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = 6;
self.update = function () {
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
// Game variables
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Game variables
var playerCar;
var enemyCars = [];
var coins = [];
var roadLines = [];
var trees = [];
var bushes = [];
var gameSpeed = 6;
var lanes = [2048 / 4, 2048 / 2, 3 * 2048 / 4]; // Three lanes
var spawnTimer = 0;
var coinSpawnTimer = 0;
var roadLineSpawnTimer = 0;
var treeSpawnTimer = 0;
var bushSpawnTimer = 0;
var distanceScore = 0;
var fuelTanks = [];
var fuelTankSpawnTimer = 0;
var currentFuel = 100;
var maxFuel = 100;
var fuelConsumptionRate = 0.1;
var dragActive = false;
var showingLeaderboard = false;
var leaderboardContainer;
var leaderboardScores = storage.leaderboard || [];
var gameStartTime = Date.now();
var gameTime = 0;
var spilledFuels = [];
var spilledFuelSpawnTimer = 0;
var isSliding = false;
var slideDirection = 0;
var slideTimer = 0;
var humans = [];
var humanSpawnTimer = 0;
var distanceForNextHumans = 300; // Track when to spawn next humans
// Create score display using asset
var scoreDisplay = LK.getAsset('Score', {
anchorX: 0.5,
anchorY: 0
});
LK.gui.top.addChild(scoreDisplay);
// Create score text display
var scoreTxt = new Text2('0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
scoreTxt.x = scoreDisplay.x + 60; // Position next to score image
scoreTxt.y = scoreDisplay.y;
LK.gui.top.addChild(scoreTxt);
// Create score button to show/hide score
var scoreButton = new Text2('📊', {
size: 80,
fill: 0x00FF00
});
scoreButton.anchor.set(0.5, 0);
scoreButton.x = 2048 - 200;
scoreButton.y = 20;
LK.gui.top.addChild(scoreButton);
// Create leaderboard button
var leaderboardButton = new Text2('🏆', {
size: 80,
fill: 0xFFD700
});
leaderboardButton.anchor.set(0.5, 0);
leaderboardButton.x = 2048 - 100;
leaderboardButton.y = 20;
LK.gui.top.addChild(leaderboardButton);
// Score visibility state
var showScore = true;
// Create distance display
var distanceTxt = new Text2('Distance: 0m', {
size: 60,
fill: 0xFFFFFF
});
distanceTxt.anchor.set(0.5, 0);
distanceTxt.y = 100;
LK.gui.top.addChild(distanceTxt);
// Create speedometer display
var speedometerTxt = new Text2('Speed: 0 km/h', {
size: 60,
fill: 0xFFFFFF
});
speedometerTxt.anchor.set(0.5, 0);
speedometerTxt.y = 170;
LK.gui.top.addChild(speedometerTxt);
// Create fuel display
var fuelTxt = new Text2('Fuel: 100%', {
size: 60,
fill: 0x00FF00
});
fuelTxt.anchor.set(0.5, 0);
fuelTxt.y = 240;
LK.gui.top.addChild(fuelTxt);
// Create time display
var timeTxt = new Text2('Time: 0:00', {
size: 60,
fill: 0xFFFFFF
});
timeTxt.anchor.set(0.5, 0);
timeTxt.y = 310;
LK.gui.top.addChild(timeTxt);
// Create left arrow button
var leftArrow = LK.getAsset('Oktusu', {
width: 250,
height: 250,
anchorX: 0.5,
anchorY: 0.5
});
leftArrow.x = 100;
leftArrow.y = 2732 - 200;
game.addChild(leftArrow);
// Create left arrow text
var leftArrowTxt = new Text2('←', {
size: 80,
fill: 0xFFFFFF
});
leftArrowTxt.anchor.set(0.5, 0.5);
leftArrowTxt.x = leftArrow.x;
leftArrowTxt.y = leftArrow.y;
game.addChild(leftArrowTxt);
// Create right arrow button
var rightArrow = LK.getAsset('Oktusu', {
width: 250,
height: 250,
anchorX: 0.5,
anchorY: 0.5
});
rightArrow.x = 400;
rightArrow.y = 2732 - 200;
game.addChild(rightArrow);
// Create right arrow text
var rightArrowTxt = new Text2('→', {
size: 80,
fill: 0xFFFFFF
});
rightArrowTxt.anchor.set(0.5, 0.5);
rightArrowTxt.x = rightArrow.x;
rightArrowTxt.y = rightArrow.y;
game.addChild(rightArrowTxt);
// Create gas pedal
var gasPedal = LK.getAsset('Gaz', {
width: 350,
height: 350,
anchorX: 0.5,
anchorY: 0.5
});
gasPedal.x = 2048 - 200;
gasPedal.y = 2732 - 350;
game.addChild(gasPedal);
// Create gas pedal text
var gasPedalTxt = new Text2('GAS', {
size: 70,
fill: 0xFFFFFF
});
gasPedalTxt.anchor.set(0.5, 0.5);
gasPedalTxt.x = gasPedal.x;
gasPedalTxt.y = gasPedal.y;
game.addChild(gasPedalTxt);
// Gas pedal variables
var isGasPedalPressed = false;
var boostMultiplier = 1.0;
// Function to show leaderboard
function showLeaderboard() {
if (showingLeaderboard) return;
showingLeaderboard = true;
leaderboardContainer = new Container();
game.addChild(leaderboardContainer);
// Semi-transparent background
var background = LK.getAsset('highway', {
width: 1800,
height: 2200,
anchorX: 0.5,
anchorY: 0.5
});
background.x = 2048 / 2;
background.y = 2732 / 2;
background.alpha = 0.8;
background.tint = 0x000000;
leaderboardContainer.addChild(background);
// Title
var titleText = new Text2('🏆 TOP SCORES 🏆', {
size: 100,
fill: 0xFFD700
});
titleText.anchor.set(0.5, 0);
titleText.x = 2048 / 2;
titleText.y = 400;
leaderboardContainer.addChild(titleText);
// Display top 10 scores
var sortedScores = leaderboardScores.slice().sort(function (a, b) {
return b - a;
});
for (var i = 0; i < Math.min(10, sortedScores.length); i++) {
var rankText = new Text2(i + 1 + '. ' + sortedScores[i] + ' points', {
size: 80,
fill: i < 3 ? 0xFFD700 : 0xFFFFFF
});
rankText.anchor.set(0.5, 0);
rankText.x = 2048 / 2;
rankText.y = 600 + i * 120;
leaderboardContainer.addChild(rankText);
}
// Close button
var closeButton = new Text2('❌ CLOSE', {
size: 80,
fill: 0xFF4444
});
closeButton.anchor.set(0.5, 0);
closeButton.x = 2048 / 2;
closeButton.y = 2200;
leaderboardContainer.addChild(closeButton);
}
// Function to hide leaderboard
function hideLeaderboard() {
if (!showingLeaderboard) return;
showingLeaderboard = false;
if (leaderboardContainer) {
leaderboardContainer.destroy();
leaderboardContainer = null;
}
}
// Function to save score to leaderboard
function saveScore(score) {
leaderboardScores.push(score);
leaderboardScores.sort(function (a, b) {
return b - a;
});
// Keep only top 20 scores
if (leaderboardScores.length > 20) {
leaderboardScores = leaderboardScores.slice(0, 20);
}
storage.leaderboard = leaderboardScores;
}
// Create player car
playerCar = game.addChild(new Car());
playerCar.x = lanes[1]; // Start in middle lane
playerCar.y = 2732 - 300;
playerCar.targetX = playerCar.x;
// Touch controls
game.down = function (x, y, obj) {
// Check if leaderboard is showing and handle close button
if (showingLeaderboard) {
var closeButtonBounds = {
left: 2048 / 2 - 150,
right: 2048 / 2 + 150,
top: 2200 - 50,
bottom: 2200 + 50
};
if (x >= closeButtonBounds.left && x <= closeButtonBounds.right && y >= closeButtonBounds.top && y <= closeButtonBounds.bottom) {
hideLeaderboard();
return;
}
// Ignore other touches when leaderboard is showing
return;
}
// Check if score button is pressed
var scoreBounds = {
left: scoreButton.x - 50,
right: scoreButton.x + 50,
top: scoreButton.y,
bottom: scoreButton.y + 80
};
if (x >= scoreBounds.left && x <= scoreBounds.right && y >= scoreBounds.top && y <= scoreBounds.bottom) {
showScore = !showScore;
if (showScore) {
scoreDisplay.alpha = 1;
scoreTxt.alpha = 1;
} else {
scoreDisplay.alpha = 0;
scoreTxt.alpha = 0;
}
return;
}
// Check if leaderboard button is pressed
var leaderboardBounds = {
left: leaderboardButton.x - 50,
right: leaderboardButton.x + 50,
top: leaderboardButton.y,
bottom: leaderboardButton.y + 80
};
if (x >= leaderboardBounds.left && x <= leaderboardBounds.right && y >= leaderboardBounds.top && y <= leaderboardBounds.bottom) {
showLeaderboard();
return;
}
// Check if gas pedal is pressed first
var gasPedalBounds = {
left: gasPedal.x - 175,
right: gasPedal.x + 175,
top: gasPedal.y - 175,
bottom: gasPedal.y + 175
};
if (x >= gasPedalBounds.left && x <= gasPedalBounds.right && y >= gasPedalBounds.top && y <= gasPedalBounds.bottom) {
isGasPedalPressed = true;
gasPedal.tint = 0xffff00; // Yellow when pressed
}
// Check if left arrow is pressed
var leftArrowBounds = {
left: leftArrow.x - 125,
right: leftArrow.x + 125,
top: leftArrow.y - 125,
bottom: leftArrow.y + 125
};
if (x >= leftArrowBounds.left && x <= leftArrowBounds.right && y >= leftArrowBounds.top && y <= leftArrowBounds.bottom) {
// Move car to left lane
if (playerCar.lane > 0) {
playerCar.lane--;
playerCar.targetX = lanes[playerCar.lane];
}
leftArrow.tint = 0xffff00; // Yellow when pressed
}
// Check if right arrow is pressed
var rightArrowBounds = {
left: rightArrow.x - 125,
right: rightArrow.x + 125,
top: rightArrow.y - 125,
bottom: rightArrow.y + 125
};
if (x >= rightArrowBounds.left && x <= rightArrowBounds.right && y >= rightArrowBounds.top && y <= rightArrowBounds.bottom) {
// Move car to right lane
if (playerCar.lane < 2) {
playerCar.lane++;
playerCar.targetX = lanes[playerCar.lane];
}
rightArrow.tint = 0xffff00; // Yellow when pressed
}
// Handle drag controls for general screen touches
if (!(x >= leftArrowBounds.left && x <= leftArrowBounds.right && y >= leftArrowBounds.top && y <= leftArrowBounds.bottom) && !(x >= rightArrowBounds.left && x <= rightArrowBounds.right && y >= rightArrowBounds.top && y <= rightArrowBounds.bottom) && !(x >= gasPedalBounds.left && x <= gasPedalBounds.right && y >= gasPedalBounds.top && y <= gasPedalBounds.bottom)) {
dragActive = true;
// Move car to closest lane based on touch position
var closestLane = 1;
var minDistance = Math.abs(x - lanes[1]);
for (var i = 0; i < lanes.length; i++) {
var distance = Math.abs(x - lanes[i]);
if (distance < minDistance) {
minDistance = distance;
closestLane = i;
}
}
playerCar.lane = closestLane;
playerCar.targetX = lanes[closestLane];
}
};
game.move = function (x, y, obj) {
// Don't allow movement when leaderboard is showing
if (showingLeaderboard) return;
// Allow steering even when gas pedal is pressed
var gasPedalBounds = {
left: gasPedal.x - 175,
right: gasPedal.x + 175,
top: gasPedal.y - 175,
bottom: gasPedal.y + 175
};
var leftArrowBounds = {
left: leftArrow.x - 125,
right: leftArrow.x + 125,
top: leftArrow.y - 125,
bottom: leftArrow.y + 125
};
var rightArrowBounds = {
left: rightArrow.x - 125,
right: rightArrow.x + 125,
top: rightArrow.y - 125,
bottom: rightArrow.y + 125
};
// Allow movement if dragging or if touch is outside control areas
if (dragActive || !(x >= leftArrowBounds.left && x <= leftArrowBounds.right && y >= leftArrowBounds.top && y <= leftArrowBounds.bottom) && !(x >= rightArrowBounds.left && x <= rightArrowBounds.right && y >= rightArrowBounds.top && y <= rightArrowBounds.bottom) && !(x >= gasPedalBounds.left && x <= gasPedalBounds.right && y >= gasPedalBounds.top && y <= gasPedalBounds.bottom)) {
// Move car to closest lane based on drag position
var closestLane = 1;
var minDistance = Math.abs(x - lanes[1]);
for (var i = 0; i < lanes.length; i++) {
var distance = Math.abs(x - lanes[i]);
if (distance < minDistance) {
minDistance = distance;
closestLane = i;
}
}
playerCar.lane = closestLane;
playerCar.targetX = lanes[closestLane];
}
};
game.up = function (x, y, obj) {
// Don't process touches when leaderboard is showing
if (showingLeaderboard) return;
dragActive = false;
// Reset arrow button colors
leftArrow.tint = 0xffffff;
rightArrow.tint = 0xffffff;
// Only release gas pedal if the touch was released within gas pedal bounds
var gasPedalBounds = {
left: gasPedal.x - 175,
right: gasPedal.x + 175,
top: gasPedal.y - 175,
bottom: gasPedal.y + 175
};
if (isGasPedalPressed && x >= gasPedalBounds.left && x <= gasPedalBounds.right && y >= gasPedalBounds.top && y <= gasPedalBounds.bottom) {
isGasPedalPressed = false;
gasPedal.tint = 0xffffff; // Back to normal color
}
};
// Main game loop
game.update = function () {
// Don't update game when leaderboard is showing
if (showingLeaderboard) return;
// Update game time
gameTime = Math.floor((Date.now() - gameStartTime) / 1000);
var minutes = Math.floor(gameTime / 60);
var seconds = gameTime % 60;
var timeString = minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
timeTxt.setText('Time: ' + timeString);
// Handle sliding mechanics
if (isSliding) {
slideTimer--;
// Apply sliding movement with tween for smooth effect
var slideAmount = slideDirection * 8;
playerCar.x += slideAmount;
// Constrain car to stay within road bounds
playerCar.x = Math.max(lanes[0] - 100, Math.min(lanes[2] + 100, playerCar.x));
// Add visual sliding effect
tween(playerCar, {
rotation: slideDirection * 0.3
}, {
duration: 100,
easing: tween.easeOut
});
if (slideTimer <= 0) {
isSliding = false;
slideDirection = 0;
// Return car to normal rotation
tween(playerCar, {
rotation: 0
}, {
duration: 500,
easing: tween.easeOut
});
// Snap back to nearest lane
var closestLane = 1;
var minDistance = Math.abs(playerCar.x - lanes[1]);
for (var i = 0; i < lanes.length; i++) {
var distance = Math.abs(playerCar.x - lanes[i]);
if (distance < minDistance) {
minDistance = distance;
closestLane = i;
}
}
playerCar.lane = closestLane;
playerCar.targetX = lanes[closestLane];
}
} else {
// Normal smooth car movement to target lane
var moveSpeed = 15;
if (Math.abs(playerCar.x - playerCar.targetX) > moveSpeed) {
if (playerCar.x < playerCar.targetX) {
playerCar.x += moveSpeed;
} else {
playerCar.x -= moveSpeed;
}
} else {
playerCar.x = playerCar.targetX;
}
}
// Increase game speed over time
gameSpeed += 0.002;
// Apply boost when gas pedal is pressed with smooth transition
if (isGasPedalPressed) {
// Smoothly increase speed to 2.0 over 1 second
tween(this, {
boostMultiplier: 2.0
}, {
duration: 1000,
easing: tween.easeOut
});
} else {
// Smoothly decrease speed to 1.0 over 0.5 seconds
tween(this, {
boostMultiplier: 1.0
}, {
duration: 500,
easing: tween.easeOut
});
}
// Limit effective speed to prevent exceeding 150 km/h
var maxEffectiveSpeed = 15; // 15 * 10 = 150 km/h display limit
var effectiveSpeed = Math.min(gameSpeed * boostMultiplier, maxEffectiveSpeed);
var speedLimitRatio = effectiveSpeed / (gameSpeed * boostMultiplier);
// Update distance score
distanceScore += effectiveSpeed * 0.1;
distanceTxt.setText('Distance: ' + Math.floor(distanceScore) + 'm');
// Update speedometer display
var currentSpeed = Math.floor(gameSpeed * boostMultiplier * 10); // Convert to km/h scale
// Limit maximum displayed speed to 150 km/h
currentSpeed = Math.min(currentSpeed, 150);
speedometerTxt.setText('Speed: ' + currentSpeed + ' km/h');
// Spawn road lines
roadLineSpawnTimer++;
if (roadLineSpawnTimer >= 20) {
roadLineSpawnTimer = 0;
for (var i = 0; i < 2; i++) {
var roadLine = new RoadLine();
roadLine.x = lanes[0] + i * (lanes[2] - lanes[0]);
roadLine.y = -50;
roadLine.speed = effectiveSpeed;
roadLines.push(roadLine);
game.addChild(roadLine);
}
}
// Spawn enemy cars
spawnTimer++;
// Increase spawn rate based on score and distance
var spawnRateBonus = Math.floor(LK.getScore() / 100) + Math.floor(distanceScore / 1000);
var baseSpawnRate = Math.max(20, 90 - Math.floor(gameSpeed) - spawnRateBonus);
if (spawnTimer >= baseSpawnRate) {
spawnTimer = 0;
var enemyCar = new EnemyCar();
var randomLane = Math.floor(Math.random() * 3);
enemyCar.x = lanes[randomLane];
enemyCar.y = -100;
enemyCar.speed = (gameSpeed + Math.random() * 3) * boostMultiplier;
enemyCar.lastY = enemyCar.y;
enemyCar.lastIntersecting = enemyCar.intersects(playerCar);
enemyCars.push(enemyCar);
game.addChild(enemyCar);
}
// Spawn trees
treeSpawnTimer++;
if (treeSpawnTimer >= 60) {
treeSpawnTimer = 0;
// Spawn trees on left side
if (Math.random() < 0.8) {
var leftTree = new Tree();
leftTree.x = Math.random() * (lanes[0] - 100); // Random position on left side
leftTree.y = -100;
leftTree.speed = effectiveSpeed;
trees.push(leftTree);
game.addChild(leftTree);
}
// Spawn trees on right side
if (Math.random() < 0.8) {
var rightTree = new Tree();
rightTree.x = lanes[2] + 100 + Math.random() * (2048 - lanes[2] - 200); // Random position on right side
rightTree.y = -100;
rightTree.speed = effectiveSpeed;
trees.push(rightTree);
game.addChild(rightTree);
}
}
// Spawn bushes
bushSpawnTimer++;
if (bushSpawnTimer >= 40) {
bushSpawnTimer = 0;
// Spawn bushes on left side between trees
if (Math.random() < 0.6) {
var leftBush = new Bush();
leftBush.x = Math.random() * (lanes[0] - 50); // Random position on left side
leftBush.y = -50;
leftBush.speed = effectiveSpeed;
bushes.push(leftBush);
game.addChild(leftBush);
}
// Spawn bushes on right side between trees
if (Math.random() < 0.6) {
var rightBush = new Bush();
rightBush.x = lanes[2] + 50 + Math.random() * (2048 - lanes[2] - 150); // Random position on right side
rightBush.y = -50;
rightBush.speed = effectiveSpeed;
bushes.push(rightBush);
game.addChild(rightBush);
}
}
// Spawn coins
coinSpawnTimer++;
if (coinSpawnTimer >= 120) {
coinSpawnTimer = 0;
if (Math.random() < 0.7) {
var coin = new Coin();
var randomLane = Math.floor(Math.random() * 3);
coin.x = lanes[randomLane];
coin.y = -50;
coin.speed = effectiveSpeed;
coin.lastY = coin.y;
coin.lastIntersecting = coin.intersects(playerCar);
coins.push(coin);
game.addChild(coin);
}
}
// Spawn fuel tanks
fuelTankSpawnTimer++;
if (fuelTankSpawnTimer >= 150) {
fuelTankSpawnTimer = 0;
if (Math.random() < 0.7) {
var fuelTank = new FuelTank();
var randomLane = Math.floor(Math.random() * 3);
fuelTank.x = lanes[randomLane];
fuelTank.y = -50;
fuelTank.speed = effectiveSpeed;
fuelTank.lastY = fuelTank.y;
fuelTank.lastIntersecting = fuelTank.intersects(playerCar);
fuelTanks.push(fuelTank);
game.addChild(fuelTank);
}
}
// Spawn spilled fuel
spilledFuelSpawnTimer++;
if (spilledFuelSpawnTimer >= 200) {
spilledFuelSpawnTimer = 0;
if (Math.random() < 0.4) {
var spilledFuel = new SpilledFuel();
var randomLane = Math.floor(Math.random() * 3);
spilledFuel.x = lanes[randomLane];
spilledFuel.y = -50;
spilledFuel.speed = effectiveSpeed;
spilledFuel.lastY = spilledFuel.y;
spilledFuel.lastIntersecting = spilledFuel.intersects(playerCar);
spilledFuels.push(spilledFuel);
game.addChild(spilledFuel);
}
}
// Spawn humans every 300 meters
if (Math.floor(distanceScore) >= distanceForNextHumans) {
distanceForNextHumans += 300;
// Spawn 2 humans
for (var h = 0; h < 2; h++) {
var human = new Human();
var randomLane = Math.floor(Math.random() * 3);
human.x = lanes[randomLane];
human.y = -100 - h * 150; // Space them out vertically
human.speed = effectiveSpeed;
human.lastY = human.y;
human.lastIntersecting = human.intersects(playerCar);
humans.push(human);
game.addChild(human);
}
}
// Update and check road lines
for (var i = roadLines.length - 1; i >= 0; i--) {
var roadLine = roadLines[i];
roadLine.speed = effectiveSpeed;
if (roadLine.lastY === undefined) roadLine.lastY = roadLine.y;
// Remove road lines that go off screen
if (roadLine.lastY <= 2732 + 50 && roadLine.y > 2732 + 50) {
roadLine.destroy();
roadLines.splice(i, 1);
continue;
}
roadLine.lastY = roadLine.y;
}
// Update and check enemy cars
for (var i = enemyCars.length - 1; i >= 0; i--) {
var enemyCar = enemyCars[i];
// Increase enemy speed based on score and distance
var speedBonus = Math.floor(LK.getScore() / 50) + Math.floor(distanceScore / 500);
var enemyBaseSpeed = (gameSpeed + 2 + speedBonus) * boostMultiplier;
enemyCar.speed = Math.min(enemyBaseSpeed, maxEffectiveSpeed + 2);
// Remove cars that go off screen
if (enemyCar.lastY <= 2732 + 100 && enemyCar.y > 2732 + 100) {
enemyCar.destroy();
enemyCars.splice(i, 1);
continue;
}
// Check collision with player
var currentIntersecting = enemyCar.intersects(playerCar);
if (!enemyCar.lastIntersecting && currentIntersecting) {
// Collision detected - game over
saveScore(LK.getScore());
LK.getSound('crash').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
enemyCar.lastY = enemyCar.y;
enemyCar.lastIntersecting = currentIntersecting;
}
// Update and check trees
for (var i = trees.length - 1; i >= 0; i--) {
var tree = trees[i];
tree.speed = effectiveSpeed;
if (tree.lastY === undefined) tree.lastY = tree.y;
// Remove trees that go off screen
if (tree.lastY <= 2732 + 100 && tree.y > 2732 + 100) {
tree.destroy();
trees.splice(i, 1);
continue;
}
tree.lastY = tree.y;
}
// Update and check bushes
for (var i = bushes.length - 1; i >= 0; i--) {
var bush = bushes[i];
bush.speed = effectiveSpeed;
if (bush.lastY === undefined) bush.lastY = bush.y;
// Remove bushes that go off screen
if (bush.lastY <= 2732 + 50 && bush.y > 2732 + 50) {
bush.destroy();
bushes.splice(i, 1);
continue;
}
bush.lastY = bush.y;
}
// Update and check coins
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
coin.speed = effectiveSpeed;
// Remove coins that go off screen
if (coin.lastY <= 2732 + 50 && coin.y > 2732 + 50) {
coin.destroy();
coins.splice(i, 1);
continue;
}
// Check collection by player
var currentIntersecting = coin.intersects(playerCar);
if (!coin.lastIntersecting && currentIntersecting) {
// Coin collected
LK.setScore(LK.getScore() + 10);
scoreTxt.setText(LK.getScore().toString());
LK.getSound('collectCoin').play();
coin.destroy();
coins.splice(i, 1);
continue;
}
coin.lastY = coin.y;
coin.lastIntersecting = currentIntersecting;
}
// Update fuel system
currentFuel -= fuelConsumptionRate * boostMultiplier;
if (currentFuel <= 0) {
currentFuel = 0;
// Game over due to no fuel
saveScore(LK.getScore());
LK.effects.flashScreen(0xff8800, 1000);
LK.showGameOver();
return;
}
// Update fuel display with color coding
var fuelPercentage = Math.floor(currentFuel / maxFuel * 100);
fuelTxt.setText('Fuel: ' + fuelPercentage + '%');
if (fuelPercentage > 50) {
fuelTxt.fill = 0x00FF00; // Green
} else if (fuelPercentage > 25) {
fuelTxt.fill = 0xFFFF00; // Yellow
} else {
fuelTxt.fill = 0xFF0000; // Red
}
// Update and check fuel tanks
for (var i = fuelTanks.length - 1; i >= 0; i--) {
var fuelTank = fuelTanks[i];
fuelTank.speed = effectiveSpeed;
// Remove fuel tanks that go off screen
if (fuelTank.lastY <= 2732 + 50 && fuelTank.y > 2732 + 50) {
fuelTank.destroy();
fuelTanks.splice(i, 1);
continue;
}
// Check collection by player
var currentIntersecting = fuelTank.intersects(playerCar);
if (!fuelTank.lastIntersecting && currentIntersecting) {
// Fuel tank collected
currentFuel = Math.min(currentFuel + 30, maxFuel);
LK.setScore(LK.getScore() + 5);
scoreTxt.setText(LK.getScore().toString());
LK.getSound('collectCoin').play();
fuelTank.destroy();
fuelTanks.splice(i, 1);
continue;
}
fuelTank.lastY = fuelTank.y;
fuelTank.lastIntersecting = currentIntersecting;
}
// Update and check spilled fuel
for (var i = spilledFuels.length - 1; i >= 0; i--) {
var spilledFuel = spilledFuels[i];
spilledFuel.speed = effectiveSpeed;
// Remove spilled fuel that goes off screen
if (spilledFuel.lastY <= 2732 + 50 && spilledFuel.y > 2732 + 50) {
spilledFuel.destroy();
spilledFuels.splice(i, 1);
continue;
}
// Check collision with player
var currentIntersecting = spilledFuel.intersects(playerCar);
if (!spilledFuel.lastIntersecting && currentIntersecting && !isSliding) {
// Spilled fuel collision - make car slide
isSliding = true;
slideDirection = (Math.random() - 0.5) * 2; // Random slide direction
slideTimer = 90; // Slide for 1.5 seconds at 60fps
// Visual effect for hitting spilled fuel
LK.effects.flashObject(playerCar, 0x8B4513, 500);
// Add spinning rotation effect
tween(playerCar, {
rotation: playerCar.rotation + Math.PI * 4 // Spin 2 full rotations
}, {
duration: 1500,
easing: tween.easeOut
});
}
spilledFuel.lastY = spilledFuel.y;
spilledFuel.lastIntersecting = currentIntersecting;
}
// Update and check humans
for (var i = humans.length - 1; i >= 0; i--) {
var human = humans[i];
human.speed = effectiveSpeed;
// Remove humans that go off screen
if (human.lastY <= 2732 + 100 && human.y > 2732 + 100) {
human.destroy();
humans.splice(i, 1);
continue;
}
// Check collision with player
var currentIntersecting = human.intersects(playerCar);
if (!human.lastIntersecting && currentIntersecting) {
// Human collision detected - game over
saveScore(LK.getScore());
LK.getSound('crash').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
human.lastY = human.y;
human.lastIntersecting = currentIntersecting;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -175,9 +175,9 @@
var slideDirection = 0;
var slideTimer = 0;
var humans = [];
var humanSpawnTimer = 0;
-var distanceForNextHumans = 100; // Track when to spawn next humans
+var distanceForNextHumans = 300; // Track when to spawn next humans
// Create score display using asset
var scoreDisplay = LK.getAsset('Score', {
anchorX: 0.5,
anchorY: 0
@@ -758,11 +758,11 @@
spilledFuels.push(spilledFuel);
game.addChild(spilledFuel);
}
}
- // Spawn humans every 100 meters
+ // Spawn humans every 300 meters
if (Math.floor(distanceScore) >= distanceForNextHumans) {
- distanceForNextHumans += 100;
+ distanceForNextHumans += 300;
// Spawn 2 humans
for (var h = 0; h < 2; h++) {
var human = new Human();
var randomLane = Math.floor(Math.random() * 3);
Coin. In-Game asset. 2d. High contrast. No shadows
Yol hattı. In-Game asset. 2d. High contrast. No shadows
Score. In-Game asset. 2d. High contrast. No shadows
Şehir. In-Game asset. 2d. High contrast. No shadows
Gaz pedalı. In-Game asset. 2d. High contrast. No shadows
Sağ sola hareket oktuşuşlar. In-Game asset. 2d. High contrast. No shadows
Kuş bakışı ağaç. In-Game asset. 2d. High contrast. No shadows
Çalı. In-Game asset. 2d. High contrast. No shadows
Benzin kutusu. In-Game asset. 2d. High contrast. No shadows
Dökülmüş benzin. In-Game asset. 2d. High contrast. No shadows
Yola koyulmuş kutular. In-Game asset. 2d. High contrast. No shadows
Kuş bakışı Ferrari araba. In-Game asset. 2d. High contrast. No shadows
Kuş bakışı Lamborghini. In-Game asset. 2d. High contrast. No shadows
Kuş bakışı kosiegg. In-Game asset. 2d. High contrast. No shadows
Bugatti kuş bakışı. In-Game asset. 2d. High contrast. No shadows