===================================================================
--- original.js
+++ change.js
@@ -1,21 +1,7 @@
/****
* Classes
-****/
-var Particle = Container.expand(function () {
- var self = Container.call(this);
- var particleGraphics = self.attachAsset('particle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- particleGraphics.rotation = Math.PI / 4;
- self.lifetime = 100;
- self.tick = function () {
- if (--self.lifetime <= 0) {
- self.destroy();
- }
- };
-});
+****/
var Car = Container.expand(function () {
var self = Container.call(this);
self.projectMovement = function (vector) {
var angle = -Math.PI / 4;
@@ -35,9 +21,9 @@
self.momentum = {
x: 0,
y: 0
};
- self.move = function () {
+ self._move_migrated = function () {
var momentumModifier = 0.1;
if (self.direction === 0) {
self.momentum.x += self.speed * momentumModifier;
} else {
@@ -62,19 +48,33 @@
self.direction = self.direction === 0 ? 1 : 0;
carGraphics.scale.x *= -1;
};
});
+var Particle = Container.expand(function () {
+ var self = Container.call(this);
+ var particleGraphics = self.attachAsset('particle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ particleGraphics.rotation = Math.PI / 4;
+ self.lifetime = 100;
+ self.tick = function () {
+ if (--self.lifetime <= 0) {
+ self.destroy();
+ }
+ };
+});
/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
-****/
+****/
game.calculateDistanceToPoint = function (point, segmentStart, segmentEnd) {
var A = point.x - segmentStart.x;
var B = point.y - segmentStart.y;
var C = segmentEnd.x - segmentStart.x;
@@ -152,20 +152,20 @@
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
scoreText.anchor.set(0.5, 0);
-LK.gui.topCenter.addChild(scoreText);
+LK.gui.top.addChild(scoreText);
var car = mainContainer.addChild(new Car());
car.x = 2048 / 2;
car.y = 2732 / 2;
var isGameOver = false;
var score = 0;
var closestSegment = null;
-game.on('down', function (obj) {
+game.on('down', function (x, y, obj) {
car.changeDirection();
});
LK.on('tick', function () {
- car.move();
+ car._move_migrated();
var carIsOnRoad = false;
var carPosition = {
x: car.x,
y: car.y