/****
* Classes
****/
var Background = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 2048 / 2;
self.y = 2732 / 2;
});
var Background4 = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background4', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 2048 / 2;
self.y = 2732 / 2;
});
var Background6 = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background6', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 2048 / 2;
self.y = 2732 / 2;
});
var Food = Container.expand(function () {
var self = Container.call(this);
var foodGraphics = self.attachAsset('food', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
var index = obstacles.indexOf(self);
if (index > -1) {
obstacles.splice(index, 1);
}
}
};
});
var Food2m = Container.expand(function () {
var self = Container.call(this);
var food2mGraphics = self.attachAsset('food2m', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
var index = obstacles.indexOf(self);
if (index > -1) {
obstacles.splice(index, 1);
}
}
};
});
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Hero update logic
if (self.x < 0) {
self.x = 0;
} else if (self.x > 2048) {
self.x = 2048;
}
};
// Removed jump logic
});
//<Assets used in the game will automatically appear here>
// Hero2 class
var Hero2 = Container.expand(function () {
var self = Container.call(this);
var hero2Graphics = self.attachAsset('hero2', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
if (self.x < 0) {
self.x = 0;
} else if (self.x > 2048) {
self.x = 2048;
}
};
});
var Hero3 = Container.expand(function () {
var self = Container.call(this);
var hero3Graphics = self.attachAsset('hero3', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
if (self.x < 0) {
self.x = 0;
} else if (self.x > 2048) {
self.x = 2048;
}
};
});
var Hero4 = Container.expand(function () {
var self = Container.call(this);
var hero4Graphics = self.attachAsset('hero4', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
if (self.x < 0) {
self.x = 0;
} else if (self.x > 2048) {
self.x = 2048;
}
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Obstacle1e class
var Obstacle1e = Container.expand(function () {
var self = Container.call(this);
var obstacle1eGraphics = self.attachAsset('obstacle1e', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle1g = Container.expand(function () {
var self = Container.call(this);
var obstacle1gGraphics = self.attachAsset('obstacle1g', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle1k = Container.expand(function () {
var self = Container.call(this);
var obstacle1kGraphics = self.attachAsset('obstacle1k', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Obstacle2e class
var Obstacle2e = Container.expand(function () {
var self = Container.call(this);
var obstacle2eGraphics = self.attachAsset('obstacle2e', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle2g = Container.expand(function () {
var self = Container.call(this);
var obstacle2gGraphics = self.attachAsset('obstacle2g', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle2k = Container.expand(function () {
var self = Container.call(this);
var obstacle2kGraphics = self.attachAsset('obstacle2k', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle2m = Container.expand(function () {
var self = Container.call(this);
var obstacle2mGraphics = self.attachAsset('obstacle2m', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Obstacle3e class
var Obstacle3e = Container.expand(function () {
var self = Container.call(this);
var obstacle3eGraphics = self.attachAsset('obstacle3e', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle3g = Container.expand(function () {
var self = Container.call(this);
var obstacle3gGraphics = self.attachAsset('obstacle3g', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle3k = Container.expand(function () {
var self = Container.call(this);
var obstacle3kGraphics = self.attachAsset('obstacle3k', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle3m = Container.expand(function () {
var self = Container.call(this);
var obstacle3mGraphics = self.attachAsset('obstacle3m', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var background = new Background();
game.addChild(background);
var hero;
var obstacles = [];
var scoreTxt;
var score = 0;
var foodCounter = 0;
var timeTxt;
var timeElapsed = -6000;
var gameSpeed = 5;
// Initialize hero
function initHero() {
hero = new Hero();
hero.x = 1024; // Center horizontally
hero.y = 2500;
game.addChild(hero);
}
// Initialize score text
function initScore() {
scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
foodCounterTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
foodCounterTxt.anchor.set(0, 1);
LK.gui.bottomLeft.addChild(foodCounterTxt);
}
// Update score
function updateScore() {
score += 1;
scoreTxt.setText(score);
}
// Spawn obstacle
function spawnObstacle() {
var randomValue = Math.random();
if (randomValue < 0.25) {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048;
obstacle.y = -obstacle.height / 2;
obstacles.push(obstacle);
game.addChild(obstacle);
} else if (randomValue < 0.5) {
var food = new Food();
food.x = Math.random() * 2048;
food.y = -food.height / 2;
obstacles.push(food);
game.addChild(food);
} else if (randomValue < 0.75) {
var obstacle2m = new Obstacle2m();
obstacle2m.x = Math.random() * 2048;
obstacle2m.y = -obstacle2m.height / 2;
obstacles.push(obstacle2m);
game.addChild(obstacle2m);
} else if (randomValue < 0.875) {
var obstacle3m = new Obstacle3m();
obstacle3m.x = Math.random() * 2048;
obstacle3m.y = -obstacle3m.height / 2;
obstacles.push(obstacle3m);
game.addChild(obstacle3m);
} else {
var food2m = new Food2m();
food2m.x = Math.random() * 2048;
food2m.y = -food2m.height / 2;
obstacles.push(food2m);
game.addChild(food2m);
}
}
// Handle game over
function handleGameOver() {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Handle move event
function handleMove(x, y, obj) {
if (hero) {
hero.x = x;
}
}
// Handle down event
function handleDown(x, y, obj) {
// Removed call to hero jump
}
// Game update function
game.update = function () {
// Update hero
if (hero) {
hero.update();
}
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
if (obstacles[i]) {
obstacles[i].update();
}
if (hero && (obstacles[i] instanceof Obstacle || obstacles[i] instanceof Obstacle1e || obstacles[i] instanceof Obstacle2e || obstacles[i] instanceof Obstacle3e || obstacles[i] instanceof Obstacle1g || obstacles[i] instanceof Obstacle2g || obstacles[i] instanceof Obstacle3g || obstacles[i] instanceof Obstacle1k || obstacles[i] instanceof Obstacle2k || obstacles[i] instanceof Obstacle3k) && hero.intersects(obstacles[i])) {
handleGameOver();
} else if (hero && (obstacles[i] instanceof Food || obstacles[i] instanceof Food2m) && hero.intersects(obstacles[i])) {
obstacles[i].destroy();
obstacles.splice(i, 1);
updateScore();
foodCounter += 1;
foodCounterTxt.setText(foodCounter);
timeElapsed += 100; // Add 100 to the time counter
timeTxt.setText(timeElapsed); // Update the time counter text
if (foodCounter === 10) {
background.attachAsset('background2', {
anchorX: 0.5,
anchorY: 0.5
});
LK.setTimeout(function () {
background.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
}, 5000);
gameSpeed += 1;
}
if (foodCounter === 30) {
background.attachAsset('background3', {
anchorX: 0.5,
anchorY: 0.5
});
hero.destroy();
hero = new Hero2();
hero.x = 1024; // Center horizontally
hero.y = 2500;
game.addChild(hero);
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
spawnObstacle = function spawnObstacle() {
var randomValue = Math.random();
if (randomValue < 0.25) {
var obstacle1e = new Obstacle1e();
obstacle1e.x = Math.random() * 2048;
obstacle1e.y = -obstacle1e.height / 2;
obstacles.push(obstacle1e);
game.addChild(obstacle1e);
} else if (randomValue < 0.5) {
var food = new Food();
food.x = Math.random() * 2048;
food.y = -food.height / 2;
obstacles.push(food);
game.addChild(food);
} else if (randomValue < 0.75) {
var obstacle2e = new Obstacle2e();
obstacle2e.x = Math.random() * 2048;
obstacle2e.y = -obstacle2e.height / 2;
obstacles.push(obstacle2e);
game.addChild(obstacle2e);
} else if (randomValue < 0.875) {
var obstacle3e = new Obstacle3e();
obstacle3e.x = Math.random() * 2048;
obstacle3e.y = -obstacle3e.height / 2;
obstacles.push(obstacle3e);
game.addChild(obstacle3e);
} else {
var food2m = new Food2m();
food2m.x = Math.random() * 2048;
food2m.y = -food2m.height / 2;
obstacles.push(food2m);
game.addChild(food2m);
}
};
}
if (foodCounter === 35) {
background.attachAsset('background4', {
anchorX: 0.5,
anchorY: 0.5
});
LK.setTimeout(function () {
background.attachAsset('background3', {
anchorX: 0.5,
anchorY: 0.5
});
}, 5000);
}
if (foodCounter === 60) {
background.attachAsset('background6', {
anchorX: 0.5,
anchorY: 0.5
});
LK.setTimeout(function () {
background.attachAsset('background5', {
anchorX: 0.5,
anchorY: 0.5
});
}, 5000);
} else if (foodCounter === 65) {
background.attachAsset('background7', {
anchorX: 0.5,
anchorY: 0.5
});
hero.destroy();
hero = new Hero4();
hero.x = 1024; // Center horizontally
hero.y = 2500;
game.addChild(hero);
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
spawnObstacle = function spawnObstacle() {
var randomValue = Math.random();
if (randomValue < 0.25) {
var obstacle1k = new Obstacle1k();
obstacle1k.x = Math.random() * 2048;
obstacle1k.y = -obstacle1k.height / 2;
obstacles.push(obstacle1k);
game.addChild(obstacle1k);
} else if (randomValue < 0.5) {
var food = new Food();
food.x = Math.random() * 2048;
food.y = -food.height / 2;
obstacles.push(food);
game.addChild(food);
} else if (randomValue < 0.75) {
var obstacle2k = new Obstacle2k();
obstacle2k.x = Math.random() * 2048;
obstacle2k.y = -obstacle2k.height / 2;
obstacles.push(obstacle2k);
game.addChild(obstacle2k);
} else if (randomValue < 0.875) {
var obstacle3k = new Obstacle3k();
obstacle3k.x = Math.random() * 2048;
obstacle3k.y = -obstacle3k.height / 2;
obstacles.push(obstacle3k);
game.addChild(obstacle3k);
} else {
var food2m = new Food2m();
food2m.x = Math.random() * 2048;
food2m.y = -food2m.height / 2;
obstacles.push(food2m);
game.addChild(food2m);
}
};
background.attachAsset('background5', {
anchorX: 0.5,
anchorY: 0.5
});
hero.destroy();
hero = new Hero3();
hero.x = 1024; // Center horizontally
hero.y = 2500;
game.addChild(hero);
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
spawnObstacle = function spawnObstacle() {
var randomValue = Math.random();
if (randomValue < 0.25) {
var obstacle1g = new Obstacle1g();
obstacle1g.x = Math.random() * 2048;
obstacle1g.y = -obstacle1g.height / 2;
obstacles.push(obstacle1g);
game.addChild(obstacle1g);
} else if (randomValue < 0.5) {
var food = new Food();
food.x = Math.random() * 2048;
food.y = -food.height / 2;
obstacles.push(food);
game.addChild(food);
} else if (randomValue < 0.75) {
var obstacle2g = new Obstacle2g();
obstacle2g.x = Math.random() * 2048;
obstacle2g.y = -obstacle2g.height / 2;
obstacles.push(obstacle2g);
game.addChild(obstacle2g);
} else if (randomValue < 0.875) {
var obstacle3g = new Obstacle3g();
obstacle3g.x = Math.random() * 2048;
obstacle3g.y = -obstacle3g.height / 2;
obstacles.push(obstacle3g);
game.addChild(obstacle3g);
} else {
var food2m = new Food2m();
food2m.x = Math.random() * 2048;
food2m.y = -food2m.height / 2;
obstacles.push(food2m);
game.addChild(food2m);
}
};
}
}
}
// Spawn new obstacle
if (LK.ticks % (180 / gameSpeed) == 0) {
spawnObstacle();
}
// Update score
if (LK.ticks % 60 == 0) {
updateScore();
}
};
// Initialize game elements
initHero();
initScore();
initTimeCounter();
// Set event listeners
game.move = handleMove;
game.down = handleDown;
// Initialize time counter text
function initTimeCounter() {
timeTxt = new Text2(timeElapsed.toString(), {
size: 150,
fill: "#ffffff"
});
timeTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(timeTxt);
timeTxt.setText(timeElapsed); // Set initial time
// Update time counter every second
if (LK.ticks % 60 == 0) {
updateTimeCounter();
}
}
// Update time counter
function updateTimeCounter() {
timeElapsed += 1;
timeTxt.setText(timeElapsed);
} /****
* Classes
****/
var Background = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 2048 / 2;
self.y = 2732 / 2;
});
var Background4 = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background4', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 2048 / 2;
self.y = 2732 / 2;
});
var Background6 = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background6', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 2048 / 2;
self.y = 2732 / 2;
});
var Food = Container.expand(function () {
var self = Container.call(this);
var foodGraphics = self.attachAsset('food', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
var index = obstacles.indexOf(self);
if (index > -1) {
obstacles.splice(index, 1);
}
}
};
});
var Food2m = Container.expand(function () {
var self = Container.call(this);
var food2mGraphics = self.attachAsset('food2m', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
var index = obstacles.indexOf(self);
if (index > -1) {
obstacles.splice(index, 1);
}
}
};
});
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Hero update logic
if (self.x < 0) {
self.x = 0;
} else if (self.x > 2048) {
self.x = 2048;
}
};
// Removed jump logic
});
//<Assets used in the game will automatically appear here>
// Hero2 class
var Hero2 = Container.expand(function () {
var self = Container.call(this);
var hero2Graphics = self.attachAsset('hero2', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
if (self.x < 0) {
self.x = 0;
} else if (self.x > 2048) {
self.x = 2048;
}
};
});
var Hero3 = Container.expand(function () {
var self = Container.call(this);
var hero3Graphics = self.attachAsset('hero3', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
if (self.x < 0) {
self.x = 0;
} else if (self.x > 2048) {
self.x = 2048;
}
};
});
var Hero4 = Container.expand(function () {
var self = Container.call(this);
var hero4Graphics = self.attachAsset('hero4', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
if (self.x < 0) {
self.x = 0;
} else if (self.x > 2048) {
self.x = 2048;
}
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Obstacle1e class
var Obstacle1e = Container.expand(function () {
var self = Container.call(this);
var obstacle1eGraphics = self.attachAsset('obstacle1e', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle1g = Container.expand(function () {
var self = Container.call(this);
var obstacle1gGraphics = self.attachAsset('obstacle1g', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle1k = Container.expand(function () {
var self = Container.call(this);
var obstacle1kGraphics = self.attachAsset('obstacle1k', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Obstacle2e class
var Obstacle2e = Container.expand(function () {
var self = Container.call(this);
var obstacle2eGraphics = self.attachAsset('obstacle2e', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle2g = Container.expand(function () {
var self = Container.call(this);
var obstacle2gGraphics = self.attachAsset('obstacle2g', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle2k = Container.expand(function () {
var self = Container.call(this);
var obstacle2kGraphics = self.attachAsset('obstacle2k', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle2m = Container.expand(function () {
var self = Container.call(this);
var obstacle2mGraphics = self.attachAsset('obstacle2m', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Obstacle3e class
var Obstacle3e = Container.expand(function () {
var self = Container.call(this);
var obstacle3eGraphics = self.attachAsset('obstacle3e', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle3g = Container.expand(function () {
var self = Container.call(this);
var obstacle3gGraphics = self.attachAsset('obstacle3g', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle3k = Container.expand(function () {
var self = Container.call(this);
var obstacle3kGraphics = self.attachAsset('obstacle3k', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
var Obstacle3m = Container.expand(function () {
var self = Container.call(this);
var obstacle3mGraphics = self.attachAsset('obstacle3m', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var background = new Background();
game.addChild(background);
var hero;
var obstacles = [];
var scoreTxt;
var score = 0;
var foodCounter = 0;
var timeTxt;
var timeElapsed = -6000;
var gameSpeed = 5;
// Initialize hero
function initHero() {
hero = new Hero();
hero.x = 1024; // Center horizontally
hero.y = 2500;
game.addChild(hero);
}
// Initialize score text
function initScore() {
scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
foodCounterTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
foodCounterTxt.anchor.set(0, 1);
LK.gui.bottomLeft.addChild(foodCounterTxt);
}
// Update score
function updateScore() {
score += 1;
scoreTxt.setText(score);
}
// Spawn obstacle
function spawnObstacle() {
var randomValue = Math.random();
if (randomValue < 0.25) {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048;
obstacle.y = -obstacle.height / 2;
obstacles.push(obstacle);
game.addChild(obstacle);
} else if (randomValue < 0.5) {
var food = new Food();
food.x = Math.random() * 2048;
food.y = -food.height / 2;
obstacles.push(food);
game.addChild(food);
} else if (randomValue < 0.75) {
var obstacle2m = new Obstacle2m();
obstacle2m.x = Math.random() * 2048;
obstacle2m.y = -obstacle2m.height / 2;
obstacles.push(obstacle2m);
game.addChild(obstacle2m);
} else if (randomValue < 0.875) {
var obstacle3m = new Obstacle3m();
obstacle3m.x = Math.random() * 2048;
obstacle3m.y = -obstacle3m.height / 2;
obstacles.push(obstacle3m);
game.addChild(obstacle3m);
} else {
var food2m = new Food2m();
food2m.x = Math.random() * 2048;
food2m.y = -food2m.height / 2;
obstacles.push(food2m);
game.addChild(food2m);
}
}
// Handle game over
function handleGameOver() {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Handle move event
function handleMove(x, y, obj) {
if (hero) {
hero.x = x;
}
}
// Handle down event
function handleDown(x, y, obj) {
// Removed call to hero jump
}
// Game update function
game.update = function () {
// Update hero
if (hero) {
hero.update();
}
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
if (obstacles[i]) {
obstacles[i].update();
}
if (hero && (obstacles[i] instanceof Obstacle || obstacles[i] instanceof Obstacle1e || obstacles[i] instanceof Obstacle2e || obstacles[i] instanceof Obstacle3e || obstacles[i] instanceof Obstacle1g || obstacles[i] instanceof Obstacle2g || obstacles[i] instanceof Obstacle3g || obstacles[i] instanceof Obstacle1k || obstacles[i] instanceof Obstacle2k || obstacles[i] instanceof Obstacle3k) && hero.intersects(obstacles[i])) {
handleGameOver();
} else if (hero && (obstacles[i] instanceof Food || obstacles[i] instanceof Food2m) && hero.intersects(obstacles[i])) {
obstacles[i].destroy();
obstacles.splice(i, 1);
updateScore();
foodCounter += 1;
foodCounterTxt.setText(foodCounter);
timeElapsed += 100; // Add 100 to the time counter
timeTxt.setText(timeElapsed); // Update the time counter text
if (foodCounter === 10) {
background.attachAsset('background2', {
anchorX: 0.5,
anchorY: 0.5
});
LK.setTimeout(function () {
background.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
}, 5000);
gameSpeed += 1;
}
if (foodCounter === 30) {
background.attachAsset('background3', {
anchorX: 0.5,
anchorY: 0.5
});
hero.destroy();
hero = new Hero2();
hero.x = 1024; // Center horizontally
hero.y = 2500;
game.addChild(hero);
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
spawnObstacle = function spawnObstacle() {
var randomValue = Math.random();
if (randomValue < 0.25) {
var obstacle1e = new Obstacle1e();
obstacle1e.x = Math.random() * 2048;
obstacle1e.y = -obstacle1e.height / 2;
obstacles.push(obstacle1e);
game.addChild(obstacle1e);
} else if (randomValue < 0.5) {
var food = new Food();
food.x = Math.random() * 2048;
food.y = -food.height / 2;
obstacles.push(food);
game.addChild(food);
} else if (randomValue < 0.75) {
var obstacle2e = new Obstacle2e();
obstacle2e.x = Math.random() * 2048;
obstacle2e.y = -obstacle2e.height / 2;
obstacles.push(obstacle2e);
game.addChild(obstacle2e);
} else if (randomValue < 0.875) {
var obstacle3e = new Obstacle3e();
obstacle3e.x = Math.random() * 2048;
obstacle3e.y = -obstacle3e.height / 2;
obstacles.push(obstacle3e);
game.addChild(obstacle3e);
} else {
var food2m = new Food2m();
food2m.x = Math.random() * 2048;
food2m.y = -food2m.height / 2;
obstacles.push(food2m);
game.addChild(food2m);
}
};
}
if (foodCounter === 35) {
background.attachAsset('background4', {
anchorX: 0.5,
anchorY: 0.5
});
LK.setTimeout(function () {
background.attachAsset('background3', {
anchorX: 0.5,
anchorY: 0.5
});
}, 5000);
}
if (foodCounter === 60) {
background.attachAsset('background6', {
anchorX: 0.5,
anchorY: 0.5
});
LK.setTimeout(function () {
background.attachAsset('background5', {
anchorX: 0.5,
anchorY: 0.5
});
}, 5000);
} else if (foodCounter === 65) {
background.attachAsset('background7', {
anchorX: 0.5,
anchorY: 0.5
});
hero.destroy();
hero = new Hero4();
hero.x = 1024; // Center horizontally
hero.y = 2500;
game.addChild(hero);
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
spawnObstacle = function spawnObstacle() {
var randomValue = Math.random();
if (randomValue < 0.25) {
var obstacle1k = new Obstacle1k();
obstacle1k.x = Math.random() * 2048;
obstacle1k.y = -obstacle1k.height / 2;
obstacles.push(obstacle1k);
game.addChild(obstacle1k);
} else if (randomValue < 0.5) {
var food = new Food();
food.x = Math.random() * 2048;
food.y = -food.height / 2;
obstacles.push(food);
game.addChild(food);
} else if (randomValue < 0.75) {
var obstacle2k = new Obstacle2k();
obstacle2k.x = Math.random() * 2048;
obstacle2k.y = -obstacle2k.height / 2;
obstacles.push(obstacle2k);
game.addChild(obstacle2k);
} else if (randomValue < 0.875) {
var obstacle3k = new Obstacle3k();
obstacle3k.x = Math.random() * 2048;
obstacle3k.y = -obstacle3k.height / 2;
obstacles.push(obstacle3k);
game.addChild(obstacle3k);
} else {
var food2m = new Food2m();
food2m.x = Math.random() * 2048;
food2m.y = -food2m.height / 2;
obstacles.push(food2m);
game.addChild(food2m);
}
};
background.attachAsset('background5', {
anchorX: 0.5,
anchorY: 0.5
});
hero.destroy();
hero = new Hero3();
hero.x = 1024; // Center horizontally
hero.y = 2500;
game.addChild(hero);
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
spawnObstacle = function spawnObstacle() {
var randomValue = Math.random();
if (randomValue < 0.25) {
var obstacle1g = new Obstacle1g();
obstacle1g.x = Math.random() * 2048;
obstacle1g.y = -obstacle1g.height / 2;
obstacles.push(obstacle1g);
game.addChild(obstacle1g);
} else if (randomValue < 0.5) {
var food = new Food();
food.x = Math.random() * 2048;
food.y = -food.height / 2;
obstacles.push(food);
game.addChild(food);
} else if (randomValue < 0.75) {
var obstacle2g = new Obstacle2g();
obstacle2g.x = Math.random() * 2048;
obstacle2g.y = -obstacle2g.height / 2;
obstacles.push(obstacle2g);
game.addChild(obstacle2g);
} else if (randomValue < 0.875) {
var obstacle3g = new Obstacle3g();
obstacle3g.x = Math.random() * 2048;
obstacle3g.y = -obstacle3g.height / 2;
obstacles.push(obstacle3g);
game.addChild(obstacle3g);
} else {
var food2m = new Food2m();
food2m.x = Math.random() * 2048;
food2m.y = -food2m.height / 2;
obstacles.push(food2m);
game.addChild(food2m);
}
};
}
}
}
// Spawn new obstacle
if (LK.ticks % (180 / gameSpeed) == 0) {
spawnObstacle();
}
// Update score
if (LK.ticks % 60 == 0) {
updateScore();
}
};
// Initialize game elements
initHero();
initScore();
initTimeCounter();
// Set event listeners
game.move = handleMove;
game.down = handleDown;
// Initialize time counter text
function initTimeCounter() {
timeTxt = new Text2(timeElapsed.toString(), {
size: 150,
fill: "#ffffff"
});
timeTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(timeTxt);
timeTxt.setText(timeElapsed); // Set initial time
// Update time counter every second
if (LK.ticks % 60 == 0) {
updateTimeCounter();
}
}
// Update time counter
function updateTimeCounter() {
timeElapsed += 1;
timeTxt.setText(timeElapsed);
}
a caveman with a club, seen from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of a delicious meat. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A animated image of a stone boulder. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A animated image of a mommoth. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A animated image of a aggressive caveman with a club. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A road in a jungle with a cave nearby
An animated image of a wooden wheel with a sign: The invention of the wheel. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of a desert with a pyramid. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an egyptian warrior. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an aggressive egyptian warrior. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of a wooden arrow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of a lion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an unfinished pyramid, with a label 'The building of the Pyramids of Giza. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an ancient greek city with an Acropolis. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an ancient greek warrior. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an aggressive ancient greek warrior. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of the colosseum. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image a medieval city with a castle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image a medieval knight. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image an aggressive medieval knight. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image a fierce wolf. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.