/****
* Classes
****/
// The assets for the game will be automatically created and loaded by the LK engine.
// Car class
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.x += self.speed;
};
});
// Track class
var Track = Container.expand(function () {
var self = Container.call(this);
var trackGraphics = self.attachAsset('track', {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize the track
var track = game.addChild(new Track());
track.x = 2048 / 2;
track.y = 2732 / 2;
// Initialize the cars
var cars = [];
for (var i = 0; i < 4; i++) {
var car = game.addChild(new Car());
car.x = 2048 / 2;
car.y = 2732 / 4 * i;
cars.push(car);
}
// Game update function
game.update = function () {
// Update the position of each car
for (var i = 0; i < cars.length; i++) {
cars[i].update();
}
}; /****
* Classes
****/
// The assets for the game will be automatically created and loaded by the LK engine.
// Car class
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.x += self.speed;
};
});
// Track class
var Track = Container.expand(function () {
var self = Container.call(this);
var trackGraphics = self.attachAsset('track', {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize the track
var track = game.addChild(new Track());
track.x = 2048 / 2;
track.y = 2732 / 2;
// Initialize the cars
var cars = [];
for (var i = 0; i < 4; i++) {
var car = game.addChild(new Car());
car.x = 2048 / 2;
car.y = 2732 / 4 * i;
cars.push(car);
}
// Game update function
game.update = function () {
// Update the position of each car
for (var i = 0; i < cars.length; i++) {
cars[i].update();
}
};