/****
* Classes
****/
// Class for coins
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
// Class for the first obstacle
var Obstacle1 = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
// Class for the second obstacle
var Obstacle2 = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('newObstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Player update logic
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
}));
// Initialize player
var player = game.addChild(new Player());
player.x = 200;
player.y = 1366; // Centered vertically
// Arrays to keep track of obstacles and coins
var obstacles = [];
var coins = [];
// Score display
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF,
font: "'Courier New', monospace"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to spawn obstacles
function spawnObstacle() {
var obstacle1 = new Obstacle1();
obstacle1.x = 2048;
obstacle1.y = Math.random() * 2732;
obstacles.push(obstacle1);
game.addChild(obstacle1);
var obstacle2 = new Obstacle2();
obstacle2.x = 2048;
obstacle2.y = Math.random() * 2732;
obstacles.push(obstacle2);
game.addChild(obstacle2);
}
// Function to spawn coins
function spawnCoin() {
var coin = new Coin();
coin.x = 2048;
coin.y = Math.random() * 2732;
coins.push(coin);
game.addChild(coin);
}
// Handle player movement
game.down = function (x, y, obj) {
player.y = y;
};
// Game update loop
game.update = function () {
// Update player
player.update();
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
obstacle.speed = -5 - Math.floor(LK.ticks / 600); // Increase speed over time
obstacle.update();
if (player.intersects(obstacle)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update coins
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
coin.speed = -5 - Math.floor(LK.ticks / 600); // Increase speed over time
coin.update();
if (player.intersects(coin)) {
score += 10;
scoreTxt.setText('Score: ' + score);
coin.destroy();
coins.splice(i, 1);
LK.getSound('CollectCoin').play();
}
}
// Spawn obstacles and coins at intervals
if (LK.ticks % 60 === 0) {
spawnObstacle();
}
if (LK.ticks % 90 === 0) {
spawnCoin();
}
}; /****
* Classes
****/
// Class for coins
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
// Class for the first obstacle
var Obstacle1 = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
// Class for the second obstacle
var Obstacle2 = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('newObstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Player update logic
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
}));
// Initialize player
var player = game.addChild(new Player());
player.x = 200;
player.y = 1366; // Centered vertically
// Arrays to keep track of obstacles and coins
var obstacles = [];
var coins = [];
// Score display
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF,
font: "'Courier New', monospace"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to spawn obstacles
function spawnObstacle() {
var obstacle1 = new Obstacle1();
obstacle1.x = 2048;
obstacle1.y = Math.random() * 2732;
obstacles.push(obstacle1);
game.addChild(obstacle1);
var obstacle2 = new Obstacle2();
obstacle2.x = 2048;
obstacle2.y = Math.random() * 2732;
obstacles.push(obstacle2);
game.addChild(obstacle2);
}
// Function to spawn coins
function spawnCoin() {
var coin = new Coin();
coin.x = 2048;
coin.y = Math.random() * 2732;
coins.push(coin);
game.addChild(coin);
}
// Handle player movement
game.down = function (x, y, obj) {
player.y = y;
};
// Game update loop
game.update = function () {
// Update player
player.update();
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
obstacle.speed = -5 - Math.floor(LK.ticks / 600); // Increase speed over time
obstacle.update();
if (player.intersects(obstacle)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update coins
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
coin.speed = -5 - Math.floor(LK.ticks / 600); // Increase speed over time
coin.update();
if (player.intersects(coin)) {
score += 10;
scoreTxt.setText('Score: ' + score);
coin.destroy();
coins.splice(i, 1);
LK.getSound('CollectCoin').play();
}
}
// Spawn obstacles and coins at intervals
if (LK.ticks % 60 === 0) {
spawnObstacle();
}
if (LK.ticks % 90 === 0) {
spawnCoin();
}
};
Pixelated cactus seen from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Pixelated gold coin. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Running person 64×64 pixel art. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Pixelated desert floor without objects. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows