User prompt
add a background
Code edit (15 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: consold is not defined' in or related to this line: 'consold.log(alpha);' Line Number: 89
Code edit (1 edits merged)
Please save this source code
User prompt
fade out skidmarks
User prompt
use a variable alpha for skidmarks, less alpha if rotation didn't change much
User prompt
only add skidmarks if rotation changed since last update
User prompt
only add skidmarks when turning
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'dust is not defined' in or related to this line: 'dust.x = i;' Line Number: 123
Code edit (1 edits merged)
Please save this source code
User prompt
fade out the skidmarks
User prompt
leave skidmarks from 4 tires when turning
Code edit (7 edits merged)
Please save this source code
User prompt
add friction so the car drifts when turning
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: console is not a function' in or related to this line: 'console(dx);' Line Number: 119
Code edit (1 edits merged)
Please save this source code
User prompt
change the steering so that dragging left rotates the car and dragging right rotates the car
User prompt
rotate relative to position on screen, continously on down
User prompt
add drifting
User prompt
Please fix the bug: 'ReferenceError: x is not defined' in or related to this line: 'var distanceFromMid = x - midScreenX;' Line Number: 63
Code edit (1 edits merged)
Please save this source code
User prompt
rotation should keep increasing when down, based on distanceFromMid
/****
* Classes
****/
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.acceleration = 0;
});
var Dust = Container.expand(function () {
var self = Container.call(this);
var dustGraphics = self.attachAsset('dirt', {
anchorX: 0.5,
anchorY: 0.5
});
});
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('dirt', {
anchorX: 0.5,
anchorY: 0.5
});
self.alpha = 1;
self.update = function () {
self.alpha -= 0.01;
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;
if (car.rotation != 0) {
var skidmark = game.addChildAt(new Skidmark(), 0);
skidmark.x = car.x;
skidmark.y = car.y;
if (skidmark.alpha <= 0) {
skidmark.destroy();
}
}
}
car.x += Math.sin(car.rotation) * car.acceleration;
car.y -= Math.cos(car.rotation) * car.acceleration;
if (game.isDown) {
car.acceleration *= 0.98; // Apply friction to slow down the car
} else {
car.acceleration *= 0.85; // Apply more friction when not accelerating
}
if (LK.ticks % 5 == 0) {
// Every few ticks
var dust = game.addChildAt(new Dust(), 0);
dust.x = car.x;
dust.y = car.y;
dust.alpha = 0.1;
}
if (car.x < 0) {
car.x = 0;
car.acceleration = 0;
}
if (car.x > 2048) {
car.x = 2048;
car.acceleration = 0;
}
if (car.y < 0) {
car.y = 0;
car.acceleration = 0;
}
if (car.y > 2732) {
car.y = 2732;
car.acceleration = 0;
}
};
var car = game.addChild(new Car());
car.x = 2048 / 2;
car.y = 2732 / 2 + 500;
for (var i = 0; i < 2048; i += 100) {
for (var j = 0; j < 2732; j += 100) {
if (Math.random() < 0.1) {
var dust = game.addChildAt(new Dust(), 0);
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
@@ -68,13 +68,15 @@
var obstacles = [];
game.update = function () {
if (game.isDown) {
car.acceleration += 0.2;
- var skidmark = game.addChildAt(new Skidmark(), 0);
- skidmark.x = car.x;
- skidmark.y = car.y;
- if (skidmark.alpha <= 0) {
- skidmark.destroy();
+ if (car.rotation != 0) {
+ var skidmark = game.addChildAt(new Skidmark(), 0);
+ skidmark.x = car.x;
+ skidmark.y = car.y;
+ if (skidmark.alpha <= 0) {
+ skidmark.destroy();
+ }
}
}
car.x += Math.sin(car.rotation) * car.acceleration;
car.y -= Math.cos(car.rotation) * car.acceleration;
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.