/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = carGraphics.width;
self.height = carGraphics.height;
self.speed = 0;
self.maxSpeed = 15;
self.acceleration = 0.2;
self.deceleration = 0.1;
self.turnSpeed = 5;
self.moving = false;
self.accelerate = function () {
self.moving = true;
if (self.speed < self.maxSpeed) {
tween(self, {
speed: self.maxSpeed
}, {
duration: 500,
easing: tween.easeOut
});
}
};
self.brake = function () {
if (self.speed > 0) {
tween(self, {
speed: 0
}, {
duration: 300,
easing: tween.easeIn
});
}
};
self.coast = function () {
self.moving = false;
if (self.speed > 0) {
tween(self, {
speed: 0
}, {
duration: 1000,
easing: tween.easeOut
});
}
};
self.turnLeft = function () {
self.x -= self.turnSpeed * (self.speed / self.maxSpeed) * 2;
};
self.turnRight = function () {
self.x += self.turnSpeed * (self.speed / self.maxSpeed) * 2;
};
self.update = function () {
if (self.moving) {
self.accelerate();
} else {
self.coast();
}
// Keep car within bounds
if (self.x < roadLeft + self.width / 2) {
self.x = roadLeft + self.width / 2;
}
if (self.x > roadRight - self.width / 2) {
self.x = roadRight - self.width / 2;
}
};
return self;
});
var Checkpoint = Container.expand(function () {
var self = Container.call(this);
var checkpointGraphics = self.attachAsset('checkpoint', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = checkpointGraphics.width;
self.height = checkpointGraphics.height;
self.update = function () {
self.y += playerCar.speed;
// Check if off screen
if (self.y > 2732 + self.height) {
self.destroy();
var index = checkpoints.indexOf(self);
if (index > -1) {
checkpoints.splice(index, 1);
}
}
};
return self;
});
var Fuel = Container.expand(function () {
var self = Container.call(this);
var fuelGraphics = self.attachAsset('fuel', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = fuelGraphics.width;
self.height = fuelGraphics.height;
self.update = function () {
self.y += playerCar.speed;
// Check if off screen
if (self.y > 2732 + self.height) {
self.destroy();
var index = fuels.indexOf(self);
if (index > -1) {
fuels.splice(index, 1);
}
}
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = obstacleGraphics.width;
self.height = obstacleGraphics.height;
self.speed = 5;
self.update = function () {
self.y += playerCar.speed;
// Check if off screen
if (self.y > 2732 + self.height) {
self.destroy();
var index = obstacles.indexOf(self);
if (index > -1) {
obstacles.splice(index, 1);
}
}
};
return self;
});
var Road = Container.expand(function () {
var self = Container.call(this);
var roadGraphics = self.attachAsset('road', {
anchorX: 0.5,
anchorY: 0
});
self.width = roadGraphics.width;
self.height = roadGraphics.height;
self.update = function () {
// Update logic for the road can be added here if needed
};
return self;
});
var RoadLine = Container.expand(function () {
var self = Container.call(this);
var line = self.attachAsset('roadLine', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + line.height) {
self.y = -line.height;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x808080
});
/****
* Game Code
****/
// Update road lines
var roadWidth = 1000;
var roadLeft = (2048 - roadWidth) / 2;
var roadRight = roadLeft + roadWidth;
var gameSpeed = 1;
var score = 0;
var fuelLevel = 100;
var timeRemaining = 30;
var isGameOver = false;
var isGameStarted = false;
var lastObstacleTime = 0;
var lastFuelTime = 0;
var lastCheckpointTime = 0;
var obstacles = [];
var fuels = [];
var checkpoints = [];
var roadLines = [];
// Create road
var road = new Road();
road.x = 2048 / 2;
road.y = 0;
game.addChild(road);
// Create road lines
for (var i = 0; i < 20; i++) {
var roadLine = new RoadLine();
roadLine.x = 2048 / 2;
roadLine.y = i * 150 - 100;
roadLines.push(roadLine);
game.addChild(roadLine);
}
// Create player car
var playerCar = new Car();
playerCar.x = 2048 / 2;
playerCar.y = 2732 - 500;
game.addChild(playerCar);
// Create UI elements
var scoreTxt = new Text2('SCORE: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreTxt);
var fuelTxt = new Text2('FUEL: 100%', {
size: 60,
fill: 0xFFFFFF
});
fuelTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(fuelTxt);
var timeTxt = new Text2('TIME: 30s', {
size: 60,
fill: 0xFFFFFF
});
timeTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(timeTxt);
var startTxt = new Text2('TAP TO START', {
size: 100,
fill: 0xFFFFFF
});
startTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(startTxt);
// Left control
var leftControlArea = new Container();
var leftControlGraphics = LK.getAsset('road', {
anchorX: 0,
anchorY: 0,
width: 2048 / 2,
height: 2732,
alpha: 0
});
leftControlArea.addChild(leftControlGraphics);
game.addChild(leftControlArea);
// Right control
var rightControlArea = new Container();
var rightControlGraphics = LK.getAsset('road', {
anchorX: 0,
anchorY: 0,
width: 2048 / 2,
height: 2732,
alpha: 0
});
rightControlArea.x = 2048 / 2;
rightControlArea.addChild(rightControlGraphics);
game.addChild(rightControlArea);
// Controls
var leftPressed = false;
var rightPressed = false;
// Event handlers
game.down = function (x, y, obj) {
if (!isGameStarted) {
startGame();
return;
}
if (x < 2048 / 2) {
leftPressed = true;
} else {
rightPressed = true;
}
};
game.up = function (x, y, obj) {
if (x < 2048 / 2) {
leftPressed = false;
} else {
rightPressed = false;
}
};
game.move = function (x, y, obj) {
// No additional move handling needed
};
// Game functions
function startGame() {
isGameStarted = true;
startTxt.visible = false;
score = 0;
fuelLevel = 100;
timeRemaining = 30;
isGameOver = false;
playerCar.speed = 0;
// Clear existing objects
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
for (var i = 0; i < fuels.length; i++) {
fuels[i].destroy();
}
fuels = [];
for (var i = 0; i < checkpoints.length; i++) {
checkpoints[i].destroy();
}
checkpoints = [];
// Start the timer
startTimer();
// Start background music
LK.playMusic('bgmusic');
}
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = roadLeft + Math.random() * roadWidth;
obstacle.y = -obstacle.height;
obstacles.push(obstacle);
game.addChild(obstacle);
}
function spawnFuel() {
var fuel = new Fuel();
fuel.x = roadLeft + Math.random() * roadWidth;
fuel.y = -fuel.height;
fuels.push(fuel);
game.addChild(fuel);
}
function spawnCheckpoint() {
var checkpoint = new Checkpoint();
checkpoint.x = 2048 / 2;
checkpoint.y = -checkpoint.height;
checkpoints.push(checkpoint);
game.addChild(checkpoint);
}
function startTimer() {
LK.clearInterval(gameTimer);
gameTimer = LK.setInterval(function () {
if (isGameStarted && !isGameOver) {
timeRemaining--;
timeTxt.setText('TIME: ' + timeRemaining + 's');
if (timeRemaining <= 0) {
gameOver();
}
}
}, 1000);
}
function gameOver() {
isGameOver = true;
LK.showGameOver();
LK.stopMusic();
}
// Main game loop
var gameTimer;
game.update = function () {
if (!isGameStarted || isGameOver) {
return;
}
// Update score
score += playerCar.speed * 0.1;
scoreTxt.setText('SCORE: ' + Math.floor(score));
// Update fuel
fuelLevel -= 0.05 * (playerCar.speed / playerCar.maxSpeed);
if (fuelLevel <= 0) {
fuelLevel = 0;
gameOver();
}
fuelTxt.setText('FUEL: ' + Math.floor(fuelLevel) + '%');
// Handle controls
if (leftPressed) {
playerCar.turnLeft();
}
if (rightPressed) {
playerCar.turnRight();
}
if (leftPressed || rightPressed) {
playerCar.accelerate();
} else {
playerCar.coast();
}
// Spawn objects
if (LK.ticks - lastObstacleTime > 90) {
spawnObstacle();
lastObstacleTime = LK.ticks;
}
if (LK.ticks - lastFuelTime > 180) {
spawnFuel();
lastFuelTime = LK.ticks;
}
if (LK.ticks - lastCheckpointTime > 600) {
spawnCheckpoint();
lastCheckpointTime = LK.ticks;
}
// Update road lines
for (var i = 0; i < roadLines.length; i++) {
roadLines[i].speed = playerCar.speed;
roadLines[i].update();
}
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
obstacle.update();
// Check collision
if (playerCar.intersects(obstacle)) {
LK.getSound('crash').play();
LK.effects.flashObject(playerCar, 0xFF0000, 500);
playerCar.speed *= 0.5;
score -= 50;
fuelLevel -= fuelLevel * 0.29; // Reduce fuel by 29%
if (score < 0) {
score = 0;
}
// Remove obstacle
obstacle.destroy();
obstacles.splice(i, 1);
}
}
// Update fuels
for (var i = fuels.length - 1; i >= 0; i--) {
var fuel = fuels[i];
fuel.update();
// Check collection
if (playerCar.intersects(fuel)) {
LK.getSound('pickup').play();
LK.effects.flashObject(fuel, 0x00FF00, 300);
fuelLevel += 20;
if (fuelLevel > 100) {
fuelLevel = 100;
}
// Remove fuel
fuel.destroy();
fuels.splice(i, 1);
}
}
// Update checkpoints
for (var i = checkpoints.length - 1; i >= 0; i--) {
var checkpoint = checkpoints[i];
checkpoint.update();
// Check collection
if (playerCar.intersects(checkpoint)) {
LK.getSound('checkpoint_reached').play();
LK.effects.flashScreen(0xFFFF00, 300);
timeRemaining += 15;
score += 100;
// Remove checkpoint
checkpoint.destroy();
checkpoints.splice(i, 1);
}
}
// Update player car
playerCar.update();
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = carGraphics.width;
self.height = carGraphics.height;
self.speed = 0;
self.maxSpeed = 15;
self.acceleration = 0.2;
self.deceleration = 0.1;
self.turnSpeed = 5;
self.moving = false;
self.accelerate = function () {
self.moving = true;
if (self.speed < self.maxSpeed) {
tween(self, {
speed: self.maxSpeed
}, {
duration: 500,
easing: tween.easeOut
});
}
};
self.brake = function () {
if (self.speed > 0) {
tween(self, {
speed: 0
}, {
duration: 300,
easing: tween.easeIn
});
}
};
self.coast = function () {
self.moving = false;
if (self.speed > 0) {
tween(self, {
speed: 0
}, {
duration: 1000,
easing: tween.easeOut
});
}
};
self.turnLeft = function () {
self.x -= self.turnSpeed * (self.speed / self.maxSpeed) * 2;
};
self.turnRight = function () {
self.x += self.turnSpeed * (self.speed / self.maxSpeed) * 2;
};
self.update = function () {
if (self.moving) {
self.accelerate();
} else {
self.coast();
}
// Keep car within bounds
if (self.x < roadLeft + self.width / 2) {
self.x = roadLeft + self.width / 2;
}
if (self.x > roadRight - self.width / 2) {
self.x = roadRight - self.width / 2;
}
};
return self;
});
var Checkpoint = Container.expand(function () {
var self = Container.call(this);
var checkpointGraphics = self.attachAsset('checkpoint', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = checkpointGraphics.width;
self.height = checkpointGraphics.height;
self.update = function () {
self.y += playerCar.speed;
// Check if off screen
if (self.y > 2732 + self.height) {
self.destroy();
var index = checkpoints.indexOf(self);
if (index > -1) {
checkpoints.splice(index, 1);
}
}
};
return self;
});
var Fuel = Container.expand(function () {
var self = Container.call(this);
var fuelGraphics = self.attachAsset('fuel', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = fuelGraphics.width;
self.height = fuelGraphics.height;
self.update = function () {
self.y += playerCar.speed;
// Check if off screen
if (self.y > 2732 + self.height) {
self.destroy();
var index = fuels.indexOf(self);
if (index > -1) {
fuels.splice(index, 1);
}
}
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = obstacleGraphics.width;
self.height = obstacleGraphics.height;
self.speed = 5;
self.update = function () {
self.y += playerCar.speed;
// Check if off screen
if (self.y > 2732 + self.height) {
self.destroy();
var index = obstacles.indexOf(self);
if (index > -1) {
obstacles.splice(index, 1);
}
}
};
return self;
});
var Road = Container.expand(function () {
var self = Container.call(this);
var roadGraphics = self.attachAsset('road', {
anchorX: 0.5,
anchorY: 0
});
self.width = roadGraphics.width;
self.height = roadGraphics.height;
self.update = function () {
// Update logic for the road can be added here if needed
};
return self;
});
var RoadLine = Container.expand(function () {
var self = Container.call(this);
var line = self.attachAsset('roadLine', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + line.height) {
self.y = -line.height;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x808080
});
/****
* Game Code
****/
// Update road lines
var roadWidth = 1000;
var roadLeft = (2048 - roadWidth) / 2;
var roadRight = roadLeft + roadWidth;
var gameSpeed = 1;
var score = 0;
var fuelLevel = 100;
var timeRemaining = 30;
var isGameOver = false;
var isGameStarted = false;
var lastObstacleTime = 0;
var lastFuelTime = 0;
var lastCheckpointTime = 0;
var obstacles = [];
var fuels = [];
var checkpoints = [];
var roadLines = [];
// Create road
var road = new Road();
road.x = 2048 / 2;
road.y = 0;
game.addChild(road);
// Create road lines
for (var i = 0; i < 20; i++) {
var roadLine = new RoadLine();
roadLine.x = 2048 / 2;
roadLine.y = i * 150 - 100;
roadLines.push(roadLine);
game.addChild(roadLine);
}
// Create player car
var playerCar = new Car();
playerCar.x = 2048 / 2;
playerCar.y = 2732 - 500;
game.addChild(playerCar);
// Create UI elements
var scoreTxt = new Text2('SCORE: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreTxt);
var fuelTxt = new Text2('FUEL: 100%', {
size: 60,
fill: 0xFFFFFF
});
fuelTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(fuelTxt);
var timeTxt = new Text2('TIME: 30s', {
size: 60,
fill: 0xFFFFFF
});
timeTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(timeTxt);
var startTxt = new Text2('TAP TO START', {
size: 100,
fill: 0xFFFFFF
});
startTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(startTxt);
// Left control
var leftControlArea = new Container();
var leftControlGraphics = LK.getAsset('road', {
anchorX: 0,
anchorY: 0,
width: 2048 / 2,
height: 2732,
alpha: 0
});
leftControlArea.addChild(leftControlGraphics);
game.addChild(leftControlArea);
// Right control
var rightControlArea = new Container();
var rightControlGraphics = LK.getAsset('road', {
anchorX: 0,
anchorY: 0,
width: 2048 / 2,
height: 2732,
alpha: 0
});
rightControlArea.x = 2048 / 2;
rightControlArea.addChild(rightControlGraphics);
game.addChild(rightControlArea);
// Controls
var leftPressed = false;
var rightPressed = false;
// Event handlers
game.down = function (x, y, obj) {
if (!isGameStarted) {
startGame();
return;
}
if (x < 2048 / 2) {
leftPressed = true;
} else {
rightPressed = true;
}
};
game.up = function (x, y, obj) {
if (x < 2048 / 2) {
leftPressed = false;
} else {
rightPressed = false;
}
};
game.move = function (x, y, obj) {
// No additional move handling needed
};
// Game functions
function startGame() {
isGameStarted = true;
startTxt.visible = false;
score = 0;
fuelLevel = 100;
timeRemaining = 30;
isGameOver = false;
playerCar.speed = 0;
// Clear existing objects
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
for (var i = 0; i < fuels.length; i++) {
fuels[i].destroy();
}
fuels = [];
for (var i = 0; i < checkpoints.length; i++) {
checkpoints[i].destroy();
}
checkpoints = [];
// Start the timer
startTimer();
// Start background music
LK.playMusic('bgmusic');
}
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = roadLeft + Math.random() * roadWidth;
obstacle.y = -obstacle.height;
obstacles.push(obstacle);
game.addChild(obstacle);
}
function spawnFuel() {
var fuel = new Fuel();
fuel.x = roadLeft + Math.random() * roadWidth;
fuel.y = -fuel.height;
fuels.push(fuel);
game.addChild(fuel);
}
function spawnCheckpoint() {
var checkpoint = new Checkpoint();
checkpoint.x = 2048 / 2;
checkpoint.y = -checkpoint.height;
checkpoints.push(checkpoint);
game.addChild(checkpoint);
}
function startTimer() {
LK.clearInterval(gameTimer);
gameTimer = LK.setInterval(function () {
if (isGameStarted && !isGameOver) {
timeRemaining--;
timeTxt.setText('TIME: ' + timeRemaining + 's');
if (timeRemaining <= 0) {
gameOver();
}
}
}, 1000);
}
function gameOver() {
isGameOver = true;
LK.showGameOver();
LK.stopMusic();
}
// Main game loop
var gameTimer;
game.update = function () {
if (!isGameStarted || isGameOver) {
return;
}
// Update score
score += playerCar.speed * 0.1;
scoreTxt.setText('SCORE: ' + Math.floor(score));
// Update fuel
fuelLevel -= 0.05 * (playerCar.speed / playerCar.maxSpeed);
if (fuelLevel <= 0) {
fuelLevel = 0;
gameOver();
}
fuelTxt.setText('FUEL: ' + Math.floor(fuelLevel) + '%');
// Handle controls
if (leftPressed) {
playerCar.turnLeft();
}
if (rightPressed) {
playerCar.turnRight();
}
if (leftPressed || rightPressed) {
playerCar.accelerate();
} else {
playerCar.coast();
}
// Spawn objects
if (LK.ticks - lastObstacleTime > 90) {
spawnObstacle();
lastObstacleTime = LK.ticks;
}
if (LK.ticks - lastFuelTime > 180) {
spawnFuel();
lastFuelTime = LK.ticks;
}
if (LK.ticks - lastCheckpointTime > 600) {
spawnCheckpoint();
lastCheckpointTime = LK.ticks;
}
// Update road lines
for (var i = 0; i < roadLines.length; i++) {
roadLines[i].speed = playerCar.speed;
roadLines[i].update();
}
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
obstacle.update();
// Check collision
if (playerCar.intersects(obstacle)) {
LK.getSound('crash').play();
LK.effects.flashObject(playerCar, 0xFF0000, 500);
playerCar.speed *= 0.5;
score -= 50;
fuelLevel -= fuelLevel * 0.29; // Reduce fuel by 29%
if (score < 0) {
score = 0;
}
// Remove obstacle
obstacle.destroy();
obstacles.splice(i, 1);
}
}
// Update fuels
for (var i = fuels.length - 1; i >= 0; i--) {
var fuel = fuels[i];
fuel.update();
// Check collection
if (playerCar.intersects(fuel)) {
LK.getSound('pickup').play();
LK.effects.flashObject(fuel, 0x00FF00, 300);
fuelLevel += 20;
if (fuelLevel > 100) {
fuelLevel = 100;
}
// Remove fuel
fuel.destroy();
fuels.splice(i, 1);
}
}
// Update checkpoints
for (var i = checkpoints.length - 1; i >= 0; i--) {
var checkpoint = checkpoints[i];
checkpoint.update();
// Check collection
if (playerCar.intersects(checkpoint)) {
LK.getSound('checkpoint_reached').play();
LK.effects.flashScreen(0xFFFF00, 300);
timeRemaining += 15;
score += 100;
// Remove checkpoint
checkpoint.destroy();
checkpoints.splice(i, 1);
}
}
// Update player car
playerCar.update();
};
Pixel art benzin bidonu. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Piksel sanatı kırmızı bayrak. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Piksel sanatı trafik engeli. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Piksel sanatı formula arabası kırmızı kuş bakışı. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows