/**** * Classes ****/ // Define the Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5, width: 300, height: 300 }); if (LK.getScore() < 45) { self.speed = 5; } else if (LK.getScore() < 100) { self.speed = 10; } else { self.speed = 15; } self.update = function () { self.y += self.speed; if (self.y > player.y) { self.destroy(); } }; }); //<Assets used in the game will automatically appear 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, width: 200, height: 200 }); self.speed = 60 * 999999999; self.update = function () { // Player update logic }; self.move = function (x, y) { self.x = x; self.y = y; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Replace 'background_image_id' with the actual id of the highway background image // Initialize and display the score in the game. var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.setText(LK.getScore()); // LK.getScore is initialized to zero at game start. scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize and display the background var background = LK.getAsset('background', { anchorX: 0.0, anchorY: 0.0, x: 0, y: 0 }); game.addChild(background); // Initialize player var player = new Player(); player.x = 2048 / 2; player.y = 2732 - 200; game.addChild(player); // Initialize obstacles array var obstacles = []; // Function to spawn a new obstacle function spawnObstacle() { var obstacle = new Obstacle(); obstacle.x = Math.random() * 2048; obstacle.y = -50; obstacles.push(obstacle); game.addChild(obstacle); } // Handle player movement game.move = function (x, y, obj) { player.move(x, y); }; // Update game state game.update = function () { // Update player player.update(); // Update obstacles for (var i = obstacles.length - 1; i >= 0; i--) { obstacles[i].update(); if (player.intersects(obstacles[i]) && player.x > obstacles[i].x - 50 && player.x < obstacles[i].x + 50 && player.y > obstacles[i].y - 50 && player.y < obstacles[i].y + 50) { LK.showGameOver(); } } // Check if player is 5 millimeters from the game boundary if (player.x < 5 || player.x > 2048 - player.width - 5 || player.y < 5 || player.y > 2727) { LK.showGameOver(); } // Spawn new obstacle every 10 ticks (0.16 second) initially, then decrease the interval as time passes var spawnInterval = Math.max(3, 40 - Math.floor(LK.ticks / 200)); if (LK.ticks % spawnInterval == 0) { spawnObstacle(); // If score is 30 or more, spawn an additional obstacle if (LK.getScore() >= 30) { spawnObstacle(); } } // Increase score by 1 every second if (LK.ticks % 60 == 0) { LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); } };
/****
* Classes
****/
// Define the Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5,
width: 300,
height: 300
});
if (LK.getScore() < 45) {
self.speed = 5;
} else if (LK.getScore() < 100) {
self.speed = 10;
} else {
self.speed = 15;
}
self.update = function () {
self.y += self.speed;
if (self.y > player.y) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear 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,
width: 200,
height: 200
});
self.speed = 60 * 999999999;
self.update = function () {
// Player update logic
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Replace 'background_image_id' with the actual id of the highway background image
// Initialize and display the score in the game.
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.setText(LK.getScore()); // LK.getScore is initialized to zero at game start.
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize and display the background
var background = LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0
});
game.addChild(background);
// Initialize player
var player = new Player();
player.x = 2048 / 2;
player.y = 2732 - 200;
game.addChild(player);
// Initialize obstacles array
var obstacles = [];
// Function to spawn a new obstacle
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048;
obstacle.y = -50;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Handle player movement
game.move = function (x, y, obj) {
player.move(x, y);
};
// Update game state
game.update = function () {
// Update player
player.update();
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
if (player.intersects(obstacles[i]) && player.x > obstacles[i].x - 50 && player.x < obstacles[i].x + 50 && player.y > obstacles[i].y - 50 && player.y < obstacles[i].y + 50) {
LK.showGameOver();
}
}
// Check if player is 5 millimeters from the game boundary
if (player.x < 5 || player.x > 2048 - player.width - 5 || player.y < 5 || player.y > 2727) {
LK.showGameOver();
}
// Spawn new obstacle every 10 ticks (0.16 second) initially, then decrease the interval as time passes
var spawnInterval = Math.max(3, 40 - Math.floor(LK.ticks / 200));
if (LK.ticks % spawnInterval == 0) {
spawnObstacle();
// If score is 30 or more, spawn an additional obstacle
if (LK.getScore() >= 30) {
spawnObstacle();
}
}
// Increase score by 1 every second
if (LK.ticks % 60 == 0) {
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
}
};
Chevalier à moitié mort. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Château fort détruit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Épée argenté dirigée vers bas. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.