User prompt
add a background
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: '[object Object]addChildAt: The index undefined supplied is out of bounds 1' in or related to this line: 'self.addChildAt(backgroundGraphics, 0);' Line Number: 19
User prompt
Please fix the bug: '[object Object]addChildAt: The index undefined supplied is out of bounds 1' in or related to this line: 'self.addChild(backgroundGraphics);' Line Number: 19
User prompt
Please fix the bug: '[object Object]addChildAt: The index undefined supplied is out of bounds 1' in or related to this line: 'self.addChildAt(backgroundGraphics, 0);' Line Number: 19
User prompt
Please fix the bug: '[object Object]addChildAt: The index undefined supplied is out of bounds 1' in or related to this line: 'self.addChildAt(backgroundGraphics, 0);' Line Number: 19
User prompt
Please fix the bug: '[object Object]addChildAt: The index undefined supplied is out of bounds 1' in or related to this line: 'self.addChild(backgroundGraphics);' Line Number: 19
User prompt
Please fix the bug: '[object Object]addChildAt: The index undefined supplied is out of bounds 1' in or related to this line: 'self.addChildAt(backgroundGraphics, 0);' Line Number: 19
User prompt
Please fix the bug: '[object Object]addChildAt: The index undefined supplied is out of bounds 1' in or related to this line: 'self.addChild(backgroundGraphics);' Line Number: 19
User prompt
Please fix the bug: '[object Object]addChildAt: The index undefined supplied is out of bounds 1' in or related to this line: 'var backgroundGraphics = self.attachAsset('background', {' Line Number: 15
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: '[object Object]addChildAt: The index -1 supplied is out of bounds 0' in or related to this line: 'var backgroundGraphics = self.attachAsset('background', {' Line Number: 15
Code edit (1 edits merged)
Please save this source code
User prompt
background should be behind everything else
User prompt
place the background behind everything else
User prompt
add a background asset
Code edit (1 edits merged)
Please save this source code
User prompt
background should have a separate asset
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
/****
* Classes
****/
var Background = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background', {
anchorX: 0.0,
anchorY: 0.0
});
});
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
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.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('skidmark', {
anchorX: 0.5,
anchorY: 0.5
});
self.alpha = 1;
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 dAcc = Math.abs(car.rotation - car.prevRotation);
if (dAcc > 0) {
var alpha = Math.min(7 * dAcc, 1);
var skidmark = game.addChildAt(new Skidmark(), 0);
skidmark.x = car.x;
skidmark.y = car.y;
skidmark.alpha = alpha;
console.log(alpha);
} else {
var skidmark = game.addChildAt(new Skidmark(), 0);
skidmark.x = car.x;
skidmark.y = car.y;
skidmark.alpha = 0.1;
}
}
car.x += Math.sin(car.rotation) * car.acceleration;
car.y -= Math.cos(car.rotation) * car.acceleration;
car.prevRotation = car.rotation;
if (game.isDown) {
car.acceleration *= 0.98; // Apply friction to slow down the car
} else {
car.acceleration *= 0.98; // Apply more friction when not accelerating
}
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 background = game.addChildAt(new Background(), 0);
var car = game.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 = 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
@@ -117,8 +117,12 @@
car.acceleration = 0;
}
};
var background = game.addChildAt(new Background(), 0);
+var car = game.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 = game.addChildAt(new Dust(), 0);
@@ -126,12 +130,8 @@
dust.y = j;
}
}
}
-var car = game.addChild(new Car());
-car.x = 2048 / 2;
-car.y = 2732 / 2 + 500;
-car.prevRotation = car.rotation;
var oldX, oldY;
game.move = function (x, y, obj) {
if (!oldX) {
oldX = x;
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.