/**** * Classes ****/ var Chimney = Container.expand(function () { var self = Container.call(this); var chimneyGraphics = self.attachAsset('chimney', { anchorX: 0.5, anchorY: 0.5 }); self.originalTint = 0xFFFFFF; self.presentDeliveredTint = 0x808080; self.hasPresent = false; self.speed = 2; self._move_migrated = function () { self.x -= self.speed; if (self.x < -self.width) { self.x = 2048; } }; self.checkCollision = function () {}; }); var Hazard = Container.expand(function () { var self = Container.call(this); var hazardGraphics = self.attachAsset('hazard', { anchorX: 0.5, anchorY: 0.5 }); self._move_migrated = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); return true; } return false; }; }); var LifeIcon = Container.expand(function () { var self = Container.call(this); var lifeIconGraphics = self.attachAsset('lifeIcon', { anchorX: 0.5, anchorY: 0.5 }); }); var Present = Container.expand(function () { var self = Container.call(this); var presentGraphics = self.attachAsset('present', { anchorX: 0.5, anchorY: 0.5 }); self._move_migrated = function (hazards) { this.y += 5; hazards.forEach(function (hazard) { var collisionBuffer = 10; if (this.intersects(hazard) && Math.abs(this.x - hazard.x) < (this.width + hazard.width) / 2 - collisionBuffer && Math.abs(this.y - hazard.y) < (this.height + hazard.height) / 2 - collisionBuffer) { LK.effects.flashObject(this, 0xff0000, 300); LK.setTimeout(function () { this.destroy(); }.bind(this), 300); } }.bind(this)); }; }); var PresentIcon = Container.expand(function () { var self = Container.call(this); var presentIconGraphics = self.attachAsset('presentIcon', { anchorX: 0.5, anchorY: 0.5 }); }); var PresentTopper = Container.expand(function (speed) { var self = Container.call(this); var topperGraphics = self.attachAsset('presentTopper', { anchorX: 0.5, anchorY: 1 }); self.speed = speed; self._move_migrated = function () { self.x -= self.speed; }; }); var RandomMover = Container.expand(function () { var self = Container.call(this); var moverGraphics = self.attachAsset('randomMover', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = (Math.random() * 4 - 2) * 4; self.speedY = (Math.random() * 4 - 2) * 4; self._move_migrated = function () { self.x += self.speedX; self.y += self.speedY; if (self.x < 0 || self.x > 2048) { self.speedX *= -1; } if (self.y < 0 || self.y > 2732) { self.speedY *= -1; } }; }); var Santa = Container.expand(function () { var self = Container.call(this); self.resetPresents = function () { this.presentCounter = 5; this.parent.presentIcons.forEach(function (icon, index) { icon.visible = index < this.presentCounter; }.bind(this)); }; var santaGraphics = self.attachAsset('santa', { anchorX: 0.5, anchorY: 0.5 }); self._move_migrated = function () { if (this.lastTouchPosition) { var dx = this.lastTouchPosition.x - this.x; var dy = this.lastTouchPosition.y - this.y; var distance = Math.sqrt(dx * dx + dy * dy); var speed = 10; if (distance > speed) { dx = dx / distance * speed; dy = dy / distance * speed; } this.x += dx; this.y += dy; if (distance < speed) { this.lastTouchPosition = null; } } }; self.throwPresent = function () { if (this.presentCounter > 0) { var present = new Present(); present.x = this.x; present.y = this.y; this.parent.addChild(present); this.parent.presents.push(present); this.presentCounter--; this.parent.presentIcons.forEach(function (icon, index) { icon.visible = index < this.presentCounter; }.bind(this)); } if (this.presentCounter === 0) { this.parent.hazardSpeed *= 1.5; this.parent.hazardSpawnRate = Math.max(this.parent.hazardSpawnRate * 0.8, 20); this.parent.rudolph.visible = true; } else { this.parent.rudolph.visible = false; } }; }); var ScoreBackground = Container.expand(function () { var self = Container.call(this); var scoreBgGraphics = self.attachAsset('scoreBg', { anchorX: 0.5 }); scoreBgGraphics.height -= 100; }); var Star = Container.expand(function () { var self = Container.call(this); var starGraphics = self.attachAsset('star', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2 + Math.random() * 3; self._move_migrated = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); return true; } return false; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ game.toppers = []; game.stars = []; var starSpawnRate = 15; var starSpawnCounter = 0; var santa = game.addChild(new Santa()); santa.x = 2048 / 2; santa.y = 2732 / 2; santa.presentDropTimer = 0; game.lastTapTime = 0; game.rudolph = game.addChild(new RandomMover()); game.rudolph.x = Math.random() * 2048; game.rudolph.y = Math.random() * 2732; game.rudolph.visible = false; santa.lives = 3; game.lifeIcons = []; var lifeIconSpacing = 20; var lifeIconSize = 64; for (var i = 0; i < santa.lives; i++) { var lifeIcon = new LifeIcon(); lifeIcon.x = lifeIconSpacing + 1050 + i * (lifeIconSize + lifeIconSpacing); lifeIcon.y = lifeIconSpacing + 50; game.lifeIcons.push(lifeIcon); LK.gui.topLeft.addChild(lifeIcon); } santa.presentCounter = 5; game.presents = []; var chimneys = []; var hazards = []; var hazardSpeed = 8; var hazardSpawnRate = 80; var hazardSpawnCounter = 0; var rudolphSpawnCounter = 0; var scoreBackground = new ScoreBackground(); scoreBackground.x = 2048 / 2 - scoreBackground.width / 2 - 880; scoreBackground.y = 0; game.addChild(scoreBackground); var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff", font: "'Press Start 2P', monospace", dropShadow: true, dropShadowColor: '#000000', dropShadowBlur: 4 }); game.presentIcons = []; for (var i = 0; i < santa.presentCounter; i++) { var presentIcon = new PresentIcon(); presentIcon.x = 1060 + i * (presentIcon.width + 10); presentIcon.y = game.lifeIcons[game.lifeIcons.length - 1].y + lifeIconSize + lifeIconSpacing; game.presentIcons.push(presentIcon); LK.gui.topLeft.addChild(presentIcon); } var maxChimneys = 5; LK.on('tick', function () { var currentTick = LK.ticks; santa._move_migrated(); if (santa.presentDropTimer++ >= 120) { santa.throwPresent(); santa.presentDropTimer = 0; } game.on('down', function (x, y, obj) { var event = obj; santa.lastTouchPosition = game.toLocal(event.global); }); game.toppers = game.toppers.filter(function (topper) { return topper.x + topper.width > 0; }); game.toppers.forEach(function (topper) { topper._move_migrated(); }); if (starSpawnCounter++ >= starSpawnRate) { var newStar = new Star(); newStar.x = 2048; newStar.y = Math.random() * (2732 * 0.8); game.stars.push(newStar); game.addChild(newStar); starSpawnCounter = 0; } if (chimneys.length < maxChimneys) { var lastChimney = chimneys[chimneys.length - 1]; var chimneySpacing = 500; if (!lastChimney || lastChimney.x < 2048 - chimneySpacing) { var newChimney = new Chimney(); newChimney.x = 2048; newChimney.y = 2732 - newChimney.height - Math.random() * 500 + 750; chimneys.push(newChimney); game.addChild(newChimney); } } chimneys.forEach(function (chimney) { chimney._move_migrated(); game.presents.forEach(function (present, index) { var chimneyCollisionBuffer = 15; if (present.intersects(chimney) && !chimney.hasPresent && Math.abs(present.x - chimney.x) < (present.width + chimney.width) / 2 - chimneyCollisionBuffer && Math.abs(present.y - chimney.y) < (present.height + chimney.height) / 2 - chimneyCollisionBuffer) { present.destroy(); game.presents.splice(index, 1); chimney.hasPresent = true; chimney.tint = chimney.presentDeliveredTint; var newScore = LK.getScore() + 1; LK.setScore(newScore); scoreTxt.setText(newScore.toString()); var presentTopper = new PresentTopper(chimney.speed); presentTopper.x = chimney.x; presentTopper.y = chimney.y - chimney.height / 2; game.addChild(presentTopper); game.toppers.push(presentTopper); } }); }); chimneys = chimneys.filter(function (chimney) { if (chimney.x + chimney.width <= 0) { chimney.destroy(); return false; } return true; }); }); scoreTxt.anchor.set(.5, 0); scoreTxt.y += 15; LK.gui.top.addChild(scoreBackground); LK.gui.top.addChild(scoreTxt); LK.on('tick', function () { for (var i = game.presents.length - 1; i >= 0; i--) { game.presents[i]._move_migrated(hazards); } for (var i = chimneys.length - 1; i >= 0; i--) { chimneys[i].checkCollision(); } if (hazardSpawnCounter++ >= hazardSpawnRate) { var newHazard = new Hazard(); newHazard.x = 2048; newHazard.y = Math.random() * 2732; newHazard.speed = hazardSpeed; hazards.unshift(newHazard); game.addChild(newHazard); hazardSpawnCounter = 0; } hazards = hazards.filter(function (hazard) { return !hazard._move_migrated(); }); var santaHit = false; hazards.forEach(function (hazard, index) { var santaCollisionBuffer = 15; if (!santaHit && santa.intersects(hazard) && Math.abs(santa.x - hazard.x) < (santa.width + hazard.width) / 2 - santaCollisionBuffer && Math.abs(santa.y - hazard.y) < (santa.height + hazard.height) / 2 - santaCollisionBuffer) { LK.effects.flashObject(santa, 0xffff00, 500); hazard.destroy(); hazards.splice(index, 1); santaHit = true; santa.lives--; if (game.lifeIcons.length > santa.lives) { var removedLifeIcon = game.lifeIcons.pop(); removedLifeIcon.destroy(); } if (santa.lives <= 0) { LK.showGameOver(); } } }); hazards = hazards.filter(function (hazard) { return !hazard.hitSanta; }); game.stars.forEach(function (star, index) { if (star._move_migrated()) { star.destroy(); game.stars.splice(index, 1); } }); game.rudolph._move_migrated(); if (game.rudolph.visible && santa.intersects(game.rudolph)) { santa.resetPresents(); game.rudolph.visible = false; } });
/****
* Classes
****/
var Chimney = Container.expand(function () {
var self = Container.call(this);
var chimneyGraphics = self.attachAsset('chimney', {
anchorX: 0.5,
anchorY: 0.5
});
self.originalTint = 0xFFFFFF;
self.presentDeliveredTint = 0x808080;
self.hasPresent = false;
self.speed = 2;
self._move_migrated = function () {
self.x -= self.speed;
if (self.x < -self.width) {
self.x = 2048;
}
};
self.checkCollision = function () {};
});
var Hazard = Container.expand(function () {
var self = Container.call(this);
var hazardGraphics = self.attachAsset('hazard', {
anchorX: 0.5,
anchorY: 0.5
});
self._move_migrated = function () {
self.x -= self.speed;
if (self.x < -self.width) {
self.destroy();
return true;
}
return false;
};
});
var LifeIcon = Container.expand(function () {
var self = Container.call(this);
var lifeIconGraphics = self.attachAsset('lifeIcon', {
anchorX: 0.5,
anchorY: 0.5
});
});
var Present = Container.expand(function () {
var self = Container.call(this);
var presentGraphics = self.attachAsset('present', {
anchorX: 0.5,
anchorY: 0.5
});
self._move_migrated = function (hazards) {
this.y += 5;
hazards.forEach(function (hazard) {
var collisionBuffer = 10;
if (this.intersects(hazard) && Math.abs(this.x - hazard.x) < (this.width + hazard.width) / 2 - collisionBuffer && Math.abs(this.y - hazard.y) < (this.height + hazard.height) / 2 - collisionBuffer) {
LK.effects.flashObject(this, 0xff0000, 300);
LK.setTimeout(function () {
this.destroy();
}.bind(this), 300);
}
}.bind(this));
};
});
var PresentIcon = Container.expand(function () {
var self = Container.call(this);
var presentIconGraphics = self.attachAsset('presentIcon', {
anchorX: 0.5,
anchorY: 0.5
});
});
var PresentTopper = Container.expand(function (speed) {
var self = Container.call(this);
var topperGraphics = self.attachAsset('presentTopper', {
anchorX: 0.5,
anchorY: 1
});
self.speed = speed;
self._move_migrated = function () {
self.x -= self.speed;
};
});
var RandomMover = Container.expand(function () {
var self = Container.call(this);
var moverGraphics = self.attachAsset('randomMover', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = (Math.random() * 4 - 2) * 4;
self.speedY = (Math.random() * 4 - 2) * 4;
self._move_migrated = function () {
self.x += self.speedX;
self.y += self.speedY;
if (self.x < 0 || self.x > 2048) {
self.speedX *= -1;
}
if (self.y < 0 || self.y > 2732) {
self.speedY *= -1;
}
};
});
var Santa = Container.expand(function () {
var self = Container.call(this);
self.resetPresents = function () {
this.presentCounter = 5;
this.parent.presentIcons.forEach(function (icon, index) {
icon.visible = index < this.presentCounter;
}.bind(this));
};
var santaGraphics = self.attachAsset('santa', {
anchorX: 0.5,
anchorY: 0.5
});
self._move_migrated = function () {
if (this.lastTouchPosition) {
var dx = this.lastTouchPosition.x - this.x;
var dy = this.lastTouchPosition.y - this.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var speed = 10;
if (distance > speed) {
dx = dx / distance * speed;
dy = dy / distance * speed;
}
this.x += dx;
this.y += dy;
if (distance < speed) {
this.lastTouchPosition = null;
}
}
};
self.throwPresent = function () {
if (this.presentCounter > 0) {
var present = new Present();
present.x = this.x;
present.y = this.y;
this.parent.addChild(present);
this.parent.presents.push(present);
this.presentCounter--;
this.parent.presentIcons.forEach(function (icon, index) {
icon.visible = index < this.presentCounter;
}.bind(this));
}
if (this.presentCounter === 0) {
this.parent.hazardSpeed *= 1.5;
this.parent.hazardSpawnRate = Math.max(this.parent.hazardSpawnRate * 0.8, 20);
this.parent.rudolph.visible = true;
} else {
this.parent.rudolph.visible = false;
}
};
});
var ScoreBackground = Container.expand(function () {
var self = Container.call(this);
var scoreBgGraphics = self.attachAsset('scoreBg', {
anchorX: 0.5
});
scoreBgGraphics.height -= 100;
});
var Star = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2 + Math.random() * 3;
self._move_migrated = function () {
self.x -= self.speed;
if (self.x < -self.width) {
self.destroy();
return true;
}
return false;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
game.toppers = [];
game.stars = [];
var starSpawnRate = 15;
var starSpawnCounter = 0;
var santa = game.addChild(new Santa());
santa.x = 2048 / 2;
santa.y = 2732 / 2;
santa.presentDropTimer = 0;
game.lastTapTime = 0;
game.rudolph = game.addChild(new RandomMover());
game.rudolph.x = Math.random() * 2048;
game.rudolph.y = Math.random() * 2732;
game.rudolph.visible = false;
santa.lives = 3;
game.lifeIcons = [];
var lifeIconSpacing = 20;
var lifeIconSize = 64;
for (var i = 0; i < santa.lives; i++) {
var lifeIcon = new LifeIcon();
lifeIcon.x = lifeIconSpacing + 1050 + i * (lifeIconSize + lifeIconSpacing);
lifeIcon.y = lifeIconSpacing + 50;
game.lifeIcons.push(lifeIcon);
LK.gui.topLeft.addChild(lifeIcon);
}
santa.presentCounter = 5;
game.presents = [];
var chimneys = [];
var hazards = [];
var hazardSpeed = 8;
var hazardSpawnRate = 80;
var hazardSpawnCounter = 0;
var rudolphSpawnCounter = 0;
var scoreBackground = new ScoreBackground();
scoreBackground.x = 2048 / 2 - scoreBackground.width / 2 - 880;
scoreBackground.y = 0;
game.addChild(scoreBackground);
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff",
font: "'Press Start 2P', monospace",
dropShadow: true,
dropShadowColor: '#000000',
dropShadowBlur: 4
});
game.presentIcons = [];
for (var i = 0; i < santa.presentCounter; i++) {
var presentIcon = new PresentIcon();
presentIcon.x = 1060 + i * (presentIcon.width + 10);
presentIcon.y = game.lifeIcons[game.lifeIcons.length - 1].y + lifeIconSize + lifeIconSpacing;
game.presentIcons.push(presentIcon);
LK.gui.topLeft.addChild(presentIcon);
}
var maxChimneys = 5;
LK.on('tick', function () {
var currentTick = LK.ticks;
santa._move_migrated();
if (santa.presentDropTimer++ >= 120) {
santa.throwPresent();
santa.presentDropTimer = 0;
}
game.on('down', function (x, y, obj) {
var event = obj;
santa.lastTouchPosition = game.toLocal(event.global);
});
game.toppers = game.toppers.filter(function (topper) {
return topper.x + topper.width > 0;
});
game.toppers.forEach(function (topper) {
topper._move_migrated();
});
if (starSpawnCounter++ >= starSpawnRate) {
var newStar = new Star();
newStar.x = 2048;
newStar.y = Math.random() * (2732 * 0.8);
game.stars.push(newStar);
game.addChild(newStar);
starSpawnCounter = 0;
}
if (chimneys.length < maxChimneys) {
var lastChimney = chimneys[chimneys.length - 1];
var chimneySpacing = 500;
if (!lastChimney || lastChimney.x < 2048 - chimneySpacing) {
var newChimney = new Chimney();
newChimney.x = 2048;
newChimney.y = 2732 - newChimney.height - Math.random() * 500 + 750;
chimneys.push(newChimney);
game.addChild(newChimney);
}
}
chimneys.forEach(function (chimney) {
chimney._move_migrated();
game.presents.forEach(function (present, index) {
var chimneyCollisionBuffer = 15;
if (present.intersects(chimney) && !chimney.hasPresent && Math.abs(present.x - chimney.x) < (present.width + chimney.width) / 2 - chimneyCollisionBuffer && Math.abs(present.y - chimney.y) < (present.height + chimney.height) / 2 - chimneyCollisionBuffer) {
present.destroy();
game.presents.splice(index, 1);
chimney.hasPresent = true;
chimney.tint = chimney.presentDeliveredTint;
var newScore = LK.getScore() + 1;
LK.setScore(newScore);
scoreTxt.setText(newScore.toString());
var presentTopper = new PresentTopper(chimney.speed);
presentTopper.x = chimney.x;
presentTopper.y = chimney.y - chimney.height / 2;
game.addChild(presentTopper);
game.toppers.push(presentTopper);
}
});
});
chimneys = chimneys.filter(function (chimney) {
if (chimney.x + chimney.width <= 0) {
chimney.destroy();
return false;
}
return true;
});
});
scoreTxt.anchor.set(.5, 0);
scoreTxt.y += 15;
LK.gui.top.addChild(scoreBackground);
LK.gui.top.addChild(scoreTxt);
LK.on('tick', function () {
for (var i = game.presents.length - 1; i >= 0; i--) {
game.presents[i]._move_migrated(hazards);
}
for (var i = chimneys.length - 1; i >= 0; i--) {
chimneys[i].checkCollision();
}
if (hazardSpawnCounter++ >= hazardSpawnRate) {
var newHazard = new Hazard();
newHazard.x = 2048;
newHazard.y = Math.random() * 2732;
newHazard.speed = hazardSpeed;
hazards.unshift(newHazard);
game.addChild(newHazard);
hazardSpawnCounter = 0;
}
hazards = hazards.filter(function (hazard) {
return !hazard._move_migrated();
});
var santaHit = false;
hazards.forEach(function (hazard, index) {
var santaCollisionBuffer = 15;
if (!santaHit && santa.intersects(hazard) && Math.abs(santa.x - hazard.x) < (santa.width + hazard.width) / 2 - santaCollisionBuffer && Math.abs(santa.y - hazard.y) < (santa.height + hazard.height) / 2 - santaCollisionBuffer) {
LK.effects.flashObject(santa, 0xffff00, 500);
hazard.destroy();
hazards.splice(index, 1);
santaHit = true;
santa.lives--;
if (game.lifeIcons.length > santa.lives) {
var removedLifeIcon = game.lifeIcons.pop();
removedLifeIcon.destroy();
}
if (santa.lives <= 0) {
LK.showGameOver();
}
}
});
hazards = hazards.filter(function (hazard) {
return !hazard.hitSanta;
});
game.stars.forEach(function (star, index) {
if (star._move_migrated()) {
star.destroy();
game.stars.splice(index, 1);
}
});
game.rudolph._move_migrated();
if (game.rudolph.visible && santa.intersects(game.rudolph)) {
santa.resetPresents();
game.rudolph.visible = false;
}
});
8-bit cloud with lightning. in game asset. white cloude. yellow lighning. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8 bit x mas pressent. in game asset. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit. cartoon. santa on sledge. smiling. in game asset. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.