/**** * Classes ****/ var HalfTree = Container.expand(function () { var self = Container.call(this); var treeGraphics = self.attachAsset('halfTree', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += 2; if (self.y > 2732) { self.y = 0; self.x = Math.random() * 2048; } }; }); //<Write entity 'classes' with empty functions for important behavior here> var Parrot = Container.expand(function () { var self = Container.call(this); var parrotGraphics = self.attachAsset('parrot', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB //Init game with sky blue background }); /**** * Game Code ****/ //<Write game logic code here, including initializing arrays and variables> //<Assets used in the game will automatically appear here> var parrot = game.addChild(new Parrot()); parrot.x = 1024; parrot.y = 1366; var halfTrees = []; for (var i = 0; i < 5; i++) { var halfTree = new HalfTree(); halfTree.x = Math.random() * 2048; halfTree.y = Math.random() * 2732; halfTrees.push(halfTree); game.addChild(halfTree); } game.update = function () { parrot.update(); for (var i = 0; i < halfTrees.length; i++) { halfTrees[i].update(); if (parrot.intersects(halfTrees[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } }; game.down = function (x, y, obj) { parrot.y -= 50; }; game.move = function (x, y, obj) { parrot.x = x; };
/****
* Classes
****/
var HalfTree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('halfTree', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 2;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
};
});
//<Write entity 'classes' with empty functions for important behavior here>
var Parrot = Container.expand(function () {
var self = Container.call(this);
var parrotGraphics = self.attachAsset('parrot', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB //Init game with sky blue background
});
/****
* Game Code
****/
//<Write game logic code here, including initializing arrays and variables>
//<Assets used in the game will automatically appear here>
var parrot = game.addChild(new Parrot());
parrot.x = 1024;
parrot.y = 1366;
var halfTrees = [];
for (var i = 0; i < 5; i++) {
var halfTree = new HalfTree();
halfTree.x = Math.random() * 2048;
halfTree.y = Math.random() * 2732;
halfTrees.push(halfTree);
game.addChild(halfTree);
}
game.update = function () {
parrot.update();
for (var i = 0; i < halfTrees.length; i++) {
halfTrees[i].update();
if (parrot.intersects(halfTrees[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
};
game.down = function (x, y, obj) {
parrot.y -= 50;
};
game.move = function (x, y, obj) {
parrot.x = x;
};