Code edit (8 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: t is not defined' in or related to this line: 'car.forceX += Math.sin(car.rotation) * (0.2 * 1 / t);' Line Number: 107
User prompt
Please fix the bug: 'ReferenceError: t is not defined' in or related to this line: 'console.log(t, car.noAccelerationUpdates);' Line Number: 106
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: forceX is not defined' in or related to this line: 'car.x += forceX;' Line Number: 102
Code edit (18 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: forceX is not defined' in or related to this line: 'car.oldForceX = forceX;' Line Number: 105
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
When accelerating, add a force in the direction the car is facing.
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: skidmark1 is not defined' in or related to this line: 'skidmark1.alpha = alpha;' Line Number: 93
Code edit (11 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: distY is not defined' in or related to this line: 'skidmark1.y = car.y - distY;' Line Number: 93
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
There should be two skidmarks, one per back wheel
User prompt
skidmarks should have same rotations as car
Code edit (2 edits merged)
Please save this source code
User prompt
add a game layer for the car, dust and skidmarks
User prompt
draw background on a separate layer that is under everything else
User prompt
background is still in front of dust and skidmarks
Code edit (1 edits merged)
Please save this source code
/****
* Classes
****/
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.75
});
self.noAccelerationUpdates = 0;
self.forceX = self.forceY = 0;
self.acceleration = 0;
self.prevRotation = 0;
});
var Dust = Container.expand(function () {
var self = Container.call(this);
var dustGraphics = self.attachAsset('dirt', {
anchorX: 0.5,
anchorY: 0.75
});
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.y -= self.speed;
};
});
var Skidmark = Container.expand(function () {
var self = Container.call(this);
var skidmarkGraphics = self.attachAsset('skidmark', {
anchorX: 0.5,
anchorY: 0.8
});
self.alpha = 1;
self.rotation = 0;
self.width = 90;
self.height = 90;
self.update = function () {
self.alpha -= 0.001;
if (self.alpha <= 0) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2e2e2e
});
/****
* Game Code
****/
game.down = function (x, y, obj) {
game.isDown = true;
var midScreenX = 2048 / 2;
var distanceFromMid = x - midScreenX;
if (distanceFromMid < 0) {
car.rotation -= 0.1; // Rotate left
} else {
car.rotation += 0.1; // Rotate right
}
};
game.up = function (x, y) {
game.isDown = false;
};
var obstacles = [];
game.update = function () {
if (game.isDown) {
car.acceleration += 0.2;
var distX = 30;
var dAcc = Math.abs(car.rotation - car.prevRotation);
var skidmark = gameLayer.addChildAt(new Skidmark(), 0);
skidmark.rotation = car.rotation;
skidmark.x = car.x;
skidmark.y = car.y;
var alpha = Math.min(10 * dAcc, 1);
if (dAcc == 0) {
alpha = 0.1;
}
skidmark.alpha = alpha;
}
if (game.isDown) {
car.forceX += Math.sin(car.rotation) * 0.5;
car.forceY += Math.cos(car.rotation) * 0.5;
} else {
car.noAccelerationUpdates += 1;
var t = Math.min(car.noAccelerationUpdates, 20) / 10;
t = Math.min(0.1, t);
if (t < 0.01) {
t = 0;
}
console.log(t, car.noAccelerationUpdates);
car.forceX += Math.sin(car.rotation) * (0.1 * t);
car.forceY += Math.cos(car.rotation) * (0.1 * t);
}
car.x += car.forceX;
car.y -= car.forceY;
car.prevRotation = car.rotation;
car.forceX *= 0.97; // Apply friction to slow down the car
car.forceY *= 0.97;
if (car.x < 0) {
car.x = 0;
}
if (car.x > 2048) {
car.x = 2048;
}
if (car.y < 0) {
car.y = 0;
}
if (car.y > 2732) {
car.y = 2732;
}
};
var backgroundLayer = new Container();
game.addChildAt(backgroundLayer, 0);
var background = backgroundLayer.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
}));
background.x = 2048 / 2;
background.y = 2732 / 2;
var gameLayer = new Container();
game.addChild(gameLayer);
var car = gameLayer.addChild(new Car());
car.x = 2048 / 2;
car.y = 2732 / 2 + 500;
car.prevRotation = car.rotation;
for (var i = 0; i < 2048; i += 100) {
for (var j = 0; j < 2732; j += 100) {
if (Math.random() < 0.1) {
var dust = gameLayer.addChild(new Dust());
dust.x = i;
dust.y = j;
}
}
}
var oldX, oldY;
game.move = function (x, y, obj) {
if (!oldX) {
oldX = x;
}
if (!oldY) {
oldY = y;
}
if (game.isDown) {
var dx = x - oldX;
if (dx < 0) {
dx = Math.max(dx, -4);
}
if (dx > 0) {
dx = Math.min(dx, 4);
}
car.rotation += dx / 100; // Rotate left
oldX = x;
oldY = y;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -6,8 +6,9 @@
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.75
});
+ self.noAccelerationUpdates = 0;
self.forceX = self.forceY = 0;
self.acceleration = 0;
self.prevRotation = 0;
});
@@ -85,15 +86,21 @@
alpha = 0.1;
}
skidmark.alpha = alpha;
}
- car.forceX += Math.sin(car.rotation) * 0.5;
- car.forceY += Math.cos(car.rotation) * 0.5;
- car.forceX *= 0.97; // Apply friction to slow down the car
- car.forceY *= 0.97;
if (game.isDown) {
car.forceX += Math.sin(car.rotation) * 0.5;
car.forceY += Math.cos(car.rotation) * 0.5;
+ } else {
+ car.noAccelerationUpdates += 1;
+ var t = Math.min(car.noAccelerationUpdates, 20) / 10;
+ t = Math.min(0.1, t);
+ if (t < 0.01) {
+ t = 0;
+ }
+ console.log(t, car.noAccelerationUpdates);
+ car.forceX += Math.sin(car.rotation) * (0.1 * t);
+ car.forceY += Math.cos(car.rotation) * (0.1 * t);
}
car.x += car.forceX;
car.y -= car.forceY;
car.prevRotation = car.rotation;
A cute looking car, facing up, viewed top down. Suitable for a game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
some dust Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An arrow pointing upwards. Should look like it's pointing to something valuable. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a orange road cone. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a coffee cup, viewed from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cinnamon bun, viewed from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a gold coin with a car one it, simple graphics. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cheese sandwich, viewed from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a salt can, viewed from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A checked pattern in nice soft pastel colors. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.