/**** 
* 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('carImage', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 0;
	self.angle = 0;
	self.update = function () {
		self.x += self.speed * Math.cos(self.angle);
		self.y += self.speed * Math.sin(self.angle);
	};
	self.drift = function (direction) {
		if (direction === 'left') {
			self.angle -= 0.1;
		} else if (direction === 'right') {
			self.angle += 0.1;
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0xC2B280 // Desert sand color
});
/**** 
* Game Code
****/ 
// Initialize car
var car = game.addChild(new Car());
car.x = 2048 / 2;
car.y = 2732 / 2;
car.speed = 5;
car.angle = 0;
// Event listeners for touch controls
var dragNode = null;
function handleMove(x, y, obj) {
	if (dragNode) {
		var game_position = game.toLocal(obj.global);
		if (game_position.x < 2048 / 2) {
			dragNode.drift('left');
		} else {
			dragNode.drift('right');
		}
	}
}
game.down = function (x, y, obj) {
	dragNode = car;
	handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
	dragNode = null;
};
game.move = handleMove;
// Update game state
game.update = function () {
	car.update();
}; /**** 
* 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('carImage', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 0;
	self.angle = 0;
	self.update = function () {
		self.x += self.speed * Math.cos(self.angle);
		self.y += self.speed * Math.sin(self.angle);
	};
	self.drift = function (direction) {
		if (direction === 'left') {
			self.angle -= 0.1;
		} else if (direction === 'right') {
			self.angle += 0.1;
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0xC2B280 // Desert sand color
});
/**** 
* Game Code
****/ 
// Initialize car
var car = game.addChild(new Car());
car.x = 2048 / 2;
car.y = 2732 / 2;
car.speed = 5;
car.angle = 0;
// Event listeners for touch controls
var dragNode = null;
function handleMove(x, y, obj) {
	if (dragNode) {
		var game_position = game.toLocal(obj.global);
		if (game_position.x < 2048 / 2) {
			dragNode.drift('left');
		} else {
			dragNode.drift('right');
		}
	}
}
game.down = function (x, y, obj) {
	dragNode = car;
	handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
	dragNode = null;
};
game.move = handleMove;
// Update game state
game.update = function () {
	car.update();
};