/****
* Classes
****/
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Coin update logic
};
});
// 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 = -5;
self.update = function () {
self.y += self.speed;
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Player class
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
****/
// Initialize player
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
}));
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 200;
// Arrays to hold obstacles and coins
var obstacles = [];
var coins = [];
// Score and timer
var score = 0;
var timer = 60; // 60 seconds timer
// Display score
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Display timer
var timerTxt = new Text2('Time: 60', {
size: 100,
fill: 0xFFFFFF
});
timerTxt.anchor.set(0.5, 0);
LK.gui.topRight.addChild(timerTxt);
// Handle player movement
game.down = function (x, y, obj) {
player.x = x;
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.update();
if (obstacle.y < -50) {
obstacle.destroy();
obstacles.splice(i, 1);
}
if (player.intersects(obstacle)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update coins
for (var j = coins.length - 1; j >= 0; j--) {
var coin = coins[j];
coin.update();
if (coin.y < -50) {
coin.destroy();
coins.splice(j, 1);
}
if (player.intersects(coin)) {
score += 10;
scoreTxt.setText('Score: ' + score);
coin.destroy();
coins.splice(j, 1);
}
}
// Spawn obstacles and coins
if (LK.ticks % 60 == 0) {
var newObstacle = new Obstacle();
newObstacle.x = Math.random() * 2048;
newObstacle.y = 2732;
obstacles.push(newObstacle);
game.addChild(newObstacle);
var newCoin = new Coin();
newCoin.x = Math.random() * 2048;
newCoin.y = 2732;
coins.push(newCoin);
game.addChild(newCoin);
}
// Update timer
if (LK.ticks % 60 == 0) {
timer--;
timerTxt.setText('Time: ' + timer);
if (timer <= 0) {
LK.showGameOver();
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -49,8 +49,12 @@
/****
* Game Code
****/
// Initialize player
+var background = game.addChild(LK.getAsset('background', {
+ anchorX: 0,
+ anchorY: 0
+}));
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 200;
// Arrays to hold obstacles and coins
MG bunny. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
carrote. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
MG AUTO. Single Game Texture. In-Game asset. 2d. High contrast. No shadows
background city mg. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows