/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Motorcycle class representing the player
var Motorcycle = Container.expand(function () {
var self = Container.call(this);
var motorcycleGraphics = self.attachAsset('motorcycle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Update logic for motorcycle
};
});
// Package class representing the packages to be collected
var Package = Container.expand(function () {
var self = Container.call(this);
var packageGraphics = self.attachAsset('package', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for package
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Init game with sky blue background
});
/****
* Game Code
****/
// Initialize game variables
var motorcycle;
var packages = [];
var score = 0;
var scoreTxt;
// Function to handle game updates
game.update = function () {
// Update motorcycle position
motorcycle.update();
// Update packages and check for collisions
for (var i = packages.length - 1; i >= 0; i--) {
packages[i].update();
if (motorcycle.intersects(packages[i])) {
score += 10;
scoreTxt.setText(score);
packages[i].destroy();
packages.splice(i, 1);
}
}
// Spawn new packages
if (LK.ticks % 60 == 0) {
var newPackage = new Package();
newPackage.x = Math.random() * 2048;
newPackage.y = Math.random() * 2732;
packages.push(newPackage);
game.addChild(newPackage);
}
};
// Initialize motorcycle
motorcycle = game.addChild(new Motorcycle());
motorcycle.x = 2048 / 2;
motorcycle.y = 2732 - 200;
// Initialize score text
scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle touch events for moving the motorcycle
game.down = function (x, y, obj) {
motorcycle.x = x;
motorcycle.y = y;
};
game.move = function (x, y, obj) {
motorcycle.x = x;
motorcycle.y = y;
};
game.up = function (x, y, obj) {
// Stop moving the motorcycle
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Motorcycle class representing the player
var Motorcycle = Container.expand(function () {
var self = Container.call(this);
var motorcycleGraphics = self.attachAsset('motorcycle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Update logic for motorcycle
};
});
// Package class representing the packages to be collected
var Package = Container.expand(function () {
var self = Container.call(this);
var packageGraphics = self.attachAsset('package', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for package
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Init game with sky blue background
});
/****
* Game Code
****/
// Initialize game variables
var motorcycle;
var packages = [];
var score = 0;
var scoreTxt;
// Function to handle game updates
game.update = function () {
// Update motorcycle position
motorcycle.update();
// Update packages and check for collisions
for (var i = packages.length - 1; i >= 0; i--) {
packages[i].update();
if (motorcycle.intersects(packages[i])) {
score += 10;
scoreTxt.setText(score);
packages[i].destroy();
packages.splice(i, 1);
}
}
// Spawn new packages
if (LK.ticks % 60 == 0) {
var newPackage = new Package();
newPackage.x = Math.random() * 2048;
newPackage.y = Math.random() * 2732;
packages.push(newPackage);
game.addChild(newPackage);
}
};
// Initialize motorcycle
motorcycle = game.addChild(new Motorcycle());
motorcycle.x = 2048 / 2;
motorcycle.y = 2732 - 200;
// Initialize score text
scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle touch events for moving the motorcycle
game.down = function (x, y, obj) {
motorcycle.x = x;
motorcycle.y = y;
};
game.move = function (x, y, obj) {
motorcycle.x = x;
motorcycle.y = y;
};
game.up = function (x, y, obj) {
// Stop moving the motorcycle
};