User prompt
I can't duck now.
User prompt
Add a best score and make the game easier. ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
I still can't jump over a cactus.
User prompt
can you get rid of the distance and replace it with score so when you jump over a cactus or a bird or duck under a bird you get a score
User prompt
I can't jump over the cactus.
User prompt
Fix the dinosaur acid.
User prompt
Make the dinosaur the same size as the cactus.
User prompt
Make an asset for the dinosaur ducking, so when you duck it's just a dinosaur duck.
User prompt
Delete the dino part because I already have a dino.
User prompt
Make the dinosaur the same size as the cactus.
User prompt
Make the cactus bigger so the player can actually see it. And make the player an actual dino.
Code edit (1 edits merged)
Please save this source code
User prompt
Dino Runner
Initial prompt
Make the Dino Game
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cactus = Container.expand(function () {
var self = Container.call(this);
var cactusGraphics = self.attachAsset('cactus', {
anchorX: 0.5,
anchorY: 1
});
self.speed = gameSpeed;
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Dino = Container.expand(function () {
var self = Container.call(this);
var dinoGraphics = self.attachAsset('dino', {
anchorX: 0.5,
anchorY: 1
});
self.groundY = 2600;
self.x = 300;
self.y = self.groundY;
self.velocityY = 0;
self.isJumping = false;
self.isDucking = false;
self.jumpPower = -25;
self.gravity = 1.2;
self.duckHeight = 40;
self.normalHeight = 80;
self.jump = function () {
if (!self.isJumping) {
self.velocityY = self.jumpPower;
self.isJumping = true;
}
};
self.duck = function () {
if (!self.isDucking && !self.isJumping) {
self.isDucking = true;
dinoGraphics.height = self.duckHeight;
self.y = self.groundY - self.duckHeight + self.normalHeight;
}
};
self.stopDuck = function () {
if (self.isDucking) {
self.isDucking = false;
dinoGraphics.height = self.normalHeight;
self.y = self.groundY;
}
};
self.update = function () {
if (self.isJumping) {
self.velocityY += self.gravity;
self.y += self.velocityY;
if (self.y >= self.groundY) {
self.y = self.groundY;
self.velocityY = 0;
self.isJumping = false;
}
}
};
return self;
});
var Ground = Container.expand(function () {
var self = Container.call(this);
var groundGraphics = self.attachAsset('ground', {
anchorX: 0,
anchorY: 0
});
self.speed = gameSpeed;
self.update = function () {
self.x -= self.speed;
if (self.x <= -2048) {
self.x = 0;
}
};
return self;
});
var Pterodactyl = Container.expand(function () {
var self = Container.call(this);
var pterodactylGraphics = self.attachAsset('pterodactyl', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = gameSpeed;
self.update = function () {
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xffffff
});
/****
* Game Code
****/
var dino;
var obstacles = [];
var groundElements = [];
var gameSpeed = 8;
var baseSpeed = 8;
var maxSpeed = 20;
var speedIncrement = 0.01;
var obstacleSpawnTimer = 0;
var obstacleSpawnDelay = 120;
var minSpawnDelay = 60;
var distance = 0;
var isPressed = false;
// Create score display
var scoreText = new Text2('Distance: 0', {
size: 60,
fill: 0x000000
});
scoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreText);
scoreText.x = -300;
scoreText.y = 50;
// Create dino
dino = new Dino();
game.addChild(dino);
// Create ground elements
for (var i = 0; i < 3; i++) {
var ground = new Ground();
ground.x = i * 2048;
ground.y = 2620;
groundElements.push(ground);
game.addChild(ground);
}
function spawnObstacle() {
var obstacleType = Math.random();
var obstacle;
if (obstacleType < 0.7) {
// Spawn cactus
obstacle = new Cactus();
obstacle.x = 2200;
obstacle.y = 2600;
} else {
// Spawn pterodactyl
obstacle = new Pterodactyl();
obstacle.x = 2200;
obstacle.y = 2450 + Math.random() * 100;
}
obstacle.speed = gameSpeed;
obstacles.push(obstacle);
game.addChild(obstacle);
}
function checkCollisions() {
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
if (dino.intersects(obstacle)) {
LK.showGameOver();
return;
}
}
}
game.down = function (x, y, obj) {
isPressed = true;
if (!dino.isJumping) {
dino.jump();
}
};
game.up = function (x, y, obj) {
isPressed = false;
dino.stopDuck();
};
game.update = function () {
// Handle ducking
if (isPressed && !dino.isJumping) {
dino.duck();
}
// Update game speed
gameSpeed = Math.min(baseSpeed + distance * speedIncrement, maxSpeed);
// Update distance and score
distance += gameSpeed * 0.1;
LK.setScore(Math.floor(distance));
scoreText.setText('Distance: ' + Math.floor(distance));
// Update ground speed
for (var i = 0; i < groundElements.length; i++) {
groundElements[i].speed = gameSpeed;
}
// Spawn obstacles
obstacleSpawnTimer++;
var currentSpawnDelay = Math.max(obstacleSpawnDelay - distance * 0.5, minSpawnDelay);
if (obstacleSpawnTimer >= currentSpawnDelay) {
spawnObstacle();
obstacleSpawnTimer = 0;
}
// Update obstacle speeds and remove off-screen obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
obstacle.speed = gameSpeed;
if (obstacle.x < -100) {
obstacle.destroy();
obstacles.splice(i, 1);
}
}
// Check collisions
checkCollisions();
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,210 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Cactus = Container.expand(function () {
+ var self = Container.call(this);
+ var cactusGraphics = self.attachAsset('cactus', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ self.speed = gameSpeed;
+ self.update = function () {
+ self.x -= self.speed;
+ };
+ return self;
+});
+var Dino = Container.expand(function () {
+ var self = Container.call(this);
+ var dinoGraphics = self.attachAsset('dino', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ self.groundY = 2600;
+ self.x = 300;
+ self.y = self.groundY;
+ self.velocityY = 0;
+ self.isJumping = false;
+ self.isDucking = false;
+ self.jumpPower = -25;
+ self.gravity = 1.2;
+ self.duckHeight = 40;
+ self.normalHeight = 80;
+ self.jump = function () {
+ if (!self.isJumping) {
+ self.velocityY = self.jumpPower;
+ self.isJumping = true;
+ }
+ };
+ self.duck = function () {
+ if (!self.isDucking && !self.isJumping) {
+ self.isDucking = true;
+ dinoGraphics.height = self.duckHeight;
+ self.y = self.groundY - self.duckHeight + self.normalHeight;
+ }
+ };
+ self.stopDuck = function () {
+ if (self.isDucking) {
+ self.isDucking = false;
+ dinoGraphics.height = self.normalHeight;
+ self.y = self.groundY;
+ }
+ };
+ self.update = function () {
+ if (self.isJumping) {
+ self.velocityY += self.gravity;
+ self.y += self.velocityY;
+ if (self.y >= self.groundY) {
+ self.y = self.groundY;
+ self.velocityY = 0;
+ self.isJumping = false;
+ }
+ }
+ };
+ return self;
+});
+var Ground = Container.expand(function () {
+ var self = Container.call(this);
+ var groundGraphics = self.attachAsset('ground', {
+ anchorX: 0,
+ anchorY: 0
+ });
+ self.speed = gameSpeed;
+ self.update = function () {
+ self.x -= self.speed;
+ if (self.x <= -2048) {
+ self.x = 0;
+ }
+ };
+ return self;
+});
+var Pterodactyl = Container.expand(function () {
+ var self = Container.call(this);
+ var pterodactylGraphics = self.attachAsset('pterodactyl', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = gameSpeed;
+ self.update = function () {
+ self.x -= self.speed;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xffffff
+});
+
+/****
+* Game Code
+****/
+var dino;
+var obstacles = [];
+var groundElements = [];
+var gameSpeed = 8;
+var baseSpeed = 8;
+var maxSpeed = 20;
+var speedIncrement = 0.01;
+var obstacleSpawnTimer = 0;
+var obstacleSpawnDelay = 120;
+var minSpawnDelay = 60;
+var distance = 0;
+var isPressed = false;
+// Create score display
+var scoreText = new Text2('Distance: 0', {
+ size: 60,
+ fill: 0x000000
+});
+scoreText.anchor.set(0, 0);
+LK.gui.topRight.addChild(scoreText);
+scoreText.x = -300;
+scoreText.y = 50;
+// Create dino
+dino = new Dino();
+game.addChild(dino);
+// Create ground elements
+for (var i = 0; i < 3; i++) {
+ var ground = new Ground();
+ ground.x = i * 2048;
+ ground.y = 2620;
+ groundElements.push(ground);
+ game.addChild(ground);
+}
+function spawnObstacle() {
+ var obstacleType = Math.random();
+ var obstacle;
+ if (obstacleType < 0.7) {
+ // Spawn cactus
+ obstacle = new Cactus();
+ obstacle.x = 2200;
+ obstacle.y = 2600;
+ } else {
+ // Spawn pterodactyl
+ obstacle = new Pterodactyl();
+ obstacle.x = 2200;
+ obstacle.y = 2450 + Math.random() * 100;
+ }
+ obstacle.speed = gameSpeed;
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
+}
+function checkCollisions() {
+ for (var i = 0; i < obstacles.length; i++) {
+ var obstacle = obstacles[i];
+ if (dino.intersects(obstacle)) {
+ LK.showGameOver();
+ return;
+ }
+ }
+}
+game.down = function (x, y, obj) {
+ isPressed = true;
+ if (!dino.isJumping) {
+ dino.jump();
+ }
+};
+game.up = function (x, y, obj) {
+ isPressed = false;
+ dino.stopDuck();
+};
+game.update = function () {
+ // Handle ducking
+ if (isPressed && !dino.isJumping) {
+ dino.duck();
+ }
+ // Update game speed
+ gameSpeed = Math.min(baseSpeed + distance * speedIncrement, maxSpeed);
+ // Update distance and score
+ distance += gameSpeed * 0.1;
+ LK.setScore(Math.floor(distance));
+ scoreText.setText('Distance: ' + Math.floor(distance));
+ // Update ground speed
+ for (var i = 0; i < groundElements.length; i++) {
+ groundElements[i].speed = gameSpeed;
+ }
+ // Spawn obstacles
+ obstacleSpawnTimer++;
+ var currentSpawnDelay = Math.max(obstacleSpawnDelay - distance * 0.5, minSpawnDelay);
+ if (obstacleSpawnTimer >= currentSpawnDelay) {
+ spawnObstacle();
+ obstacleSpawnTimer = 0;
+ }
+ // Update obstacle speeds and remove off-screen obstacles
+ for (var i = obstacles.length - 1; i >= 0; i--) {
+ var obstacle = obstacles[i];
+ obstacle.speed = gameSpeed;
+ if (obstacle.x < -100) {
+ obstacle.destroy();
+ obstacles.splice(i, 1);
+ }
+ }
+ // Check collisions
+ checkCollisions();
+};
\ No newline at end of file