/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cat = Container.expand(function () {
var self = Container.call(this);
var catGraphics = self.attachAsset('cat', {
anchorX: 0.5,
anchorY: 1
});
var catJumpGraphics = self.attachAsset('cat_jump', {
anchorX: 0.5,
anchorY: 1,
visible: false
});
self.isJumping = false;
self.isDucking = false;
self.groundY = 2400;
self.jumpHeight = 200;
self.normalHeight = 80;
self.duckHeight = 40;
self.jump = function () {
if (!self.isJumping && !self.isDucking) {
self.isJumping = true;
LK.getSound('jump').play();
// Switch to jumping sprite
catGraphics.visible = false;
catJumpGraphics.visible = true;
tween(self, {
y: self.groundY - self.jumpHeight
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
y: self.groundY
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
// Switch back to normal sprite
catJumpGraphics.visible = false;
catGraphics.visible = true;
self.isJumping = false;
}
});
}
});
}
};
self.duck = function () {
if (!self.isJumping && !self.isDucking) {
self.isDucking = true;
LK.getSound('duck').play();
catGraphics.height = self.duckHeight;
LK.setTimeout(function () {
catGraphics.height = self.normalHeight;
self.isDucking = false;
}, 400);
}
};
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 <= -self.width) {
self.x += self.width * groundTiles.length;
}
};
return self;
});
var Obstacle = Container.expand(function (type) {
var self = Container.call(this);
self.type = type;
self.speed = gameSpeed;
if (type === 'taco') {
var obstacleGraphics = self.attachAsset('taco', {
anchorX: 0.5,
anchorY: 1
});
self.y = 2400;
self.isLow = true;
} else if (type === 'dinosaur') {
var obstacleGraphics = self.attachAsset('dinosaur', {
anchorX: 0.5,
anchorY: 1
});
self.y = 2200;
self.isLow = false;
}
self.update = function () {
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
var gameSpeed = 8;
var obstacleSpawnTimer = 0;
var obstacleSpawnRate = 90;
var minSpawnRate = 30;
var difficultyIncreaseRate = 0.1;
var cat = game.addChild(new Cat());
cat.x = 400;
cat.y = 2400;
var obstacles = [];
var groundTiles = [];
// Create ground tiles
for (var i = 0; i < 15; i++) {
var groundTile = new Ground();
groundTile.x = i * 200;
groundTile.y = 2400;
groundTiles.push(groundTile);
game.addChild(groundTile);
}
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var distance = 0;
// Play background music
LK.playMusic('background');
function spawnObstacle() {
var obstacleType = Math.random() < 0.5 ? 'taco' : 'dinosaur';
var obstacle = new Obstacle(obstacleType);
obstacle.x = 2200;
obstacles.push(obstacle);
game.addChild(obstacle);
}
function checkCollision() {
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
if (cat.intersects(obstacle)) {
LK.getSound('collision').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return true;
}
}
return false;
}
function handleInput() {
if (Math.random() < 0.5) {
cat.jump();
} else {
cat.duck();
}
}
game.down = function (x, y, obj) {
if (y > 2732 / 2) {
cat.jump();
} else {
cat.duck();
}
};
game.update = function () {
distance += gameSpeed;
var score = Math.floor(distance / 10);
LK.setScore(score);
scoreTxt.setText(score);
// Increase difficulty over time
if (obstacleSpawnRate > minSpawnRate) {
obstacleSpawnRate -= difficultyIncreaseRate;
}
gameSpeed += 0.002;
// Spawn obstacles
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= obstacleSpawnRate) {
spawnObstacle();
obstacleSpawnTimer = 0;
}
// Update 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);
}
}
// Update ground tiles
for (var j = 0; j < groundTiles.length; j++) {
groundTiles[j].speed = gameSpeed;
}
// Check for collisions
checkCollision();
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cat = Container.expand(function () {
var self = Container.call(this);
var catGraphics = self.attachAsset('cat', {
anchorX: 0.5,
anchorY: 1
});
var catJumpGraphics = self.attachAsset('cat_jump', {
anchorX: 0.5,
anchorY: 1,
visible: false
});
self.isJumping = false;
self.isDucking = false;
self.groundY = 2400;
self.jumpHeight = 200;
self.normalHeight = 80;
self.duckHeight = 40;
self.jump = function () {
if (!self.isJumping && !self.isDucking) {
self.isJumping = true;
LK.getSound('jump').play();
// Switch to jumping sprite
catGraphics.visible = false;
catJumpGraphics.visible = true;
tween(self, {
y: self.groundY - self.jumpHeight
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
y: self.groundY
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
// Switch back to normal sprite
catJumpGraphics.visible = false;
catGraphics.visible = true;
self.isJumping = false;
}
});
}
});
}
};
self.duck = function () {
if (!self.isJumping && !self.isDucking) {
self.isDucking = true;
LK.getSound('duck').play();
catGraphics.height = self.duckHeight;
LK.setTimeout(function () {
catGraphics.height = self.normalHeight;
self.isDucking = false;
}, 400);
}
};
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 <= -self.width) {
self.x += self.width * groundTiles.length;
}
};
return self;
});
var Obstacle = Container.expand(function (type) {
var self = Container.call(this);
self.type = type;
self.speed = gameSpeed;
if (type === 'taco') {
var obstacleGraphics = self.attachAsset('taco', {
anchorX: 0.5,
anchorY: 1
});
self.y = 2400;
self.isLow = true;
} else if (type === 'dinosaur') {
var obstacleGraphics = self.attachAsset('dinosaur', {
anchorX: 0.5,
anchorY: 1
});
self.y = 2200;
self.isLow = false;
}
self.update = function () {
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
var gameSpeed = 8;
var obstacleSpawnTimer = 0;
var obstacleSpawnRate = 90;
var minSpawnRate = 30;
var difficultyIncreaseRate = 0.1;
var cat = game.addChild(new Cat());
cat.x = 400;
cat.y = 2400;
var obstacles = [];
var groundTiles = [];
// Create ground tiles
for (var i = 0; i < 15; i++) {
var groundTile = new Ground();
groundTile.x = i * 200;
groundTile.y = 2400;
groundTiles.push(groundTile);
game.addChild(groundTile);
}
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var distance = 0;
// Play background music
LK.playMusic('background');
function spawnObstacle() {
var obstacleType = Math.random() < 0.5 ? 'taco' : 'dinosaur';
var obstacle = new Obstacle(obstacleType);
obstacle.x = 2200;
obstacles.push(obstacle);
game.addChild(obstacle);
}
function checkCollision() {
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
if (cat.intersects(obstacle)) {
LK.getSound('collision').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return true;
}
}
return false;
}
function handleInput() {
if (Math.random() < 0.5) {
cat.jump();
} else {
cat.duck();
}
}
game.down = function (x, y, obj) {
if (y > 2732 / 2) {
cat.jump();
} else {
cat.duck();
}
};
game.update = function () {
distance += gameSpeed;
var score = Math.floor(distance / 10);
LK.setScore(score);
scoreTxt.setText(score);
// Increase difficulty over time
if (obstacleSpawnRate > minSpawnRate) {
obstacleSpawnRate -= difficultyIncreaseRate;
}
gameSpeed += 0.002;
// Spawn obstacles
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= obstacleSpawnRate) {
spawnObstacle();
obstacleSpawnTimer = 0;
}
// Update 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);
}
}
// Update ground tiles
for (var j = 0; j < groundTiles.length; j++) {
groundTiles[j].speed = gameSpeed;
}
// Check for collisions
checkCollision();
};