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");
var storage = LK.import("@upit/storage.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 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 = 6;
var baseSpeed = 6;
var maxSpeed = 15;
var speedIncrement = 0.005;
var obstacleSpawnTimer = 0;
var obstacleSpawnDelay = 150;
var minSpawnDelay = 90;
var isPressed = false;
// Initialize best score from storage
var bestScore = storage.bestScore || 0;
// Create score display
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0x000000
});
scoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreText);
scoreText.x = -300;
scoreText.y = 50;
// Create best score display
var bestScoreText = new Text2('Best: ' + bestScore, {
size: 40,
fill: 0x666666
});
bestScoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(bestScoreText);
bestScoreText.x = -300;
bestScoreText.y = 120;
// Create dino
dino = game.attachAsset('dino', {
anchorX: 0.5,
anchorY: 1
});
dino.x = 300;
dino.y = 2600;
dino.velocityY = 0;
dino.isJumping = false;
dino.isDucking = false;
dino.jumpPower = -50;
dino.gravity = 1.2;
dino.groundY = 2600;
dino.duckHeight = 80;
dino.normalHeight = 160;
dino.jump = function () {
if (!dino.isJumping) {
dino.velocityY = dino.jumpPower;
dino.isJumping = true;
}
};
dino.duck = function () {
if (!dino.isDucking && !dino.isJumping) {
dino.isDucking = true;
// Remove current dino asset
dino.removeChildren();
// Add ducking asset
var duckGraphics = dino.attachAsset('dinoDuck', {
anchorX: 0.5,
anchorY: 1
});
dino.height = dino.duckHeight;
dino.y = dino.groundY;
}
};
dino.stopDuck = function () {
if (dino.isDucking) {
dino.isDucking = false;
// Remove ducking asset
dino.removeChildren();
// Add normal dino asset
var normalGraphics = dino.attachAsset('dino', {
anchorX: 0.5,
anchorY: 1
});
dino.height = dino.normalHeight;
dino.y = dino.groundY;
}
};
dino.update = function () {
if (dino.isJumping) {
dino.velocityY += dino.gravity;
dino.y += dino.velocityY;
if (dino.y >= dino.groundY) {
dino.y = dino.groundY;
dino.velocityY = 0;
dino.isJumping = false;
}
}
};
// 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;
obstacle.scored = false; // Track if player has scored from this obstacle
obstacles.push(obstacle);
game.addChild(obstacle);
}
function checkCollisions() {
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
if (dino.intersects(obstacle)) {
// Update best score if current score is higher
if (LK.getScore() > bestScore) {
bestScore = LK.getScore();
storage.bestScore = bestScore;
bestScoreText.setText('Best: ' + bestScore);
}
LK.showGameOver();
return;
}
}
}
game.down = function (x, y, obj) {
isPressed = true;
if (!dino.isJumping) {
dino.jump();
}
};
game.up = function (x, y, obj) {
isPressed = false;
};
game.update = function () {
// Handle ducking - duck when pressed and not jumping, stop ducking when not pressed
if (isPressed && !dino.isJumping && !dino.isDucking) {
dino.duck();
} else if (!isPressed && dino.isDucking) {
dino.stopDuck();
}
// Update game speed based on current score
gameSpeed = Math.min(baseSpeed + LK.getScore() * speedIncrement * 10, maxSpeed);
// Update ground speed
for (var i = 0; i < groundElements.length; i++) {
groundElements[i].speed = gameSpeed;
}
// Spawn obstacles
obstacleSpawnTimer++;
var currentSpawnDelay = Math.max(obstacleSpawnDelay - LK.getScore() * 3, 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;
// Check if player has passed the obstacle and award score
if (!obstacle.scored && obstacle.x < dino.x - 50) {
LK.setScore(LK.getScore() + 1);
scoreText.setText('Score: ' + LK.getScore());
obstacle.scored = true;
}
if (obstacle.x < -100) {
obstacle.destroy();
obstacles.splice(i, 1);
}
}
// Update dino
dino.update();
// Check collisions
checkCollisions();
}; ===================================================================
--- original.js
+++ change.js
@@ -197,14 +197,15 @@
}
};
game.up = function (x, y, obj) {
isPressed = false;
- dino.stopDuck();
};
game.update = function () {
- // Handle ducking
- if (isPressed && !dino.isJumping) {
+ // Handle ducking - duck when pressed and not jumping, stop ducking when not pressed
+ if (isPressed && !dino.isJumping && !dino.isDucking) {
dino.duck();
+ } else if (!isPressed && dino.isDucking) {
+ dino.stopDuck();
}
// Update game speed based on current score
gameSpeed = Math.min(baseSpeed + LK.getScore() * speedIncrement * 10, maxSpeed);
// Update ground speed