var Gift = Container.expand(function () {
var self = Container.call(this);
var giftGraphics = self.createAsset('gift', 'Gift Graphics', .5, .5);
self.speed = 5;
self.move = function () {
self.y += self.speed;
};
});
var Asteroid = Container.expand(function () {
var self = Container.call(this);
var asteroidGraphics = self.createAsset('asteroid', 'Asteroid Graphics', .5, .5);
self.speed = 7;
self.move = function () {
self.y += self.speed;
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.createAsset('player', 'Player Graphics', .5, .5);
self.speed = 10;
self.hearts = 3;
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var background = self.createAsset('festiveBackground', 'Festive Background', 0, 0);
self.addChildAt(background, 0);
var gifts = [];
var asteroids = [];
var player = self.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
var heartsTxt = new Text2('Hearts: 3', {
size: 100,
fill: "#ffffff"
});
LK.setScore(0);
scoreTxt.setText(0);
scoreTxt.anchor.set(.5, 0);
heartsTxt.anchor.set(0, 0);
heartsTxt.x = scoreTxt.width + 20;
LK.gui.topCenter.addChild(scoreTxt);
LK.gui.topCenter.addChild(heartsTxt);
var dragNode = null;
player.on('down', function (obj) {
dragNode = player;
});
function handleMove(obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
if (dragNode) {
dragNode.move(pos.x, pos.y);
}
}
stage.on('move', handleMove);
stage.on('up', function (obj) {
dragNode = null;
});
LK.on('tick', function () {
for (var a = gifts.length - 1; a >= 0; a--) {
gifts[a].move();
if (gifts[a].y > 2732) {
gifts[a].destroy();
gifts.splice(a, 1);
} else if (player.intersects(gifts[a])) {
LK.setScore(LK.getScore() + 10);
scoreTxt.setText(LK.getScore());
gifts[a].destroy();
gifts.splice(a, 1);
}
}
for (var a = asteroids.length - 1; a >= 0; a--) {
var asteroid = asteroids[a];
if (asteroid) {
asteroid.move();
if (asteroid.y > 2732) {
asteroid.destroy();
asteroids.splice(a, 1);
} else if (player.intersects(asteroid)) {
player.hearts = Math.max(player.hearts - 1, 0);
heartsTxt.setText('Hearts: ' + player.hearts);
if (player.hearts <= 0) {
LK.showGameOver();
}
asteroid.destroy();
asteroids.splice(a, 1);
}
}
}
if (LK.ticks % 60 == 0) {
var newGift = new Gift();
newGift.x = Math.random() * 2048;
newGift.y = 0;
gifts.push(newGift);
self.addChild(newGift);
}
if (LK.ticks % 30 == 0) {
var newAsteroid = new Asteroid();
newAsteroid.x = Math.random() * 2048;
newAsteroid.y = 0;
asteroids.push(newAsteroid);
self.addChild(newAsteroid);
}
});
});
Asteroid, falling Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Red gift Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Santas sled, with santa in it Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Top down view
festive background Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.