/****
* Classes
****/
var FuelCanister = Container.expand(function () {
var self = Container.call(this);
var fuelGraphics = self.attachAsset('fuelCanister', {
anchorX: 0.5,
anchorY: 0.5,
width: 111,
height: 150
});
self.update = function () {
self.y += 25; // Move the fuel canister downwards at the same speed as the road
if (self.y > 2732) {
self.destroy(); // Remove the canister if it goes off-screen
}
self.lastY = self.y; // Track last Y position for correct repositioning
};
});
var FuelGauge = Container.expand(function () {
var self = Container.call(this);
var gaugeGraphics = self.attachAsset('gauge', {
anchorX: 0.5,
anchorY: 0.5
});
self.rotation = Math.PI; // Start at 50% fuel level
self.update = function () {
// Rotate counterclockwise to decrease fuel
self.lastRotation = self.lastRotation || self.rotation; // Initialize lastRotation if undefined
self.rotation -= Math.PI / 100 / 60; // 1% per second
if (self.rotation <= 0) {
self.rotation = 0; // Stop at 0% fuel
player.speed = 2; // Slow down the player's vehicle
LK.setTimeout(function () {
player.speed = 0; // Stop the player's vehicle after 3 seconds
LK.showGameOver(); // Trigger game over
}, 3000);
}
self.lastRotation = self.rotation; // Update lastRotation
};
});
// Define the Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics;
var vehicleTypes = ['motorracer', 'ccrcar', 'truck', 'truck2', 'ccrcar2'];
var randomNum = Math.floor(Math.random() * vehicleTypes.length);
obstacleGraphics = self.attachAsset(vehicleTypes[randomNum], {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 10 + 5; // Assign a random speed between 5 and 15
if (obstacleGraphics.id === 'motorracer') {
LK.getSound('crossmotor').play({
loop: true
});
} else if (obstacleGraphics.id === 'ccrcar' || obstacleGraphics.id === 'ccrcar2') {
LK.getSound('car').play({
loop: true
});
self.sandDust = new SandDust();
self.sandDust.x = self.x;
self.sandDust.y = self.y + self.height / 2;
game.addChild(self.sandDust);
}
self.update = function () {
self.y += self.speed;
// Prevent obstacles from reaching the left and right sides of the map
if (self.x < 100) {
self.x = 100;
} else if (self.x > 1948 - self.width) {
self.x = 1948 - self.width;
}
if (self.lastY !== undefined && self.y > self.lastY) {
for (var i = 0; i < obstacles.length; i++) {
if (obstacles[i] !== self && self.intersects(obstacles[i])) {
if (self.x < obstacles[i].x) {
if (self.x - 10 > 0) {
// Ensure there's enough space on the left
self.x -= 10; // Move left to overtake
}
} else {
if (self.x + 10 < 2048 - self.width) {
// Ensure there's enough space on the right
self.x += 10; // Move right to overtake
}
}
}
}
// Check if the obstacle is close to the left or right edge and adjust speed for overtaking
if (self.x < 100 || self.x > 1948) {
self.speed += 10; // Increase speed more to ensure overtaking
} else {
self.speed = obstacleGraphics.id === '6782d97d7974b0fd3cf55603' ? 40 : 5; // Reset speed
}
}
self.lastY = self.y;
if (self.sandDust) {
self.sandDust.x = self.x;
self.sandDust.y = self.y + self.height / 2;
self.sandDust.update();
self.sandDust.animate();
}
if (self.y > 2732) {
self.y = -self.height;
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define the Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Player update logic
};
});
// Define the SandDust class
var SandDust = Container.expand(function () {
var self = Container.call(this);
var dustGraphics = self.attachAsset('sandDust', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -self.height;
}
};
self.animate = function () {
// Add animation logic here
dustGraphics.alpha -= 0.08;
if (dustGraphics.alpha <= 0) {
dustGraphics.alpha = 1;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var fuelCanister; // Define fuelCanister in the global scope
var road = game.attachAsset('road', {
anchorX: 0.5,
anchorY: 0.5
});
road.x = 2048 / 2;
road.y = 2732 / 2;
// Initialize fuel indicator
var fuelIndicator = LK.getAsset('fuelIndicator', {
anchorX: 0.5,
anchorY: 0.5
});
game.addChild(fuelIndicator);
// Initialize Max asset
var max = LK.getAsset('max', {
anchorX: 0.5,
// Center the anchor point
anchorY: 0.5
});
max.x = 2048 / 2 + 920; // Move right by 920 units
max.y = 2732 / 2 - 1180; // Move up by 1180 units
game.addChild(max);
// Initialize score
var player = new Player();
player.x = 2048 / 2;
player.y = 2732 - 200;
game.addChild(player);
// Initialize fuel gauge
var fuelGauge = new FuelGauge();
fuelGauge.x = 2048 - fuelGauge.width / 2 - 70; // Move the gauge right by 10 units
fuelGauge.y = 2732 - fuelGauge.height / 2 - 2450; // Move the gauge up by 2450 units
game.addChild(fuelGauge);
// Initialize score
var score = 0;
// Ensure the game load variable is initialized
var gameLoad = true;
var scoreLabel = new Text2('Overtakes:', {
size: 56.25,
fill: 0xFFFFFF
});
scoreLabel.anchor.set(1, 0); // Align to the right of the text
scoreLabel.x = 1024 - 10 - 777 - 77; // Move left by an additional 77 units
scoreLabel.y = 0;
LK.gui.top.addChild(scoreLabel);
var scoreTxt = new Text2(score.toString(), {
size: 56.25,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
scoreTxt.x = 1024 + 10 - 777 - 77; // Move left by an additional 77 units
LK.gui.top.addChild(scoreTxt);
// Initialize sand dust under the player
var sandDust = new SandDust();
sandDust.x = player.x;
sandDust.y = player.y + player.height / 2;
game.addChild(sandDust);
// Initialize obstacles
var obstacles = [];
var obstacleLoadDelay = 2000; // 2 seconds delay for loading new obstacles
var lastObstacleLoadTime = Date.now();
var previousY = -300; // Initialize previousY to ensure the first obstacle is placed correctly with a minimum distance of 300 units
var minDistance = 300; // Ensure minimum distance between obstacles is 300 units
var minXDistance = 300; // Ensure minimum distance between obstacles on the X axis
var lastX = 0; // Track last X position for obstacles
var vehicleTypes = ['motorracer', 'ccrcar', 'truck', 'ccrcar2', 'truck2'];
// Handle touch events for player movement
game.down = function (x, y, obj) {
this.startX = x;
};
game.move = function (x, y, obj) {
if (this.startX) {
var deltaX = x - this.startX;
this.startX = x;
player.x += deltaX;
}
};
game.up = function (x, y, obj) {
this.startX = null;
};
// Update game logic
game.update = function () {
if (LK.ticks % (60 * 20) === 0) {
// Every 20 seconds
LK.setTimeout(function () {
fuelCanister = new FuelCanister();
fuelCanister.x = 50 + Math.random() * (2048 - fuelCanister.width - 100);
fuelCanister.y = -fuelCanister.height; // Start above the screen
game.addChild(fuelCanister);
}, 3000); // Delay by 3 seconds
}
player.update();
fuelGauge.update();
// Ensure fuelGauge position remains constant
fuelGauge.x = 2048 - fuelGauge.width / 2 - 70; // Position 70 units from the right
fuelGauge.y = 2732 - fuelGauge.height / 2 - 2450; // Position 2450 units from the top
// Ensure fuelIndicator position remains constant
fuelIndicator.x = 2048 - 50 - fuelIndicator.width / 2; // Position 50 units from the right
fuelIndicator.y = 50 + fuelIndicator.height / 2; // Position 50 units from the top
// Handle fuel depletion effects
if (fuelGauge.rotation <= 0) {
road.y += player.speed * (fuelGauge.rotation / Math.PI); // Slow down the road as fuel depletes
if (road.y > 2732) {
road.y = 0;
}
} else {
road.y += 25;
if (road.y > 2732) {
road.y = 0;
}
}
sandDust.update();
sandDust.animate();
sandDust.x = player.x;
sandDust.y = player.y + player.height / 2;
if (Date.now() - lastObstacleLoadTime >= obstacleLoadDelay * 3 && obstacles.length < 5) {
var obstacle = new Obstacle(vehicleTypes[Math.floor(Math.random() * vehicleTypes.length)]);
obstacle.lastY = obstacle.y; // Initialize lastY for tracking changes on Y
obstacle.x = 100 + Math.random() * (2048 - obstacle.width - 200);
obstacle.y = previousY - minDistance - Math.random() * 100;
var repositionAttempts = 0;
while (repositionAttempts < 10) {
var overlap = false;
for (var j = 0; j < obstacles.length; j++) {
if (obstacle.intersects(obstacles[j]) || Math.abs(obstacle.x - obstacles[j].x) < minXDistance * 1.5) {
overlap = true;
break;
}
}
if (!overlap) {
break;
}
obstacle.x = 50 + Math.random() * (2048 - obstacle.width - 100);
obstacle.y = previousY - minDistance - Math.random() * 100;
repositionAttempts++;
}
if (overlap) {
obstacle.destroy(); // Remove the obstacle if it still overlaps after 10 attempts
} else {
obstacles.push(obstacle);
game.addChild(obstacle);
lastObstacleLoadTime = Date.now();
}
previousY = obstacle.y; // Update previousY after setting the obstacle's y position
obstacles.push(obstacle);
game.addChild(obstacle);
lastObstacleLoadTime = Date.now();
}
obstacles.forEach(function (obstacle) {
var lastY = obstacle.lastY || obstacle.y;
var lastX = obstacle.lastX || obstacle.x;
obstacle.lastY = obstacle.y; // Track last Y position for correct repositioning
obstacle.lastX = obstacle.x; // Track last X position for correct repositioning
obstacle.update();
if (player.intersects(obstacle)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
} else if (lastY > player.y && obstacle.y <= player.y) {
score++;
scoreTxt.setText(score.toString());
obstacle.speed += 10; // Increase speed when overtaking player
}
// Check for intersection with FuelCanister
if (fuelCanister && player.intersects(fuelCanister)) {
fuelGauge.rotation += Math.PI / 100 * 50; // Increase fuel by 50%
if (fuelGauge.rotation > Math.PI) {
fuelGauge.rotation = Math.PI; // Cap at 100%
}
fuelCanister.destroy(); // Remove the canister after use
fuelCanister = null; // Set fuelCanister to null to ensure it is removed
fuelGauge.lastRotation = fuelGauge.rotation; // Update lastRotation after refueling
}
obstacle.lastY = obstacle.y;
obstacle.lastX = obstacle.x;
});
// Move the road downwards to create an illusion of player moving forward
road.y += 25;
// If the road has moved off the screen, reset its position to create a loop
if (road.y > 2732) {
road.y = 0;
}
}; /****
* Classes
****/
var FuelCanister = Container.expand(function () {
var self = Container.call(this);
var fuelGraphics = self.attachAsset('fuelCanister', {
anchorX: 0.5,
anchorY: 0.5,
width: 111,
height: 150
});
self.update = function () {
self.y += 25; // Move the fuel canister downwards at the same speed as the road
if (self.y > 2732) {
self.destroy(); // Remove the canister if it goes off-screen
}
self.lastY = self.y; // Track last Y position for correct repositioning
};
});
var FuelGauge = Container.expand(function () {
var self = Container.call(this);
var gaugeGraphics = self.attachAsset('gauge', {
anchorX: 0.5,
anchorY: 0.5
});
self.rotation = Math.PI; // Start at 50% fuel level
self.update = function () {
// Rotate counterclockwise to decrease fuel
self.lastRotation = self.lastRotation || self.rotation; // Initialize lastRotation if undefined
self.rotation -= Math.PI / 100 / 60; // 1% per second
if (self.rotation <= 0) {
self.rotation = 0; // Stop at 0% fuel
player.speed = 2; // Slow down the player's vehicle
LK.setTimeout(function () {
player.speed = 0; // Stop the player's vehicle after 3 seconds
LK.showGameOver(); // Trigger game over
}, 3000);
}
self.lastRotation = self.rotation; // Update lastRotation
};
});
// Define the Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics;
var vehicleTypes = ['motorracer', 'ccrcar', 'truck', 'truck2', 'ccrcar2'];
var randomNum = Math.floor(Math.random() * vehicleTypes.length);
obstacleGraphics = self.attachAsset(vehicleTypes[randomNum], {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 10 + 5; // Assign a random speed between 5 and 15
if (obstacleGraphics.id === 'motorracer') {
LK.getSound('crossmotor').play({
loop: true
});
} else if (obstacleGraphics.id === 'ccrcar' || obstacleGraphics.id === 'ccrcar2') {
LK.getSound('car').play({
loop: true
});
self.sandDust = new SandDust();
self.sandDust.x = self.x;
self.sandDust.y = self.y + self.height / 2;
game.addChild(self.sandDust);
}
self.update = function () {
self.y += self.speed;
// Prevent obstacles from reaching the left and right sides of the map
if (self.x < 100) {
self.x = 100;
} else if (self.x > 1948 - self.width) {
self.x = 1948 - self.width;
}
if (self.lastY !== undefined && self.y > self.lastY) {
for (var i = 0; i < obstacles.length; i++) {
if (obstacles[i] !== self && self.intersects(obstacles[i])) {
if (self.x < obstacles[i].x) {
if (self.x - 10 > 0) {
// Ensure there's enough space on the left
self.x -= 10; // Move left to overtake
}
} else {
if (self.x + 10 < 2048 - self.width) {
// Ensure there's enough space on the right
self.x += 10; // Move right to overtake
}
}
}
}
// Check if the obstacle is close to the left or right edge and adjust speed for overtaking
if (self.x < 100 || self.x > 1948) {
self.speed += 10; // Increase speed more to ensure overtaking
} else {
self.speed = obstacleGraphics.id === '6782d97d7974b0fd3cf55603' ? 40 : 5; // Reset speed
}
}
self.lastY = self.y;
if (self.sandDust) {
self.sandDust.x = self.x;
self.sandDust.y = self.y + self.height / 2;
self.sandDust.update();
self.sandDust.animate();
}
if (self.y > 2732) {
self.y = -self.height;
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define the Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Player update logic
};
});
// Define the SandDust class
var SandDust = Container.expand(function () {
var self = Container.call(this);
var dustGraphics = self.attachAsset('sandDust', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -self.height;
}
};
self.animate = function () {
// Add animation logic here
dustGraphics.alpha -= 0.08;
if (dustGraphics.alpha <= 0) {
dustGraphics.alpha = 1;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var fuelCanister; // Define fuelCanister in the global scope
var road = game.attachAsset('road', {
anchorX: 0.5,
anchorY: 0.5
});
road.x = 2048 / 2;
road.y = 2732 / 2;
// Initialize fuel indicator
var fuelIndicator = LK.getAsset('fuelIndicator', {
anchorX: 0.5,
anchorY: 0.5
});
game.addChild(fuelIndicator);
// Initialize Max asset
var max = LK.getAsset('max', {
anchorX: 0.5,
// Center the anchor point
anchorY: 0.5
});
max.x = 2048 / 2 + 920; // Move right by 920 units
max.y = 2732 / 2 - 1180; // Move up by 1180 units
game.addChild(max);
// Initialize score
var player = new Player();
player.x = 2048 / 2;
player.y = 2732 - 200;
game.addChild(player);
// Initialize fuel gauge
var fuelGauge = new FuelGauge();
fuelGauge.x = 2048 - fuelGauge.width / 2 - 70; // Move the gauge right by 10 units
fuelGauge.y = 2732 - fuelGauge.height / 2 - 2450; // Move the gauge up by 2450 units
game.addChild(fuelGauge);
// Initialize score
var score = 0;
// Ensure the game load variable is initialized
var gameLoad = true;
var scoreLabel = new Text2('Overtakes:', {
size: 56.25,
fill: 0xFFFFFF
});
scoreLabel.anchor.set(1, 0); // Align to the right of the text
scoreLabel.x = 1024 - 10 - 777 - 77; // Move left by an additional 77 units
scoreLabel.y = 0;
LK.gui.top.addChild(scoreLabel);
var scoreTxt = new Text2(score.toString(), {
size: 56.25,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
scoreTxt.x = 1024 + 10 - 777 - 77; // Move left by an additional 77 units
LK.gui.top.addChild(scoreTxt);
// Initialize sand dust under the player
var sandDust = new SandDust();
sandDust.x = player.x;
sandDust.y = player.y + player.height / 2;
game.addChild(sandDust);
// Initialize obstacles
var obstacles = [];
var obstacleLoadDelay = 2000; // 2 seconds delay for loading new obstacles
var lastObstacleLoadTime = Date.now();
var previousY = -300; // Initialize previousY to ensure the first obstacle is placed correctly with a minimum distance of 300 units
var minDistance = 300; // Ensure minimum distance between obstacles is 300 units
var minXDistance = 300; // Ensure minimum distance between obstacles on the X axis
var lastX = 0; // Track last X position for obstacles
var vehicleTypes = ['motorracer', 'ccrcar', 'truck', 'ccrcar2', 'truck2'];
// Handle touch events for player movement
game.down = function (x, y, obj) {
this.startX = x;
};
game.move = function (x, y, obj) {
if (this.startX) {
var deltaX = x - this.startX;
this.startX = x;
player.x += deltaX;
}
};
game.up = function (x, y, obj) {
this.startX = null;
};
// Update game logic
game.update = function () {
if (LK.ticks % (60 * 20) === 0) {
// Every 20 seconds
LK.setTimeout(function () {
fuelCanister = new FuelCanister();
fuelCanister.x = 50 + Math.random() * (2048 - fuelCanister.width - 100);
fuelCanister.y = -fuelCanister.height; // Start above the screen
game.addChild(fuelCanister);
}, 3000); // Delay by 3 seconds
}
player.update();
fuelGauge.update();
// Ensure fuelGauge position remains constant
fuelGauge.x = 2048 - fuelGauge.width / 2 - 70; // Position 70 units from the right
fuelGauge.y = 2732 - fuelGauge.height / 2 - 2450; // Position 2450 units from the top
// Ensure fuelIndicator position remains constant
fuelIndicator.x = 2048 - 50 - fuelIndicator.width / 2; // Position 50 units from the right
fuelIndicator.y = 50 + fuelIndicator.height / 2; // Position 50 units from the top
// Handle fuel depletion effects
if (fuelGauge.rotation <= 0) {
road.y += player.speed * (fuelGauge.rotation / Math.PI); // Slow down the road as fuel depletes
if (road.y > 2732) {
road.y = 0;
}
} else {
road.y += 25;
if (road.y > 2732) {
road.y = 0;
}
}
sandDust.update();
sandDust.animate();
sandDust.x = player.x;
sandDust.y = player.y + player.height / 2;
if (Date.now() - lastObstacleLoadTime >= obstacleLoadDelay * 3 && obstacles.length < 5) {
var obstacle = new Obstacle(vehicleTypes[Math.floor(Math.random() * vehicleTypes.length)]);
obstacle.lastY = obstacle.y; // Initialize lastY for tracking changes on Y
obstacle.x = 100 + Math.random() * (2048 - obstacle.width - 200);
obstacle.y = previousY - minDistance - Math.random() * 100;
var repositionAttempts = 0;
while (repositionAttempts < 10) {
var overlap = false;
for (var j = 0; j < obstacles.length; j++) {
if (obstacle.intersects(obstacles[j]) || Math.abs(obstacle.x - obstacles[j].x) < minXDistance * 1.5) {
overlap = true;
break;
}
}
if (!overlap) {
break;
}
obstacle.x = 50 + Math.random() * (2048 - obstacle.width - 100);
obstacle.y = previousY - minDistance - Math.random() * 100;
repositionAttempts++;
}
if (overlap) {
obstacle.destroy(); // Remove the obstacle if it still overlaps after 10 attempts
} else {
obstacles.push(obstacle);
game.addChild(obstacle);
lastObstacleLoadTime = Date.now();
}
previousY = obstacle.y; // Update previousY after setting the obstacle's y position
obstacles.push(obstacle);
game.addChild(obstacle);
lastObstacleLoadTime = Date.now();
}
obstacles.forEach(function (obstacle) {
var lastY = obstacle.lastY || obstacle.y;
var lastX = obstacle.lastX || obstacle.x;
obstacle.lastY = obstacle.y; // Track last Y position for correct repositioning
obstacle.lastX = obstacle.x; // Track last X position for correct repositioning
obstacle.update();
if (player.intersects(obstacle)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
} else if (lastY > player.y && obstacle.y <= player.y) {
score++;
scoreTxt.setText(score.toString());
obstacle.speed += 10; // Increase speed when overtaking player
}
// Check for intersection with FuelCanister
if (fuelCanister && player.intersects(fuelCanister)) {
fuelGauge.rotation += Math.PI / 100 * 50; // Increase fuel by 50%
if (fuelGauge.rotation > Math.PI) {
fuelGauge.rotation = Math.PI; // Cap at 100%
}
fuelCanister.destroy(); // Remove the canister after use
fuelCanister = null; // Set fuelCanister to null to ensure it is removed
fuelGauge.lastRotation = fuelGauge.rotation; // Update lastRotation after refueling
}
obstacle.lastY = obstacle.y;
obstacle.lastX = obstacle.x;
});
// Move the road downwards to create an illusion of player moving forward
road.y += 25;
// If the road has moved off the screen, reset its position to create a loop
if (road.y > 2732) {
road.y = 0;
}
};
Photorealistic crossmotor racer, from back and verytop view
Photorealistic Cross-Country Dakar-Rally-Car from back,Top view.
Photorealistic Cross-Country Dakar-Rally-Car from topback view.
Photorealistic Dakar-Rally-Truck from back, Top view.
TOTALY SMOOT SANDROAD TEXTURE TOP VIEW
DUNE BUSH, TOP VIEW
Black fuelindicator no-gauge, with chrome round frame, white levelindicators, front view.