/**** * Classes ****/ var Bike = Container.expand(function () { var self = Container.call(this); var bikeGraphics = self.attachAsset('bike', { anchorX: 0, anchorY: -2.3, scaleX: 3, scaleY: 3 }); self.update = function () { self.x += 1.2; if (self.x > 2048) { self.x = -100; } // Play bike movement sound LK.getSound('bike_move').play(); }; self.jumping = false; self.jumpCounter = 0; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 3.4, anchorY: 3, scaleX: 3, scaleY: 3 }); self.update = function () { self.x += 10; }; }); var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: -3, anchorY: -2.3, scaleX: 3, scaleY: 3 }); self.update = function () { self.x -= 10; }; }); var Obstacle2 = Container.expand(function () { var self = Container.call(this); var obstacle2Graphics = self.attachAsset('obstacle2', { anchorX: -3, anchorY: 2.3, scaleX: 2, scaleY: 2 }); self.update = function () { self.x -= 10; self.y += 5; // Add a default downward movement for obstacle2 }; }); var Road = Container.expand(function () { var self = Container.call(this); var roadGraphics = self.attachAsset('road', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ LK.playMusic('bg_music'); var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var road = game.addChild(new Road()); road.x = 2048 / 2; road.y = 2732 / 2; var background1 = road; var background2 = new Road(); game.addChild(background2); background2.x = background1.x + 2048; background2.y = 2732 / 2; // Position background2 at the center of the screen vertically var bike = game.addChild(new Bike()); var obstacle = game.addChild(new Obstacle()); obstacle.x = 2048 / 2; obstacle.y = 2732 / 2; bike.x = 0; bike.y = 2732 / 2; var obstacle2; // Define obstacle2 in the global scope game.update = function () { var roadSpeed = 6; background1.x -= roadSpeed; background2.x -= roadSpeed; score += 5; // Increase the score based on the bike's distance scoreTxt.setText(score); // Update the score text if (background1.x <= -1024) { background1.x = background2.x + 2048; } if (background2.x <= -1024) { background2.x = background1.x + 2048; } if (LK.ticks % Math.floor(Math.random() * 1800) == 0) { // 60 ticks per second, so 1800 ticks = 30 seconds var newObstacle = new Obstacle(); newObstacle.x = 2048; // spawn at the right edge of the screen newObstacle.y = 2732 / 2; // spawn at the middle of the screen vertically game.addChild(newObstacle); obstacle2 = new Obstacle2(); // Assign the new Obstacle2 instance to the global obstacle2 variable obstacle2.x = 2048; // spawn at the right edge of the screen obstacle2.y = bike.y; // spawn at the player's vertical position game.addChild(obstacle2); // Play obstacle2 spawn sound LK.getSound('obstacle2_spawn').play(); } if (LK.ticks % 150 == 0) { // 60 ticks per second, so 300 ticks = 5 seconds var newBullet = new Bullet(); newBullet.x = 2048 / 2; // spawn at the center of the screen horizontally newBullet.y = 2732 / 2; // spawn at the center of the screen vertically game.addChild(newBullet); // Play bullet sound LK.getSound('bullet_sound').play(); } // Check if bike collides with obstacle2 if (bike.intersects(obstacle2)) { // Show game over. The game will be automatically paused while game over is showing. LK.showGameOver(); // Calling this will destroy the 'Game' and reset entire game state. } if (bike.jumping) { bike.y -= 50; bike.jumpCounter++; if (bike.jumpCounter > 20) { bike.jumping = false; } } else if (bike.y < 2732 / 2) { bike.y += 15; } else { bike.jumpCounter = 0; } }; game.down = function (x, y, obj) { if (!bike.jumping) { bike.jumping = true; LK.getSound('bike_jump').play(); } };
/****
* Classes
****/
var Bike = Container.expand(function () {
var self = Container.call(this);
var bikeGraphics = self.attachAsset('bike', {
anchorX: 0,
anchorY: -2.3,
scaleX: 3,
scaleY: 3
});
self.update = function () {
self.x += 1.2;
if (self.x > 2048) {
self.x = -100;
}
// Play bike movement sound
LK.getSound('bike_move').play();
};
self.jumping = false;
self.jumpCounter = 0;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 3.4,
anchorY: 3,
scaleX: 3,
scaleY: 3
});
self.update = function () {
self.x += 10;
};
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: -3,
anchorY: -2.3,
scaleX: 3,
scaleY: 3
});
self.update = function () {
self.x -= 10;
};
});
var Obstacle2 = Container.expand(function () {
var self = Container.call(this);
var obstacle2Graphics = self.attachAsset('obstacle2', {
anchorX: -3,
anchorY: 2.3,
scaleX: 2,
scaleY: 2
});
self.update = function () {
self.x -= 10;
self.y += 5; // Add a default downward movement for obstacle2
};
});
var Road = Container.expand(function () {
var self = Container.call(this);
var roadGraphics = self.attachAsset('road', {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
LK.playMusic('bg_music');
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var road = game.addChild(new Road());
road.x = 2048 / 2;
road.y = 2732 / 2;
var background1 = road;
var background2 = new Road();
game.addChild(background2);
background2.x = background1.x + 2048;
background2.y = 2732 / 2; // Position background2 at the center of the screen vertically
var bike = game.addChild(new Bike());
var obstacle = game.addChild(new Obstacle());
obstacle.x = 2048 / 2;
obstacle.y = 2732 / 2;
bike.x = 0;
bike.y = 2732 / 2;
var obstacle2; // Define obstacle2 in the global scope
game.update = function () {
var roadSpeed = 6;
background1.x -= roadSpeed;
background2.x -= roadSpeed;
score += 5; // Increase the score based on the bike's distance
scoreTxt.setText(score); // Update the score text
if (background1.x <= -1024) {
background1.x = background2.x + 2048;
}
if (background2.x <= -1024) {
background2.x = background1.x + 2048;
}
if (LK.ticks % Math.floor(Math.random() * 1800) == 0) {
// 60 ticks per second, so 1800 ticks = 30 seconds
var newObstacle = new Obstacle();
newObstacle.x = 2048; // spawn at the right edge of the screen
newObstacle.y = 2732 / 2; // spawn at the middle of the screen vertically
game.addChild(newObstacle);
obstacle2 = new Obstacle2(); // Assign the new Obstacle2 instance to the global obstacle2 variable
obstacle2.x = 2048; // spawn at the right edge of the screen
obstacle2.y = bike.y; // spawn at the player's vertical position
game.addChild(obstacle2);
// Play obstacle2 spawn sound
LK.getSound('obstacle2_spawn').play();
}
if (LK.ticks % 150 == 0) {
// 60 ticks per second, so 300 ticks = 5 seconds
var newBullet = new Bullet();
newBullet.x = 2048 / 2; // spawn at the center of the screen horizontally
newBullet.y = 2732 / 2; // spawn at the center of the screen vertically
game.addChild(newBullet);
// Play bullet sound
LK.getSound('bullet_sound').play();
}
// Check if bike collides with obstacle2
if (bike.intersects(obstacle2)) {
// Show game over. The game will be automatically paused while game over is showing.
LK.showGameOver(); // Calling this will destroy the 'Game' and reset entire game state.
}
if (bike.jumping) {
bike.y -= 50;
bike.jumpCounter++;
if (bike.jumpCounter > 20) {
bike.jumping = false;
}
} else if (bike.y < 2732 / 2) {
bike.y += 15;
} else {
bike.jumpCounter = 0;
}
};
game.down = function (x, y, obj) {
if (!bike.jumping) {
bike.jumping = true;
LK.getSound('bike_jump').play();
}
};
sci fi bike with person riding facing right side Single Game Texture. In-Game asset. High contrast. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sci fi bike with person riding facing right side Single Game Texture. In-Game asset. High contrast.
asteroid falling diffrent colors Single Game Texture. In-Game asset. High contrast. No Background