/**** * Plugins ****/ var storage = LK.import("@upit/storage.v1", { coins: 0, score: 0, towerLevels: [1, 1, 1, 1, 1], towerCosts: [100, 100, 100, 100, 100], enemySpeedIncrement: 0 }); /**** * Classes ****/ var Base = Container.expand(function () { var self = Container.call(this); self.health = 100; self.updateHealth = function () {}; }); var Enemy = Container.expand(function (spawnerInstance, gameInstance) { var self = Container.call(this); self.showExplosion = function () { self.gameInstance.showExplosion(self.x, self.y); self.destroy(); }; self.gameInstance = gameInstance; var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.tiltDirection = 1; self._move_migrated = function () { self.y += self.speed; self.rotation += 0.005 * self.tiltDirection; if (self.rotation > 0.15 || self.rotation < -0.15) { self.tiltDirection *= -1; } }; self.on('down', function () { self.destroyEnemy(); }); self.destroyEnemy = function () { self.showExplosion(); LK.getSound('Hit').play(); self.gameInstance.updateCoins(10 + self.gameInstance.enemyRewardIncrement); self.gameInstance.removeEnemy(self); self.gameInstance.incrementScore(); }; }); var Enemy_2 = Container.expand(function (spawnerInstance, gameInstance) { var self = Container.call(this); self.showExplosion = function () { self.gameInstance.showExplosion(self.x, self.y); self.destroy(); }; self.gameInstance = gameInstance; var enemyGraphics = self.attachAsset('enemy_2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 6; self.tiltDirection = 1; self._move_migrated = function () { self.y += self.speed; self.rotation += 0.005 * self.tiltDirection; if (self.rotation > 0.15 || self.rotation < -0.15) { self.tiltDirection *= -1; } }; self.on('down', function () { self.destroyEnemy(); }); self.destroyEnemy = function () { self.showExplosion(); LK.getSound('Hit').play(); self.gameInstance.updateCoins(20 + self.gameInstance.enemyRewardIncrement); self.gameInstance.removeEnemy(self); self.gameInstance.incrementScore(); }; }); var Enemy_3 = Container.expand(function (spawnerInstance, gameInstance) { var self = Container.call(this); self.showExplosion = function () { self.gameInstance.showExplosion(self.x, self.y); self.destroy(); }; self.gameInstance = gameInstance; var enemyGraphics = self.attachAsset('enemy_3', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.tiltDirection = 1; self._move_migrated = function () { self.y += self.speed; self.rotation += 0.005 * self.tiltDirection; if (self.rotation > 0.15 || self.rotation < -0.15) { self.tiltDirection *= -1; } }; self.on('down', function () { self.destroyEnemy(); }); self.destroyEnemy = function () { self.showExplosion(); LK.getSound('Hit').play(); self.gameInstance.updateCoins(30 + self.gameInstance.enemyRewardIncrement); self.gameInstance.removeEnemy(self); self.gameInstance.incrementScore(); }; }); var Snowball = Container.expand(function (speed) { var self = Container.call(this); self.x = arguments[1]; self.y = arguments[2]; self.speed = speed; self.rotationSpeed = 0.05; var snowballGraphics = self.attachAsset('snowball', { anchorX: 0.5, anchorY: 0.5 }); self._move_migrated = function () { self.rotation += self.rotationSpeed; }; }); var Spawner = Container.expand(function (x, y) { var self = Container.call(this); var spawnerGraphics = self.attachAsset('spawner', { anchorX: 0.5, anchorY: 0.5 }); self.x = x; self.y = y; self.enemyWeights = { 'Enemy': 70, 'Enemy_2': 21, 'Enemy_3': 9, 'total': 100, 'bucket': [] }; self.resetEnemyBucket = function () { for (var key in self.enemyWeights) { if (key !== 'total' && key !== 'bucket') { for (var i = 0; i < self.enemyWeights[key]; i++) { self.enemyWeights.bucket.push(key); } } } }; self.resetEnemyBucket(); self.spawnEnemy = function () { if (self.enemyWeights.bucket.length === 0) { self.resetEnemyBucket(); } var randomIndex = Math.floor(Math.random() * self.enemyWeights.bucket.length); var chosenEnemy = self.enemyWeights.bucket.splice(randomIndex, 1)[0]; var enemy; switch (chosenEnemy) { case 'Enemy': enemy = new Enemy(self, self.parent); enemy.speed += self.parent.enemySpeedIncrement; break; case 'Enemy_2': enemy = new Enemy_2(self, self.parent); enemy.speed += self.parent.enemySpeedIncrement; break; case 'Enemy_3': enemy = new Enemy_3(self, self.parent); enemy.speed += self.parent.enemySpeedIncrement; break; } if (!enemy) { throw new Error('Invalid enemy type: ' + chosenEnemy); } enemy.x = self.x + 20; enemy.y = self.y + 250; self.parent.enemyLayer.addChild(enemy); self.parent.enemies.push(enemy); }; }); var Tower = Container.expand(function (gameInstance, index) { var self = Container.call(this); self.gameInstance = gameInstance; self.index = index; self.level = storage.towerLevels[index] || 1; self.upgradeCost = storage.towerCosts[index] || 50; self.snowballSpeed = 5 + (self.level - 1) * 2; self.isActive = self.level > 1; self.activeSnowball = null; self.BuyBtn = null; self.alpha = 1; self.x = 1024; self.y = 1366; self.createAndShootSnowball = function () { var snowball = new Snowball(self.snowballSpeed); var towerBounds = self.getBounds(); snowball.x = self.x + towerBounds.width / 2 + 15; snowball.y = self.y + towerBounds.height / 2 + 15; self.activeSnowball = snowball; snowball.on('destroyed', self.onSnowballDestroyed); self.gameInstance.bullets.push(snowball); if (self.BuyBtn && self.gameInstance.getChildIndex(self.BuyBtn) !== -1) { self.gameInstance.addChildAt(snowball, self.gameInstance.getChildIndex(self.BuyBtn)); } else { self.gameInstance.addChild(snowball); } }; self.shootSnowball = function () { if (self.isActive && !self.gameInstance.isGameOver && self.activeSnowball === null) { self.createAndShootSnowball(); } }; self.scheduleNextSnowball = function () { if (self.isActive) { self.shootSnowball(); LK.setTimeout(self.scheduleNextSnowball.bind(self), 2000); } }; self.onSnowballDestroyed = function () { self.activeSnowball = null; self.scheduleNextSnowball(); }; self.upgrade = function () { if (self.gameInstance.coins >= self.upgradeCost) { self.gameInstance.coins -= self.upgradeCost; LK.getSound('Buy').play(); self.gameInstance.updateCoins(0); self.level++; self.isActive = true; self.scheduleNextSnowball(); self.snowballSpeed += 2; self.upgradeCost += 100; self.towerCostText.setText(self.upgradeCost.toString()); storage.towerLevels[self.index] = self.level; storage.towerCosts[self.index] = self.upgradeCost; self.gameInstance.increaseEnemySpeed(0.5); self.gameInstance.enemyRewardIncrement += 1; // Show speedup banner var speedUpBanner = self.gameInstance.attachAsset('SpeedUp', { anchorX: 0.5, anchorY: 0.5 }); speedUpBanner.x = self.gameInstance.width / 2; speedUpBanner.y = self.gameInstance.height / 2; self.gameInstance.addChild(speedUpBanner); LK.setTimeout(function () { speedUpBanner.destroy(); }, 1000); } if (self.BuyBtn) { self.BuyBtn.visible = self.gameInstance.coins >= self.upgradeCost; self.towerCostText.alpha = self.gameInstance.coins >= self.upgradeCost ? 1 : 0.5; } }; if (self.isActive) { self.scheduleNextSnowball(); } }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ game.showExplosion = function (x, y) { var explosion = game.attachAsset('explosion', { anchorX: 0.5, anchorY: 0.5 }); explosion.x = x; explosion.y = y; game.addChild(explosion); LK.setTimeout(function () { explosion.destroy(); }, 150); }; game.increaseEnemySpeed = function (speedIncrement) { game.enemies.forEach(function (enemy) { enemy.speed += speedIncrement; }); game.enemySpeedIncrement += speedIncrement; storage.enemySpeedIncrement = game.enemySpeedIncrement; }; game.updateTowerButtons = function () { game.towers.forEach(function (tower) { var canAffordUpgrade = game.coins >= tower.upgradeCost; if (tower.BuyBtn) { tower.BuyBtn.visible = canAffordUpgrade; } tower.towerCostText.alpha = canAffordUpgrade ? 1 : 0.5; console.log('Current coin count: ' + game.coins + ', Upgrade cost for tower: ' + tower.upgradeCost); }); }; game.removeEnemy = function (enemy) { game.enemies = game.enemies.filter(function (e) { return e !== enemy; }); game.updateTowerButtons(); }; var background = game.attachAsset('background', {}); background.width = 2048; background.height = 2732; var GUI = game.attachAsset('GUI', { anchorX: 0.5, anchorY: 0.5 }); GUI.x = 1024; GUI.y = 3650; game.addChild(GUI); var Kills = game.attachAsset('kills', { anchorX: 0.5, anchorY: 0.5 }); Kills.x = 1024; Kills.y = 1366; game.addChild(Kills); game.Kills = Kills; game.Kills.x = 1940; game.Kills.y = 2620; var Coin = game.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); Coin.x = 124; Coin.y = 2620; game.addChild(Coin); game.GUI = GUI; game.coins = storage.coins || 0; game.coinDisplay = new Text2(game.coins.toString(), { size: 100, fill: 0xFFFFFF, align: 'center', stroke: '#000000', strokeThickness: 10 }); game.coinDisplay.anchor.set(0, 1); game.coinDisplay.x = 150; game.coinDisplay.y = -5; LK.gui.bottomLeft.addChild(game.coinDisplay); game.scoreDisplay = new Text2('0', { size: 100, fill: '#ffffff', align: 'center', stroke: '#000000', strokeThickness: 10 }); game.scoreDisplay.anchor.set(1, 1); game.scoreDisplay.x = 1290; game.scoreDisplay.y = -5; LK.gui.bottomLeft.addChild(game.scoreDisplay); game.removeCoinDisplay = function () { LK.gui.removeChild(game.coinDisplay); }; game.incrementScore = function () { game.score++; LK.setScore(game.score); game.scoreDisplay.setText(LK.getScore().toString()); storage.score = game.score; }; game.updateCoins = function (coinIncrement) { game.coins += coinIncrement; game.coinDisplay.setText(game.coins.toString()); storage.coins = game.coins; game.towers.forEach(function (tower, index) { var canAffordUpgrade = game.coins >= tower.upgradeCost; if (canAffordUpgrade && !tower.BuyBtn.visible) { LK.getSound('BuyReady').play(); } tower.BuyBtn.visible = canAffordUpgrade; tower.towerCostText.alpha = canAffordUpgrade ? 1 : 0.5; storage.towerLevels[index] = tower.level; // Store current tower levels in storage storage.towerCosts[index] = tower.upgradeCost; // Store current tower costs in storage }); if (game.tower) { game.towerButton.alpha = 1; } }; game.enemies = []; var base = game.addChild(new Base()); game.bullets = []; game.enemySpeedIncrement = storage.enemySpeedIncrement || 0; game.enemyRewardIncrement = 0; game.score = storage.score || 0; game.scoreDisplay.setText(game.score.toString()); game.snowballSpeed = 7; game.initializeTower = function (x, y, index) { var tower = game.addChild(new Tower(game, index)); tower.x = x; tower.y = y; tower.scale.x = 1; tower.scale.y = 1; tower.alpha = 1; if (tower.x < 0) { tower.x = 0; } if (tower.y < 0) { tower.y = 0; } if (tower.x > 2048) { tower.x = 2048 - tower.width; } if (tower.y > 2732) { tower.y = 2732 - tower.height; } tower.BuyBtn = LK.getAsset('buyButton', { anchorX: 0.5, anchorY: 0.5 }); tower.BuyBtn.x = tower.x - 140; tower.BuyBtn.y = tower.y + tower.height / 2 + 80; var towerButton = LK.getAsset('towerButton', { anchorX: 0.5, anchorY: 0.5 }); towerButton.x = tower.BuyBtn.x; towerButton.y = tower.BuyBtn.y; tower.BuyBtn.visible = false; game.addChild(towerButton); game.addChild(tower.BuyBtn); tower.BuyBtn.on('down', function () { this.upgrade(); }.bind(tower)); var towerCostText = new Text2(tower.upgradeCost.toString(), { size: 100, fill: 0xFFFFFF, align: 'center', stroke: '#000000', strokeThickness: 10 }); towerCostText.anchor.set(0.5, 0.5); towerCostText.x = tower.BuyBtn.x; towerCostText.y = tower.BuyBtn.y; towerCostText.alpha = 0.5; tower.towerCostText = towerCostText; game.addChild(towerCostText); tower.towerCostText.setText(tower.upgradeCost.toString()); return tower; }; var towerCenterX = 2048 / 2; var towerCenterY = 2732 / 2 + 200; game.towers = [game.initializeTower(towerCenterX - 700, towerCenterY + 650, 0), game.initializeTower(towerCenterX - 700, towerCenterY + 250, 1), game.initializeTower(towerCenterX - 700, towerCenterY - 150, 2), game.initializeTower(towerCenterX - 700, towerCenterY - 550, 3), game.initializeTower(towerCenterX - 700, towerCenterY - 950, 4)]; // Load tower levels from storage game.towers.forEach(function (tower, index) { tower.level = storage.towerLevels[index] || 1; if (tower.level > 1) { tower.isActive = true; tower.scheduleNextSnowball(); } }); base.x = 2048 / 2; base.y = 2732 - base.height / 2; game.enemyLayer = new Container(); game.addChild(game.enemyLayer); var spawner1 = new Spawner(2048 / 6 + 200, -200); var spawner2 = new Spawner(2048 / 2 + 100, -200); var spawner3 = new Spawner(2048 / 6 * 5, -200); game.addChild(spawner1); game.addChild(spawner2); game.addChild(spawner3); var spawner1Timer = LK.setInterval(function () { spawner1.spawnEnemy(); }, 3000); spawner1.spawnEnemy(); var spawner2Timer = LK.setInterval(function () { spawner2.spawnEnemy(); }, 2500); spawner2.spawnEnemy(); var spawner3Timer = LK.setInterval(function () { spawner3.spawnEnemy(); }, 2000); spawner3.spawnEnemy(); LK.on('tick', function () { game.enemies.forEach(function (enemy) { enemy._move_migrated(); if (enemy.y >= game.GUI.y - 1250) { game.removeCoinDisplay(); LK.showGameOver(); game.coins = 0; game.coinDisplay.setText(game.coins.toString()); storage.coins = game.coins; game.score = 0; game.scoreDisplay.setText(game.score.toString()); storage.score = game.score; game.killedEnemies = 0; // Reset killed enemies count game.towers.forEach(function (tower, index) { tower.level = 0; tower.isActive = false; tower.snowballSpeed = 5; tower.upgradeCost = 100; storage.towerLevels[index] = tower.level; storage.towerCosts[index] = tower.upgradeCost; // Reset stored tower cost tower.towerCostText.setText(tower.upgradeCost.toString()); tower.BuyBtn.visible = false; tower.towerCostText.alpha = 0.5; }); // Reset enemy speed increment game.enemySpeedIncrement = 0; storage.enemySpeedIncrement = game.enemySpeedIncrement; } }); game.bullets.forEach(function (snowball) { snowball._move_migrated(); snowball.x += snowball.speed; game.enemies.forEach(function (enemy) { if (snowball.intersects(enemy)) { enemy.destroyEnemy(); var tower = game.towers.find(function (t) { return t.activeSnowball === snowball; }); if (tower) { tower.onSnowballDestroyed(snowball); } game.bullets = game.bullets.filter(function (b) { return b !== snowball; }); snowball.destroy(); } }); if (snowball.x > 2048) { var tower = game.towers.find(function (t) { return t.activeSnowball === snowball; }); if (tower) { tower.onSnowballDestroyed(snowball); } game.bullets = game.bullets.filter(function (b) { return b !== snowball; }); snowball.destroy(); } }); });
/****
* Plugins
****/
var storage = LK.import("@upit/storage.v1", {
coins: 0,
score: 0,
towerLevels: [1, 1, 1, 1, 1],
towerCosts: [100, 100, 100, 100, 100],
enemySpeedIncrement: 0
});
/****
* Classes
****/
var Base = Container.expand(function () {
var self = Container.call(this);
self.health = 100;
self.updateHealth = function () {};
});
var Enemy = Container.expand(function (spawnerInstance, gameInstance) {
var self = Container.call(this);
self.showExplosion = function () {
self.gameInstance.showExplosion(self.x, self.y);
self.destroy();
};
self.gameInstance = gameInstance;
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.tiltDirection = 1;
self._move_migrated = function () {
self.y += self.speed;
self.rotation += 0.005 * self.tiltDirection;
if (self.rotation > 0.15 || self.rotation < -0.15) {
self.tiltDirection *= -1;
}
};
self.on('down', function () {
self.destroyEnemy();
});
self.destroyEnemy = function () {
self.showExplosion();
LK.getSound('Hit').play();
self.gameInstance.updateCoins(10 + self.gameInstance.enemyRewardIncrement);
self.gameInstance.removeEnemy(self);
self.gameInstance.incrementScore();
};
});
var Enemy_2 = Container.expand(function (spawnerInstance, gameInstance) {
var self = Container.call(this);
self.showExplosion = function () {
self.gameInstance.showExplosion(self.x, self.y);
self.destroy();
};
self.gameInstance = gameInstance;
var enemyGraphics = self.attachAsset('enemy_2', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.tiltDirection = 1;
self._move_migrated = function () {
self.y += self.speed;
self.rotation += 0.005 * self.tiltDirection;
if (self.rotation > 0.15 || self.rotation < -0.15) {
self.tiltDirection *= -1;
}
};
self.on('down', function () {
self.destroyEnemy();
});
self.destroyEnemy = function () {
self.showExplosion();
LK.getSound('Hit').play();
self.gameInstance.updateCoins(20 + self.gameInstance.enemyRewardIncrement);
self.gameInstance.removeEnemy(self);
self.gameInstance.incrementScore();
};
});
var Enemy_3 = Container.expand(function (spawnerInstance, gameInstance) {
var self = Container.call(this);
self.showExplosion = function () {
self.gameInstance.showExplosion(self.x, self.y);
self.destroy();
};
self.gameInstance = gameInstance;
var enemyGraphics = self.attachAsset('enemy_3', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.tiltDirection = 1;
self._move_migrated = function () {
self.y += self.speed;
self.rotation += 0.005 * self.tiltDirection;
if (self.rotation > 0.15 || self.rotation < -0.15) {
self.tiltDirection *= -1;
}
};
self.on('down', function () {
self.destroyEnemy();
});
self.destroyEnemy = function () {
self.showExplosion();
LK.getSound('Hit').play();
self.gameInstance.updateCoins(30 + self.gameInstance.enemyRewardIncrement);
self.gameInstance.removeEnemy(self);
self.gameInstance.incrementScore();
};
});
var Snowball = Container.expand(function (speed) {
var self = Container.call(this);
self.x = arguments[1];
self.y = arguments[2];
self.speed = speed;
self.rotationSpeed = 0.05;
var snowballGraphics = self.attachAsset('snowball', {
anchorX: 0.5,
anchorY: 0.5
});
self._move_migrated = function () {
self.rotation += self.rotationSpeed;
};
});
var Spawner = Container.expand(function (x, y) {
var self = Container.call(this);
var spawnerGraphics = self.attachAsset('spawner', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.enemyWeights = {
'Enemy': 70,
'Enemy_2': 21,
'Enemy_3': 9,
'total': 100,
'bucket': []
};
self.resetEnemyBucket = function () {
for (var key in self.enemyWeights) {
if (key !== 'total' && key !== 'bucket') {
for (var i = 0; i < self.enemyWeights[key]; i++) {
self.enemyWeights.bucket.push(key);
}
}
}
};
self.resetEnemyBucket();
self.spawnEnemy = function () {
if (self.enemyWeights.bucket.length === 0) {
self.resetEnemyBucket();
}
var randomIndex = Math.floor(Math.random() * self.enemyWeights.bucket.length);
var chosenEnemy = self.enemyWeights.bucket.splice(randomIndex, 1)[0];
var enemy;
switch (chosenEnemy) {
case 'Enemy':
enemy = new Enemy(self, self.parent);
enemy.speed += self.parent.enemySpeedIncrement;
break;
case 'Enemy_2':
enemy = new Enemy_2(self, self.parent);
enemy.speed += self.parent.enemySpeedIncrement;
break;
case 'Enemy_3':
enemy = new Enemy_3(self, self.parent);
enemy.speed += self.parent.enemySpeedIncrement;
break;
}
if (!enemy) {
throw new Error('Invalid enemy type: ' + chosenEnemy);
}
enemy.x = self.x + 20;
enemy.y = self.y + 250;
self.parent.enemyLayer.addChild(enemy);
self.parent.enemies.push(enemy);
};
});
var Tower = Container.expand(function (gameInstance, index) {
var self = Container.call(this);
self.gameInstance = gameInstance;
self.index = index;
self.level = storage.towerLevels[index] || 1;
self.upgradeCost = storage.towerCosts[index] || 50;
self.snowballSpeed = 5 + (self.level - 1) * 2;
self.isActive = self.level > 1;
self.activeSnowball = null;
self.BuyBtn = null;
self.alpha = 1;
self.x = 1024;
self.y = 1366;
self.createAndShootSnowball = function () {
var snowball = new Snowball(self.snowballSpeed);
var towerBounds = self.getBounds();
snowball.x = self.x + towerBounds.width / 2 + 15;
snowball.y = self.y + towerBounds.height / 2 + 15;
self.activeSnowball = snowball;
snowball.on('destroyed', self.onSnowballDestroyed);
self.gameInstance.bullets.push(snowball);
if (self.BuyBtn && self.gameInstance.getChildIndex(self.BuyBtn) !== -1) {
self.gameInstance.addChildAt(snowball, self.gameInstance.getChildIndex(self.BuyBtn));
} else {
self.gameInstance.addChild(snowball);
}
};
self.shootSnowball = function () {
if (self.isActive && !self.gameInstance.isGameOver && self.activeSnowball === null) {
self.createAndShootSnowball();
}
};
self.scheduleNextSnowball = function () {
if (self.isActive) {
self.shootSnowball();
LK.setTimeout(self.scheduleNextSnowball.bind(self), 2000);
}
};
self.onSnowballDestroyed = function () {
self.activeSnowball = null;
self.scheduleNextSnowball();
};
self.upgrade = function () {
if (self.gameInstance.coins >= self.upgradeCost) {
self.gameInstance.coins -= self.upgradeCost;
LK.getSound('Buy').play();
self.gameInstance.updateCoins(0);
self.level++;
self.isActive = true;
self.scheduleNextSnowball();
self.snowballSpeed += 2;
self.upgradeCost += 100;
self.towerCostText.setText(self.upgradeCost.toString());
storage.towerLevels[self.index] = self.level;
storage.towerCosts[self.index] = self.upgradeCost;
self.gameInstance.increaseEnemySpeed(0.5);
self.gameInstance.enemyRewardIncrement += 1;
// Show speedup banner
var speedUpBanner = self.gameInstance.attachAsset('SpeedUp', {
anchorX: 0.5,
anchorY: 0.5
});
speedUpBanner.x = self.gameInstance.width / 2;
speedUpBanner.y = self.gameInstance.height / 2;
self.gameInstance.addChild(speedUpBanner);
LK.setTimeout(function () {
speedUpBanner.destroy();
}, 1000);
}
if (self.BuyBtn) {
self.BuyBtn.visible = self.gameInstance.coins >= self.upgradeCost;
self.towerCostText.alpha = self.gameInstance.coins >= self.upgradeCost ? 1 : 0.5;
}
};
if (self.isActive) {
self.scheduleNextSnowball();
}
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
game.showExplosion = function (x, y) {
var explosion = game.attachAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5
});
explosion.x = x;
explosion.y = y;
game.addChild(explosion);
LK.setTimeout(function () {
explosion.destroy();
}, 150);
};
game.increaseEnemySpeed = function (speedIncrement) {
game.enemies.forEach(function (enemy) {
enemy.speed += speedIncrement;
});
game.enemySpeedIncrement += speedIncrement;
storage.enemySpeedIncrement = game.enemySpeedIncrement;
};
game.updateTowerButtons = function () {
game.towers.forEach(function (tower) {
var canAffordUpgrade = game.coins >= tower.upgradeCost;
if (tower.BuyBtn) {
tower.BuyBtn.visible = canAffordUpgrade;
}
tower.towerCostText.alpha = canAffordUpgrade ? 1 : 0.5;
console.log('Current coin count: ' + game.coins + ', Upgrade cost for tower: ' + tower.upgradeCost);
});
};
game.removeEnemy = function (enemy) {
game.enemies = game.enemies.filter(function (e) {
return e !== enemy;
});
game.updateTowerButtons();
};
var background = game.attachAsset('background', {});
background.width = 2048;
background.height = 2732;
var GUI = game.attachAsset('GUI', {
anchorX: 0.5,
anchorY: 0.5
});
GUI.x = 1024;
GUI.y = 3650;
game.addChild(GUI);
var Kills = game.attachAsset('kills', {
anchorX: 0.5,
anchorY: 0.5
});
Kills.x = 1024;
Kills.y = 1366;
game.addChild(Kills);
game.Kills = Kills;
game.Kills.x = 1940;
game.Kills.y = 2620;
var Coin = game.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
Coin.x = 124;
Coin.y = 2620;
game.addChild(Coin);
game.GUI = GUI;
game.coins = storage.coins || 0;
game.coinDisplay = new Text2(game.coins.toString(), {
size: 100,
fill: 0xFFFFFF,
align: 'center',
stroke: '#000000',
strokeThickness: 10
});
game.coinDisplay.anchor.set(0, 1);
game.coinDisplay.x = 150;
game.coinDisplay.y = -5;
LK.gui.bottomLeft.addChild(game.coinDisplay);
game.scoreDisplay = new Text2('0', {
size: 100,
fill: '#ffffff',
align: 'center',
stroke: '#000000',
strokeThickness: 10
});
game.scoreDisplay.anchor.set(1, 1);
game.scoreDisplay.x = 1290;
game.scoreDisplay.y = -5;
LK.gui.bottomLeft.addChild(game.scoreDisplay);
game.removeCoinDisplay = function () {
LK.gui.removeChild(game.coinDisplay);
};
game.incrementScore = function () {
game.score++;
LK.setScore(game.score);
game.scoreDisplay.setText(LK.getScore().toString());
storage.score = game.score;
};
game.updateCoins = function (coinIncrement) {
game.coins += coinIncrement;
game.coinDisplay.setText(game.coins.toString());
storage.coins = game.coins;
game.towers.forEach(function (tower, index) {
var canAffordUpgrade = game.coins >= tower.upgradeCost;
if (canAffordUpgrade && !tower.BuyBtn.visible) {
LK.getSound('BuyReady').play();
}
tower.BuyBtn.visible = canAffordUpgrade;
tower.towerCostText.alpha = canAffordUpgrade ? 1 : 0.5;
storage.towerLevels[index] = tower.level; // Store current tower levels in storage
storage.towerCosts[index] = tower.upgradeCost; // Store current tower costs in storage
});
if (game.tower) {
game.towerButton.alpha = 1;
}
};
game.enemies = [];
var base = game.addChild(new Base());
game.bullets = [];
game.enemySpeedIncrement = storage.enemySpeedIncrement || 0;
game.enemyRewardIncrement = 0;
game.score = storage.score || 0;
game.scoreDisplay.setText(game.score.toString());
game.snowballSpeed = 7;
game.initializeTower = function (x, y, index) {
var tower = game.addChild(new Tower(game, index));
tower.x = x;
tower.y = y;
tower.scale.x = 1;
tower.scale.y = 1;
tower.alpha = 1;
if (tower.x < 0) {
tower.x = 0;
}
if (tower.y < 0) {
tower.y = 0;
}
if (tower.x > 2048) {
tower.x = 2048 - tower.width;
}
if (tower.y > 2732) {
tower.y = 2732 - tower.height;
}
tower.BuyBtn = LK.getAsset('buyButton', {
anchorX: 0.5,
anchorY: 0.5
});
tower.BuyBtn.x = tower.x - 140;
tower.BuyBtn.y = tower.y + tower.height / 2 + 80;
var towerButton = LK.getAsset('towerButton', {
anchorX: 0.5,
anchorY: 0.5
});
towerButton.x = tower.BuyBtn.x;
towerButton.y = tower.BuyBtn.y;
tower.BuyBtn.visible = false;
game.addChild(towerButton);
game.addChild(tower.BuyBtn);
tower.BuyBtn.on('down', function () {
this.upgrade();
}.bind(tower));
var towerCostText = new Text2(tower.upgradeCost.toString(), {
size: 100,
fill: 0xFFFFFF,
align: 'center',
stroke: '#000000',
strokeThickness: 10
});
towerCostText.anchor.set(0.5, 0.5);
towerCostText.x = tower.BuyBtn.x;
towerCostText.y = tower.BuyBtn.y;
towerCostText.alpha = 0.5;
tower.towerCostText = towerCostText;
game.addChild(towerCostText);
tower.towerCostText.setText(tower.upgradeCost.toString());
return tower;
};
var towerCenterX = 2048 / 2;
var towerCenterY = 2732 / 2 + 200;
game.towers = [game.initializeTower(towerCenterX - 700, towerCenterY + 650, 0), game.initializeTower(towerCenterX - 700, towerCenterY + 250, 1), game.initializeTower(towerCenterX - 700, towerCenterY - 150, 2), game.initializeTower(towerCenterX - 700, towerCenterY - 550, 3), game.initializeTower(towerCenterX - 700, towerCenterY - 950, 4)];
// Load tower levels from storage
game.towers.forEach(function (tower, index) {
tower.level = storage.towerLevels[index] || 1;
if (tower.level > 1) {
tower.isActive = true;
tower.scheduleNextSnowball();
}
});
base.x = 2048 / 2;
base.y = 2732 - base.height / 2;
game.enemyLayer = new Container();
game.addChild(game.enemyLayer);
var spawner1 = new Spawner(2048 / 6 + 200, -200);
var spawner2 = new Spawner(2048 / 2 + 100, -200);
var spawner3 = new Spawner(2048 / 6 * 5, -200);
game.addChild(spawner1);
game.addChild(spawner2);
game.addChild(spawner3);
var spawner1Timer = LK.setInterval(function () {
spawner1.spawnEnemy();
}, 3000);
spawner1.spawnEnemy();
var spawner2Timer = LK.setInterval(function () {
spawner2.spawnEnemy();
}, 2500);
spawner2.spawnEnemy();
var spawner3Timer = LK.setInterval(function () {
spawner3.spawnEnemy();
}, 2000);
spawner3.spawnEnemy();
LK.on('tick', function () {
game.enemies.forEach(function (enemy) {
enemy._move_migrated();
if (enemy.y >= game.GUI.y - 1250) {
game.removeCoinDisplay();
LK.showGameOver();
game.coins = 0;
game.coinDisplay.setText(game.coins.toString());
storage.coins = game.coins;
game.score = 0;
game.scoreDisplay.setText(game.score.toString());
storage.score = game.score;
game.killedEnemies = 0; // Reset killed enemies count
game.towers.forEach(function (tower, index) {
tower.level = 0;
tower.isActive = false;
tower.snowballSpeed = 5;
tower.upgradeCost = 100;
storage.towerLevels[index] = tower.level;
storage.towerCosts[index] = tower.upgradeCost; // Reset stored tower cost
tower.towerCostText.setText(tower.upgradeCost.toString());
tower.BuyBtn.visible = false;
tower.towerCostText.alpha = 0.5;
});
// Reset enemy speed increment
game.enemySpeedIncrement = 0;
storage.enemySpeedIncrement = game.enemySpeedIncrement;
}
});
game.bullets.forEach(function (snowball) {
snowball._move_migrated();
snowball.x += snowball.speed;
game.enemies.forEach(function (enemy) {
if (snowball.intersects(enemy)) {
enemy.destroyEnemy();
var tower = game.towers.find(function (t) {
return t.activeSnowball === snowball;
});
if (tower) {
tower.onSnowballDestroyed(snowball);
}
game.bullets = game.bullets.filter(function (b) {
return b !== snowball;
});
snowball.destroy();
}
});
if (snowball.x > 2048) {
var tower = game.towers.find(function (t) {
return t.activeSnowball === snowball;
});
if (tower) {
tower.onSnowballDestroyed(snowball);
}
game.bullets = game.bullets.filter(function (b) {
return b !== snowball;
});
snowball.destroy();
}
});
});
Create a pixel rendition of a winter skyline for a pixel game. The image should feature a light blue sky dominating the scene, with subtle pixelated outlines of mountain crests at the bottom. The sky needs to be clear and bright, showcasing the crispness of a winter day in a pixel art style. Use a gradient of light blue near the pixelated mountain silhouettes, gradually transitioning to a deeper blue towards the top of the image, all in a charming, pixelated format to evoke a serene, wintry atmosphere.. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cute chubby angry parachuting penguin wearing a santa hat. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
frosty tube. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
game coin with a snowflake symbol. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
green plain UI button. pixelated. 8 bit. rectangular. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
puff of snowy smoke. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
round snowball. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
frosty text saying (SPEED UP).wings on the edges. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cute fat chubby parachuting penguin wearing a santa hat. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
plain frosty user interface panel. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. High contrast. No shadows.
cute angry parachuting penguin wearing a santa hat. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.