/**** * Classes ****/ // The assets will be automatically created and loaded by the LK engine // Class for the Player var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Player movement and actions will be defined here }; }); // Class for the Trees var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = self.attachAsset('tree', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Tree movement and actions will be defined here }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player and trees var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; var trees = []; for (var i = 0; i < 10; i++) { var tree = game.addChild(new Tree()); tree.x = Math.random() * 2048; tree.y = Math.random() * 2732; trees.push(tree); } // Game update function game.update = function () { // Check for collisions between player and trees for (var i = 0; i < trees.length; i++) { if (player.intersects(trees[i])) { // Game over if player collides with a tree LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } }; // Player movement game.move = function (x, y, obj) { player.x = x; player.y = y; };
/****
* Classes
****/
// The assets will be automatically created and loaded by the LK engine
// Class for the Player
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Player movement and actions will be defined here
};
});
// Class for the Trees
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Tree movement and actions will be defined here
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize player and trees
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
var trees = [];
for (var i = 0; i < 10; i++) {
var tree = game.addChild(new Tree());
tree.x = Math.random() * 2048;
tree.y = Math.random() * 2732;
trees.push(tree);
}
// Game update function
game.update = function () {
// Check for collisions between player and trees
for (var i = 0; i < trees.length; i++) {
if (player.intersects(trees[i])) {
// Game over if player collides with a tree
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
};
// Player movement
game.move = function (x, y, obj) {
player.x = x;
player.y = y;
};