Code edit (16 edits merged)
Please save this source code
User prompt
Create a bike racing game with upward movement continuously
Code edit (1 edits merged)
Please save this source code
User prompt
create a bike racing game with forward movement continously
User prompt
remove previous game code
User prompt
make the bike move forward continously
User prompt
make the bike move forward
Code edit (2 edits merged)
Please save this source code
User prompt
create a bike racing game
User prompt
remove previous game code
Code edit (1 edits merged)
Please save this source code
User prompt
spawn enemies in forward of the player also
User prompt
remove all sound effects assets and code
User prompt
add default forward movement to the player
User prompt
press left click to shoot the bullets
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'ArrowLeft')' in or related to this line: 'if (LK.keys['ArrowLeft']) {' Line Number: 93
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'Space')' in or related to this line: 'if (LK.keys['Space']) {' Line Number: 122
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'Space')' in or related to this line: 'if (LK.keys['Space']) {' Line Number: 120
User prompt
create a game like road rash
User prompt
remove previous game code
User prompt
remove previous game code
User prompt
create a geometry dash game
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'ArrowLeft')' in or related to this line: 'if (LK.keys['ArrowLeft']) {' Line Number: 76
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'ArrowLeft')' in or related to this line: 'if (LK.keys['ArrowLeft']) {' Line Number: 76
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'ArrowLeft')' in or related to this line: 'if (LK.keys['ArrowLeft']) {' Line Number: 76
/**** * Classes ****/ var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.update = function () { self.y += self.speed; if (self.y < -enemyGraphics.height) { self.destroy(); } }; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('car', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { if (self.y < 0) { self.y = 0; } if (self.y > 2732 - playerGraphics.height) { self.y = 2732 - playerGraphics.height; } }; self.move = function (x, y, obj) { self.y = y; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; var enemies = []; game.update = function () { if (LK.ticks % 30 == 0) { var newEnemy = new Enemy(); newEnemy.x = Math.random() * 2048; newEnemy.y = 2732; enemies.push(newEnemy); game.addChild(newEnemy); } for (var i = enemies.length - 1; i >= 0; i--) { if (player.intersects(enemies[i])) { LK.getSound('enemyDestroyed').play(); enemies[i].destroy(); enemies.splice(i, 1); } } };
===================================================================
--- original.js
+++ change.js
@@ -1,41 +1,38 @@
/****
* Classes
****/
-// Bullet class
-var Bullet = Container.expand(function () {
+var Enemy = Container.expand(function () {
var self = Container.call(this);
- var bulletGraphics = self.attachAsset('bullet', {
+ var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.y += self.speed;
+ if (self.y < -enemyGraphics.height) {
+ self.destroy();
+ }
};
});
-// Car class
-var Car = Container.expand(function () {
+var Player = Container.expand(function () {
var self = Container.call(this);
- var carGraphics = self.attachAsset('car', {
+ var playerGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
- self.y += self.speed;
+ if (self.y < 0) {
+ self.y = 0;
+ }
+ if (self.y > 2732 - playerGraphics.height) {
+ self.y = 2732 - playerGraphics.height;
+ }
};
-});
-// Enemy class
-var Enemy = Container.expand(function () {
- var self = Container.call(this);
- var enemyGraphics = self.attachAsset('enemy', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 2;
- self.update = function () {
- self.y += self.speed;
+ self.move = function (x, y, obj) {
+ self.y = y;
};
});
/****
@@ -47,56 +44,24 @@
/****
* Game Code
****/
-// Initialize the car
-var car = game.addChild(new Car());
-car.x = 2048 / 2;
-car.y = 2732 - 100;
-// Initialize the bullets
-var bullets = [];
-// Initialize the enemies
+var player = game.addChild(new Player());
+player.x = 2048 / 2;
+player.y = 2732 / 2;
var enemies = [];
-for (var i = 0; i < 10; i++) {
- var enemy = game.addChild(new Enemy());
- enemy.x = Math.random() * 2048;
- enemy.y = Math.random() * 500;
- enemies.push(enemy);
-}
-// Initialize LK.keys object
-LK.keys = {
- 'ArrowLeft': false,
- 'ArrowRight': false,
- 'Space': false
-};
game.update = function () {
- // Move the car
- if (LK.keys['ArrowLeft']) {
- car.x -= car.speed;
+ if (LK.ticks % 30 == 0) {
+ var newEnemy = new Enemy();
+ newEnemy.x = Math.random() * 2048;
+ newEnemy.y = 2732;
+ enemies.push(newEnemy);
+ game.addChild(newEnemy);
}
- if (LK.keys['ArrowRight']) {
- car.x += car.speed;
- }
- // Shoot bullets
- if (LK.keys['Space']) {
- var bullet = game.addChild(new Bullet());
- bullet.x = car.x;
- bullet.y = car.y;
- bullets.push(bullet);
- LK.getSound('shoot').play();
- }
- // Check for collisions
- for (var i = bullets.length - 1; i >= 0; i--) {
- var bullet = bullets[i];
- for (var j = enemies.length - 1; j >= 0; j--) {
- var enemy = enemies[j];
- if (bullet.intersects(enemy)) {
- bullet.destroy();
- bullets.splice(i, 1);
- enemy.destroy();
- enemies.splice(j, 1);
- LK.getSound('enemyDestroyed').play();
- break;
- }
+ for (var i = enemies.length - 1; i >= 0; i--) {
+ if (player.intersects(enemies[i])) {
+ LK.getSound('enemyDestroyed').play();
+ enemies[i].destroy();
+ enemies.splice(i, 1);
}
}
};
\ No newline at end of file
sci fi bike with person riding facing right side Single Game Texture. In-Game asset. High contrast. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sci fi bike with person riding facing right side Single Game Texture. In-Game asset. High contrast.
asteroid falling diffrent colors Single Game Texture. In-Game asset. High contrast. No Background