User prompt
adjust the road movement speed with a variable
User prompt
adjust the road movement speed with a variable
Code edit (2 edits merged)
Please save this source code
User prompt
display the score on the game over UI on the screen
User prompt
display the score on the game over screen
Code edit (7 edits merged)
Please save this source code
User prompt
display the scoreboard on the screen
User prompt
Create a scoreboard based on bike distance
Code edit (7 edits merged)
Please save this source code
User prompt
dont attach bullet to bike
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
create an asset called bullet and set spawn from the bike horizontally on the game
User prompt
remove bullet logic
User prompt
remove bullet asset
User prompt
remove make the bike asset to shoot every 5 seconds
Code edit (1 edits merged)
Please save this source code
User prompt
make the bike asset to shoot every 5 seconds
User prompt
attach the bullet to the bike
User prompt
make the bullet comes from the bike
User prompt
make the bike able to shoot
Code edit (1 edits merged)
Please save this source code
User prompt
spawn the obstacle3 asset in the game don't replace the obstacle2 and bike
User prompt
spawn the obstacle3 asset in the game
Code edit (3 edits merged)
Please save this source code
/**** * Classes ****/ var Bike = Container.expand(function () { var self = Container.call(this); var bikeGraphics = self.attachAsset('bike', { anchorX: 0, anchorY: -2.5, scaleX: 3, scaleY: 3 }); self.update = function () { self.x += 0.5; if (self.x > 2048) { self.x = -100; } }; self.jumping = false; self.jumpCounter = 0; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5, scaleX: 1, scaleY: 1 }); self.speed = 10; self.update = function () { self.x += self.speed; }; }); var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: -3, anchorY: -2.3, scaleX: 3, scaleY: 3 }); self.update = function () { self.x -= 10; }; }); var Obstacle2 = Container.expand(function () { var self = Container.call(this); var obstacle2Graphics = self.attachAsset('obstacle2', { anchorX: -3, anchorY: 2.3, scaleX: 2, scaleY: 2 }); self.update = function () { self.x -= 10; self.y += 5; // Add a default downward movement for obstacle2 }; }); var Road = Container.expand(function () { var self = Container.call(this); var roadGraphics = self.attachAsset('road', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var road = game.addChild(new Road()); road.x = 2048 / 2; road.y = 2732 / 2; var background1 = road; var background2 = new Road(); game.addChild(background2); background2.x = background1.x + 2048; background2.y = 2732 / 2; // Position background2 at the center of the screen vertically var bike = game.addChild(new Bike()); var obstacle = game.addChild(new Obstacle()); obstacle.x = 2048 / 2; obstacle.y = 2732 / 2; bike.x = 0; bike.y = 2732 / 2; var obstacle2; // Define obstacle2 in the global scope var bullets = []; // Array to keep track of bullets game.update = function () { background1.x -= 5; background2.x -= 5; if (background1.x <= -1024) { background1.x = background2.x + 2048; } if (background2.x <= -1024) { background2.x = background1.x + 2048; } if (LK.ticks % Math.floor(Math.random() * 1800) == 0) { var newObstacle = new Obstacle(); newObstacle.x = 2048; newObstacle.y = 2732 / 2; game.addChild(newObstacle); obstacle2 = new Obstacle2(); obstacle2.x = 2048; obstacle2.y = bike.y; game.addChild(obstacle2); } for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; if (bullet.x > 2048) { game.removeChild(bullet); bullets.splice(i, 1); } else if (bullet.intersects(obstacle2)) { game.removeChild(bullet); bullets.splice(i, 1); game.removeChild(obstacle2); obstacle2 = null; } } if (bike.intersects(obstacle2)) { LK.showGameOver(); } if (bike.jumping) { bike.y -= 50; bike.jumpCounter++; if (bike.jumpCounter > 20) { bike.jumping = false; } } else if (bike.y < 2732 / 2) { bike.y += 15; } else { bike.jumpCounter = 0; } }; game.down = function (x, y, obj) { if (!bike.jumping) { bike.jumping = true; } var bullet = new Bullet(); bullet.x = bike.x; bullet.y = bike.y; game.addChild(bullet); bullets.push(bullet); };
===================================================================
--- original.js
+++ change.js
@@ -17,8 +17,21 @@
};
self.jumping = false;
self.jumpCounter = 0;
});
+var Bullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 1,
+ scaleY: 1
+ });
+ self.speed = 10;
+ self.update = function () {
+ self.x += self.speed;
+ };
+});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: -3,
@@ -75,8 +88,9 @@
obstacle.y = 2732 / 2;
bike.x = 0;
bike.y = 2732 / 2;
var obstacle2; // Define obstacle2 in the global scope
+var bullets = []; // Array to keep track of bullets
game.update = function () {
background1.x -= 5;
background2.x -= 5;
if (background1.x <= -1024) {
@@ -85,22 +99,31 @@
if (background2.x <= -1024) {
background2.x = background1.x + 2048;
}
if (LK.ticks % Math.floor(Math.random() * 1800) == 0) {
- // 60 ticks per second, so 1800 ticks = 30 seconds
var newObstacle = new Obstacle();
- newObstacle.x = 2048; // spawn at the right edge of the screen
- newObstacle.y = 2732 / 2; // spawn at the middle of the screen vertically
+ newObstacle.x = 2048;
+ newObstacle.y = 2732 / 2;
game.addChild(newObstacle);
- obstacle2 = new Obstacle2(); // Assign the new Obstacle2 instance to the global obstacle2 variable
- obstacle2.x = 2048; // spawn at the right edge of the screen
- obstacle2.y = bike.y; // spawn at the player's vertical position
+ obstacle2 = new Obstacle2();
+ obstacle2.x = 2048;
+ obstacle2.y = bike.y;
game.addChild(obstacle2);
}
- // Check if bike collides with obstacle2
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ var bullet = bullets[i];
+ if (bullet.x > 2048) {
+ game.removeChild(bullet);
+ bullets.splice(i, 1);
+ } else if (bullet.intersects(obstacle2)) {
+ game.removeChild(bullet);
+ bullets.splice(i, 1);
+ game.removeChild(obstacle2);
+ obstacle2 = null;
+ }
+ }
if (bike.intersects(obstacle2)) {
- // Show game over. The game will be automatically paused while game over is showing.
- LK.showGameOver(); // Calling this will destroy the 'Game' and reset entire game state.
+ LK.showGameOver();
}
if (bike.jumping) {
bike.y -= 50;
bike.jumpCounter++;
@@ -116,5 +139,10 @@
game.down = function (x, y, obj) {
if (!bike.jumping) {
bike.jumping = true;
}
+ var bullet = new Bullet();
+ bullet.x = bike.x;
+ bullet.y = bike.y;
+ game.addChild(bullet);
+ bullets.push(bullet);
};
\ 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