/**** * Classes ****/ // Define the Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = -self.height; self.x = Math.random() * 2048; } }; }); // Define the 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 () { // Obstacle update logic }; }); //<Assets used in the game will automatically appear here> // Define the 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 = 5; self.update = function () { // Player update logic }; self.move = function (x, y) { self.x = x; self.y = y; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 200; // Initialize enemies var enemies = []; for (var i = 0; i < 5; i++) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = Math.random() * -2732; enemies.push(enemy); game.addChild(enemy); } // Initialize obstacles var obstacles = []; for (var i = 0; i < 3; i++) { var obstacle = new Obstacle(); obstacle.x = Math.random() * 2048; obstacle.y = Math.random() * 2732; obstacles.push(obstacle); game.addChild(obstacle); } // Handle player movement var dragNode = null; game.down = function (x, y, obj) { dragNode = player; handleMove(x, y, obj); }; game.move = function (x, y, obj) { if (dragNode) { dragNode.move(x, y); } }; game.up = function (x, y, obj) { dragNode = null; }; // Update game state game.update = function () { player.update(); enemies.forEach(function (enemy) { enemy.update(); if (player.intersects(enemy)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }); obstacles.forEach(function (obstacle) { obstacle.update(); if (player.intersects(obstacle)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }); }; function handleMove(x, y, obj) { if (dragNode) { dragNode.move(x, y); } }
/****
* Classes
****/
// Define the Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -self.height;
self.x = Math.random() * 2048;
}
};
});
// Define the 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 () {
// Obstacle update logic
};
});
//<Assets used in the game will automatically appear here>
// Define the 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 = 5;
self.update = function () {
// Player update logic
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize player
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 200;
// Initialize enemies
var enemies = [];
for (var i = 0; i < 5; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = Math.random() * -2732;
enemies.push(enemy);
game.addChild(enemy);
}
// Initialize obstacles
var obstacles = [];
for (var i = 0; i < 3; i++) {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048;
obstacle.y = Math.random() * 2732;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Handle player movement
var dragNode = null;
game.down = function (x, y, obj) {
dragNode = player;
handleMove(x, y, obj);
};
game.move = function (x, y, obj) {
if (dragNode) {
dragNode.move(x, y);
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Update game state
game.update = function () {
player.update();
enemies.forEach(function (enemy) {
enemy.update();
if (player.intersects(enemy)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
});
obstacles.forEach(function (obstacle) {
obstacle.update();
if (player.intersects(obstacle)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
});
};
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.move(x, y);
}
}
A single Ghost. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A simple 2d Player. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A single Ghosts. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.