/****
* 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.0
});
self.speed = 8;
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1;
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.0
});
self.isJumping = false;
self.isDucking = false;
self.jumpVelocity = 0;
self.groundY = 2500;
self.jumpPower = -25;
self.gravity = 1.2;
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.jumpVelocity = self.jumpPower;
LK.getSound('jump').play();
}
};
self.duck = function () {
if (!self.isJumping) {
self.isDucking = true;
dinoGraphics.scaleY = 0.6;
}
};
self.stopDucking = function () {
self.isDucking = false;
dinoGraphics.scaleY = 1.0;
};
self.update = function () {
if (self.isJumping) {
self.jumpVelocity += self.gravity;
self.y += self.jumpVelocity;
if (self.y >= self.groundY) {
self.y = self.groundY;
self.isJumping = false;
self.jumpVelocity = 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 = 8;
self.update = function () {
self.x -= self.speed;
// Simple flying animation
pterodactylGraphics.y = Math.sin(LK.ticks * 0.2) * 10;
};
return self;
});
var Rose = Container.expand(function () {
var self = Container.call(this);
var roseGraphics = self.attachAsset('rose', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Tree = Container.expand(function () {
var self = Container.call(this);
var trunk = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1.0
});
var leaves = self.attachAsset('treetop', {
anchorX: 0.5,
anchorY: 1.0,
y: -180
});
self.speed = 2;
self.update = function () {
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game state variables
var gameRunning = false;
var gameSpeed = 8;
var distanceScore = 0;
var speedIncrement = 0.002;
var lastObstacleSpawn = 0;
var minObstacleDistance = 200;
var maxObstacleDistance = 400;
var nextObstacleDistance = 300;
var isNightMode = false;
var dayNightThreshold = 500;
var rosesCollected = 0;
var lastRoseSpawn = 0;
var roseSpawnInterval = 180;
// Game objects
var dino;
var obstacles = [];
var grounds = [];
var roses = [];
var trees = [];
var clouds = [];
// UI elements
var scoreText;
var highScoreText;
var instructionText;
var rosesText;
// Initialize high score from storage
var highScore = storage.highScore || 0;
// Create ground segments
function createGroundSegments() {
for (var i = 0; i < 4; i++) {
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: i * 2048,
y: 2520
}));
grounds.push(ground);
}
}
// Update ground scrolling
function updateGround() {
for (var i = 0; i < grounds.length; i++) {
var ground = grounds[i];
ground.x -= gameSpeed;
if (ground.x <= -2048) {
ground.x = ground.x + 2048 * grounds.length;
}
}
}
// Create background trees
function createBackgroundTrees() {
for (var i = 0; i < 15; i++) {
var tree = new Tree();
tree.x = Math.random() * 3000 + 200;
tree.y = 2520;
tree.speed = 2;
trees.push(tree);
game.addChild(tree);
}
}
// Create clouds
function createClouds() {
for (var i = 0; i < 20; i++) {
var cloud = new Cloud();
cloud.x = Math.random() * 3000 + 200;
cloud.y = 300 + Math.random() * 400;
cloud.speed = 1;
clouds.push(cloud);
game.addChild(cloud);
}
}
// Update background trees
function updateTrees() {
for (var i = trees.length - 1; i >= 0; i--) {
var tree = trees[i];
tree.speed = gameSpeed * 0.3;
if (tree.x < -100) {
tree.x = 2200 + Math.random() * 400;
}
}
}
// Update clouds
function updateClouds() {
for (var i = clouds.length - 1; i >= 0; i--) {
var cloud = clouds[i];
cloud.speed = gameSpeed * 0.15;
if (cloud.x < -150) {
cloud.x = 2300 + Math.random() * 600;
}
}
}
// Spawn obstacle
function spawnObstacle() {
var obstacle;
var obstacleType = Math.random();
if (obstacleType < 0.7) {
// Spawn cactus
obstacle = new Cactus();
obstacle.x = 2200;
obstacle.y = 2520;
} else {
// Spawn pterodactyl
obstacle = new Pterodactyl();
obstacle.x = 2200;
obstacle.y = 2200 - Math.random() * 150;
}
obstacle.speed = gameSpeed;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Spawn rose
function spawnRose() {
var rose = new Rose();
rose.x = 2200;
rose.y = 2520;
rose.speed = gameSpeed;
roses.push(rose);
game.addChild(rose);
}
// Update obstacles
function updateObstacles() {
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);
}
}
}
// Update roses
function updateRoses() {
for (var i = roses.length - 1; i >= 0; i--) {
var rose = roses[i];
rose.speed = gameSpeed;
if (rose.x < -100) {
rose.destroy();
roses.splice(i, 1);
}
}
}
// Check rose collections
function checkRoseCollections() {
for (var i = roses.length - 1; i >= 0; i--) {
var rose = roses[i];
if (dino.intersects(rose)) {
rosesCollected++;
rosesText.setText('Roses: ' + rosesCollected);
LK.getSound('collect').play();
rose.destroy();
roses.splice(i, 1);
}
}
}
// Check collisions
function checkCollisions() {
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
if (dino.intersects(obstacle)) {
// Only trigger collision if Dino is on the ground or very close to it
// Allow safe jumping over obstacles
if (!dino.isJumping || dino.y > dino.groundY - 50) {
gameOver();
return;
}
}
}
}
// Game over
function gameOver() {
gameRunning = false;
LK.getSound('collision').play();
// Update high score
if (distanceScore > highScore) {
highScore = distanceScore;
storage.highScore = highScore;
}
LK.showGameOver();
}
// Start game
function startGame() {
if (!gameRunning) {
gameRunning = true;
instructionText.alpha = 0;
rosesCollected = 0;
rosesText.setText('Roses: 0');
}
}
// Update day/night cycle
function updateDayNight() {
if (distanceScore > dayNightThreshold && !isNightMode) {
isNightMode = true;
tween(game, {
backgroundColor: 0x191970
}, {
duration: 2000
});
} else if (distanceScore > dayNightThreshold * 2 && isNightMode) {
isNightMode = false;
dayNightThreshold *= 3;
tween(game, {
backgroundColor: 0x87CEEB
}, {
duration: 2000
});
}
}
// Initialize game elements
createGroundSegments();
createBackgroundTrees();
createClouds();
// Create dino
dino = game.addChild(new Dino());
dino.x = 300;
dino.y = 2520;
// Create UI
scoreText = new Text2('0', {
size: 60,
fill: 0x000000
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreText.y = 100;
highScoreText = new Text2('HI: ' + highScore, {
size: 40,
fill: 0x666666
});
highScoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(highScoreText);
highScoreText.y = 180;
instructionText = new Text2('TAP TO START', {
size: 80,
fill: 0x000000
});
instructionText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(instructionText);
rosesText = new Text2('Roses: 0', {
size: 40,
fill: 0x8B4513
});
rosesText.anchor.set(0, 0);
LK.gui.topRight.addChild(rosesText);
rosesText.x = -200;
rosesText.y = 50;
// Input handling
var isPressed = false;
game.down = function (x, y, obj) {
if (!gameRunning) {
startGame();
} else {
dino.jump();
}
isPressed = true;
};
game.up = function (x, y, obj) {
isPressed = false;
if (gameRunning) {
dino.stopDucking();
}
};
// Main game loop
game.update = function () {
if (!gameRunning) {
return;
}
// Handle ducking
if (isPressed && !dino.isJumping) {
dino.duck();
}
// Update game speed and score
gameSpeed += speedIncrement;
distanceScore = Math.floor(LK.ticks / 6);
scoreText.setText(distanceScore.toString());
// Update ground
updateGround();
// Update background elements
updateTrees();
updateClouds();
// Spawn obstacles
if (LK.ticks - lastObstacleSpawn > nextObstacleDistance) {
spawnObstacle();
lastObstacleSpawn = LK.ticks;
nextObstacleDistance = minObstacleDistance + Math.random() * (maxObstacleDistance - minObstacleDistance);
}
// Spawn roses
if (LK.ticks - lastRoseSpawn > roseSpawnInterval) {
spawnRose();
lastRoseSpawn = LK.ticks;
roseSpawnInterval = 120 + Math.random() * 120;
}
// Update obstacles
updateObstacles();
// Update roses
updateRoses();
// Check collisions
checkCollisions();
// Check rose collections
checkRoseCollections();
// Update day/night cycle
updateDayNight();
}; /****
* 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.0
});
self.speed = 8;
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1;
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.0
});
self.isJumping = false;
self.isDucking = false;
self.jumpVelocity = 0;
self.groundY = 2500;
self.jumpPower = -25;
self.gravity = 1.2;
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.jumpVelocity = self.jumpPower;
LK.getSound('jump').play();
}
};
self.duck = function () {
if (!self.isJumping) {
self.isDucking = true;
dinoGraphics.scaleY = 0.6;
}
};
self.stopDucking = function () {
self.isDucking = false;
dinoGraphics.scaleY = 1.0;
};
self.update = function () {
if (self.isJumping) {
self.jumpVelocity += self.gravity;
self.y += self.jumpVelocity;
if (self.y >= self.groundY) {
self.y = self.groundY;
self.isJumping = false;
self.jumpVelocity = 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 = 8;
self.update = function () {
self.x -= self.speed;
// Simple flying animation
pterodactylGraphics.y = Math.sin(LK.ticks * 0.2) * 10;
};
return self;
});
var Rose = Container.expand(function () {
var self = Container.call(this);
var roseGraphics = self.attachAsset('rose', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Tree = Container.expand(function () {
var self = Container.call(this);
var trunk = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1.0
});
var leaves = self.attachAsset('treetop', {
anchorX: 0.5,
anchorY: 1.0,
y: -180
});
self.speed = 2;
self.update = function () {
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game state variables
var gameRunning = false;
var gameSpeed = 8;
var distanceScore = 0;
var speedIncrement = 0.002;
var lastObstacleSpawn = 0;
var minObstacleDistance = 200;
var maxObstacleDistance = 400;
var nextObstacleDistance = 300;
var isNightMode = false;
var dayNightThreshold = 500;
var rosesCollected = 0;
var lastRoseSpawn = 0;
var roseSpawnInterval = 180;
// Game objects
var dino;
var obstacles = [];
var grounds = [];
var roses = [];
var trees = [];
var clouds = [];
// UI elements
var scoreText;
var highScoreText;
var instructionText;
var rosesText;
// Initialize high score from storage
var highScore = storage.highScore || 0;
// Create ground segments
function createGroundSegments() {
for (var i = 0; i < 4; i++) {
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: i * 2048,
y: 2520
}));
grounds.push(ground);
}
}
// Update ground scrolling
function updateGround() {
for (var i = 0; i < grounds.length; i++) {
var ground = grounds[i];
ground.x -= gameSpeed;
if (ground.x <= -2048) {
ground.x = ground.x + 2048 * grounds.length;
}
}
}
// Create background trees
function createBackgroundTrees() {
for (var i = 0; i < 15; i++) {
var tree = new Tree();
tree.x = Math.random() * 3000 + 200;
tree.y = 2520;
tree.speed = 2;
trees.push(tree);
game.addChild(tree);
}
}
// Create clouds
function createClouds() {
for (var i = 0; i < 20; i++) {
var cloud = new Cloud();
cloud.x = Math.random() * 3000 + 200;
cloud.y = 300 + Math.random() * 400;
cloud.speed = 1;
clouds.push(cloud);
game.addChild(cloud);
}
}
// Update background trees
function updateTrees() {
for (var i = trees.length - 1; i >= 0; i--) {
var tree = trees[i];
tree.speed = gameSpeed * 0.3;
if (tree.x < -100) {
tree.x = 2200 + Math.random() * 400;
}
}
}
// Update clouds
function updateClouds() {
for (var i = clouds.length - 1; i >= 0; i--) {
var cloud = clouds[i];
cloud.speed = gameSpeed * 0.15;
if (cloud.x < -150) {
cloud.x = 2300 + Math.random() * 600;
}
}
}
// Spawn obstacle
function spawnObstacle() {
var obstacle;
var obstacleType = Math.random();
if (obstacleType < 0.7) {
// Spawn cactus
obstacle = new Cactus();
obstacle.x = 2200;
obstacle.y = 2520;
} else {
// Spawn pterodactyl
obstacle = new Pterodactyl();
obstacle.x = 2200;
obstacle.y = 2200 - Math.random() * 150;
}
obstacle.speed = gameSpeed;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Spawn rose
function spawnRose() {
var rose = new Rose();
rose.x = 2200;
rose.y = 2520;
rose.speed = gameSpeed;
roses.push(rose);
game.addChild(rose);
}
// Update obstacles
function updateObstacles() {
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);
}
}
}
// Update roses
function updateRoses() {
for (var i = roses.length - 1; i >= 0; i--) {
var rose = roses[i];
rose.speed = gameSpeed;
if (rose.x < -100) {
rose.destroy();
roses.splice(i, 1);
}
}
}
// Check rose collections
function checkRoseCollections() {
for (var i = roses.length - 1; i >= 0; i--) {
var rose = roses[i];
if (dino.intersects(rose)) {
rosesCollected++;
rosesText.setText('Roses: ' + rosesCollected);
LK.getSound('collect').play();
rose.destroy();
roses.splice(i, 1);
}
}
}
// Check collisions
function checkCollisions() {
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
if (dino.intersects(obstacle)) {
// Only trigger collision if Dino is on the ground or very close to it
// Allow safe jumping over obstacles
if (!dino.isJumping || dino.y > dino.groundY - 50) {
gameOver();
return;
}
}
}
}
// Game over
function gameOver() {
gameRunning = false;
LK.getSound('collision').play();
// Update high score
if (distanceScore > highScore) {
highScore = distanceScore;
storage.highScore = highScore;
}
LK.showGameOver();
}
// Start game
function startGame() {
if (!gameRunning) {
gameRunning = true;
instructionText.alpha = 0;
rosesCollected = 0;
rosesText.setText('Roses: 0');
}
}
// Update day/night cycle
function updateDayNight() {
if (distanceScore > dayNightThreshold && !isNightMode) {
isNightMode = true;
tween(game, {
backgroundColor: 0x191970
}, {
duration: 2000
});
} else if (distanceScore > dayNightThreshold * 2 && isNightMode) {
isNightMode = false;
dayNightThreshold *= 3;
tween(game, {
backgroundColor: 0x87CEEB
}, {
duration: 2000
});
}
}
// Initialize game elements
createGroundSegments();
createBackgroundTrees();
createClouds();
// Create dino
dino = game.addChild(new Dino());
dino.x = 300;
dino.y = 2520;
// Create UI
scoreText = new Text2('0', {
size: 60,
fill: 0x000000
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreText.y = 100;
highScoreText = new Text2('HI: ' + highScore, {
size: 40,
fill: 0x666666
});
highScoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(highScoreText);
highScoreText.y = 180;
instructionText = new Text2('TAP TO START', {
size: 80,
fill: 0x000000
});
instructionText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(instructionText);
rosesText = new Text2('Roses: 0', {
size: 40,
fill: 0x8B4513
});
rosesText.anchor.set(0, 0);
LK.gui.topRight.addChild(rosesText);
rosesText.x = -200;
rosesText.y = 50;
// Input handling
var isPressed = false;
game.down = function (x, y, obj) {
if (!gameRunning) {
startGame();
} else {
dino.jump();
}
isPressed = true;
};
game.up = function (x, y, obj) {
isPressed = false;
if (gameRunning) {
dino.stopDucking();
}
};
// Main game loop
game.update = function () {
if (!gameRunning) {
return;
}
// Handle ducking
if (isPressed && !dino.isJumping) {
dino.duck();
}
// Update game speed and score
gameSpeed += speedIncrement;
distanceScore = Math.floor(LK.ticks / 6);
scoreText.setText(distanceScore.toString());
// Update ground
updateGround();
// Update background elements
updateTrees();
updateClouds();
// Spawn obstacles
if (LK.ticks - lastObstacleSpawn > nextObstacleDistance) {
spawnObstacle();
lastObstacleSpawn = LK.ticks;
nextObstacleDistance = minObstacleDistance + Math.random() * (maxObstacleDistance - minObstacleDistance);
}
// Spawn roses
if (LK.ticks - lastRoseSpawn > roseSpawnInterval) {
spawnRose();
lastRoseSpawn = LK.ticks;
roseSpawnInterval = 120 + Math.random() * 120;
}
// Update obstacles
updateObstacles();
// Update roses
updateRoses();
// Check collisions
checkCollisions();
// Check rose collections
checkRoseCollections();
// Update day/night cycle
updateDayNight();
};