/****
* Classes
****/
// The assets will be automatically loaded by the game 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 = 0;
self.direction = 0;
self.update = function () {
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * 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 car and the track
var car = game.addChild(new Car());
car.x = 2048 / 2;
car.y = 2732 / 2;
var track = game.addChild(new Track());
track.x = 2048 / 2;
track.y = 2732 / 2;
// Game update function
game.update = function () {
// Check if the car is on the track
if (!car.intersects(track)) {
// The car is off the track, reduce the speed
car.speed *= 0.9;
}
// Update the car's direction based on the user's input
// This will be implemented in the next steps
};
// User input handling
game.down = function (x, y, obj) {
// The user touched the screen, start turning the car
// This will be implemented in the next steps
};
game.up = function (x, y, obj) {
// The user released the screen, stop turning the car
// This will be implemented in the next steps
};