User prompt
With both animations, just change one sprite with the other, dont use alpha values different than 1 or 0 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the same with dino ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the flying obstacle cycle his 2 images 4 times per second ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make each coin collected increase the score by 10
User prompt
It says final score 13, make it say meters travelled 13 instead
User prompt
Make the game over screen show meters travelled instead of final score
User prompt
I try to create coin sound but it says sound with id coin already exists
User prompt
Make the game over screen show "meters travelled" instead of "final score" and also show coins collected
User prompt
Make score be 1/10 of its actual value
User prompt
Dont spawn coins on flying obstacles
User prompt
Generate a coin above every obstacle, destroy the coin if the player collides with it or if it leaves the screen on the left, print the number of coins right below the score
User prompt
Hide hitboxes
User prompt
Revert changes
User prompt
Give the game an horizontal display, 4:3 ratio
User prompt
Move every obstacle 10 more pixels down
User prompt
Move every obstacle 10px down, make ground be behind obstacles
User prompt
Clouds get bigger as the game gets faster, make them preserve their initial size
User prompt
Bigger clouds are still behind small clouds, reverse that
User prompt
Make sure big clouds are always drawn in front of smaller ones
User prompt
Make the bird fly 40px lower
User prompt
Make it move even faster over time
User prompt
Now make everything move faster with time
User prompt
Now with the flying one
User prompt
Now do the same to the small rock
User prompt
Assign the big rock hitbox to the rock as made with the player
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
self.baseSpeed = Math.random() * 3 + 2; // Random base speed between 2 and 5
self.speed = self.baseSpeed; // Initialize speed
self.update = function () {
if (!hasGameStopped) {
// Update speed based on current game speed
self.speed = self.baseSpeed * (gameSpeed / 6); // Scale with game speed (6 is initial speed)
self.x -= self.speed;
}
};
return self;
});
var Dinosaur = Container.expand(function () {
var self = Container.call(this);
var dinoGraphics = self.attachAsset('dino', {
anchorX: 0.5,
anchorY: 1.0
});
self.hitbox = self.attachAsset('dino-hitbox', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityY = 0;
self.gravity = 1;
self.jumpPower = -30;
self.isGrounded = false;
self.groundY = 0;
self.hasCollided = false;
// Jump is now handled by the input system
self.update = function () {
// Apply gravity
self.velocityY += self.gravity;
self.y += self.velocityY;
// If collided, add horizontal movement to simulate being thrown
if (self.hasCollided) {
self.x += 3; // Move right when thrown
}
// Check ground collision
if (self.y >= self.groundY && !self.hasCollided) {
self.y = self.groundY;
self.velocityY = 0;
self.isGrounded = true;
}
// Check if fallen off screen (game over condition) - only trigger if collided
if (self.y > 2732 + 100 && self.hasCollided) {
LK.showGameOver();
}
};
return self;
});
var FlyingObstacle = Container.expand(function () {
var self = Container.call(this);
var flyingGraphics = self.attachAsset('flying_obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.hitbox = self.attachAsset('flying_obstacle-hitbox', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
if (!hasGameStopped) {
self.x += -gameSpeed * 2 * 1.5;
}
};
return self;
});
var GroundTile = Container.expand(function () {
var self = Container.call(this);
var groundGraphics = self.attachAsset('ground', {
anchorX: 0,
anchorY: 0
});
self.update = function () {
if (!hasGameStopped) {
self.x += -gameSpeed * 1.5;
}
};
return self;
});
var Obstacle = Container.expand(function (size) {
var self = Container.call(this);
// Determine which asset to use based on size parameter
var assetId = size === 'large' ? 'obstacle_large' : 'obstacle_small';
var obstacleGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 1.0
});
// Add hitbox for obstacles
if (size === 'large') {
self.hitbox = self.attachAsset('obstacle_large-hitbox', {
anchorX: 0.5,
anchorY: 1.0
});
} else if (size === 'small') {
self.hitbox = self.attachAsset('obstacle_small-hitbox', {
anchorX: 0.5,
anchorY: 1.0
});
}
self.size = size;
self.update = function () {
if (!hasGameStopped) {
self.x += -gameSpeed * 1.5;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var dinosaur;
var groundTiles = [];
var obstacles = [];
var flyingObstacle = null;
var flyingObstacleSpawnTimer = 0;
var flyingObstacleHeight = 2040; // Just above ground obstacles (flying obstacle height is 60)
var groundY = 2732 - 120; // Ground level - position ground tiles so they fill to bottom of screen
var gameSpeed = 6;
var distanceScore = 0;
var gameSpeedBeforeCollision = 6;
var hasGameStopped = false;
var obstacleSpawnTimer = 0;
var minObstacleSpacing = 600;
var maxObstacles = 3;
var clouds = [];
var cloudSpawnTimer = 0;
// Create score display
var scoreTxt = new Text2('0', {
size: 80,
fill: 0x333333
});
scoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreTxt);
// Create dinosaur
dinosaur = game.addChild(new Dinosaur());
dinosaur.x = 400;
dinosaur.y = groundY;
dinosaur.groundY = groundY;
// Create initial ground tiles
function createGroundTile(x) {
var tile = new GroundTile();
tile.x = x;
tile.y = groundY;
return tile;
}
// Create obstacle function
function createObstacle(x) {
var sizes = ['small', 'large'];
var randomSize = sizes[Math.floor(Math.random() * sizes.length)];
var obstacle = new Obstacle(randomSize);
obstacle.x = x;
obstacle.y = groundY + 10;
return obstacle;
}
// Create flying obstacle function
function createFlyingObstacle(x) {
var obstacle = new FlyingObstacle();
obstacle.x = x;
obstacle.y = flyingObstacleHeight + 10;
return obstacle;
}
// Create cloud function
function createCloud(x, y) {
var cloud = new Cloud();
cloud.x = x;
cloud.y = y;
var randomScale = 0.6 + Math.random() * 0.8; // Random scale between 0.6 and 1.4
cloud.scaleX = randomScale;
cloud.scaleY = randomScale;
return cloud;
}
// Create initial ground tiles to cover screen width plus extra for scrolling
for (var i = 0; i < 15; i++) {
var tile = game.addChild(createGroundTile(i * 200));
groundTiles.push(tile);
}
// Create initial background clouds
for (var c = 0; c < 8; c++) {
var cloudX = Math.random() * (2048 + 400) - 200; // Spread across screen width
var cloudY = Math.random() * 800 + 200; // Upper portion of screen
var cloud = game.addChild(createCloud(cloudX, cloudY));
clouds.push(cloud);
}
// Play main theme music
LK.playMusic('main-theme');
// Override LK.showGameOver - defeat sound now plays on collision
var originalShowGameOver = LK.showGameOver;
LK.showGameOver = function () {
originalShowGameOver.call(this);
};
// Game input handling - variable jump system
var isHolding = false;
var jumpHoldTime = 0;
var maxJumpHoldTime = 20; // Maximum frames to hold for full jump
var minJumpPower = -20; // Minimum jump power for taps
var maxJumpPower = -35; // Maximum jump power for full hold
game.down = function (x, y, obj) {
if (dinosaur.isGrounded && !hasGameStopped) {
isHolding = true;
jumpHoldTime = 0;
// Start with minimum jump
dinosaur.velocityY = minJumpPower;
dinosaur.isGrounded = false;
LK.getSound('jump').play();
}
};
game.up = function (x, y, obj) {
isHolding = false;
};
// Main game update loop
game.update = function () {
// Handle variable jump height
if (isHolding && !dinosaur.isGrounded && jumpHoldTime < maxJumpHoldTime && !hasGameStopped) {
jumpHoldTime++;
// Apply additional upward force while holding
var holdForce = -0.8; // Additional upward force per frame
dinosaur.velocityY += holdForce;
// Ensure we don't exceed maximum jump power
if (dinosaur.velocityY < maxJumpPower) {
dinosaur.velocityY = maxJumpPower;
}
}
// Only update score and spawn objects if game hasn't stopped
if (!hasGameStopped) {
// Update distance score
distanceScore += gameSpeed;
var displayScore = Math.floor(distanceScore / 10);
LK.setScore(displayScore);
scoreTxt.setText(displayScore);
}
// Manage ground tiles
for (var i = groundTiles.length - 1; i >= 0; i--) {
var tile = groundTiles[i];
// Remove tiles that have scrolled off screen
if (tile.x < -250) {
tile.destroy();
groundTiles.splice(i, 1);
}
}
// Add new ground tiles as needed
var lastTile = groundTiles[groundTiles.length - 1];
if (lastTile && lastTile.x + 200 < 2048 + 200) {
var newTile = game.addChild(createGroundTile(lastTile.x + 200));
groundTiles.push(newTile);
}
// Manage obstacles
for (var k = obstacles.length - 1; k >= 0; k--) {
var obstacle = obstacles[k];
// Remove obstacles that have scrolled off screen
if (obstacle.x < -200) {
obstacle.destroy();
obstacles.splice(k, 1);
}
}
// Manage flying obstacle
if (flyingObstacle) {
// Remove flying obstacle if it's off screen
if (flyingObstacle.x < -200) {
flyingObstacle.destroy();
flyingObstacle = null;
}
}
// Spawn flying obstacle
if (!hasGameStopped) {
flyingObstacleSpawnTimer++;
}
if (!hasGameStopped && !flyingObstacle && flyingObstacleSpawnTimer > 300) {
// Spawn every 5 seconds
flyingObstacle = game.addChild(createFlyingObstacle(2048 + 100));
flyingObstacleSpawnTimer = 0;
}
// Spawn new obstacles
if (!hasGameStopped) {
obstacleSpawnTimer++;
var baseSpawnTime = 120; // Base spawn time (2 seconds at 60fps)
var spawnVariation = 120; // ±2 second variation for more varied spacing
var currentSpawnTime = baseSpawnTime + Math.floor(Math.random() * spawnVariation * 2) - spawnVariation;
}
if (!hasGameStopped && obstacles.length < maxObstacles && obstacleSpawnTimer > currentSpawnTime) {
var canSpawn = true;
var spawnX = 2048 + 200; // Spawn well off-screen to the right
// Check if there's enough space from last obstacle
if (obstacles.length > 0) {
var lastObstacle = obstacles[obstacles.length - 1];
if (lastObstacle.x > spawnX - 600) {
// Ensure minimum 600px spacing
canSpawn = false;
}
}
if (canSpawn) {
// Add random horizontal offset while maintaining minimum spacing
var offsetRange = 100; // Reduced range to ensure proper spacing
var horizontalOffset = Math.floor(Math.random() * offsetRange);
var newObstacle = game.addChild(createObstacle(spawnX + horizontalOffset));
obstacles.push(newObstacle);
// Reset timer with additional random offset for next spawn
obstacleSpawnTimer = -Math.floor(Math.random() * 60); // Start next timer with up to 1 second head start
}
}
// Collision detection with ground obstacles
for (var o = 0; o < obstacles.length; o++) {
var obstacle = obstacles[o];
var collisionTarget = obstacle.hitbox || obstacle;
if (dinosaur.hitbox.intersects(collisionTarget) && !dinosaur.hasCollided) {
dinosaur.hasCollided = true;
hasGameStopped = true;
gameSpeedBeforeCollision = gameSpeed;
gameSpeed = 0;
LK.stopMusic();
// Play defeat sound
LK.getSound('defeat').play();
// Throw dinosaur up and to the right
dinosaur.velocityY = -50;
dinosaur.isGrounded = false;
// Add spinning animation
tween(dinosaur, {
rotation: Math.PI * 4
}, {
duration: 1500,
easing: tween.easeOut
});
return; // Stop processing other collisions
}
}
// Collision detection with flying obstacle
var flyingCollisionTarget = flyingObstacle && flyingObstacle.hitbox ? flyingObstacle.hitbox : flyingObstacle;
if (flyingObstacle && dinosaur.hitbox.intersects(flyingCollisionTarget) && !dinosaur.hasCollided) {
dinosaur.hasCollided = true;
hasGameStopped = true;
gameSpeedBeforeCollision = gameSpeed;
gameSpeed = 0;
LK.stopMusic();
// Play defeat sound
LK.getSound('defeat').play();
// Throw dinosaur up and to the right
dinosaur.velocityY = -50;
dinosaur.isGrounded = false;
// Add spinning animation
tween(dinosaur, {
rotation: Math.PI * 4
}, {
duration: 1500,
easing: tween.easeOut
});
return; // Stop processing other collisions
}
// Gradually increase game speed for difficulty progression
if (!hasGameStopped && LK.ticks % 360 === 0) {
// Every 6 seconds at 60fps
gameSpeed += 0.8;
for (var j = 0; j < groundTiles.length; j++) {
groundTiles[j].scrollSpeed = -gameSpeed;
}
}
// Manage clouds
for (var c = clouds.length - 1; c >= 0; c--) {
var cloud = clouds[c];
// Remove clouds that have scrolled off screen
if (cloud.x < -200) {
cloud.destroy();
clouds.splice(c, 1);
}
}
// Sort clouds by scale so bigger ones are drawn on top
clouds.sort(function (a, b) {
return a.scaleX - b.scaleX; // Smaller clouds first (drawn behind), bigger clouds last (drawn on top)
});
// Reorder clouds in the display list based on sorted order
for (var i = 0; i < clouds.length; i++) {
game.removeChild(clouds[i]);
game.addChild(clouds[i]);
}
// Spawn new clouds
if (!hasGameStopped) {
cloudSpawnTimer++;
}
if (!hasGameStopped && cloudSpawnTimer > 180) {
// Spawn new cloud every 3 seconds
var cloudY = Math.random() * 800 + 200; // Upper portion of screen
var newCloud = game.addChild(createCloud(2048 + 150, cloudY));
clouds.push(newCloud);
cloudSpawnTimer = 0;
}
// Ensure ground tiles are behind obstacles
for (var g = 0; g < groundTiles.length; g++) {
if (game.children.indexOf(groundTiles[g]) !== -1) {
game.removeChild(groundTiles[g]);
game.addChildAt(groundTiles[g], 0);
}
}
// Ensure dinosaur is always drawn on top of everything
if (game.children.indexOf(dinosaur) !== -1) {
game.removeChild(dinosaur);
game.addChild(dinosaur);
}
}; ===================================================================
--- original.js
+++ change.js
@@ -171,16 +171,16 @@
var sizes = ['small', 'large'];
var randomSize = sizes[Math.floor(Math.random() * sizes.length)];
var obstacle = new Obstacle(randomSize);
obstacle.x = x;
- obstacle.y = groundY;
+ obstacle.y = groundY + 10;
return obstacle;
}
// Create flying obstacle function
function createFlyingObstacle(x) {
var obstacle = new FlyingObstacle();
obstacle.x = x;
- obstacle.y = flyingObstacleHeight;
+ obstacle.y = flyingObstacleHeight + 10;
return obstacle;
}
// Create cloud function
function createCloud(x, y) {
@@ -403,8 +403,15 @@
var newCloud = game.addChild(createCloud(2048 + 150, cloudY));
clouds.push(newCloud);
cloudSpawnTimer = 0;
}
+ // Ensure ground tiles are behind obstacles
+ for (var g = 0; g < groundTiles.length; g++) {
+ if (game.children.indexOf(groundTiles[g]) !== -1) {
+ game.removeChild(groundTiles[g]);
+ game.addChildAt(groundTiles[g], 0);
+ }
+ }
// Ensure dinosaur is always drawn on top of everything
if (game.children.indexOf(dinosaur) !== -1) {
game.removeChild(dinosaur);
game.addChild(dinosaur);
dont crop parts of the image, show full image, give black outline
make him be flying with both wings, dont crop the image
tall rock, brown, very solid, really thick black outline
smaller rock, more rounded, really thick black outline, same brown color
white rounded cloud, really thick black outline
Simple golden coin, rounded, shiny, big black outline, funny
Same dinosaur but with wings down
Same dinosaur but legs running