/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Castle = Container.expand(function () {
var self = Container.call(this);
var castleGraphics = self.attachAsset('castle', {
anchorX: 0.5,
anchorY: 1
});
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 10;
self.bobOffset = Math.random() * Math.PI * 2;
self.update = function () {
// Bobbing animation
self.y += Math.sin(LK.ticks * 0.1 + self.bobOffset) * 0.5;
// Rotate
coinGraphics.rotation += 0.1;
};
return self;
});
var Elf = Container.expand(function () {
var self = Container.call(this);
var elfGraphics = self.attachAsset('elf', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 2;
self.speed = 2;
self.shootCooldown = 0;
self.direction = 1;
self.update = function () {
// Move towards player
if (player.y > self.y) {
self.y += self.speed;
}
// Side to side movement
self.x += self.direction * 1;
if (self.x <= 100 || self.x >= 1948) {
self.direction *= -1;
}
// Shoot at player
if (self.shootCooldown <= 0 && Math.random() < 0.02) {
self.shoot();
self.shootCooldown = 60;
} else {
self.shootCooldown--;
}
};
self.shoot = function () {
var bullet = new ElfBullet();
bullet.x = self.x;
bullet.y = self.y + 40;
elfBullets.push(bullet);
game.addChild(bullet);
};
self.takeDamage = function (damage) {
self.health -= damage;
LK.effects.flashObject(self, 0xFF0000, 200);
if (self.health <= 0) {
self.die();
}
};
self.die = function () {
// Drop coin
var coin = new Coin();
coin.x = self.x;
coin.y = self.y;
coins.push(coin);
game.addChild(coin);
// Remove from array
for (var i = elves.length - 1; i >= 0; i--) {
if (elves[i] === self) {
elves.splice(i, 1);
break;
}
}
self.destroy();
elvesKilled++;
};
return self;
});
var ElfBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('elfBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 3;
self.maxHealth = 3;
self.damage = 1;
self.speed = 8;
self.shootCooldown = 0;
self.update = function () {
// Move based on drag position if being dragged
if (self.isDragging && dragTarget === self) {
// Movement is handled in game.move
}
// Auto-shoot
if (self.shootCooldown <= 0) {
self.shoot();
self.shootCooldown = 15; // Shoot every 15 frames
} else {
self.shootCooldown--;
}
};
self.shoot = function () {
// Don't shoot bullets if game hasn't started yet
if (!gameStarted) {
return;
}
var bullet = new PlayerBullet();
bullet.x = self.x;
bullet.y = self.y - 50;
bullet.damage = self.damage;
playerBullets.push(bullet);
game.addChild(bullet);
LK.getSound('shoot').play();
};
self.takeDamage = function () {
self.health--;
LK.effects.flashObject(self, 0xFF0000, 500);
LK.getSound('hit').play();
updateHealthDisplay();
if (self.health <= 0) {
LK.showGameOver();
}
};
self.heal = function () {
if (self.health < self.maxHealth) {
self.health++;
updateHealthDisplay();
LK.effects.flashObject(self, 0x00FF00, 500);
}
};
return self;
});
var PlayerBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 12;
self.damage = 1;
self.update = function () {
self.y -= self.speed;
};
return self;
});
var Santa = Container.expand(function () {
var self = Container.call(this);
var santaGraphics = self.attachAsset('santa', {
anchorX: 0.5,
anchorY: 0.5
});
self.captured = false;
return self;
});
var Snowflake = Container.expand(function () {
var self = Container.call(this);
var snowGraphics = self.attachAsset('snowflake', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 3 + 1;
self.drift = Math.random() * 2 - 1;
self.update = function () {
self.y += self.speed;
self.x += self.drift;
// Reset when off screen
if (self.y > 2800) {
self.y = -50;
self.x = Math.random() * 2048;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var player;
var elves = [];
var playerBullets = [];
var elfBullets = [];
var coins = [];
var snowflakes = [];
var castle;
var santa;
var money = 0;
var elvesKilled = 0;
var gamePhase = 'combat'; // 'combat', 'castle', 'victory'
var dragTarget = null;
var shopVisible = false;
var healthPotionCost = 50;
var strengthUpgradeCost = 100;
var speedPotionCost = 75;
var gameTimer = 60 * 60; // 60 seconds at 60 FPS
var santaSpawned = false;
var gameStarted = false;
var gamePaused = false;
var gameState = 'start'; // 'start', 'playing', 'shop'
// UI Elements
var moneyText = new Text2('Money: $0', {
size: 60,
fill: 0xFFD700
});
moneyText.anchor.set(1, 0);
moneyText.x = -20;
LK.gui.topRight.addChild(moneyText);
var healthText = new Text2('Health: 3/3', {
size: 60,
fill: 0xFF1744
});
healthText.anchor.set(0, 0);
healthText.x = 120; // Move away from top-left menu icon
LK.gui.top.addChild(healthText);
var timerText = new Text2('Time: 60s', {
size: 60,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0);
LK.gui.top.addChild(timerText);
var shopButton = game.addChild(LK.getAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1750,
y: 2550,
scaleX: 2.5,
scaleY: 2.5
}));
shopButton.visible = false; // Hide shop button during start screen
var shopText = new Text2('SHOP', {
size: 70,
fill: 0xFFFFFF
});
shopText.anchor.set(0.5, 0.5);
shopText.x = shopButton.x;
shopText.y = shopButton.y;
shopText.visible = false; // Hide shop text during start screen
game.addChild(shopText);
// Shop background (initially hidden)
var shopBackground = game.addChild(LK.getAsset('shopBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
scaleX: 1.5,
scaleY: 1.5
}));
shopBackground.visible = false;
// Start screen visuals
var startScreenSanta = game.addChild(LK.getAsset('santa', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 - 200,
y: 1000,
scaleX: 2,
scaleY: 2
}));
var startScreenPlayer = game.addChild(LK.getAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 + 200,
y: 1000,
scaleX: 2,
scaleY: 2
}));
// Start screen background houses
var startScreenHouses = game.addChild(LK.getAsset('houses', {
anchorX: 0.5,
anchorY: 1,
x: 1024,
y: 800,
scaleX: 2,
scaleY: 2
}));
// Start button
var startButton = game.addChild(LK.getAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
scaleX: 3,
scaleY: 3
}));
var startText = new Text2('START', {
size: 80,
fill: 0xFFFFFF
});
startText.anchor.set(0.5, 0.5);
startText.x = startButton.x;
startText.y = startButton.y;
game.addChild(startText);
// Shop items (initially hidden)
var healthPotionButton = game.addChild(LK.getAsset('healthPotion', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
scaleX: 2,
scaleY: 2
}));
healthPotionButton.visible = false;
var strengthUpgradeButton = game.addChild(LK.getAsset('strengthUpgrade', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 + 200,
y: 1366,
scaleX: 2,
scaleY: 2
}));
strengthUpgradeButton.visible = false;
var speedPotionButton = game.addChild(LK.getAsset('healthPotion', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 - 200,
y: 1366,
scaleX: 2,
scaleY: 2,
tint: 0x00FFFF
}));
speedPotionButton.visible = false;
var healthPotionText = new Text2('Health Potion\n$' + healthPotionCost, {
size: 60,
fill: 0xFFFFFF
});
healthPotionText.anchor.set(0.5, 0.5);
healthPotionText.x = healthPotionButton.x;
healthPotionText.y = healthPotionButton.y + 120;
healthPotionText.visible = false;
game.addChild(healthPotionText);
var strengthUpgradeText = new Text2('Strength Upgrade\n$' + strengthUpgradeCost, {
size: 60,
fill: 0xFFFFFF
});
strengthUpgradeText.anchor.set(0.5, 0.5);
strengthUpgradeText.x = strengthUpgradeButton.x;
strengthUpgradeText.y = strengthUpgradeButton.y + 120;
strengthUpgradeText.visible = false;
game.addChild(strengthUpgradeText);
var speedPotionText = new Text2('Speed Potion\n$' + speedPotionCost, {
size: 60,
fill: 0xFFFFFF
});
speedPotionText.anchor.set(0.5, 0.5);
speedPotionText.x = speedPotionButton.x;
speedPotionText.y = speedPotionButton.y + 120;
speedPotionText.visible = false;
game.addChild(speedPotionText);
// Initialize player
player = game.addChild(new Player());
player.x = 1024;
player.y = 2400;
player.visible = false; // Hide player during start screen
// Create snow effect
for (var i = 0; i < 50; i++) {
var snowflake = new Snowflake();
snowflake.x = Math.random() * 2048;
snowflake.y = Math.random() * 2732;
snowflake.visible = false; // Hide snowflakes during start screen
snowflakes.push(snowflake);
game.addChild(snowflake);
}
// Functions
function updateMoneyDisplay() {
moneyText.setText('Money: $' + money);
}
function updateHealthDisplay() {
healthText.setText('Health: ' + player.health + '/' + player.maxHealth);
}
function updateTimerDisplay() {
var seconds = Math.ceil(gameTimer / 60);
timerText.setText('Time: ' + seconds + 's');
}
function spawnElf() {
var elf = new Elf();
elf.x = Math.random() * 1848 + 100;
elf.y = Math.random() * 500 + 100;
elves.push(elf);
game.addChild(elf);
}
function toggleShop() {
shopVisible = !shopVisible;
if (shopVisible) {
gameState = 'shop';
gamePaused = true;
} else {
gameState = 'playing';
gamePaused = false;
}
shopBackground.visible = shopVisible;
healthPotionButton.visible = shopVisible;
strengthUpgradeButton.visible = shopVisible;
speedPotionButton.visible = shopVisible;
healthPotionText.visible = shopVisible;
strengthUpgradeText.visible = shopVisible;
speedPotionText.visible = shopVisible;
}
function buyHealthPotion() {
if (money >= healthPotionCost && player.health < player.maxHealth) {
money -= healthPotionCost;
player.heal();
updateMoneyDisplay();
LK.getSound('purchase').play();
// Visual feedback
tween(healthPotionButton, {
scaleX: 2.2,
scaleY: 2.2
}, {
duration: 100,
onFinish: function onFinish() {
tween(healthPotionButton, {
scaleX: 2,
scaleY: 2
}, {
duration: 100
});
}
});
}
}
function buyStrengthUpgrade() {
if (money >= strengthUpgradeCost) {
money -= strengthUpgradeCost;
player.damage++;
strengthUpgradeCost += 50; // Increase cost for next upgrade
strengthUpgradeText.setText('Strength Upgrade\n$' + strengthUpgradeCost);
updateMoneyDisplay();
LK.getSound('purchase').play();
// Visual feedback
tween(strengthUpgradeButton, {
scaleX: 2.2,
scaleY: 2.2
}, {
duration: 100,
onFinish: function onFinish() {
tween(strengthUpgradeButton, {
scaleX: 2,
scaleY: 2
}, {
duration: 100
});
}
});
}
}
function buySpeedPotion() {
if (money >= speedPotionCost) {
money -= speedPotionCost;
gameTimer = Math.max(gameTimer - 600, 0); // Remove 10 seconds (600 frames)
updateMoneyDisplay();
LK.getSound('purchase').play();
// Visual feedback
tween(speedPotionButton, {
scaleX: 2.2,
scaleY: 2.2
}, {
duration: 100,
onFinish: function onFinish() {
tween(speedPotionButton, {
scaleX: 2,
scaleY: 2
}, {
duration: 100
});
}
});
}
}
function checkVictoryCondition() {
if (elvesKilled >= 20 && gamePhase === 'combat') {
gamePhase = 'castle';
// Clear remaining elves and bullets
for (var i = elves.length - 1; i >= 0; i--) {
elves[i].destroy();
}
elves = [];
for (var j = elfBullets.length - 1; j >= 0; j--) {
elfBullets[j].destroy();
}
elfBullets = [];
// Create castle
castle = game.addChild(new Castle());
castle.x = 1024;
castle.y = 800;
// Create Santa
santa = game.addChild(new Santa());
santa.x = 1024;
santa.y = 600;
}
}
// Event handlers
shopButton.down = function (x, y, obj) {
toggleShop();
};
healthPotionButton.down = function (x, y, obj) {
buyHealthPotion();
};
strengthUpgradeButton.down = function (x, y, obj) {
buyStrengthUpgrade();
};
speedPotionButton.down = function (x, y, obj) {
buySpeedPotion();
};
startButton.down = function (x, y, obj) {
if (!gameStarted) {
gameStarted = true;
gameState = 'playing';
// Hide start screen elements
startButton.visible = false;
startText.visible = false;
startScreenSanta.visible = false;
startScreenPlayer.visible = false;
startScreenHouses.visible = false;
// Show game elements
player.visible = true;
shopButton.visible = true;
shopText.visible = true;
// Show all snowflakes
for (var i = 0; i < snowflakes.length; i++) {
snowflakes[i].visible = true;
}
}
};
game.down = function (x, y, obj) {
dragTarget = player;
player.isDragging = true;
};
game.move = function (x, y, obj) {
if (dragTarget === player && player.isDragging) {
player.x = x;
player.y = y;
// Keep player in bounds
if (player.x < 50) player.x = 50;
if (player.x > 1998) player.x = 1998;
if (player.y < 50) player.y = 50;
if (player.y > 2682) player.y = 2682;
}
};
game.up = function (x, y, obj) {
dragTarget = null;
if (player) player.isDragging = false;
};
// Main game update
game.update = function () {
try {
// Don't update game if in start state or shop state
if (gameState === 'start' || gameState === 'shop') {
return;
}
// Don't spawn enemies or update game logic if not started
if (!gameStarted) {
return;
}
// Update timer
if (gameTimer > 0) {
gameTimer--;
updateTimerDisplay();
}
// Spawn Santa when timer reaches 0
if (gameTimer <= 0 && !santaSpawned && gamePhase === 'combat') {
santaSpawned = true;
gamePhase = 'castle';
// Clear remaining elves and bullets
for (var i = elves.length - 1; i >= 0; i--) {
elves[i].destroy();
}
elves = [];
for (var j = elfBullets.length - 1; j >= 0; j--) {
elfBullets[j].destroy();
}
elfBullets = [];
// Create castle with animation
castle = game.addChild(new Castle());
castle.x = 1024;
castle.y = 800;
castle.alpha = 0;
tween(castle, {
alpha: 1
}, {
duration: 1000
});
// Create Santa with animation
santa = game.addChild(new Santa());
santa.x = 1024;
santa.y = 600;
santa.alpha = 0;
tween(santa, {
alpha: 1
}, {
duration: 1500
});
}
// Spawn elves periodically during combat phase
if (gamePhase === 'combat' && LK.ticks % 120 === 0 && elves.length < 6) {
spawnElf();
}
// Update player bullets
for (var i = playerBullets.length - 1; i >= 0; i--) {
var bullet = playerBullets[i];
if (bullet.y < -50) {
bullet.destroy();
playerBullets.splice(i, 1);
continue;
}
// Check collision with elves
for (var j = elves.length - 1; j >= 0; j--) {
if (bullet.intersects(elves[j])) {
elves[j].takeDamage(bullet.damage);
bullet.destroy();
playerBullets.splice(i, 1);
break;
}
}
}
// Update elf bullets
for (var k = elfBullets.length - 1; k >= 0; k--) {
var elfBullet = elfBullets[k];
if (elfBullet.y > 2782) {
elfBullet.destroy();
elfBullets.splice(k, 1);
continue;
}
// Check collision with player
if (elfBullet.intersects(player)) {
player.takeDamage();
elfBullet.destroy();
elfBullets.splice(k, 1);
}
}
// Update coins
for (var l = coins.length - 1; l >= 0; l--) {
var coin = coins[l];
// Make coins move toward player automatically
var dx = player.x - coin.x;
var dy = player.y - coin.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
var speed = 8; // Coin collection speed
coin.x += dx / distance * speed;
coin.y += dy / distance * speed;
}
if (coin.intersects(player)) {
money += coin.value;
updateMoneyDisplay();
LK.getSound('coin').play();
coin.destroy();
coins.splice(l, 1);
}
}
// Check collision with elves
for (var m = elves.length - 1; m >= 0; m--) {
if (elves[m].intersects(player)) {
player.takeDamage();
elves[m].die();
}
}
// Castle phase - check if player reaches Santa
if (gamePhase === 'castle' && santa && player.intersects(santa)) {
gamePhase = 'victory';
LK.showYouWin();
}
checkVictoryCondition();
} catch (error) {
console.log('Game update error:', error);
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Castle = Container.expand(function () {
var self = Container.call(this);
var castleGraphics = self.attachAsset('castle', {
anchorX: 0.5,
anchorY: 1
});
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 10;
self.bobOffset = Math.random() * Math.PI * 2;
self.update = function () {
// Bobbing animation
self.y += Math.sin(LK.ticks * 0.1 + self.bobOffset) * 0.5;
// Rotate
coinGraphics.rotation += 0.1;
};
return self;
});
var Elf = Container.expand(function () {
var self = Container.call(this);
var elfGraphics = self.attachAsset('elf', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 2;
self.speed = 2;
self.shootCooldown = 0;
self.direction = 1;
self.update = function () {
// Move towards player
if (player.y > self.y) {
self.y += self.speed;
}
// Side to side movement
self.x += self.direction * 1;
if (self.x <= 100 || self.x >= 1948) {
self.direction *= -1;
}
// Shoot at player
if (self.shootCooldown <= 0 && Math.random() < 0.02) {
self.shoot();
self.shootCooldown = 60;
} else {
self.shootCooldown--;
}
};
self.shoot = function () {
var bullet = new ElfBullet();
bullet.x = self.x;
bullet.y = self.y + 40;
elfBullets.push(bullet);
game.addChild(bullet);
};
self.takeDamage = function (damage) {
self.health -= damage;
LK.effects.flashObject(self, 0xFF0000, 200);
if (self.health <= 0) {
self.die();
}
};
self.die = function () {
// Drop coin
var coin = new Coin();
coin.x = self.x;
coin.y = self.y;
coins.push(coin);
game.addChild(coin);
// Remove from array
for (var i = elves.length - 1; i >= 0; i--) {
if (elves[i] === self) {
elves.splice(i, 1);
break;
}
}
self.destroy();
elvesKilled++;
};
return self;
});
var ElfBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('elfBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 3;
self.maxHealth = 3;
self.damage = 1;
self.speed = 8;
self.shootCooldown = 0;
self.update = function () {
// Move based on drag position if being dragged
if (self.isDragging && dragTarget === self) {
// Movement is handled in game.move
}
// Auto-shoot
if (self.shootCooldown <= 0) {
self.shoot();
self.shootCooldown = 15; // Shoot every 15 frames
} else {
self.shootCooldown--;
}
};
self.shoot = function () {
// Don't shoot bullets if game hasn't started yet
if (!gameStarted) {
return;
}
var bullet = new PlayerBullet();
bullet.x = self.x;
bullet.y = self.y - 50;
bullet.damage = self.damage;
playerBullets.push(bullet);
game.addChild(bullet);
LK.getSound('shoot').play();
};
self.takeDamage = function () {
self.health--;
LK.effects.flashObject(self, 0xFF0000, 500);
LK.getSound('hit').play();
updateHealthDisplay();
if (self.health <= 0) {
LK.showGameOver();
}
};
self.heal = function () {
if (self.health < self.maxHealth) {
self.health++;
updateHealthDisplay();
LK.effects.flashObject(self, 0x00FF00, 500);
}
};
return self;
});
var PlayerBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 12;
self.damage = 1;
self.update = function () {
self.y -= self.speed;
};
return self;
});
var Santa = Container.expand(function () {
var self = Container.call(this);
var santaGraphics = self.attachAsset('santa', {
anchorX: 0.5,
anchorY: 0.5
});
self.captured = false;
return self;
});
var Snowflake = Container.expand(function () {
var self = Container.call(this);
var snowGraphics = self.attachAsset('snowflake', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 3 + 1;
self.drift = Math.random() * 2 - 1;
self.update = function () {
self.y += self.speed;
self.x += self.drift;
// Reset when off screen
if (self.y > 2800) {
self.y = -50;
self.x = Math.random() * 2048;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var player;
var elves = [];
var playerBullets = [];
var elfBullets = [];
var coins = [];
var snowflakes = [];
var castle;
var santa;
var money = 0;
var elvesKilled = 0;
var gamePhase = 'combat'; // 'combat', 'castle', 'victory'
var dragTarget = null;
var shopVisible = false;
var healthPotionCost = 50;
var strengthUpgradeCost = 100;
var speedPotionCost = 75;
var gameTimer = 60 * 60; // 60 seconds at 60 FPS
var santaSpawned = false;
var gameStarted = false;
var gamePaused = false;
var gameState = 'start'; // 'start', 'playing', 'shop'
// UI Elements
var moneyText = new Text2('Money: $0', {
size: 60,
fill: 0xFFD700
});
moneyText.anchor.set(1, 0);
moneyText.x = -20;
LK.gui.topRight.addChild(moneyText);
var healthText = new Text2('Health: 3/3', {
size: 60,
fill: 0xFF1744
});
healthText.anchor.set(0, 0);
healthText.x = 120; // Move away from top-left menu icon
LK.gui.top.addChild(healthText);
var timerText = new Text2('Time: 60s', {
size: 60,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0);
LK.gui.top.addChild(timerText);
var shopButton = game.addChild(LK.getAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1750,
y: 2550,
scaleX: 2.5,
scaleY: 2.5
}));
shopButton.visible = false; // Hide shop button during start screen
var shopText = new Text2('SHOP', {
size: 70,
fill: 0xFFFFFF
});
shopText.anchor.set(0.5, 0.5);
shopText.x = shopButton.x;
shopText.y = shopButton.y;
shopText.visible = false; // Hide shop text during start screen
game.addChild(shopText);
// Shop background (initially hidden)
var shopBackground = game.addChild(LK.getAsset('shopBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
scaleX: 1.5,
scaleY: 1.5
}));
shopBackground.visible = false;
// Start screen visuals
var startScreenSanta = game.addChild(LK.getAsset('santa', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 - 200,
y: 1000,
scaleX: 2,
scaleY: 2
}));
var startScreenPlayer = game.addChild(LK.getAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 + 200,
y: 1000,
scaleX: 2,
scaleY: 2
}));
// Start screen background houses
var startScreenHouses = game.addChild(LK.getAsset('houses', {
anchorX: 0.5,
anchorY: 1,
x: 1024,
y: 800,
scaleX: 2,
scaleY: 2
}));
// Start button
var startButton = game.addChild(LK.getAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
scaleX: 3,
scaleY: 3
}));
var startText = new Text2('START', {
size: 80,
fill: 0xFFFFFF
});
startText.anchor.set(0.5, 0.5);
startText.x = startButton.x;
startText.y = startButton.y;
game.addChild(startText);
// Shop items (initially hidden)
var healthPotionButton = game.addChild(LK.getAsset('healthPotion', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
scaleX: 2,
scaleY: 2
}));
healthPotionButton.visible = false;
var strengthUpgradeButton = game.addChild(LK.getAsset('strengthUpgrade', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 + 200,
y: 1366,
scaleX: 2,
scaleY: 2
}));
strengthUpgradeButton.visible = false;
var speedPotionButton = game.addChild(LK.getAsset('healthPotion', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 - 200,
y: 1366,
scaleX: 2,
scaleY: 2,
tint: 0x00FFFF
}));
speedPotionButton.visible = false;
var healthPotionText = new Text2('Health Potion\n$' + healthPotionCost, {
size: 60,
fill: 0xFFFFFF
});
healthPotionText.anchor.set(0.5, 0.5);
healthPotionText.x = healthPotionButton.x;
healthPotionText.y = healthPotionButton.y + 120;
healthPotionText.visible = false;
game.addChild(healthPotionText);
var strengthUpgradeText = new Text2('Strength Upgrade\n$' + strengthUpgradeCost, {
size: 60,
fill: 0xFFFFFF
});
strengthUpgradeText.anchor.set(0.5, 0.5);
strengthUpgradeText.x = strengthUpgradeButton.x;
strengthUpgradeText.y = strengthUpgradeButton.y + 120;
strengthUpgradeText.visible = false;
game.addChild(strengthUpgradeText);
var speedPotionText = new Text2('Speed Potion\n$' + speedPotionCost, {
size: 60,
fill: 0xFFFFFF
});
speedPotionText.anchor.set(0.5, 0.5);
speedPotionText.x = speedPotionButton.x;
speedPotionText.y = speedPotionButton.y + 120;
speedPotionText.visible = false;
game.addChild(speedPotionText);
// Initialize player
player = game.addChild(new Player());
player.x = 1024;
player.y = 2400;
player.visible = false; // Hide player during start screen
// Create snow effect
for (var i = 0; i < 50; i++) {
var snowflake = new Snowflake();
snowflake.x = Math.random() * 2048;
snowflake.y = Math.random() * 2732;
snowflake.visible = false; // Hide snowflakes during start screen
snowflakes.push(snowflake);
game.addChild(snowflake);
}
// Functions
function updateMoneyDisplay() {
moneyText.setText('Money: $' + money);
}
function updateHealthDisplay() {
healthText.setText('Health: ' + player.health + '/' + player.maxHealth);
}
function updateTimerDisplay() {
var seconds = Math.ceil(gameTimer / 60);
timerText.setText('Time: ' + seconds + 's');
}
function spawnElf() {
var elf = new Elf();
elf.x = Math.random() * 1848 + 100;
elf.y = Math.random() * 500 + 100;
elves.push(elf);
game.addChild(elf);
}
function toggleShop() {
shopVisible = !shopVisible;
if (shopVisible) {
gameState = 'shop';
gamePaused = true;
} else {
gameState = 'playing';
gamePaused = false;
}
shopBackground.visible = shopVisible;
healthPotionButton.visible = shopVisible;
strengthUpgradeButton.visible = shopVisible;
speedPotionButton.visible = shopVisible;
healthPotionText.visible = shopVisible;
strengthUpgradeText.visible = shopVisible;
speedPotionText.visible = shopVisible;
}
function buyHealthPotion() {
if (money >= healthPotionCost && player.health < player.maxHealth) {
money -= healthPotionCost;
player.heal();
updateMoneyDisplay();
LK.getSound('purchase').play();
// Visual feedback
tween(healthPotionButton, {
scaleX: 2.2,
scaleY: 2.2
}, {
duration: 100,
onFinish: function onFinish() {
tween(healthPotionButton, {
scaleX: 2,
scaleY: 2
}, {
duration: 100
});
}
});
}
}
function buyStrengthUpgrade() {
if (money >= strengthUpgradeCost) {
money -= strengthUpgradeCost;
player.damage++;
strengthUpgradeCost += 50; // Increase cost for next upgrade
strengthUpgradeText.setText('Strength Upgrade\n$' + strengthUpgradeCost);
updateMoneyDisplay();
LK.getSound('purchase').play();
// Visual feedback
tween(strengthUpgradeButton, {
scaleX: 2.2,
scaleY: 2.2
}, {
duration: 100,
onFinish: function onFinish() {
tween(strengthUpgradeButton, {
scaleX: 2,
scaleY: 2
}, {
duration: 100
});
}
});
}
}
function buySpeedPotion() {
if (money >= speedPotionCost) {
money -= speedPotionCost;
gameTimer = Math.max(gameTimer - 600, 0); // Remove 10 seconds (600 frames)
updateMoneyDisplay();
LK.getSound('purchase').play();
// Visual feedback
tween(speedPotionButton, {
scaleX: 2.2,
scaleY: 2.2
}, {
duration: 100,
onFinish: function onFinish() {
tween(speedPotionButton, {
scaleX: 2,
scaleY: 2
}, {
duration: 100
});
}
});
}
}
function checkVictoryCondition() {
if (elvesKilled >= 20 && gamePhase === 'combat') {
gamePhase = 'castle';
// Clear remaining elves and bullets
for (var i = elves.length - 1; i >= 0; i--) {
elves[i].destroy();
}
elves = [];
for (var j = elfBullets.length - 1; j >= 0; j--) {
elfBullets[j].destroy();
}
elfBullets = [];
// Create castle
castle = game.addChild(new Castle());
castle.x = 1024;
castle.y = 800;
// Create Santa
santa = game.addChild(new Santa());
santa.x = 1024;
santa.y = 600;
}
}
// Event handlers
shopButton.down = function (x, y, obj) {
toggleShop();
};
healthPotionButton.down = function (x, y, obj) {
buyHealthPotion();
};
strengthUpgradeButton.down = function (x, y, obj) {
buyStrengthUpgrade();
};
speedPotionButton.down = function (x, y, obj) {
buySpeedPotion();
};
startButton.down = function (x, y, obj) {
if (!gameStarted) {
gameStarted = true;
gameState = 'playing';
// Hide start screen elements
startButton.visible = false;
startText.visible = false;
startScreenSanta.visible = false;
startScreenPlayer.visible = false;
startScreenHouses.visible = false;
// Show game elements
player.visible = true;
shopButton.visible = true;
shopText.visible = true;
// Show all snowflakes
for (var i = 0; i < snowflakes.length; i++) {
snowflakes[i].visible = true;
}
}
};
game.down = function (x, y, obj) {
dragTarget = player;
player.isDragging = true;
};
game.move = function (x, y, obj) {
if (dragTarget === player && player.isDragging) {
player.x = x;
player.y = y;
// Keep player in bounds
if (player.x < 50) player.x = 50;
if (player.x > 1998) player.x = 1998;
if (player.y < 50) player.y = 50;
if (player.y > 2682) player.y = 2682;
}
};
game.up = function (x, y, obj) {
dragTarget = null;
if (player) player.isDragging = false;
};
// Main game update
game.update = function () {
try {
// Don't update game if in start state or shop state
if (gameState === 'start' || gameState === 'shop') {
return;
}
// Don't spawn enemies or update game logic if not started
if (!gameStarted) {
return;
}
// Update timer
if (gameTimer > 0) {
gameTimer--;
updateTimerDisplay();
}
// Spawn Santa when timer reaches 0
if (gameTimer <= 0 && !santaSpawned && gamePhase === 'combat') {
santaSpawned = true;
gamePhase = 'castle';
// Clear remaining elves and bullets
for (var i = elves.length - 1; i >= 0; i--) {
elves[i].destroy();
}
elves = [];
for (var j = elfBullets.length - 1; j >= 0; j--) {
elfBullets[j].destroy();
}
elfBullets = [];
// Create castle with animation
castle = game.addChild(new Castle());
castle.x = 1024;
castle.y = 800;
castle.alpha = 0;
tween(castle, {
alpha: 1
}, {
duration: 1000
});
// Create Santa with animation
santa = game.addChild(new Santa());
santa.x = 1024;
santa.y = 600;
santa.alpha = 0;
tween(santa, {
alpha: 1
}, {
duration: 1500
});
}
// Spawn elves periodically during combat phase
if (gamePhase === 'combat' && LK.ticks % 120 === 0 && elves.length < 6) {
spawnElf();
}
// Update player bullets
for (var i = playerBullets.length - 1; i >= 0; i--) {
var bullet = playerBullets[i];
if (bullet.y < -50) {
bullet.destroy();
playerBullets.splice(i, 1);
continue;
}
// Check collision with elves
for (var j = elves.length - 1; j >= 0; j--) {
if (bullet.intersects(elves[j])) {
elves[j].takeDamage(bullet.damage);
bullet.destroy();
playerBullets.splice(i, 1);
break;
}
}
}
// Update elf bullets
for (var k = elfBullets.length - 1; k >= 0; k--) {
var elfBullet = elfBullets[k];
if (elfBullet.y > 2782) {
elfBullet.destroy();
elfBullets.splice(k, 1);
continue;
}
// Check collision with player
if (elfBullet.intersects(player)) {
player.takeDamage();
elfBullet.destroy();
elfBullets.splice(k, 1);
}
}
// Update coins
for (var l = coins.length - 1; l >= 0; l--) {
var coin = coins[l];
// Make coins move toward player automatically
var dx = player.x - coin.x;
var dy = player.y - coin.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
var speed = 8; // Coin collection speed
coin.x += dx / distance * speed;
coin.y += dy / distance * speed;
}
if (coin.intersects(player)) {
money += coin.value;
updateMoneyDisplay();
LK.getSound('coin').play();
coin.destroy();
coins.splice(l, 1);
}
}
// Check collision with elves
for (var m = elves.length - 1; m >= 0; m--) {
if (elves[m].intersects(player)) {
player.takeDamage();
elves[m].die();
}
}
// Castle phase - check if player reaches Santa
if (gamePhase === 'castle' && santa && player.intersects(santa)) {
gamePhase = 'victory';
LK.showYouWin();
}
checkVictoryCondition();
} catch (error) {
console.log('Game update error:', error);
}
};
coin. In-Game asset. 2d. High contrast. No shadows
noel castle. In-Game asset. 2d. High contrast. No shadows
santa. In-Game asset. 2d. High contrast. No shadows
snowfulke. In-Game asset. 2d. High contrast. No shadows
healtPoiton. In-Game asset. 2d. High contrast. No shadows
pixel heart. In-Game asset. 2d. High contrast. No shadows
pixel player. In-Game asset. 2d. High contrast. No shadows
pixel shop background. In-Game asset. 2d. High contrast. No shadows
speed poiton. In-Game asset. 2d. High contrast. No shadows
streng poiton. In-Game asset. 2d. High contrast. No shadows
pixel elf. In-Game asset. 2d. High contrast. No shadows
christmas house. In-Game asset. 2d. High contrast. No shadows