/**** * Classes ****/ // Define an Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('human', { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 100; self.update = function () { self.y += Math.random() > 0.5 ? self.speed : -self.speed; self.x += Math.random() > 0.5 ? self.speed : -self.speed; if (self.y > 2732 || self.y < 0 || self.x > 2048 || self.x < 0) { self.y = Math.random() * 2732; self.x = Math.random() * 2048; } }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Define a Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('goose', { 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 player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 200; // Initialize obstacles var obstacles = []; for (var i = 0; i < 5; i++) { var obstacle = new Obstacle(); obstacle.x = Math.random() * 2048; obstacle.y = Math.random() * 2732; obstacles.push(obstacle); game.addChild(obstacle); } // Handle player movement game.down = function (x, y, obj) { player.x = x; player.y = y; }; // Update game logic game.update = function () { for (var i = 0; i < obstacles.length; i++) { obstacles[i].update(); if (player.intersects(obstacles[i])) { obstacles[i].destroy(); obstacles.splice(i, 1); LK.getSound('gooseglass').play(); } } // Check if all enemies are defeated if (obstacles.length === 0) { LK.showYouWin(); } };
/****
* Classes
****/
// Define an Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('human', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 100;
self.update = function () {
self.y += Math.random() > 0.5 ? self.speed : -self.speed;
self.x += Math.random() > 0.5 ? self.speed : -self.speed;
if (self.y > 2732 || self.y < 0 || self.x > 2048 || self.x < 0) {
self.y = Math.random() * 2732;
self.x = Math.random() * 2048;
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define a Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('goose', {
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 player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 200;
// Initialize obstacles
var obstacles = [];
for (var i = 0; i < 5; i++) {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048;
obstacle.y = Math.random() * 2732;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Handle player movement
game.down = function (x, y, obj) {
player.x = x;
player.y = y;
};
// Update game logic
game.update = function () {
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].update();
if (player.intersects(obstacles[i])) {
obstacles[i].destroy();
obstacles.splice(i, 1);
LK.getSound('gooseglass').play();
}
}
// Check if all enemies are defeated
if (obstacles.length === 0) {
LK.showYouWin();
}
};