/****
* Classes
****/
// Define the AI Car class
var AICar = Container.expand(function () {
var self = Container.call(this);
var aiCarGraphics = self.attachAsset('aiCar', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 0;
self.update = function () {
self.y += self.speed;
};
});
//<Assets used in the game will automatically appear here>
// Define the 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.update = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize player car
var playerCar = game.addChild(new Car());
playerCar.x = 2048 / 2;
playerCar.y = 2732 - 200;
// Initialize AI cars
var aiCars = [];
for (var i = 0; i < 5; i++) {
var aiCar = new AICar();
aiCar.x = Math.random() * 2048;
aiCar.y = Math.random() * 2732 / 2;
aiCar.speed = Math.random() * 5 + 2;
aiCars.push(aiCar);
game.addChild(aiCar);
}
// Handle player car movement
var dragNode = null;
// Define the handleMove function
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
}
}
game.down = function (x, y, obj) {
dragNode = playerCar;
handleMove(x, y, obj);
};
game.move = function (x, y, obj) {
if (dragNode) {
dragNode.x = x;
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Update game state
game.update = function () {
playerCar.update();
for (var i = 0; i < aiCars.length; i++) {
aiCars[i].update();
if (aiCars[i].y > 2732) {
aiCars[i].y = -100;
aiCars[i].x = Math.random() * 2048;
}
}
}; /****
* Classes
****/
// Define the AI Car class
var AICar = Container.expand(function () {
var self = Container.call(this);
var aiCarGraphics = self.attachAsset('aiCar', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 0;
self.update = function () {
self.y += self.speed;
};
});
//<Assets used in the game will automatically appear here>
// Define the 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.update = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize player car
var playerCar = game.addChild(new Car());
playerCar.x = 2048 / 2;
playerCar.y = 2732 - 200;
// Initialize AI cars
var aiCars = [];
for (var i = 0; i < 5; i++) {
var aiCar = new AICar();
aiCar.x = Math.random() * 2048;
aiCar.y = Math.random() * 2732 / 2;
aiCar.speed = Math.random() * 5 + 2;
aiCars.push(aiCar);
game.addChild(aiCar);
}
// Handle player car movement
var dragNode = null;
// Define the handleMove function
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
}
}
game.down = function (x, y, obj) {
dragNode = playerCar;
handleMove(x, y, obj);
};
game.move = function (x, y, obj) {
if (dragNode) {
dragNode.x = x;
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Update game state
game.update = function () {
playerCar.update();
for (var i = 0; i < aiCars.length; i++) {
aiCars[i].update();
if (aiCars[i].y > 2732) {
aiCars[i].y = -100;
aiCars[i].x = Math.random() * 2048;
}
}
};