/****
* Classes
****/
// Define Bike class
var Bike = Container.expand(function () {
var self = Container.call(this);
// Attach bike asset
var bikeGraphics = self.attachAsset('bike', {
anchorX: 0.5,
anchorY: 0.5
});
// Set initial position
self.x = 1024; // Center horizontally
self.y = 2400; // Near bottom of the screen
// Update method for bike
self.update = function () {
// Move bike based on touch input
self.update = function () {
// Movement logic will be handled by touch events
};
};
});
// Define RedBall class
var RedBall = Container.expand(function () {
var self = Container.call(this);
// Attach red ball asset
var redBallGraphics = self.attachAsset('redBall', {
anchorX: 0.5,
anchorY: 0.5
});
// Set initial position
self.x = 1024; // Start in the middle of the screen
self.y = 0; // Start at the top of the screen
// Update method for red ball
self.update = function () {
self.y += 5; // Move downwards
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFFFFF
});
/****
* Game Code
****/
// Initialize boundary shapes
// Init game with white background
LK.setScore(0); // Initialize score to zero
LK.setScore(0); // Initialize score to zero
// Play race start sound
LK.getSound('race_start').play();
// Create and display score text on the screen
var scoreTxt = new Text2('0', {
size: 150,
fill: "#000000" // Set score text color to black
});
scoreTxt.anchor.set(0.5, 0); // Center the score text horizontally
LK.gui.top.addChild(scoreTxt); // Add the score text to the GUI overlay
// Add boundary objects to the game
var boundaryTop = LK.getAsset('boundaryTop', {
x: 0,
y: 0
});
var boundaryLeft = LK.getAsset('boundaryLeft', {
x: 0,
y: 0
});
var boundaryRight = LK.getAsset('boundaryRight', {
x: 2038,
y: 0
});
game.addChild(boundaryTop);
game.addChild(boundaryLeft);
game.addChild(boundaryRight);
// Initialize arrays and variables
var powerUps = [];
var bombs = [];
// Add bike to the game
var playerBike = new Bike();
game.addChild(playerBike);
// Handle touch events to control bike movement
game.down = function (x, y, obj) {
playerBike.x = x;
// Add red ball to the game
if (LK.ticks % 60 == 0) {
// Add a new red ball every second
var newRedBall = new RedBall();
game.addChild(newRedBall);
bombs.push(newRedBall);
}
// Update red balls
for (var i = bombs.length - 1; i >= 0; i--) {
bombs[i].update();
// Remove red balls that are off screen
if (bombs[i].y > 2732) {
bombs[i].destroy();
bombs.splice(i, 1);
}
}
};
game.move = function (x, y, obj) {
playerBike.x = x;
};
game.up = function (x, y, obj) {
// No action needed on release
};
// Update game state
game.update = function () {
playerBike.update();
}; /****
* Classes
****/
// Define Bike class
var Bike = Container.expand(function () {
var self = Container.call(this);
// Attach bike asset
var bikeGraphics = self.attachAsset('bike', {
anchorX: 0.5,
anchorY: 0.5
});
// Set initial position
self.x = 1024; // Center horizontally
self.y = 2400; // Near bottom of the screen
// Update method for bike
self.update = function () {
// Move bike based on touch input
self.update = function () {
// Movement logic will be handled by touch events
};
};
});
// Define RedBall class
var RedBall = Container.expand(function () {
var self = Container.call(this);
// Attach red ball asset
var redBallGraphics = self.attachAsset('redBall', {
anchorX: 0.5,
anchorY: 0.5
});
// Set initial position
self.x = 1024; // Start in the middle of the screen
self.y = 0; // Start at the top of the screen
// Update method for red ball
self.update = function () {
self.y += 5; // Move downwards
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFFFFF
});
/****
* Game Code
****/
// Initialize boundary shapes
// Init game with white background
LK.setScore(0); // Initialize score to zero
LK.setScore(0); // Initialize score to zero
// Play race start sound
LK.getSound('race_start').play();
// Create and display score text on the screen
var scoreTxt = new Text2('0', {
size: 150,
fill: "#000000" // Set score text color to black
});
scoreTxt.anchor.set(0.5, 0); // Center the score text horizontally
LK.gui.top.addChild(scoreTxt); // Add the score text to the GUI overlay
// Add boundary objects to the game
var boundaryTop = LK.getAsset('boundaryTop', {
x: 0,
y: 0
});
var boundaryLeft = LK.getAsset('boundaryLeft', {
x: 0,
y: 0
});
var boundaryRight = LK.getAsset('boundaryRight', {
x: 2038,
y: 0
});
game.addChild(boundaryTop);
game.addChild(boundaryLeft);
game.addChild(boundaryRight);
// Initialize arrays and variables
var powerUps = [];
var bombs = [];
// Add bike to the game
var playerBike = new Bike();
game.addChild(playerBike);
// Handle touch events to control bike movement
game.down = function (x, y, obj) {
playerBike.x = x;
// Add red ball to the game
if (LK.ticks % 60 == 0) {
// Add a new red ball every second
var newRedBall = new RedBall();
game.addChild(newRedBall);
bombs.push(newRedBall);
}
// Update red balls
for (var i = bombs.length - 1; i >= 0; i--) {
bombs[i].update();
// Remove red balls that are off screen
if (bombs[i].y > 2732) {
bombs[i].destroy();
bombs.splice(i, 1);
}
}
};
game.move = function (x, y, obj) {
playerBike.x = x;
};
game.up = function (x, y, obj) {
// No action needed on release
};
// Update game state
game.update = function () {
playerBike.update();
};