/**** * Classes ****/ // Class for coins var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += 5; // Move coins downwards }; }); // Class for obstacles var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); self.update = function () { self.y += 7; // Move obstacles downwards }; }); //<Assets used in the game will automatically appear here> // Class for the player's vehicle var PlayerVehicle = Container.expand(function () { var self = Container.call(this); var vehicleGraphics = self.attachAsset('playerVehicle', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); self.speed = 10; self.update = function () { // Update logic for player vehicle }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Create left move button var leftButton = new Text2('<', { size: 100, fill: "#ffffff" }); leftButton.anchor.set(0, 0.5); // Align the text to the left leftButton.x = 0; // Position it at the left edge leftButton.y = 2732 / 2; // Center it vertically LK.gui.left.addChild(leftButton); // Create right move button var rightButton = new Text2('>', { size: 100, fill: "#ffffff" }); rightButton.anchor.set(1, 0.5); // Align the text to the right rightButton.x = 2048; // Position it at the right edge rightButton.y = 2732 / 2; // Center it vertically LK.gui.right.addChild(rightButton); // Event listeners for left and right buttons leftButton.down = function (x, y, obj) { playerVehicle.x -= playerVehicle.speed; }; rightButton.down = function (x, y, obj) { playerVehicle.x += playerVehicle.speed; }; // Play background music from the 'b4' song LK.playMusic('b4'); // Add a highway background var background = LK.getAsset('backgroundColumn', { anchorX: 0.5, anchorY: 0.5, scaleX: 20.48, // Scale to fit the width of the game scaleY: 27.32 // Scale to fit the height of the game }); background.x = 2048 / 2; background.y = 2732 / 2; game.addChild(background); // Create a score text object to display the score at the top of the screen var scoreText = new Text2('Score: 0', { size: 100, fill: "#ffffff" }); scoreText.anchor.set(0.5, 0); // Center the text horizontally at the top LK.gui.top.addChild(scoreText); // Create a shop button to display on the right side of the top of the screen var shopButton = new Text2('Shop', { size: 100, fill: "#ffffff" }); shopButton.anchor.set(1, 0); // Align the text to the right shopButton.x = 2048; // Position it at the right edge shopButton.y = 0; // Align it to the top LK.gui.top.addChild(shopButton); // Initialize arrays for coins and obstacles var coins = []; var obstacles = []; var playerVehicle = game.addChild(new PlayerVehicle()); playerVehicle.x = 2048 / 2; playerVehicle.y = 2732 - playerVehicle.height; // Move the player's vehicle slightly upwards from the bottom // Function to handle movement function handleMove(x, y, obj) { playerVehicle.x = x; } // Event listeners for touch/mouse events game.down = function (x, y, obj) { handleMove(x, y, obj); }; game.move = function (x, y, obj) { handleMove(x, y, obj); }; // Game update loop game.update = function () { // Update player vehicle playerVehicle.update(); // Update coins for (var i = coins.length - 1; i >= 0; i--) { coins[i].update(); if (coins[i].intersects(playerVehicle)) { // Collect coin coins[i].destroy(); coins.splice(i, 1); LK.setScore(LK.getScore() + 1); // Update the score text scoreText.setText('Score: ' + LK.getScore()); if (LK.getScore() >= 30) { LK.showGameOver(); } } else if (coins[i].y > 2732) { // Remove off-screen coins coins[i].destroy(); coins.splice(i, 1); } } // Update obstacles for (var j = obstacles.length - 1; j >= 0; j--) { obstacles[j].update(); if (obstacles[j].intersects(playerVehicle)) { // Collision with obstacle LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } else if (obstacles[j].y > 2732) { // Remove off-screen obstacles obstacles[j].destroy(); obstacles.splice(j, 1); } } // Spawn new coins and obstacles if (LK.ticks % 60 == 0) { var newCoin = new Coin(); newCoin.x = Math.random() * 2048; newCoin.y = -50; coins.push(newCoin); game.addChild(newCoin); var newObstacle = new Obstacle(); newObstacle.x = Math.random() * 2048; newObstacle.y = -50; obstacles.push(newObstacle); game.addChild(newObstacle); } };
/****
* Classes
****/
// Class for coins
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 5; // Move coins downwards
};
});
// Class for obstacles
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.update = function () {
self.y += 7; // Move obstacles downwards
};
});
//<Assets used in the game will automatically appear here>
// Class for the player's vehicle
var PlayerVehicle = Container.expand(function () {
var self = Container.call(this);
var vehicleGraphics = self.attachAsset('playerVehicle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.speed = 10;
self.update = function () {
// Update logic for player vehicle
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Create left move button
var leftButton = new Text2('<', {
size: 100,
fill: "#ffffff"
});
leftButton.anchor.set(0, 0.5); // Align the text to the left
leftButton.x = 0; // Position it at the left edge
leftButton.y = 2732 / 2; // Center it vertically
LK.gui.left.addChild(leftButton);
// Create right move button
var rightButton = new Text2('>', {
size: 100,
fill: "#ffffff"
});
rightButton.anchor.set(1, 0.5); // Align the text to the right
rightButton.x = 2048; // Position it at the right edge
rightButton.y = 2732 / 2; // Center it vertically
LK.gui.right.addChild(rightButton);
// Event listeners for left and right buttons
leftButton.down = function (x, y, obj) {
playerVehicle.x -= playerVehicle.speed;
};
rightButton.down = function (x, y, obj) {
playerVehicle.x += playerVehicle.speed;
};
// Play background music from the 'b4' song
LK.playMusic('b4');
// Add a highway background
var background = LK.getAsset('backgroundColumn', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 20.48,
// Scale to fit the width of the game
scaleY: 27.32 // Scale to fit the height of the game
});
background.x = 2048 / 2;
background.y = 2732 / 2;
game.addChild(background);
// Create a score text object to display the score at the top of the screen
var scoreText = new Text2('Score: 0', {
size: 100,
fill: "#ffffff"
});
scoreText.anchor.set(0.5, 0); // Center the text horizontally at the top
LK.gui.top.addChild(scoreText);
// Create a shop button to display on the right side of the top of the screen
var shopButton = new Text2('Shop', {
size: 100,
fill: "#ffffff"
});
shopButton.anchor.set(1, 0); // Align the text to the right
shopButton.x = 2048; // Position it at the right edge
shopButton.y = 0; // Align it to the top
LK.gui.top.addChild(shopButton);
// Initialize arrays for coins and obstacles
var coins = [];
var obstacles = [];
var playerVehicle = game.addChild(new PlayerVehicle());
playerVehicle.x = 2048 / 2;
playerVehicle.y = 2732 - playerVehicle.height; // Move the player's vehicle slightly upwards from the bottom
// Function to handle movement
function handleMove(x, y, obj) {
playerVehicle.x = x;
}
// Event listeners for touch/mouse events
game.down = function (x, y, obj) {
handleMove(x, y, obj);
};
game.move = function (x, y, obj) {
handleMove(x, y, obj);
};
// Game update loop
game.update = function () {
// Update player vehicle
playerVehicle.update();
// Update coins
for (var i = coins.length - 1; i >= 0; i--) {
coins[i].update();
if (coins[i].intersects(playerVehicle)) {
// Collect coin
coins[i].destroy();
coins.splice(i, 1);
LK.setScore(LK.getScore() + 1);
// Update the score text
scoreText.setText('Score: ' + LK.getScore());
if (LK.getScore() >= 30) {
LK.showGameOver();
}
} else if (coins[i].y > 2732) {
// Remove off-screen coins
coins[i].destroy();
coins.splice(i, 1);
}
}
// Update obstacles
for (var j = obstacles.length - 1; j >= 0; j--) {
obstacles[j].update();
if (obstacles[j].intersects(playerVehicle)) {
// Collision with obstacle
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
} else if (obstacles[j].y > 2732) {
// Remove off-screen obstacles
obstacles[j].destroy();
obstacles.splice(j, 1);
}
}
// Spawn new coins and obstacles
if (LK.ticks % 60 == 0) {
var newCoin = new Coin();
newCoin.x = Math.random() * 2048;
newCoin.y = -50;
coins.push(newCoin);
game.addChild(newCoin);
var newObstacle = new Obstacle();
newObstacle.x = Math.random() * 2048;
newObstacle.y = -50;
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
};
highway. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
coin. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
thar car. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
car. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.