/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Miner class
var Miner = Container.expand(function () {
var self = Container.call(this);
var minerGraphics = self.attachAsset('miner', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.movingLeft = false;
self.movingRight = false;
self.update = function () {
// Miner update logic
if (self.movingLeft) {
self.moveLeft();
} else if (self.movingRight) {
self.moveRight();
}
};
self.moveLeft = function () {
self.x -= self.speed;
};
self.moveRight = function () {
self.x += self.speed;
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 3; // Move obstacle downwards
};
});
// Treasure class
var Treasure = Container.expand(function () {
var self = Container.call(this);
var treasureGraphics = self.attachAsset('treasure', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 2; // Move treasure downwards
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Replace 'background_image_id' with the actual id of the mine background image
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0
}));
background.x = 0;
background.y = 0;
// Initialize miner
var miner = game.addChild(new Miner());
miner.x = 2048 / 2;
miner.y = 2732 - 100;
// Initialize arrays for treasures and obstacles
var treasures = [];
var obstacles = [];
// Score and highscore display
var score = 0;
var highscore = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var highscoreTxt = new Text2('Highscore: 0', {
size: 100,
fill: "#ffffff"
});
highscoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(highscoreTxt);
highscoreTxt.y = scoreTxt.height;
// Function to spawn treasures
function spawnTreasure() {
var treasure = new Treasure();
treasure.x = Math.random() * 2048;
treasure.y = -50;
treasures.push(treasure);
game.addChild(treasure);
}
// Function to spawn obstacles
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048;
obstacle.y = -50;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Handle miner movement
game.down = function (x, y, obj) {
if (x < 2048 / 2) {
miner.movingLeft = true;
} else {
miner.movingRight = true;
}
};
// Update game state
game.up = function (x, y, obj) {
miner.movingLeft = false;
miner.movingRight = false;
};
game.update = function () {
// Update treasures
for (var i = treasures.length - 1; i >= 0; i--) {
treasures[i].update();
if (treasures[i].y > 2732) {
treasures[i].destroy();
treasures.splice(i, 1);
} else if (miner.intersects(treasures[i])) {
score += 10;
if (score > highscore) {
highscore = score;
highscoreTxt.setText('Highscore: ' + highscore);
}
scoreTxt.setText(score);
LK.getSound('Coins').play();
treasures[i].destroy();
treasures.splice(i, 1);
}
}
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
if (obstacles[i].y > 2732) {
obstacles[i].destroy();
obstacles.splice(i, 1);
} else if (miner.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
score = 0;
scoreTxt.setText(score);
LK.showGameOver();
}
}
// Spawn treasures and obstacles periodically
if (LK.ticks % 60 == 0) {
spawnTreasure();
}
if (LK.ticks % 90 == 0) {
spawnObstacle();
}
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Miner class
var Miner = Container.expand(function () {
var self = Container.call(this);
var minerGraphics = self.attachAsset('miner', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.movingLeft = false;
self.movingRight = false;
self.update = function () {
// Miner update logic
if (self.movingLeft) {
self.moveLeft();
} else if (self.movingRight) {
self.moveRight();
}
};
self.moveLeft = function () {
self.x -= self.speed;
};
self.moveRight = function () {
self.x += self.speed;
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 3; // Move obstacle downwards
};
});
// Treasure class
var Treasure = Container.expand(function () {
var self = Container.call(this);
var treasureGraphics = self.attachAsset('treasure', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 2; // Move treasure downwards
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Replace 'background_image_id' with the actual id of the mine background image
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0
}));
background.x = 0;
background.y = 0;
// Initialize miner
var miner = game.addChild(new Miner());
miner.x = 2048 / 2;
miner.y = 2732 - 100;
// Initialize arrays for treasures and obstacles
var treasures = [];
var obstacles = [];
// Score and highscore display
var score = 0;
var highscore = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var highscoreTxt = new Text2('Highscore: 0', {
size: 100,
fill: "#ffffff"
});
highscoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(highscoreTxt);
highscoreTxt.y = scoreTxt.height;
// Function to spawn treasures
function spawnTreasure() {
var treasure = new Treasure();
treasure.x = Math.random() * 2048;
treasure.y = -50;
treasures.push(treasure);
game.addChild(treasure);
}
// Function to spawn obstacles
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048;
obstacle.y = -50;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Handle miner movement
game.down = function (x, y, obj) {
if (x < 2048 / 2) {
miner.movingLeft = true;
} else {
miner.movingRight = true;
}
};
// Update game state
game.up = function (x, y, obj) {
miner.movingLeft = false;
miner.movingRight = false;
};
game.update = function () {
// Update treasures
for (var i = treasures.length - 1; i >= 0; i--) {
treasures[i].update();
if (treasures[i].y > 2732) {
treasures[i].destroy();
treasures.splice(i, 1);
} else if (miner.intersects(treasures[i])) {
score += 10;
if (score > highscore) {
highscore = score;
highscoreTxt.setText('Highscore: ' + highscore);
}
scoreTxt.setText(score);
LK.getSound('Coins').play();
treasures[i].destroy();
treasures.splice(i, 1);
}
}
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
if (obstacles[i].y > 2732) {
obstacles[i].destroy();
obstacles.splice(i, 1);
} else if (miner.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
score = 0;
scoreTxt.setText(score);
LK.showGameOver();
}
}
// Spawn treasures and obstacles periodically
if (LK.ticks % 60 == 0) {
spawnTreasure();
}
if (LK.ticks % 90 == 0) {
spawnObstacle();
}
};