/**** * Classes ****/ //<Assets used in the game will automatically appear here> // 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 = 10; self.update = function () { self.x += self.speed; if (self.x > 2048) { self.x = 0; } }; }); // Mission class var Mission = Container.expand(function () { var self = Container.call(this); var missionGraphics = self.attachAsset('mission', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Mission logic }; }); // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Player movement logic }; self.down = function (x, y, obj) { self.x = x; self.y = y; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player var player = game.addChild(new Player()); player.x = 1024; player.y = 1366; // Initialize cars var cars = []; for (var i = 0; i < 5; i++) { var car = new Car(); car.x = Math.random() * 2048; car.y = Math.random() * 2732; cars.push(car); game.addChild(car); } // Initialize missions var missions = []; for (var i = 0; i < 3; i++) { var mission = new Mission(); mission.x = Math.random() * 2048; mission.y = Math.random() * 2732; missions.push(mission); game.addChild(mission); } // Game update logic game.update = function () { player.update(); for (var i = 0; i < cars.length; i++) { cars[i].update(); } for (var i = 0; i < missions.length; i++) { missions[i].update(); } }; // Handle player movement game.down = function (x, y, obj) { player.down(x, y, obj); };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// 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 = 10;
self.update = function () {
self.x += self.speed;
if (self.x > 2048) {
self.x = 0;
}
};
});
// Mission class
var Mission = Container.expand(function () {
var self = Container.call(this);
var missionGraphics = self.attachAsset('mission', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Mission logic
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Player movement logic
};
self.down = function (x, y, obj) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize player
var player = game.addChild(new Player());
player.x = 1024;
player.y = 1366;
// Initialize cars
var cars = [];
for (var i = 0; i < 5; i++) {
var car = new Car();
car.x = Math.random() * 2048;
car.y = Math.random() * 2732;
cars.push(car);
game.addChild(car);
}
// Initialize missions
var missions = [];
for (var i = 0; i < 3; i++) {
var mission = new Mission();
mission.x = Math.random() * 2048;
mission.y = Math.random() * 2732;
missions.push(mission);
game.addChild(mission);
}
// Game update logic
game.update = function () {
player.update();
for (var i = 0; i < cars.length; i++) {
cars[i].update();
}
for (var i = 0; i < missions.length; i++) {
missions[i].update();
}
};
// Handle player movement
game.down = function (x, y, obj) {
player.down(x, y, obj);
};