/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Update logic for hero
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
// Vehicle class
var Vehicle = Container.expand(function () {
var self = Container.call(this);
var vehicleGraphics = self.attachAsset('vehicle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Update logic for vehicle
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Init game with sky blue background
});
/****
* Game Code
****/
// Initialize hero
var hero = new Hero();
hero.x = 1024; // Center horizontally
hero.y = 1366; // Center vertically
game.addChild(hero);
// Initialize vehicles
var vehicles = [];
for (var i = 0; i < 5; i++) {
var vehicle = new Vehicle();
vehicle.x = Math.random() * 2048;
vehicle.y = Math.random() * 2732;
vehicles.push(vehicle);
game.addChild(vehicle);
}
// Handle game move events
game.move = function (x, y, obj) {
hero.move(x, y);
};
// Update game logic
game.update = function () {
hero.update();
for (var i = 0; i < vehicles.length; i++) {
vehicles[i].update();
}
};