User prompt
Please fix the bug: 'ReferenceError: newCar is not defined' in or related to this line: 'newCar.x = Math.floor(Math.random() * 6) * laneWidth + laneWidth / 2;' Line Number: 138
User prompt
Please fix the bug: 'Uncaught ReferenceError: lifeCar is not defined' in or related to this line: 'lifeCar.scale.set(0.5);' Line Number: 55
User prompt
Rename car to barrel
User prompt
Rename car to barrel
User prompt
Migrate to the latest version of LK
Remix started
Copy One way road
/**** * Classes ****/ var Button = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('button', { anchorX: 0.5, anchorY: 0.5 }); }); var Car = Container.expand(function () { var self = Container.call(this); var carGraphics = self.attachAsset('car', { anchorX: 0.5, anchorY: 0.5 }); carGraphics.tint = Math.random() * 0xFFFFFF; while (carGraphics.tint < 0x0A0A0A) { carGraphics.tint = Math.random() * 0xFFFFFF; } self.speed = 5; self._move_migrated = function () { self.y += self.speed; }; }); var Lane = Container.expand(function () { var self = Container.call(this); var laneGraphics = self.attachAsset('lane', {}); laneGraphics.height = 2732; laneGraphics.width = 2; laneGraphics.tint = 0xFFFFFF; self.addChild(laneGraphics); }); var LifeIndicator = Container.expand(function () { var self = Container.call(this); self.lives = 3; self.indicators = []; for (var i = 0; i < self.lives; i++) { var lifeCar = self.attachAsset('car', { anchorX: 0.5, anchorY: 0.5 }); lifeCar.scale.set(0.5); lifeCar.x = i * (lifeCar.width + 10); self.indicators.push(lifeCar); self.addChild(lifeCar); } self.updateLives = function (lives) { self.lives = lives; for (var i = 0; i < self.indicators.length; i++) { self.indicators[i].visible = i < self.lives; } }; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.lives = 3; self.moveLeft = function (laneWidth) { self.x = Math.max(laneWidth / 2, Math.floor((self.x - laneWidth) / laneWidth) * laneWidth + laneWidth / 2); }; self.moveRight = function (laneWidth) { self.x = Math.min(2048 - laneWidth / 2, Math.ceil((self.x + laneWidth) / laneWidth) * laneWidth - laneWidth / 2); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var startTime = Date.now(); game.speedMultiplier = 1.0; game.setBackgroundColor(0x000000); var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 200; var lifeIndicator = game.addChild(new LifeIndicator()); lifeIndicator.x = 2048 - 300; lifeIndicator.y = 50; var leftButton = game.addChild(new Button()); leftButton.x = 100; leftButton.y = 2732 - 200; var rightButton = game.addChild(new Button()); rightButton.x = 2048 - 100; rightButton.y = 2732 - 200; var carsPassedTxt = new Text2('0', { size: 150, fill: '#ffffff' }); LK.gui.topLeft.addChild(carsPassedTxt); var laneWidth = 2048 / 6; for (var i = 1; i < 6; i++) { var lane = new Lane(); lane.x = i * laneWidth; game.addChild(lane); } var cars = []; var carsPassed = 0; LK.on('tick', function () { if (LK.ticks % (60 * 5) === 0) { game.speedMultiplier *= 1.1; } for (var a = cars.length - 1; a >= 0; a--) { cars[a]._move_migrated(); if (cars[a].y > 2732) { cars[a].destroy(); cars.splice(a, 1); carsPassed++; } } var currentTime = Date.now(); var timeElapsed = (currentTime - startTime) / 1000; var spawnRate = timeElapsed > 20 ? Math.pow(1.10, Math.floor((timeElapsed - 20) / 5)) : 1; if (LK.ticks % Math.floor(60 / spawnRate) == 0) { var newCar = new Car(); var laneWidth = 2048 / 6; newCar.x = Math.floor(Math.random() * 6) * laneWidth + laneWidth / 2; newCar.y = 0; newCar.speed *= game.speedMultiplier; cars.push(newCar); game.addChild(newCar); } carsPassedTxt.setText(carsPassed); for (var i = 0; i < cars.length; i++) { if (player.intersects(cars[i])) { player.lives--; lifeIndicator.updateLives(player.lives); if (player.lives <= 0) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } else { cars[i].destroy(); cars.splice(i, 1); } } } }); leftButton.on('down', function (x, y, obj) { player.moveLeft(laneWidth); }); rightButton.on('down', function (x, y, obj) { player.moveRight(laneWidth); });
===================================================================
--- original.js
+++ change.js
@@ -1,10 +1,46 @@
+/****
+* Classes
+****/
+var Button = Container.expand(function () {
+ var self = Container.call(this);
+ var buttonGraphics = self.attachAsset('button', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+});
+var Car = Container.expand(function () {
+ var self = Container.call(this);
+ var carGraphics = self.attachAsset('car', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ carGraphics.tint = Math.random() * 0xFFFFFF;
+ while (carGraphics.tint < 0x0A0A0A) {
+ carGraphics.tint = Math.random() * 0xFFFFFF;
+ }
+ self.speed = 5;
+ self._move_migrated = function () {
+ self.y += self.speed;
+ };
+});
+var Lane = Container.expand(function () {
+ var self = Container.call(this);
+ var laneGraphics = self.attachAsset('lane', {});
+ laneGraphics.height = 2732;
+ laneGraphics.width = 2;
+ laneGraphics.tint = 0xFFFFFF;
+ self.addChild(laneGraphics);
+});
var LifeIndicator = Container.expand(function () {
var self = Container.call(this);
self.lives = 3;
self.indicators = [];
for (var i = 0; i < self.lives; i++) {
- var lifeCar = self.createAsset('car', 'Life Indicator Car', 0.5, 0.5);
+ var lifeCar = self.attachAsset('car', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
lifeCar.scale.set(0.5);
lifeCar.x = i * (lifeCar.width + 10);
self.indicators.push(lifeCar);
self.addChild(lifeCar);
@@ -15,115 +51,102 @@
self.indicators[i].visible = i < self.lives;
}
};
});
-var Button = Container.expand(function () {
- var self = Container.call(this);
- var buttonGraphics = self.createAsset('button', 'Button Graphics', .5, .5);
-});
-var Lane = Container.expand(function () {
- var self = Container.call(this);
- var laneGraphics = self.createAsset('lane', 'Lane Graphics', 0, 0);
- laneGraphics.height = 2732;
- laneGraphics.width = 2;
- laneGraphics.tint = 0xFFFFFF;
- self.addChild(laneGraphics);
-});
-var Car = Container.expand(function () {
- var self = Container.call(this);
- var carGraphics = self.createAsset('car', 'Car Graphics', .5, .5);
- carGraphics.tint = Math.random() * 0xFFFFFF;
- while (carGraphics.tint < 0x0A0A0A) {
- carGraphics.tint = Math.random() * 0xFFFFFF;
- }
- self.speed = 5;
- self.move = function () {
- self.y += self.speed;
- };
-});
var Player = Container.expand(function () {
var self = Container.call(this);
- var playerGraphics = self.createAsset('player', 'Player Graphics', .5, .5);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.lives = 3;
self.moveLeft = function (laneWidth) {
self.x = Math.max(laneWidth / 2, Math.floor((self.x - laneWidth) / laneWidth) * laneWidth + laneWidth / 2);
};
self.moveRight = function (laneWidth) {
self.x = Math.min(2048 - laneWidth / 2, Math.ceil((self.x + laneWidth) / laneWidth) * laneWidth - laneWidth / 2);
};
});
-var Game = Container.expand(function () {
- var self = Container.call(this);
- var startTime = Date.now();
- self.speedMultiplier = 1.0;
- LK.stageContainer.setBackgroundColor(0x000000);
- var player = self.addChild(new Player());
- player.x = 2048 / 2;
- player.y = 2732 - 200;
- var lifeIndicator = self.addChild(new LifeIndicator());
- lifeIndicator.x = 2048 - 300;
- lifeIndicator.y = 50;
- var leftButton = self.addChild(new Button());
- leftButton.x = 100;
- leftButton.y = 2732 - 200;
- var rightButton = self.addChild(new Button());
- rightButton.x = 2048 - 100;
- rightButton.y = 2732 - 200;
- var carsPassedTxt = new Text2('0', {
- size: 150,
- fill: '#ffffff'
- });
- LK.gui.topLeft.addChild(carsPassedTxt);
- var laneWidth = 2048 / 6;
- for (var i = 1; i < 6; i++) {
- var lane = new Lane();
- lane.x = i * laneWidth;
- self.addChild(lane);
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+var startTime = Date.now();
+game.speedMultiplier = 1.0;
+game.setBackgroundColor(0x000000);
+var player = game.addChild(new Player());
+player.x = 2048 / 2;
+player.y = 2732 - 200;
+var lifeIndicator = game.addChild(new LifeIndicator());
+lifeIndicator.x = 2048 - 300;
+lifeIndicator.y = 50;
+var leftButton = game.addChild(new Button());
+leftButton.x = 100;
+leftButton.y = 2732 - 200;
+var rightButton = game.addChild(new Button());
+rightButton.x = 2048 - 100;
+rightButton.y = 2732 - 200;
+var carsPassedTxt = new Text2('0', {
+ size: 150,
+ fill: '#ffffff'
+});
+LK.gui.topLeft.addChild(carsPassedTxt);
+var laneWidth = 2048 / 6;
+for (var i = 1; i < 6; i++) {
+ var lane = new Lane();
+ lane.x = i * laneWidth;
+ game.addChild(lane);
+}
+var cars = [];
+var carsPassed = 0;
+LK.on('tick', function () {
+ if (LK.ticks % (60 * 5) === 0) {
+ game.speedMultiplier *= 1.1;
}
- var cars = [];
- var carsPassed = 0;
- LK.on('tick', function () {
- if (LK.ticks % (60 * 5) === 0) {
- self.speedMultiplier *= 1.1;
+ for (var a = cars.length - 1; a >= 0; a--) {
+ cars[a]._move_migrated();
+ if (cars[a].y > 2732) {
+ cars[a].destroy();
+ cars.splice(a, 1);
+ carsPassed++;
}
- for (var a = cars.length - 1; a >= 0; a--) {
- cars[a].move();
- if (cars[a].y > 2732) {
- cars[a].destroy();
- cars.splice(a, 1);
- carsPassed++;
+ }
+ var currentTime = Date.now();
+ var timeElapsed = (currentTime - startTime) / 1000;
+ var spawnRate = timeElapsed > 20 ? Math.pow(1.10, Math.floor((timeElapsed - 20) / 5)) : 1;
+ if (LK.ticks % Math.floor(60 / spawnRate) == 0) {
+ var newCar = new Car();
+ var laneWidth = 2048 / 6;
+ newCar.x = Math.floor(Math.random() * 6) * laneWidth + laneWidth / 2;
+ newCar.y = 0;
+ newCar.speed *= game.speedMultiplier;
+ cars.push(newCar);
+ game.addChild(newCar);
+ }
+ carsPassedTxt.setText(carsPassed);
+ for (var i = 0; i < cars.length; i++) {
+ if (player.intersects(cars[i])) {
+ player.lives--;
+ lifeIndicator.updateLives(player.lives);
+ if (player.lives <= 0) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ } else {
+ cars[i].destroy();
+ cars.splice(i, 1);
}
}
- var currentTime = Date.now();
- var timeElapsed = (currentTime - startTime) / 1000;
- var spawnRate = timeElapsed > 20 ? Math.pow(1.10, Math.floor((timeElapsed - 20) / 5)) : 1;
- if (LK.ticks % Math.floor(60 / spawnRate) == 0) {
- var newCar = new Car();
- var laneWidth = 2048 / 6;
- newCar.x = Math.floor(Math.random() * 6) * laneWidth + laneWidth / 2;
- newCar.y = 0;
- newCar.speed *= self.speedMultiplier;
- cars.push(newCar);
- self.addChild(newCar);
- }
- carsPassedTxt.setText(carsPassed);
- for (var i = 0; i < cars.length; i++) {
- if (player.intersects(cars[i])) {
- player.lives--;
- lifeIndicator.updateLives(player.lives);
- if (player.lives <= 0) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- } else {
- cars[i].destroy();
- cars.splice(i, 1);
- }
- }
- }
- });
- leftButton.on('down', function (obj) {
- player.moveLeft(laneWidth);
- });
- rightButton.on('down', function (obj) {
- player.moveRight(laneWidth);
- });
+ }
});
+leftButton.on('down', function (x, y, obj) {
+ player.moveLeft(laneWidth);
+});
+rightButton.on('down', function (x, y, obj) {
+ player.moveRight(laneWidth);
+});
\ No newline at end of file
generate a arcade like round button in red color Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
generate image single white dashed road edge marking line. vertical direction. exempted. no background. just simple line nothing else on pic Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Super Mario. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Barrel. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.