/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for animatronic characters
var Animatronic = Container.expand(function () {
var self = Container.call(this);
var animatronicGraphics = self.attachAsset('animatronic', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
self.x += self.speed;
if (self.x > 2048 || self.x < 0) {
self.speed *= -1; // Reverse direction
}
};
});
// Class for player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize player and animatronics
var player = game.addChild(new Player());
player.x = 1024;
player.y = 1366;
var animatronics = [];
for (var i = 0; i < 3; i++) {
var animatronic = new Animatronic();
animatronic.x = Math.random() * 2048;
animatronic.y = Math.random() * 2732;
animatronics.push(animatronic);
game.addChild(animatronic);
}
// Game update loop
game.update = function () {
animatronics.forEach(function (animatronic) {
animatronic.update();
if (player.intersects(animatronic)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
});
};
// Handle player movement
game.down = function (x, y, obj) {
player.down(x, y, obj);
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for animatronic characters
var Animatronic = Container.expand(function () {
var self = Container.call(this);
var animatronicGraphics = self.attachAsset('animatronic', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
self.x += self.speed;
if (self.x > 2048 || self.x < 0) {
self.speed *= -1; // Reverse direction
}
};
});
// Class for player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize player and animatronics
var player = game.addChild(new Player());
player.x = 1024;
player.y = 1366;
var animatronics = [];
for (var i = 0; i < 3; i++) {
var animatronic = new Animatronic();
animatronic.x = Math.random() * 2048;
animatronic.y = Math.random() * 2732;
animatronics.push(animatronic);
game.addChild(animatronic);
}
// Game update loop
game.update = function () {
animatronics.forEach(function (animatronic) {
animatronic.update();
if (player.intersects(animatronic)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
});
};
// Handle player movement
game.down = function (x, y, obj) {
player.down(x, y, obj);
};