/****
* Classes
****/
// Create a Grass class by using the LK expand method to extend Container.
var Grass = Container.expand(function () {
var self = Container.call(this);
// Get and automatically addChild to self asset with id 'ground' with the anchor point set to .5, .5
var grassGraphics = self.attachAsset('ground', {
anchorX: 0.5,
anchorY: 0.5
});
});
/// BUG: TRY MOVING PLAYER AFTER SPARKLES SO SPARKLES IS BEHIND PLAYER, THE CODE ALWAYS RESETS THE ORDER! (BEN/JOSH)
// Create a Player class by using the LK expand method to extend Container.
var Player = Container.expand(function () {
var self = Container.call(this);
// Get and automatically addChild to self asset with id 'Player' with the anchor point set to .5, .5
var playerGraphics = self.attachAsset('Player', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Create a Sparkles class by using the LK expand method to extend Container.
var Sparkles = Container.expand(function () {
var self = Container.call(this);
// Get and automatically addChild to self asset with id 'Sparkles' with the anchor point set to .5, .5
var sparklesGraphics = self.attachAsset('Sparkles', {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Initialize the player object and position it outside the screen
var player = game.addChild(new Player());
player.x = -player.width;
player.y = 2732 - player.height;
// Initialize the sparkles object but do not position it yet
var sparkles = game.addChild(new Sparkles());
// Initialize the grass object and position it at the bottom of the playspace
var grass = game.addChild(new Grass());
grass.x = 2048 / 2;
grass.y = 2732 - grass.height / 2;
// Ask LK engine to update game every game tick. Use this instead of Tweens
game.update = function () {
// Move the player more towards the right
if (player.x < 250) {
player.x += 5;
}
// Continuously position sparkles at the center of the player
sparkles.x = player.x + player.width / 2 - sparkles.width / 2;
sparkles.y = player.y + player.height / 2 - sparkles.height / 2 - 200;
// Continuously position grass at the bottom of the playspace
grass.x = 2048 / 2;
grass.y = 2732 - grass.height / 2 - 250;
};