/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cactus = Container.expand(function (trackIndex) {
var self = Container.call(this);
var cactusGraphics = self.attachAsset('cactus', {
anchorX: 0.5,
anchorY: 1.0
});
self.trackIndex = trackIndex;
self.speed = gameSpeed;
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Dinosaur = Container.expand(function (trackIndex) {
var self = Container.call(this);
var dinoGraphics = self.attachAsset('dinosaur', {
anchorX: 0.5,
anchorY: 1.0
});
self.trackIndex = trackIndex;
self.isJumping = false;
self.jumpHeight = 0;
self.jumpSpeed = 0;
self.groundY = 0;
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.jumpSpeed = -25;
LK.getSound('jump').play();
}
};
self.update = function () {
if (self.isJumping) {
self.jumpSpeed += 1.5; // gravity
self.jumpHeight += self.jumpSpeed;
if (self.jumpHeight >= 0) {
self.jumpHeight = 0;
self.isJumping = false;
self.jumpSpeed = 0;
}
self.y = self.groundY + self.jumpHeight;
}
};
return self;
});
var TouchZone = Container.expand(function (dinosaurIndex) {
var self = Container.call(this);
var zoneGraphics = self.attachAsset('touchZone', {
anchorX: 0.5,
anchorY: 0.5
});
zoneGraphics.alpha = 0.3;
self.dinosaurIndex = dinosaurIndex;
self.down = function (x, y, obj) {
if (dinosaurs[self.dinosaurIndex]) {
dinosaurs[self.dinosaurIndex].jump();
// Flash feedback
LK.effects.flashObject(self, 0xffffff, 200);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game variables
var dinosaurs = [];
var cacti = [];
var touchZones = [];
var gameSpeed = 8;
var spawnTimer = 0;
var spawnInterval = 90;
var trackHeight = 220;
var trackStartY = 400;
var score = 0;
var speedIncreaseTimer = 0;
// Create score display
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create ground tracks
for (var i = 0; i < 10; i++) {
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
}));
ground.x = 0;
ground.y = trackStartY + i * trackHeight;
}
// Create dinosaurs
for (var i = 0; i < 10; i++) {
var dino = game.addChild(new Dinosaur(i));
dino.x = 200;
dino.y = trackStartY + i * trackHeight;
dino.groundY = dino.y;
dinosaurs.push(dino);
}
// Create touch zones (2 columns of 5 zones each)
var zoneLabels = ['Q', 'W', 'E', 'R', 'U', 'I', 'O', 'P', 'C', 'M'];
for (var i = 0; i < 10; i++) {
var zone = game.addChild(new TouchZone(i));
// Position zones in two columns
var col = Math.floor(i / 5);
var row = i % 5;
zone.x = 1600 + col * 220;
zone.y = 500 + row * 220;
// Add label
var label = new Text2(zoneLabels[i], {
size: 40,
fill: 0xFFFFFF
});
label.anchor.set(0.5, 0.5);
zone.addChild(label);
touchZones.push(zone);
}
// Spawn cactus on random track
function spawnCactus() {
var randomTrack = Math.floor(Math.random() * 10);
var cactus = game.addChild(new Cactus(randomTrack));
cactus.x = 2200;
cactus.y = trackStartY + randomTrack * trackHeight;
cacti.push(cactus);
}
// Check collision between dinosaur and cactus
function checkCollision(dino, cactus) {
if (dino.trackIndex !== cactus.trackIndex) return false;
var dx = Math.abs(dino.x - cactus.x);
var dy = Math.abs(dino.y - cactus.y);
return dx < 50 && dy < 60;
}
// Game update loop
game.update = function () {
// Update speed over time
speedIncreaseTimer++;
if (speedIncreaseTimer >= 300) {
// Every 5 seconds
gameSpeed += 0.5;
speedIncreaseTimer = 0;
}
// Spawn cacti
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnCactus();
spawnTimer = 0;
// Decrease spawn interval slightly over time
if (spawnInterval > 30) {
spawnInterval -= 1;
}
}
// Update cacti
for (var i = cacti.length - 1; i >= 0; i--) {
var cactus = cacti[i];
cactus.speed = gameSpeed;
// Remove off-screen cacti
if (cactus.x < -100) {
cactus.destroy();
cacti.splice(i, 1);
score += 10;
scoreTxt.setText('Score: ' + score);
LK.setScore(score);
}
}
// Check collisions
for (var i = 0; i < dinosaurs.length; i++) {
var dino = dinosaurs[i];
for (var j = 0; j < cacti.length; j++) {
var cactus = cacti[j];
if (checkCollision(dino, cactus)) {
LK.getSound('crash').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cactus = Container.expand(function (trackIndex) {
var self = Container.call(this);
var cactusGraphics = self.attachAsset('cactus', {
anchorX: 0.5,
anchorY: 1.0
});
self.trackIndex = trackIndex;
self.speed = gameSpeed;
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Dinosaur = Container.expand(function (trackIndex) {
var self = Container.call(this);
var dinoGraphics = self.attachAsset('dinosaur', {
anchorX: 0.5,
anchorY: 1.0
});
self.trackIndex = trackIndex;
self.isJumping = false;
self.jumpHeight = 0;
self.jumpSpeed = 0;
self.groundY = 0;
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.jumpSpeed = -25;
LK.getSound('jump').play();
}
};
self.update = function () {
if (self.isJumping) {
self.jumpSpeed += 1.5; // gravity
self.jumpHeight += self.jumpSpeed;
if (self.jumpHeight >= 0) {
self.jumpHeight = 0;
self.isJumping = false;
self.jumpSpeed = 0;
}
self.y = self.groundY + self.jumpHeight;
}
};
return self;
});
var TouchZone = Container.expand(function (dinosaurIndex) {
var self = Container.call(this);
var zoneGraphics = self.attachAsset('touchZone', {
anchorX: 0.5,
anchorY: 0.5
});
zoneGraphics.alpha = 0.3;
self.dinosaurIndex = dinosaurIndex;
self.down = function (x, y, obj) {
if (dinosaurs[self.dinosaurIndex]) {
dinosaurs[self.dinosaurIndex].jump();
// Flash feedback
LK.effects.flashObject(self, 0xffffff, 200);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game variables
var dinosaurs = [];
var cacti = [];
var touchZones = [];
var gameSpeed = 8;
var spawnTimer = 0;
var spawnInterval = 90;
var trackHeight = 220;
var trackStartY = 400;
var score = 0;
var speedIncreaseTimer = 0;
// Create score display
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create ground tracks
for (var i = 0; i < 10; i++) {
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
}));
ground.x = 0;
ground.y = trackStartY + i * trackHeight;
}
// Create dinosaurs
for (var i = 0; i < 10; i++) {
var dino = game.addChild(new Dinosaur(i));
dino.x = 200;
dino.y = trackStartY + i * trackHeight;
dino.groundY = dino.y;
dinosaurs.push(dino);
}
// Create touch zones (2 columns of 5 zones each)
var zoneLabels = ['Q', 'W', 'E', 'R', 'U', 'I', 'O', 'P', 'C', 'M'];
for (var i = 0; i < 10; i++) {
var zone = game.addChild(new TouchZone(i));
// Position zones in two columns
var col = Math.floor(i / 5);
var row = i % 5;
zone.x = 1600 + col * 220;
zone.y = 500 + row * 220;
// Add label
var label = new Text2(zoneLabels[i], {
size: 40,
fill: 0xFFFFFF
});
label.anchor.set(0.5, 0.5);
zone.addChild(label);
touchZones.push(zone);
}
// Spawn cactus on random track
function spawnCactus() {
var randomTrack = Math.floor(Math.random() * 10);
var cactus = game.addChild(new Cactus(randomTrack));
cactus.x = 2200;
cactus.y = trackStartY + randomTrack * trackHeight;
cacti.push(cactus);
}
// Check collision between dinosaur and cactus
function checkCollision(dino, cactus) {
if (dino.trackIndex !== cactus.trackIndex) return false;
var dx = Math.abs(dino.x - cactus.x);
var dy = Math.abs(dino.y - cactus.y);
return dx < 50 && dy < 60;
}
// Game update loop
game.update = function () {
// Update speed over time
speedIncreaseTimer++;
if (speedIncreaseTimer >= 300) {
// Every 5 seconds
gameSpeed += 0.5;
speedIncreaseTimer = 0;
}
// Spawn cacti
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnCactus();
spawnTimer = 0;
// Decrease spawn interval slightly over time
if (spawnInterval > 30) {
spawnInterval -= 1;
}
}
// Update cacti
for (var i = cacti.length - 1; i >= 0; i--) {
var cactus = cacti[i];
cactus.speed = gameSpeed;
// Remove off-screen cacti
if (cactus.x < -100) {
cactus.destroy();
cacti.splice(i, 1);
score += 10;
scoreTxt.setText('Score: ' + score);
LK.setScore(score);
}
}
// Check collisions
for (var i = 0; i < dinosaurs.length; i++) {
var dino = dinosaurs[i];
for (var j = 0; j < cacti.length; j++) {
var cactus = cacti[j];
if (checkCollision(dino, cactus)) {
LK.getSound('crash').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
}
};