/****
* Classes
****/
// Block class
var Block = Container.expand(function () {
var self = Container.call(this);
var blockGraphics = self.attachAsset('block', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.move = function () {
self.y += self.speed;
};
});
// Character class
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.moveLeft = function () {
if (self.x > 50) {
self.x -= 10;
}
};
self.moveRight = function () {
if (self.x < 1998) {
self.x += 10;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize character
// Initialize assets used in this game.
var character = game.addChild(new Character());
character.x = 1024;
character.y = 2632;
// Initialize blocks array
var blocks = [];
// Initialize score
var score = 0;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle touch events
var touchPosition = null;
game.on('down', function (obj) {
touchPosition = obj.event.getLocalPosition(game);
});
game.on('up', function (obj) {
touchPosition = null;
});
game.on('move', function (obj) {
if (touchPosition) {
touchPosition = obj.event.getLocalPosition(game);
}
});
// Game tick event
LK.on('tick', function () {
// Move character based on touch position
if (touchPosition) {
if (touchPosition.x < character.x) {
character.moveLeft();
} else if (touchPosition.x > character.x) {
character.moveRight();
}
}
// Move blocks
for (var i = blocks.length - 1; i >= 0; i--) {
blocks[i].move();
// Check for collision with character
if (blocks[i].intersects(character)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Remove off-screen blocks
if (blocks[i].y > 2782) {
blocks[i].destroy();
blocks.splice(i, 1);
}
}
// Add new blocks
if (LK.ticks % 60 == 0) {
var newBlock = new Block();
newBlock.x = Math.random() * 2048;
newBlock.y = -50;
blocks.push(newBlock);
game.addChild(newBlock);
}
// Update score
score++;
scoreTxt.setText(score.toString());
});
Ghost that is spooky. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Player that is scared. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
screaming ghost. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.