/**** * Classes ****/ var Bell = Container.expand(function (score) { var self = Container.call(this); self.score = score; var bellBackground = self.attachAsset('bellBackground', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(bellBackground); var bellGraphics = self.attachAsset('bell', { anchorX: 0.5, anchorY: 0.5 }); bellGraphics.blendMode = 1; self.addChild(bellGraphics); self._move_migrated = function () { self.y += self.parent.parent.bellSpeed; }; }); var ParallaxLayer = Container.expand(function (speed) { var self = Container.call(this); self.actualY = 0; self.speed = typeof speed !== 'undefined' ? speed : 1; self.setParallaxY = function (y) { self.actualY = y * self.speed; self.y = self.actualY; }; }); var Particle = Container.expand(function (x, y, index) { var self = Container.call(this, x, y); self.index = index; var particleGraphics = self.attachAsset('particle', { anchorX: 0.5, anchorY: 0.5 }); self.x = x; self.y = y; var angle = index % 20 * (Math.PI * 2 / 20); self.fixedSpeed = 30; self.angle = angle; self._move_migrated = function () { self.fixedSpeed *= 0.95; self.x += Math.cos(self.angle) * self.fixedSpeed; self.y += Math.sin(self.angle) * self.fixedSpeed; self.cachedAlpha = (self.cachedAlpha || 3) - 0.04; self.alpha = Math.max(0, self.cachedAlpha); if (self.cachedAlpha <= 0) { self.destroy(); } }; }); var Player = Container.expand(function () { var self = Container.call(this); self.targetX = self.x; var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.hasJumped = false; self.jump = function () { if (!self.hasJumped) { self.speedy = -30; self.hasJumped = true; LK.getSound('swoosh').play(); } }; self.fall = function () {}; self._update_migrated = function () { var distance = Math.abs(self.x - self.targetX); var speed = Math.max(1, distance / 25); if (self.x < self.targetX) { self.x += Math.min(speed, self.targetX - self.x); playerGraphics.scale.x = -1; } else if (self.x > self.targetX) { self.x -= Math.min(speed, self.x - self.targetX); playerGraphics.scale.x = 1; } self.y += self.speedy; self.speedy += 0.28; }; }); var ScoreText = Container.expand(function (score, x, y) { var self = Container.call(this); self.x = x; self.y = y; var scoreText = new Text2(score.toString(), { size: 120, fill: '#ffffff', weight: 400, stroke: '#000000', strokeThickness: 10 }); scoreText.anchor.set(.5, .5); scoreText.scale.set(0, 0); self.addChild(scoreText); var scaleIncrease = 0.05; LK.on('tick', function () { if (scoreText.scale.x < 1) { scoreText.scale.x += scaleIncrease; scoreText.scale.y += scaleIncrease; } }); self._move_migrated = function () { self.alpha -= 0.02; if (self.alpha <= 0) { self.destroy(); } }; }); var Snowflake = Container.expand(function () { var self = Container.call(this); var flakeGraphics = self.attachAsset('snowflake', { anchorX: 0.5, anchorY: 0.5 }); self.speedy = Math.random() * 2 + 1; self.speedx = Math.random() * 1 - 0.5; self.rotationSpeed = Math.random() * 0.05 - 0.025; self._move_migrated = function () { self.y += self.speedy; self.scale.set(self.speedy / 3, self.speedy / 3); self.x += self.speedx; self.rotation += self.rotationSpeed; if (self.y > 2732 - self.parent.actualY) { self.y = -50 - self.parent.actualY; } if (self.x > 2048) { self.x = -50; } else if (self.x < -50) { self.x = 2048; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ game.bellSpeed = 5; game.bellSpeedIncreaseFactor = 0.001; game.totalTicks = 0; game.layers = []; var background = game.attachAsset('backgroundGraphics', { anchorX: 0.5, anchorY: 0.5 }); background.x = 2048 / 2; background.y = 2732 / 2; background.alpha = 0.5; game.addChildAt(background, 0); var mountains = game.addChild(new ParallaxLayer(.3 / 4 / 4 / 4)); var mountainGraphics = mountains.attachAsset('mountainGraphics', { anchorX: 0.5, anchorY: 1 }); mountainGraphics.x = 2048 / 2; mountainGraphics.y = 2732; mountains.addChild(mountainGraphics); game.layers.push(mountains); var valley = game.addChild(new ParallaxLayer(.3 / 4 / 4)); var valleyGraphics = valley.attachAsset('valleyGraphics', { anchorX: 0.5, anchorY: 1 }); valleyGraphics.x = 2048 / 2; valleyGraphics.y = 2732; valley.addChild(valleyGraphics); game.layers.push(valley); var forest = new ParallaxLayer(.3 / 2); var forestGraphics = forest.attachAsset('forestGraphics', { anchorX: 0.5, anchorY: 1 }); forestGraphics.x = 2048 / 2; forestGraphics.y = 2732 - 150 + 50; forest.addChild(forestGraphics); game.layers.push(forest); var foreground = new ParallaxLayer(); game.layers.push(foreground); game.particles = []; for (var i = 0; i < 100; i++) { var snowflake = new Snowflake(); snowflake.x = Math.random() * 2048; snowflake.y = Math.random() * 2732; forest.addChild(snowflake); game.particles.push(snowflake); } var groundLayer = new ParallaxLayer(.3); var groundGraphics = groundLayer.attachAsset('groundGraphics', { anchorX: 0.5, anchorY: 1 }); groundGraphics.x = 2048 / 2; groundGraphics.y = 2732 + 195; groundLayer.addChild(groundGraphics); game.layers.push(groundLayer); game.addChild(forest); game.addChild(foreground); game.addChild(groundLayer); var player = foreground.addChild(new Player()); player.x = 2048 / 2; player.targetX = player.x; player.y = 2732 - player.height - 80; game.score = 0; scoreTxt = new Text2(LK.getScore().toString(), { size: 150, fill: "#ffffff", weight: 800, dropShadow: true, dropShadowColor: '#000000', dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); scoreTxt.anchor.set(.5, 0); LK.gui.top.addChild(scoreTxt); var bells = []; game.addBell = function () { var lastBellY = bells.length > 0 ? bells[bells.length - 1].y : 2732; var nextScore = bells.length > 0 ? bells[bells.length - 1].score + 1 : 1; var bell = foreground.addChild(new Bell(nextScore)); bell.x = Math.random() * (2048 - bell.width); bell.y = lastBellY - (Math.random() * (2732 / 4 - 2732 / 6) + 2732 / 6); bells.push(bell); }; for (var i = 0; i < 8; i++) { game.addBell(); } var player; var scoreTxt; var isGameOver = false; LK.on('tick', function () { player._update_migrated(); var targetParallaxValue = 1366 - player.y + 500; var currentParallaxValue = foreground.actualY; var parallaxDifference = targetParallaxValue - currentParallaxValue; var parallaxSpeed = Math.max(1, Math.abs(parallaxDifference) / 10); background.alpha = Math.min(1, (-2790 - player.y) / 500000 + 0.5); if (currentParallaxValue < targetParallaxValue) { game.layers.forEach(function (layer) { layer.setParallaxY(currentParallaxValue + Math.min(parallaxSpeed, targetParallaxValue - currentParallaxValue)); }); } for (var i = 0; i < bells.length; i++) { bells[i]._move_migrated(); if (player.intersects(bells[i])) { player.speedy = -15; player.hasJumped = true; var newScore = LK.getScore() + bells[i].score; LK.setScore(newScore); scoreTxt.setText(newScore.toString()); game.bellSpeed += game.bellSpeedIncreaseFactor; for (var p = 0; p < 20; p++) { var layerDeltaY = forest.actualY - foreground.actualY; var particle = new Particle(bells[i].x, bells[i].y - layerDeltaY, p); game.particles.push(particle); forest.addChild(particle); var scoreText = new ScoreText(bells[i].score, bells[i].x, bells[i].y - layerDeltaY); game.particles.push(scoreText); forest.addChild(scoreText); } // Play a bell chime sound LK.getSound('bellChime').play(); bells[i].destroy(); bells.splice(i, 1); game.addBell(); } else if (bells[i].y + foreground.actualY > 2832) { bells[i].destroy(); bells.splice(i, 1); game.addBell(); } } if (player.y + foreground.y > 2732) { isGameOver = true; } game.particles.forEach(function (particle) { particle._move_migrated(); if (particle.alpha <= 0) { var index = game.particles.indexOf(particle); if (index > -1) { game.particles.splice(index, 1); } } }); game.totalTicks++; game.bellSpeed += game.bellSpeedIncreaseFactor; if (isGameOver) { LK.effects.flashScreen(0xffffff, 1000); LK.showGameOver(); } }); game.on('down', function (x, y, obj) { var event = obj; var pos = game.toLocal(event.global); player.targetX = pos.x; player.jump(); }); game.on('move', function (x, y, obj) { var event = obj; var pos = game.toLocal(event.global); player.targetX = pos.x; });
/****
* Classes
****/
var Bell = Container.expand(function (score) {
var self = Container.call(this);
self.score = score;
var bellBackground = self.attachAsset('bellBackground', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(bellBackground);
var bellGraphics = self.attachAsset('bell', {
anchorX: 0.5,
anchorY: 0.5
});
bellGraphics.blendMode = 1;
self.addChild(bellGraphics);
self._move_migrated = function () {
self.y += self.parent.parent.bellSpeed;
};
});
var ParallaxLayer = Container.expand(function (speed) {
var self = Container.call(this);
self.actualY = 0;
self.speed = typeof speed !== 'undefined' ? speed : 1;
self.setParallaxY = function (y) {
self.actualY = y * self.speed;
self.y = self.actualY;
};
});
var Particle = Container.expand(function (x, y, index) {
var self = Container.call(this, x, y);
self.index = index;
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
var angle = index % 20 * (Math.PI * 2 / 20);
self.fixedSpeed = 30;
self.angle = angle;
self._move_migrated = function () {
self.fixedSpeed *= 0.95;
self.x += Math.cos(self.angle) * self.fixedSpeed;
self.y += Math.sin(self.angle) * self.fixedSpeed;
self.cachedAlpha = (self.cachedAlpha || 3) - 0.04;
self.alpha = Math.max(0, self.cachedAlpha);
if (self.cachedAlpha <= 0) {
self.destroy();
}
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
self.targetX = self.x;
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.hasJumped = false;
self.jump = function () {
if (!self.hasJumped) {
self.speedy = -30;
self.hasJumped = true;
LK.getSound('swoosh').play();
}
};
self.fall = function () {};
self._update_migrated = function () {
var distance = Math.abs(self.x - self.targetX);
var speed = Math.max(1, distance / 25);
if (self.x < self.targetX) {
self.x += Math.min(speed, self.targetX - self.x);
playerGraphics.scale.x = -1;
} else if (self.x > self.targetX) {
self.x -= Math.min(speed, self.x - self.targetX);
playerGraphics.scale.x = 1;
}
self.y += self.speedy;
self.speedy += 0.28;
};
});
var ScoreText = Container.expand(function (score, x, y) {
var self = Container.call(this);
self.x = x;
self.y = y;
var scoreText = new Text2(score.toString(), {
size: 120,
fill: '#ffffff',
weight: 400,
stroke: '#000000',
strokeThickness: 10
});
scoreText.anchor.set(.5, .5);
scoreText.scale.set(0, 0);
self.addChild(scoreText);
var scaleIncrease = 0.05;
LK.on('tick', function () {
if (scoreText.scale.x < 1) {
scoreText.scale.x += scaleIncrease;
scoreText.scale.y += scaleIncrease;
}
});
self._move_migrated = function () {
self.alpha -= 0.02;
if (self.alpha <= 0) {
self.destroy();
}
};
});
var Snowflake = Container.expand(function () {
var self = Container.call(this);
var flakeGraphics = self.attachAsset('snowflake', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedy = Math.random() * 2 + 1;
self.speedx = Math.random() * 1 - 0.5;
self.rotationSpeed = Math.random() * 0.05 - 0.025;
self._move_migrated = function () {
self.y += self.speedy;
self.scale.set(self.speedy / 3, self.speedy / 3);
self.x += self.speedx;
self.rotation += self.rotationSpeed;
if (self.y > 2732 - self.parent.actualY) {
self.y = -50 - self.parent.actualY;
}
if (self.x > 2048) {
self.x = -50;
} else if (self.x < -50) {
self.x = 2048;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
game.bellSpeed = 5;
game.bellSpeedIncreaseFactor = 0.001;
game.totalTicks = 0;
game.layers = [];
var background = game.attachAsset('backgroundGraphics', {
anchorX: 0.5,
anchorY: 0.5
});
background.x = 2048 / 2;
background.y = 2732 / 2;
background.alpha = 0.5;
game.addChildAt(background, 0);
var mountains = game.addChild(new ParallaxLayer(.3 / 4 / 4 / 4));
var mountainGraphics = mountains.attachAsset('mountainGraphics', {
anchorX: 0.5,
anchorY: 1
});
mountainGraphics.x = 2048 / 2;
mountainGraphics.y = 2732;
mountains.addChild(mountainGraphics);
game.layers.push(mountains);
var valley = game.addChild(new ParallaxLayer(.3 / 4 / 4));
var valleyGraphics = valley.attachAsset('valleyGraphics', {
anchorX: 0.5,
anchorY: 1
});
valleyGraphics.x = 2048 / 2;
valleyGraphics.y = 2732;
valley.addChild(valleyGraphics);
game.layers.push(valley);
var forest = new ParallaxLayer(.3 / 2);
var forestGraphics = forest.attachAsset('forestGraphics', {
anchorX: 0.5,
anchorY: 1
});
forestGraphics.x = 2048 / 2;
forestGraphics.y = 2732 - 150 + 50;
forest.addChild(forestGraphics);
game.layers.push(forest);
var foreground = new ParallaxLayer();
game.layers.push(foreground);
game.particles = [];
for (var i = 0; i < 100; i++) {
var snowflake = new Snowflake();
snowflake.x = Math.random() * 2048;
snowflake.y = Math.random() * 2732;
forest.addChild(snowflake);
game.particles.push(snowflake);
}
var groundLayer = new ParallaxLayer(.3);
var groundGraphics = groundLayer.attachAsset('groundGraphics', {
anchorX: 0.5,
anchorY: 1
});
groundGraphics.x = 2048 / 2;
groundGraphics.y = 2732 + 195;
groundLayer.addChild(groundGraphics);
game.layers.push(groundLayer);
game.addChild(forest);
game.addChild(foreground);
game.addChild(groundLayer);
var player = foreground.addChild(new Player());
player.x = 2048 / 2;
player.targetX = player.x;
player.y = 2732 - player.height - 80;
game.score = 0;
scoreTxt = new Text2(LK.getScore().toString(), {
size: 150,
fill: "#ffffff",
weight: 800,
dropShadow: true,
dropShadowColor: '#000000',
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
scoreTxt.anchor.set(.5, 0);
LK.gui.top.addChild(scoreTxt);
var bells = [];
game.addBell = function () {
var lastBellY = bells.length > 0 ? bells[bells.length - 1].y : 2732;
var nextScore = bells.length > 0 ? bells[bells.length - 1].score + 1 : 1;
var bell = foreground.addChild(new Bell(nextScore));
bell.x = Math.random() * (2048 - bell.width);
bell.y = lastBellY - (Math.random() * (2732 / 4 - 2732 / 6) + 2732 / 6);
bells.push(bell);
};
for (var i = 0; i < 8; i++) {
game.addBell();
}
var player;
var scoreTxt;
var isGameOver = false;
LK.on('tick', function () {
player._update_migrated();
var targetParallaxValue = 1366 - player.y + 500;
var currentParallaxValue = foreground.actualY;
var parallaxDifference = targetParallaxValue - currentParallaxValue;
var parallaxSpeed = Math.max(1, Math.abs(parallaxDifference) / 10);
background.alpha = Math.min(1, (-2790 - player.y) / 500000 + 0.5);
if (currentParallaxValue < targetParallaxValue) {
game.layers.forEach(function (layer) {
layer.setParallaxY(currentParallaxValue + Math.min(parallaxSpeed, targetParallaxValue - currentParallaxValue));
});
}
for (var i = 0; i < bells.length; i++) {
bells[i]._move_migrated();
if (player.intersects(bells[i])) {
player.speedy = -15;
player.hasJumped = true;
var newScore = LK.getScore() + bells[i].score;
LK.setScore(newScore);
scoreTxt.setText(newScore.toString());
game.bellSpeed += game.bellSpeedIncreaseFactor;
for (var p = 0; p < 20; p++) {
var layerDeltaY = forest.actualY - foreground.actualY;
var particle = new Particle(bells[i].x, bells[i].y - layerDeltaY, p);
game.particles.push(particle);
forest.addChild(particle);
var scoreText = new ScoreText(bells[i].score, bells[i].x, bells[i].y - layerDeltaY);
game.particles.push(scoreText);
forest.addChild(scoreText);
}
// Play a bell chime sound
LK.getSound('bellChime').play();
bells[i].destroy();
bells.splice(i, 1);
game.addBell();
} else if (bells[i].y + foreground.actualY > 2832) {
bells[i].destroy();
bells.splice(i, 1);
game.addBell();
}
}
if (player.y + foreground.y > 2732) {
isGameOver = true;
}
game.particles.forEach(function (particle) {
particle._move_migrated();
if (particle.alpha <= 0) {
var index = game.particles.indexOf(particle);
if (index > -1) {
game.particles.splice(index, 1);
}
}
});
game.totalTicks++;
game.bellSpeed += game.bellSpeedIncreaseFactor;
if (isGameOver) {
LK.effects.flashScreen(0xffffff, 1000);
LK.showGameOver();
}
});
game.on('down', function (x, y, obj) {
var event = obj;
var pos = game.toLocal(event.global);
player.targetX = pos.x;
player.jump();
});
game.on('move', function (x, y, obj) {
var event = obj;
var pos = game.toLocal(event.global);
player.targetX = pos.x;
});
Tree line of snowy pine trees. Cartoon. Black background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Mountain valley with snowy trees. Scenic view. Nighttime. Cartoon. Black background. New moon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Background mountains, nighttime, snow topped Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d platform snowy ground. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cute cartoon rabbit, jumping upwards facing camera. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Starry night sky, northern lights, looking up. Cartoon style. Above clouds Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single White Christmas bell. White decorations. Cartoon. Outline Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
White Simple Cartoon snowflake Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.