User prompt
Boss 30 canlı olsun
User prompt
3te1 daha yavaş dönsün ve mermi hızı yavaşlasın. sadece bir yöne değil sürekli rotasyon değiştirsin
User prompt
dönüş hızını yavaşlat ve daha uzak bir noktada dönmesini sağla
User prompt
boss geldiğinde sabit kalmasın merkezdeki karakterin etrafında dönerek onu şaşırtsın
User prompt
bossbullet mermiler ile vurulabilir olmalı mesela minigunbullet bossbullete 3 kere vurduğunda bossbullet yok olmalı
User prompt
bossbullet ortaya ulaştığında karakter can kaybetsin fakat karakterde onu vurabilsin. bossbullet 3 vuruşta yok olsun.
User prompt
boss için boss asseti kullan boss fire için bossbullet kullan. bossbulletin hızı oldukça yavaş olsun. wizarda deyerse can kaybetsin. bossbullet silahlarla vurulabilir olsun ve 3 mermiye yok olsun. boss ise 15 canı olsun
User prompt
on score 10 stop enemyspawn and spawn a boss but it fire direcktly to wizard
User prompt
Please fix the bug: 'Error: Invalid end type for property scale: object' in or related to this line: 'tween(bullet, {' Line Number: 1628
User prompt
on score 50 stop enemyspawn and spawn a boss. But boss don't come to wizard directly. boss shoot to wizard randomly if bullet hit the wizard health -1 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
upgrade sistemi her silah için ayrı olsun. silahımdaki upgradeler ayrı ayrı kaydedilsin.
User prompt
enemylerin gelme olasığı %35 enemy1, %30 enemy2, %20 enemy3, %15 enemy4 gelsin
User prompt
buraya birde enemy4 ekleyelim ve enemy4 assetini kullansın
User prompt
add one more enemy, use enemy4 asset and it have 4 health. It should come to game at score 20
User prompt
Lazer silahının mermisini heryerde 10 yap her windowsda 10 olsun
User prompt
lasergun silahının mermisini 10 yap
User prompt
When the shot with lasergun and if it shot one enemy bullet piercing the enemy and go. This should apply every screen on game
User prompt
Lasergun mermileri düşmanların içerisinden geçip gitsin fakat geçtiği düşmana da hasar versin bu değişiklik oyunun tüm ekranlarında geçerli olsun
User prompt
Lasergun mermileri düşmanların içerisinden geçip gitsin fakat geçtiği düşmana da hasar versin bunu tüm oyun ekranlarında uygula
User prompt
Lasergun mermileri düşmanların içerisinden geçip gitsin fakat geçtiği düşmana da hasar versin. Bu değişiklik globalde olsun
User prompt
Lasergun mermileri düşmanların içerisinden geçip gitsin fakat geçtiği düşmana da hasar versin.
User prompt
Use plasma sound when fire laser gun
User prompt
Add one more gun in shop it should laser gun and 1 coin, use lasergun asset and lasergunbullet asset
User prompt
Use minigun sound when fire with minigun
User prompt
Add a joystick in the bottom left corner and connect 360 degree rotation to it
/****
* Plugins
****/
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
// Boss class: fires directly at wizard, uses boss asset and BossBullet
var Boss = Container.expand(function () {
var self = Container.call(this);
var bossSprite = self.attachAsset('boss', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 15;
self.lastX = 0;
self.lastY = 0;
self.fireCooldown = 0;
self.fireInterval = 60; // frames (1s at 60fps)
self.speed = 6;
self.state = "enter"; // "enter" or "fight"
self.update = function () {
// Enter from top, then stop and start fighting
if (self.state === "enter") {
self.y += self.speed;
if (self.y >= 400) {
self.y = 400;
self.state = "fight";
// Initialize orbit parameters
self.orbitAngle = 0;
self.orbitRadius = 420;
self.orbitSpeed = 0.035 + Math.random() * 0.02; // radians per frame, randomize a bit
self.orbitDirection = Math.random() < 0.5 ? 1 : -1; // random direction
}
} else if (self.state === "fight") {
// Orbit around wizard
if (typeof self.orbitAngle === "undefined") self.orbitAngle = 0;
if (typeof self.orbitRadius === "undefined") self.orbitRadius = 420;
if (typeof self.orbitSpeed === "undefined") self.orbitSpeed = 0.04;
if (typeof self.orbitDirection === "undefined") self.orbitDirection = 1;
// Update orbit angle
self.orbitAngle += self.orbitSpeed * self.orbitDirection;
// Orbit center is wizard's current position
var centerX = wizard.x;
var centerY = wizard.y;
// Calculate boss position on orbit
self.x = centerX + Math.cos(self.orbitAngle) * self.orbitRadius;
self.y = centerY + Math.sin(self.orbitAngle) * self.orbitRadius;
// Always face wizard
var dx = wizard.x - self.x;
var dy = wizard.y - self.y;
var angle = Math.atan2(dy, dx);
if (self.children && self.children.length > 0) {
self.children[0].rotation = angle + Math.PI / 2;
}
// Fire at wizard every interval
self.fireCooldown--;
if (self.fireCooldown <= 0) {
self.fireCooldown = self.fireInterval;
var bossBullet = new BossBullet();
bossBullet.x = self.x;
bossBullet.y = self.y + 80 * Math.sin(self.orbitAngle); // fire from boss's "front"
var dir = getDirection(self.x, self.y, wizard.x, wizard.y, 5); // slow speed
bossBullet.vx = dir.vx;
bossBullet.vy = dir.vy;
if (bossBullet.children && bossBullet.children.length > 0) {
bossBullet.children[0].rotation = angle;
}
fireballs.push(bossBullet);
game.addChild(bossBullet);
}
}
// Animate boss (pulse)
var t = LK.ticks || Date.now();
var scale = 1 + 0.18 * Math.sin((t + self.x + self.y) * 0.06);
if (self.children && self.children.length > 0) {
self.children[0].scale.x = scale;
self.children[0].scale.y = scale;
}
self.lastX = self.x;
self.lastY = self.y;
};
return self;
});
// BossBullet class: slow, destructible, 3 hits to destroy
var BossBullet = Container.expand(function () {
var self = Container.call(this);
var bulletSprite = self.attachAsset('bossbullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.vx = 0;
self.vy = 0;
self.health = 3; // 3 hits to destroy
self.lastX = 0;
self.lastY = 0;
self.update = function () {
self.x += self.vx;
self.y += self.vy;
// --- BossBullet: Damage wizard if reaches wizard center (within 40px radius) ---
if (typeof self.lastWasAtCenter === "undefined") self.lastWasAtCenter = false;
var dx = self.x - wizard.x;
var dy = self.y - wizard.y;
var dist = Math.sqrt(dx * dx + dy * dy);
var atCenter = dist <= 40;
if (!self.lastWasAtCenter && atCenter) {
// Only damage if wizard is alive
if (typeof wizardHealth !== "undefined" && wizardHealth > 0) {
wizardHealth -= 1;
storage.wizardHealth = wizardHealth;
if (wizard.children && wizard.children.length > 0) {
LK.effects.flashObject(wizard.children[0], 0xff0000, 400);
}
updateHealthBar && updateHealthBar();
// Remove bossbullet
self.destroy();
// Remove from fireballs array if present
for (var i = fireballs.length - 1; i >= 0; i--) {
if (fireballs[i] === self) {
fireballs.splice(i, 1);
break;
}
}
// Game over if health 0
if (wizardHealth <= 0) {
totalCoins += coinCount;
storage.totalCoins = totalCoins;
LK.effects.flashScreen(0xff0000, 1000);
gameStarted = false;
}
}
}
self.lastWasAtCenter = atCenter;
// Remove if off screen
if (self.x < -120 || self.x > 2048 + 120 || self.y < -120 || self.y > 2732 + 120) {
self.destroy();
}
self.lastX = self.x;
self.lastY = self.y;
};
return self;
});
// Game update: update wizard, fireballs, enemies, handle collisions, and scoring
// Coin class: represents coins dropped by enemies when destroyed
var Coin = Container.expand(function () {
var self = Container.call(this);
// Create a gold coin visual (using a yellow circle)
var coinSprite = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
// Coin movement properties
self.vx = 0;
self.vy = 0;
self.gravity = 0;
self.collected = false;
// Track last position for event triggers
self.lastX = 0;
self.lastY = 0;
self.lastWasIntersecting = false;
self.update = function () {
// No gravity or bounce logic needed
// Remove coin if it leaves the screen horizontally
if (self.x < -50 || self.x > 2048 + 50) {
self.destroy();
}
// Pulsate slightly for visual effect
var t = LK.ticks || Date.now();
var scale = 1 + 0.1 * Math.sin(t * 0.1);
if (self.children && self.children.length > 0) {
self.children[0].scale.x = scale;
self.children[0].scale.y = scale;
}
self.lastX = self.x;
self.lastY = self.y;
};
return self;
});
// Enemy class: represents an enemy that moves toward the wizard
var Enemy = Container.expand(function () {
var self = Container.call(this);
// Attach a unique enemy asset (pixel blue monster)
var enemySprite = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
// Enemy speed and direction
self.vx = 0;
self.vy = 0;
// Track last position for event triggers
self.lastX = 0;
self.lastY = 0;
self.health = 1; // Enemy1: 1 hit to kill
self.type = 1;
self.update = function () {
self.x += self.vx;
self.y += self.vy;
// Pulsate scale for movement effect
var t = LK.ticks || Date.now(); // fallback for safety
var scale = 1 + 0.15 * Math.sin((t + self.x + self.y) * 0.05);
if (self.children && self.children.length > 0) {
self.children[0].scale.x = scale;
self.children[0].scale.y = scale;
}
// Remove enemy if it leaves the screen
if (self.x < -100 || self.x > 2048 + 100 || self.y < -100 || self.y > 2732 + 100) {
self.destroy();
}
self.lastX = self.x;
self.lastY = self.y;
};
return self;
});
// Enemy2: needs 2 fireballs to die
var Enemy2 = Container.expand(function () {
var self = Container.call(this);
var enemySprite = self.attachAsset('enemy2', {
anchorX: 0.5,
anchorY: 0.5
});
self.vx = 0;
self.vy = 0;
self.lastX = 0;
self.lastY = 0;
self.health = 2;
self.type = 2;
self.update = function () {
self.x += self.vx;
self.y += self.vy;
var t = LK.ticks || Date.now();
var scale = 1 + 0.18 * Math.sin((t + self.x + self.y) * 0.06);
if (self.children && self.children.length > 0) {
self.children[0].scale.x = scale;
self.children[0].scale.y = scale;
}
if (self.x < -100 || self.x > 2048 + 100 || self.y < -100 || self.y > 2732 + 100) {
self.destroy();
}
self.lastX = self.x;
self.lastY = self.y;
};
return self;
});
// Enemy3: needs 3 fireballs to die
var Enemy3 = Container.expand(function () {
var self = Container.call(this);
var enemySprite = self.attachAsset('enemy3', {
anchorX: 0.5,
anchorY: 0.5
});
self.vx = 0;
self.vy = 0;
self.lastX = 0;
self.lastY = 0;
self.health = 3;
self.type = 3;
self.update = function () {
self.x += self.vx;
self.y += self.vy;
var t = LK.ticks || Date.now();
var scale = 1 + 0.22 * Math.sin((t + self.x + self.y) * 0.07);
if (self.children && self.children.length > 0) {
self.children[0].scale.x = scale;
self.children[0].scale.y = scale;
}
if (self.x < -100 || self.x > 2048 + 100 || self.y < -100 || self.y > 2732 + 100) {
self.destroy();
}
self.lastX = self.x;
self.lastY = self.y;
};
return self;
});
// Enemy4: needs 4 fireballs to die
var Enemy4 = Container.expand(function () {
var self = Container.call(this);
var enemySprite = self.attachAsset('enemy4', {
anchorX: 0.5,
anchorY: 0.5
});
self.vx = 0;
self.vy = 0;
self.lastX = 0;
self.lastY = 0;
self.health = 4;
self.type = 4;
self.update = function () {
self.x += self.vx;
self.y += self.vy;
var t = LK.ticks || Date.now();
var scale = 1 + 0.26 * Math.sin((t + self.x + self.y) * 0.08);
if (self.children && self.children.length > 0) {
self.children[0].scale.x = scale;
self.children[0].scale.y = scale;
}
if (self.x < -100 || self.x > 2048 + 100 || self.y < -100 || self.y > 2732 + 100) {
self.destroy();
}
self.lastX = self.x;
self.lastY = self.y;
};
return self;
});
// Explosion class: shows a quick explosion effect at (x, y)
var Explosion = Container.expand(function () {
var self = Container.call(this);
var sprite = self.attachAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5
});
// Initial scale and alpha
sprite.scale.x = 0.5;
sprite.scale.y = 0.5;
sprite.alpha = 1;
// Animate explosion: grow and fade out
var duration = 18; // frames (~0.3s)
var frame = 0;
self.update = function () {
frame++;
// Grow and fade
var progress = frame / duration;
sprite.scale.x = 0.5 + 1.2 * progress;
sprite.scale.y = 0.5 + 1.2 * progress;
sprite.alpha = 1 - progress;
if (frame >= duration) {
self.destroy();
}
};
return self;
});
// Fireball class: represents a fireball shot by the wizard
var Fireball = Container.expand(function () {
var self = Container.call(this);
// Attach fireball asset (pixel fireball)
var fireballSprite = self.attachAsset('fireball', {
anchorX: 0.5,
anchorY: 0.5
});
// Fireball speed and direction
self.vx = 0;
self.vy = 0;
// Track last position for event triggers
self.lastX = 0;
self.lastY = 0;
self.update = function () {
self.x += self.vx;
self.y += self.vy;
// Remove fireball if it leaves the screen
if (self.x < -100 || self.x > 2048 + 100 || self.y < -100 || self.y > 2732 + 100) {
self.destroy();
}
self.lastX = self.x;
self.lastY = self.y;
};
return self;
});
// Wizard class: represents the player character
var Wizard = Container.expand(function () {
var self = Container.call(this);
// Attach wizard asset (blue hat, pixel style)
var wizardSprite = self.attachAsset('wizard', {
anchorX: 0.5,
anchorY: 0.5
});
// Track last position for event triggers
self.lastX = 0;
self.lastY = 0;
// Update method (called every tick)
self.update = function () {
// No movement logic here; wizard is moved by mouse/touch
self.lastX = self.x;
self.lastY = self.y;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Explosion asset for enemy death effect
;
// Add background image to the game scene
var background = LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
width: 2048,
height: 2732
});
game.addChild(background);
// --- Game Code for Pixel Wizard: Blue Hat Adventure ---
// Create wizard instance and add to game
var wizard = new Wizard();
game.addChild(wizard);
// Center wizard on screen at start
wizard.x = 2048 / 2;
wizard.y = 2732 / 2;
// --- START & UPGRADE BUTTON UI LOGIC ---
var gameStarted = false;
// UI container for start and upgrade buttons
var startUiContainer = new Container();
// Create start button asset (simple box with text)
var startButtonWidth = 420;
var startButtonHeight = 140;
var startButton = new Container();
var startButtonBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: startButtonWidth,
height: startButtonHeight
});
startButtonBg.alpha = 0.92;
startButton.addChild(startButtonBg);
var startButtonText = new Text2("START GAME", {
size: 220,
fill: "#fff"
});
startButtonText.anchor.set(0.5, 0.5);
startButtonText.x = 0;
startButtonText.y = -120;
startButton.addChild(startButtonText);
// Create upgrade button below start button
var upgradeButtonWidth = 420;
var upgradeButtonHeight = 110;
var upgradeButton = new Container();
var upgradeButtonBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: upgradeButtonWidth,
height: upgradeButtonHeight
});
upgradeButtonBg.alpha = 0.92;
upgradeButton.addChild(upgradeButtonBg);
var upgradeButtonText = new Text2("UPGRADE", {
size: 110,
// Half of START GAME (220)
fill: "#fff"
});
upgradeButtonText.anchor.set(0.5, 0.5);
upgradeButtonText.x = 0;
upgradeButtonText.y = 0;
upgradeButton.addChild(upgradeButtonText);
// Position start, upgrade, and shop buttons in the UI container
startButton.x = 0;
startButton.y = -400; //{36} // Moved much higher
upgradeButton.x = 0;
upgradeButton.y = startButton.y + startButtonHeight / 2 + 55 + upgradeButtonHeight / 2; //{38} // Increased spacing by 15px
// --- SHOP BUTTON UI LOGIC ---
var shopButtonWidth = 420;
var shopButtonHeight = 110;
var shopButton = new Container();
var shopButtonBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: shopButtonWidth,
height: shopButtonHeight
});
shopButtonBg.alpha = 0.92;
shopButton.addChild(shopButtonBg);
var shopButtonText = new Text2("SHOP", {
size: 110,
fill: "#fff"
});
shopButtonText.anchor.set(0.5, 0.5);
shopButtonText.x = 0;
shopButtonText.y = 0;
shopButton.addChild(shopButtonText);
// Position shop button below upgrade button
shopButton.x = 0;
shopButton.y = upgradeButton.y + upgradeButtonHeight / 2 + 40 + shopButtonHeight / 2;
// Add all three buttons to the UI container
startUiContainer.addChild(startButton);
startUiContainer.addChild(upgradeButton);
startUiContainer.addChild(shopButton);
// --- RESET BUTTON UI LOGIC ---
var resetButtonWidth = 420;
var resetButtonHeight = 110;
var resetButton = new Container();
var resetButtonBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: resetButtonWidth,
height: resetButtonHeight
});
resetButtonBg.alpha = 0.92;
resetButton.addChild(resetButtonBg);
var resetButtonText = new Text2("RESET", {
size: 110,
fill: "#fff"
});
resetButtonText.anchor.set(0.5, 0.5);
resetButtonText.x = 0;
resetButtonText.y = 0;
resetButton.addChild(resetButtonText);
// Position reset button below shop button
resetButton.x = 0;
resetButton.y = shopButton.y + shopButtonHeight / 2 + 40 + resetButtonHeight / 2;
startUiContainer.addChild(resetButton);
// --- RESET POPUP LOGIC ---
var resetPopup = null;
function showResetPopup() {
if (resetPopup && !resetPopup.destroyed) return;
resetPopup = new Container();
// Popup background
var popupW = 900;
var popupH = 600;
var popupBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: popupW,
height: popupH
});
popupBg.alpha = 0.98;
resetPopup.addChild(popupBg);
// Popup text
var popupText = new Text2("Are you sure you want to reset all progress?", {
size: 80,
fill: "#fff"
});
popupText.anchor.set(0.5, 0.5);
popupText.x = 0;
popupText.y = -100;
resetPopup.addChild(popupText);
// Yes button
var yesBtn = new Container();
var yesBtnBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: 320,
height: 120
});
yesBtnBg.alpha = 0.95;
yesBtn.addChild(yesBtnBg);
var yesBtnText = new Text2("YES", {
size: 90,
fill: 0x2ECC40
});
yesBtnText.anchor.set(0.5, 0.5);
yesBtnText.x = 0;
yesBtnText.y = 0;
yesBtn.addChild(yesBtnText);
yesBtn.x = -180;
yesBtn.y = 120;
// No button
var noBtn = new Container();
var noBtnBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: 320,
height: 120
});
noBtnBg.alpha = 0.95;
noBtn.addChild(noBtnBg);
var noBtnText = new Text2("NO", {
size: 90,
fill: 0xE74C3C
});
noBtnText.anchor.set(0.5, 0.5);
noBtnText.x = 0;
noBtnText.y = 0;
noBtn.addChild(noBtnText);
noBtn.x = 180;
noBtn.y = 120;
// Add buttons to popup
resetPopup.addChild(yesBtn);
resetPopup.addChild(noBtn);
// Center popup
resetPopup.x = 2048 / 2;
resetPopup.y = 2732 / 2;
game.addChild(resetPopup);
// Yes: reset all progress and reload game state
yesBtn.down = function () {
// Clear all persistent storage
for (var key in storage) {
if (storage.hasOwnProperty(key)) {
delete storage[key];
}
}
// Optionally, force reload by reloading the page, but here we just reset all variables and UI
// Remove popup
if (resetPopup && !resetPopup.destroyed) {
resetPopup.destroy();
resetPopup = null;
}
// Remove start UI if present
if (startUiContainer && !startUiContainer.destroyed) {
startUiContainer.destroy();
}
// Remove all enemies, fireballs, coins
for (var i = enemies.length - 1; i >= 0; i--) {
if (enemies[i] && !enemies[i].destroyed) enemies[i].destroy();
enemies.splice(i, 1);
}
for (var i = fireballs.length - 1; i >= 0; i--) {
if (fireballs[i] && !fireballs[i].destroyed) fireballs[i].destroy();
fireballs.splice(i, 1);
}
for (var i = coins.length - 1; i >= 0; i--) {
if (coins[i] && !coins[i].destroyed) coins[i].destroy();
coins.splice(i, 1);
}
// Reset all progress variables
score = 0;
coinCount = 0;
speedUpgradeLevel = 0;
speedUpgradeCost = 50;
damageUpgradeLevel = 0;
damageUpgradeCost = 60;
healthUpgradeLevel = 0;
healthUpgradeCost = 25;
maxWizardHealth = 5;
wizardHealth = 5;
fireballDamage = 1;
// Reset shop purchases and upgrades
shopPurchases = {};
storage.shopPurchases = {};
wizardAsset = "wizard";
storage.wizardAsset = "wizard"; // persist default asset
storage.speedUpgradeLevel = 0;
storage.speedUpgradeCost = 50;
storage.damageUpgradeLevel = 0;
storage.damageUpgradeCost = 60;
storage.healthUpgradeLevel = 0;
storage.healthUpgradeCost = 25;
storage.maxWizardHealth = 5;
storage.wizardHealth = 5;
storage.fireballDamage = 1;
// Update UI
scoreText.setText("Score: 0");
coinText.setText("" + coinCount);
// Reset wizard asset to default and ensure only one asset exists
// Remove all children
for (var i = wizard.children.length - 1; i >= 0; i--) {
wizard.removeChild(wizard.children[i]);
}
// Attach new wizard asset as the only sprite
var newSprite = wizard.attachAsset('wizard', {
anchorX: 0.5,
anchorY: 0.5
});
// Reset health bar (no-op)
updateHealthBar();
// Center wizard
wizard.x = 2048 / 2;
wizard.y = 2732 / 2;
if (wizard.children && wizard.children.length > 0) {
wizard.children[0].rotation = Math.PI;
}
// Recreate start UI
startUiContainer = new Container();
startButton = new Container();
startButtonBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: startButtonWidth,
height: startButtonHeight
});
startButtonBg.alpha = 0.92;
startButton.addChild(startButtonBg);
startButtonText = new Text2("START GAME", {
size: 220,
fill: "#fff"
});
startButtonText.anchor.set(0.5, 0.5);
startButtonText.x = 0;
startButtonText.y = -120;
startButton.addChild(startButtonText);
upgradeButton = new Container();
upgradeButtonBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: upgradeButtonWidth,
height: upgradeButtonHeight
});
upgradeButtonBg.alpha = 0.92;
upgradeButton.addChild(upgradeButtonBg);
upgradeButtonText = new Text2("UPGRADE", {
size: 110,
fill: "#fff"
});
upgradeButtonText.anchor.set(0.5, 0.5);
upgradeButtonText.x = 0;
upgradeButtonText.y = 0;
upgradeButton.addChild(upgradeButtonText);
shopButton = new Container();
shopButtonBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: shopButtonWidth,
height: shopButtonHeight
});
shopButtonBg.alpha = 0.92;
shopButton.addChild(shopButtonBg);
shopButtonText = new Text2("SHOP", {
size: 110,
fill: "#fff"
});
shopButtonText.anchor.set(0.5, 0.5);
shopButtonText.x = 0;
shopButtonText.y = 0;
shopButton.addChild(shopButtonText);
// Re-add reset button
resetButton = new Container();
resetButtonBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: resetButtonWidth,
height: resetButtonHeight
});
resetButtonBg.alpha = 0.92;
resetButton.addChild(resetButtonBg);
resetButtonText = new Text2("RESET", {
size: 110,
fill: "#fff"
});
resetButtonText.anchor.set(0.5, 0.5);
resetButtonText.x = 0;
resetButtonText.y = 0;
resetButton.addChild(resetButtonText);
// Position all buttons
startButton.x = 0;
startButton.y = -400;
upgradeButton.x = 0;
upgradeButton.y = startButton.y + startButtonHeight / 2 + 55 + upgradeButtonHeight / 2;
shopButton.x = 0;
shopButton.y = upgradeButton.y + upgradeButtonHeight / 2 + 40 + shopButtonHeight / 2;
resetButton.x = 0;
resetButton.y = shopButton.y + shopButtonHeight / 2 + 40 + resetButtonHeight / 2;
// Add to container
startUiContainer.addChild(startButton);
startUiContainer.addChild(upgradeButton);
startUiContainer.addChild(shopButton);
startUiContainer.addChild(resetButton);
startUiContainer.x = 2048 / 2;
startUiContainer.y = 2732 / 2;
game.addChild(startUiContainer);
// Re-attach handlers
upgradeButton.down = function (x, y, obj) {
if (upgradeWindow && !upgradeWindow.destroyed) return;
showUpgradeWindow();
};
shopButton.down = function (x, y, obj) {
if (shopWindow && !shopWindow.destroyed) return;
showShopWindow();
};
startButton.down = function (x, y, obj) {
if (gameStarted) return;
gameStarted = true;
if (startUiContainer && !startUiContainer.destroyed) {
startUiContainer.destroy();
}
// Remove all enemies, fireballs, coins
for (var i = enemies.length - 1; i >= 0; i--) {
if (enemies[i] && !enemies[i].destroyed) enemies[i].destroy();
enemies.splice(i, 1);
}
for (var i = fireballs.length - 1; i >= 0; i--) {
if (fireballs[i] && !fireballs[i].destroyed) fireballs[i].destroy();
fireballs.splice(i, 1);
}
for (var i = coins.length - 1; i >= 0; i--) {
if (coins[i] && !coins[i].destroyed) coins[i].destroy();
coins.splice(i, 1);
}
score = 0;
scoreText.setText("Score: 0");
coinText.setText("" + coinCount);
wizard.x = 2048 / 2;
wizard.y = 2732 / 2;
if (wizard.children && wizard.children.length > 0) {
wizard.children[0].rotation = Math.PI;
}
// --- Reset magazine system ---
// If minigun is selected, always set to 350 ammo at new game start
if (wizardAsset === "minigun") {
wizardMaxAmmo = 350;
wizardAmmo = 350;
tapFireCooldown = 500;
} else if (wizardAsset === "Lasergun") {
wizardMaxAmmo = 10;
wizardAmmo = wizardMaxAmmo;
tapFireCooldown = 300;
} else {
wizardAmmo = wizardMaxAmmo;
}
wizardReloading = false;
if (wizardReloadTimeout) {
LK.clearTimeout(wizardReloadTimeout);
wizardReloadTimeout = null;
}
// Health bar is now fixed in the GUI, no need to reposition here
wizardHealth = maxWizardHealth;
updateHealthBar();
game.move = originalGameMove;
game.down = originalGameDown;
game.up = originalGameUp;
};
resetButton.down = function (x, y, obj) {
showResetPopup();
};
// Block input until start is pressed
blockGameInput();
gameStarted = false;
};
// No: close popup
noBtn.down = function () {
if (resetPopup && !resetPopup.destroyed) {
resetPopup.destroy();
resetPopup = null;
}
};
}
// Reset button interaction
resetButton.down = function (x, y, obj) {
showResetPopup();
};
// Position the UI container: horizontally centered, vertically centered
startUiContainer.x = 2048 / 2;
startUiContainer.y = 2732 / 2;
// Add to game
game.addChild(startUiContainer);
// Block input until start is pressed
function blockGameInput() {
game.move = function () {};
game.down = function () {};
game.up = function () {};
isFiring = false;
if (fireInterval) {
LK.clearInterval(fireInterval);
fireInterval = null;
}
}
blockGameInput();
// --- UPGRADE WINDOW LOGIC ---
var upgradeWindow = null;
function showUpgradeWindow() {
if (upgradeWindow && !upgradeWindow.destroyed) return;
upgradeWindow = new Container();
// Window background (main)
var winW = 1200 + 500 - 250,
// Decrease width by 250px
winH = 1100 + 500 + 500; // Increase height by 500px again, width unchanged
var winBg = LK.getAsset('upgradescreen', {
anchorX: 0.5,
anchorY: 0.5,
width: winW,
height: winH
});
winBg.alpha = 0.97;
upgradeWindow.addChild(winBg);
// Title removed: no upgrade window title text
// Button helper with icon
function makeUpgradeBtn(label, y, color, iconAsset, iconColor) {
var btn = new Container();
// No background for speed, power, health, or back buttons
// Icon asset (left side of button)
var icon = null;
if (iconAsset) {
// If this is the health asset, increase its size by 50px
if (iconAsset === 'health') {
icon = LK.getAsset(iconAsset, {
anchorX: 0.5,
anchorY: 0.5,
x: -360,
// 100px more to the left
y: 0,
width: 150,
height: 150
});
} else {
icon = LK.getAsset(iconAsset, {
anchorX: 0.5,
anchorY: 0.5,
x: -360,
// 100px more to the left
y: 0,
scaleX: 1.2,
scaleY: 1.2
});
}
// Remove any filter/overlay in front of the icon (if any exist)
if (icon.filters && icon.filters.length > 0) {
icon.filters = [];
}
btn.addChild(icon);
}
var btnText = new Text2(label, {
size: 100,
fill: "#fff"
});
btnText.anchor.set(0.5, 0.5);
btnText.x = 60;
btnText.y = 0;
btn.addChild(btnText);
btn.x = 0;
btn.y = y;
return btn;
}
// Hız, Hüç, Health, Geri buttons with icons and unique colors
var btnSpacing = 280; // Increased by 50 from 230 to 280
var btns = [];
// Use fast, power, background assets for each upgrade (background as health icon)
var btnLabels = [{
label: "SPEED",
iconAsset: 'fast'
}, {
label: "DAMAGE",
iconAsset: 'power'
}, {
label: "HEALTH",
iconAsset: 'health'
}];
for (var i = 0; i < btnLabels.length; i++) {
var btn = makeUpgradeBtn(btnLabels[i].label, -120 + i * btnSpacing, btnLabels[i].color, btnLabels[i].iconAsset, btnLabels[i].iconColor);
upgradeWindow.addChild(btn);
btns.push(btn);
}
// --- SPEED UPGRADE LOGIC ---
if (typeof speedUpgradeBtnText === "undefined") speedUpgradeBtnText = null;
var upgrades = getWeaponUpgrades(wizardAsset);
speedUpgradeLevel = upgrades.speedUpgradeLevel;
speedUpgradeCost = upgrades.speedUpgradeCost;
btns[0].down = function () {
var upgrades = getWeaponUpgrades(wizardAsset);
if (coinCount >= upgrades.speedUpgradeCost && upgrades.speedUpgradeLevel < 3) {
coinCount -= upgrades.speedUpgradeCost;
coinText.setText("" + coinCount);
upgrades.speedUpgradeLevel += 1;
// Set next cost based on upgrade level
if (upgrades.speedUpgradeLevel === 1) {
upgrades.speedUpgradeCost = 75;
} else if (upgrades.speedUpgradeLevel === 2) {
upgrades.speedUpgradeCost = 100;
} else if (upgrades.speedUpgradeLevel >= 3) {
upgrades.speedUpgradeCost = "-";
}
saveWeaponUpgrades(wizardAsset, upgrades);
speedUpgradeLevel = upgrades.speedUpgradeLevel;
speedUpgradeCost = upgrades.speedUpgradeCost;
// Update fire interval for faster shooting (decrease interval by 150ms per upgrade)
tapFireCooldown = Math.max(100, 850 - speedUpgradeLevel * 150);
// Update button label to show new cost or disable if maxed
if (speedUpgradeBtnText) {
if (btns[0].coinIcon && btns[0].coinIcon.parent) {
btns[0].coinIcon.parent.removeChild(btns[0].coinIcon);
btns[0].coinIcon = null;
}
if (speedUpgradeLevel < 3) {
speedUpgradeBtnText.setText("SPEED | " + speedUpgradeCost);
var coinAsset = LK.getAsset('coin', {
anchorX: 0.0,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
coinAsset.x = speedUpgradeBtnText.x + speedUpgradeBtnText.width / 2 + coinAsset.width * 0.6;
coinAsset.y = speedUpgradeBtnText.y;
btns[0].addChild(coinAsset);
btns[0].coinIcon = coinAsset;
} else {
speedUpgradeBtnText.setText("SPEED | MAX");
}
}
LK.effects.flashObject(btns[0], 0x2ecc40, 400);
} else if (speedUpgradeLevel >= 3) {
LK.effects.flashObject(btns[0], 0x888888, 400);
} else {
LK.effects.flashObject(coinText, 0xe74c3c, 600);
}
};
// Always set speedUpgradeBtnText to the SPEED button label when opening the window
speedUpgradeBtnText = btns[0].children[1];
if (speedUpgradeBtnText) {
if (btns[0].coinIcon && btns[0].coinIcon.parent) {
btns[0].coinIcon.parent.removeChild(btns[0].coinIcon);
btns[0].coinIcon = null;
}
if (speedUpgradeLevel < 3) {
speedUpgradeBtnText.setText("SPEED | " + speedUpgradeCost);
var coinAsset = LK.getAsset('coin', {
anchorX: 0.0,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
coinAsset.x = speedUpgradeBtnText.x + speedUpgradeBtnText.width / 2 + coinAsset.width * 0.6;
coinAsset.y = speedUpgradeBtnText.y;
btns[0].addChild(coinAsset);
btns[0].coinIcon = coinAsset;
} else {
speedUpgradeBtnText.setText("SPEED | MAX");
}
}
// --- DAMAGE/POWER UPGRADE LOGIC ---
if (typeof damageUpgradeBtnText === "undefined") damageUpgradeBtnText = null;
damageUpgradeLevel = upgrades.damageUpgradeLevel;
damageUpgradeCost = upgrades.damageUpgradeCost;
btns[1].down = function () {
var upgrades = getWeaponUpgrades(wizardAsset);
if (coinCount >= upgrades.damageUpgradeCost && upgrades.damageUpgradeLevel < 3) {
coinCount -= upgrades.damageUpgradeCost;
coinText.setText("" + coinCount);
upgrades.damageUpgradeLevel += 1;
upgrades.fireballDamage = 1 + upgrades.damageUpgradeLevel;
// Set next cost based on upgrade level
if (upgrades.damageUpgradeLevel === 1) {
upgrades.damageUpgradeCost = 120;
} else if (upgrades.damageUpgradeLevel === 2) {
upgrades.damageUpgradeCost = 180;
} else if (upgrades.damageUpgradeLevel >= 3) {
upgrades.damageUpgradeCost = "-";
}
saveWeaponUpgrades(wizardAsset, upgrades);
damageUpgradeLevel = upgrades.damageUpgradeLevel;
damageUpgradeCost = upgrades.damageUpgradeCost;
fireballDamage = upgrades.fireballDamage;
// Update button label to show new cost or disable if maxed
if (damageUpgradeBtnText) {
if (btns[1].coinIcon && btns[1].coinIcon.parent) {
btns[1].coinIcon.parent.removeChild(btns[1].coinIcon);
btns[1].coinIcon = null;
}
if (damageUpgradeLevel < 3) {
damageUpgradeBtnText.setText("DAMAGE | " + damageUpgradeCost);
var coinAsset = LK.getAsset('coin', {
anchorX: 0.0,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
coinAsset.x = damageUpgradeBtnText.x + damageUpgradeBtnText.width / 2 + coinAsset.width * 0.6;
coinAsset.y = damageUpgradeBtnText.y;
btns[1].addChild(coinAsset);
btns[1].coinIcon = coinAsset;
} else {
damageUpgradeBtnText.setText("DAMAGE | MAX");
}
}
LK.effects.flashObject(btns[1], 0x2ecc40, 400);
} else if (damageUpgradeLevel >= 3) {
LK.effects.flashObject(btns[1], 0x888888, 400);
} else {
LK.effects.flashObject(coinText, 0xe74c3c, 600);
}
};
// Always set damageUpgradeBtnText to the POWER button label when opening the window
damageUpgradeBtnText = btns[1].children[1];
if (damageUpgradeBtnText) {
if (btns[1].coinIcon && btns[1].coinIcon.parent) {
btns[1].coinIcon.parent.removeChild(btns[1].coinIcon);
btns[1].coinIcon = null;
}
if (damageUpgradeLevel < 3) {
damageUpgradeBtnText.setText("DAMAGE | " + damageUpgradeCost);
var coinAsset = LK.getAsset('coin', {
anchorX: 0.0,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
coinAsset.x = damageUpgradeBtnText.x + damageUpgradeBtnText.width / 2 + coinAsset.width * 0.6;
coinAsset.y = damageUpgradeBtnText.y;
btns[1].addChild(coinAsset);
btns[1].coinIcon = coinAsset;
} else {
damageUpgradeBtnText.setText("DAMAGE | MAX");
}
}
// HEALTH upgrade logic: cost increases after each purchase, +2 max health, +2 current health, max 3 upgrades: 25, 50, 75 coin
healthUpgradeLevel = upgrades.healthUpgradeLevel;
healthUpgradeCost = upgrades.healthUpgradeCost;
maxWizardHealth = upgrades.maxWizardHealth;
wizardHealth = upgrades.wizardHealth;
btns[2].down = function () {
var upgrades = getWeaponUpgrades(wizardAsset);
if (coinCount >= upgrades.healthUpgradeCost && upgrades.healthUpgradeLevel < 3) {
coinCount -= upgrades.healthUpgradeCost;
coinText.setText("" + coinCount);
upgrades.maxWizardHealth += 2;
upgrades.wizardHealth += 2;
updateHealthBar();
upgrades.healthUpgradeLevel += 1;
// Set next cost based on upgrade level
if (upgrades.healthUpgradeLevel === 1) {
upgrades.healthUpgradeCost = 50;
} else if (upgrades.healthUpgradeLevel === 2) {
upgrades.healthUpgradeCost = 75;
} else if (upgrades.healthUpgradeLevel >= 3) {
upgrades.healthUpgradeCost = "-";
}
saveWeaponUpgrades(wizardAsset, upgrades);
healthUpgradeLevel = upgrades.healthUpgradeLevel;
healthUpgradeCost = upgrades.healthUpgradeCost;
maxWizardHealth = upgrades.maxWizardHealth;
wizardHealth = upgrades.wizardHealth;
// Update button label to show new cost or disable if maxed
if (healthUpgradeBtnText) {
if (btns[2].coinIcon && btns[2].coinIcon.parent) {
btns[2].coinIcon.parent.removeChild(btns[2].coinIcon);
btns[2].coinIcon = null;
}
if (healthUpgradeLevel < 3) {
healthUpgradeBtnText.setText("HEALTH | " + healthUpgradeCost);
var coinAsset = LK.getAsset('coin', {
anchorX: 0.0,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
coinAsset.x = healthUpgradeBtnText.x + healthUpgradeBtnText.width / 2 + coinAsset.width * 0.6;
coinAsset.y = healthUpgradeBtnText.y;
btns[2].addChild(coinAsset);
btns[2].coinIcon = coinAsset;
} else {
healthUpgradeBtnText.setText("HEALTH | MAX");
}
}
} else if (healthUpgradeLevel >= 3) {
LK.effects.flashObject(btns[2], 0x888888, 400);
} else {
LK.effects.flashObject(coinText, 0xe74c3c, 600);
}
};
// Always set healthUpgradeBtnText to the HEALTH button label when opening the window
healthUpgradeBtnText = btns[2].children[1];
if (healthUpgradeBtnText) {
if (btns[2].coinIcon && btns[2].coinIcon.parent) {
btns[2].coinIcon.parent.removeChild(btns[2].coinIcon);
btns[2].coinIcon = null;
}
if (healthUpgradeLevel < 3) {
healthUpgradeBtnText.setText("HEALTH | " + healthUpgradeCost);
var coinAsset = LK.getAsset('coin', {
anchorX: 0.0,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
coinAsset.x = healthUpgradeBtnText.x + healthUpgradeBtnText.width / 2 + coinAsset.width * 0.6;
coinAsset.y = healthUpgradeBtnText.y;
btns[2].addChild(coinAsset);
btns[2].coinIcon = coinAsset;
} else {
healthUpgradeBtnText.setText("HEALTH | MAX");
}
}
// BACK button without coin asset
// Place it 500 units further from HEALTH (btnSpacing = 280, so HEALTH is at -120 + 2*280 = 440, BACK at 440+500=940)
var geriBtn = makeUpgradeBtn("BACK", 940, undefined, null, undefined);
upgradeWindow.addChild(geriBtn);
// BACK closes window
geriBtn.down = function () {
if (upgradeWindow && !upgradeWindow.destroyed) {
upgradeWindow.destroy();
upgradeWindow = null;
}
};
// Center window
upgradeWindow.x = 2048 / 2;
upgradeWindow.y = 2732 / 2;
game.addChild(upgradeWindow);
}
// Upgrade button interaction
upgradeButton.down = function (x, y, obj) {
if (upgradeWindow && !upgradeWindow.destroyed) return;
showUpgradeWindow();
};
// --- SHOP WINDOW LOGIC ---
var shopWindow = null;
function showShopWindow() {
if (shopWindow && !shopWindow.destroyed) return;
shopWindow = new Container();
// Window background
var winW = 1500;
var winH = 2000;
var winBg = LK.getAsset('shop', {
anchorX: 0.5,
anchorY: 0.5,
width: winW,
height: winH
});
winBg.alpha = 0.97;
shopWindow.addChild(winBg);
// Title text removed
// Weapon shop items
var weaponList = [{
name: "SMG",
asset: "submachine",
price: 100
}, {
name: "SAG",
asset: "MP5",
price: 150
}, {
name: "Shuriken",
asset: "shuriken",
price: 1
}, {
name: "Shotgun",
asset: "shotgun",
price: 250
}, {
name: "Minigun",
asset: "minigun",
price: 1
}, {
name: "Laser Gun",
asset: "Lasergun",
price: 1
}];
var itemStartY = -350;
var itemSpacing = 220;
var shopItemButtons = [];
var _loop = function _loop() {
weapon = weaponList[i];
itemY = itemStartY + i * itemSpacing;
shopItem = new Container(); // Icon (left)
itemIcon = LK.getAsset(weapon.asset, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.0,
scaleY: 1.0,
x: -420,
y: 0
});
shopItem.addChild(itemIcon);
// "SMG | x" text (centered)
itemText = new Text2(weapon.name + " | " + weapon.price, {
size: 90,
fill: "#fff"
});
itemText.anchor.set(0, 0.5);
itemText.x = -180;
itemText.y = 0;
shopItem.addChild(itemText);
// Coin asset (right of price)
priceCoin = LK.getAsset('coin', {
anchorX: 0.0,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7,
x: itemText.x + itemText.width + 30,
y: itemText.y
});
shopItem.addChild(priceCoin);
// PURCHASED label (hidden by default)
purchasedLabel = new Text2("PURCHASED", {
size: 80,
fill: 0x2ECC40
});
purchasedLabel.anchor.set(0, 0.5);
purchasedLabel.x = itemText.x + itemText.width + 120;
purchasedLabel.y = itemText.y;
purchasedLabel.visible = false;
shopItem.addChild(purchasedLabel);
// SELECTED label (hidden by default)
selectedLabel = new Text2("SELECTED", {
size: 80,
fill: 0xFFD700
});
selectedLabel.anchor.set(0, 0.5);
selectedLabel.x = itemText.x + itemText.width + 120;
selectedLabel.y = itemText.y;
selectedLabel.visible = false;
shopItem.addChild(selectedLabel);
// Helper to update purchased/selected state visuals
function updateShopItemState() {
var isPurchased = shopPurchases && shopPurchases[weapon.asset];
var isSelected = wizardAsset === weapon.asset;
purchasedLabel.visible = !!isPurchased && !isSelected;
selectedLabel.visible = !!isPurchased && isSelected;
if (!!isPurchased && isSelected) {
priceCoin.visible = false;
itemText.setText(weapon.name);
} else {
priceCoin.visible = !isPurchased;
itemText.setText(weapon.name + (isPurchased ? "" : " | " + weapon.price));
}
}
updateShopItemState();
// Add down handler for all shop items
(function (weapon, shopItem, purchasedLabel, selectedLabel, priceCoin, itemText, updateShopItemState) {
shopItem.down = function () {
var isPurchased = shopPurchases && shopPurchases[weapon.asset];
var isSelected = wizardAsset === weapon.asset;
if (isPurchased) {
// If already purchased, just switch to this weapon
if (!isSelected) {
// Remove all children to ensure only one wizard asset
for (var i = wizard.children.length - 1; i >= 0; i--) {
wizard.removeChild(wizard.children[i]);
}
// Add new asset as wizard's appearance
var newSprite = wizard.attachAsset(weapon.asset, {
anchorX: 0.5,
anchorY: 0.5
});
// Save wizard asset
storage.wizardAsset = weapon.asset;
wizardAsset = weapon.asset;
// Switch upgrades to selected weapon
currentWeaponUpgrades = getWeaponUpgrades(wizardAsset);
speedUpgradeLevel = currentWeaponUpgrades.speedUpgradeLevel;
speedUpgradeCost = currentWeaponUpgrades.speedUpgradeCost;
damageUpgradeLevel = currentWeaponUpgrades.damageUpgradeLevel;
damageUpgradeCost = currentWeaponUpgrades.damageUpgradeCost;
healthUpgradeLevel = currentWeaponUpgrades.healthUpgradeLevel;
healthUpgradeCost = currentWeaponUpgrades.healthUpgradeCost;
maxWizardHealth = currentWeaponUpgrades.maxWizardHealth;
wizardHealth = currentWeaponUpgrades.wizardHealth;
fireballDamage = currentWeaponUpgrades.fireballDamage;
// --- Minigun ayarları ---
if (weapon.asset === "minigun") {
// Minigun için mermi asseti ve şarjör ayarları
// If minigun is selected, always set to 350 ammo at new game start
if (wizardAsset === "minigun") {
wizardMaxAmmo = 350;
wizardAmmo = 350;
} else {
wizardAmmo = wizardMaxAmmo;
}
wizardMaxAmmo = 350;
wizardReloadTime = 2000;
tapFireCooldown = 500;
// Minigun için fireball yerine minigunbullet kullanılacak, shootFireballAt fonksiyonunda kontrol edilecek
wizardBulletType = "minigunbullet";
} else if (weapon.asset === "shuriken") {
// Shuriken için sonsuz mermi
wizardBulletType = "shurikenbullet";
wizardMaxAmmo = 7;
wizardAmmo = wizardMaxAmmo;
wizardReloadTime = 2000;
tapFireCooldown = 750;
} else if (weapon.asset === "Lasergun") {
wizardBulletType = "lasergunbullet";
wizardMaxAmmo = 10;
wizardAmmo = wizardMaxAmmo;
wizardReloadTime = 1200;
tapFireCooldown = 300;
} else {
// Diğer silahlar için default ayarlar
wizardBulletType = null;
wizardMaxAmmo = 7;
wizardAmmo = wizardMaxAmmo;
wizardReloadTime = 2000;
tapFireCooldown = Math.max(100, 850 - speedUpgradeLevel * 150);
}
// Move health bar above new asset
// Health bar is now fixed in the GUI, no need to reposition here
// Feedback
LK.effects.flashObject(wizard, 0x2ecc40, 400);
// Update visuals for all shop items
for (var si = 0; si < shopItemButtons.length; si++) {
if (shopItemButtons[si].updateShopItemState) shopItemButtons[si].updateShopItemState();
}
}
// If already selected, do nothing
return;
}
// Not purchased yet
if (coinCount >= weapon.price) {
coinCount -= weapon.price;
coinText.setText("" + coinCount);
// Remove all children to ensure only one wizard asset
for (var i = wizard.children.length - 1; i >= 0; i--) {
wizard.removeChild(wizard.children[i]);
}
// Add new asset as wizard's appearance
var newSprite = wizard.attachAsset(weapon.asset, {
anchorX: 0.5,
anchorY: 0.5
});
// Save wizard asset and shop purchase
storage.wizardAsset = weapon.asset;
wizardAsset = weapon.asset;
// Switch upgrades to selected weapon
currentWeaponUpgrades = getWeaponUpgrades(wizardAsset);
speedUpgradeLevel = currentWeaponUpgrades.speedUpgradeLevel;
speedUpgradeCost = currentWeaponUpgrades.speedUpgradeCost;
damageUpgradeLevel = currentWeaponUpgrades.damageUpgradeLevel;
damageUpgradeCost = currentWeaponUpgrades.damageUpgradeCost;
healthUpgradeLevel = currentWeaponUpgrades.healthUpgradeLevel;
healthUpgradeCost = currentWeaponUpgrades.healthUpgradeCost;
maxWizardHealth = currentWeaponUpgrades.maxWizardHealth;
wizardHealth = currentWeaponUpgrades.wizardHealth;
fireballDamage = currentWeaponUpgrades.fireballDamage;
if (!shopPurchases) shopPurchases = {};
shopPurchases[weapon.asset] = true;
storage.shopPurchases = shopPurchases;
// --- Minigun ayarları ---
if (weapon.asset === "minigun") {
// Minigun için mermi asseti ve şarjör ayarları
wizardMaxAmmo = 350;
wizardAmmo = wizardMaxAmmo;
wizardReloadTime = 2000;
tapFireCooldown = 500;
wizardBulletType = "minigunbullet";
} else if (weapon.asset === "shuriken") {
// Shuriken için sonsuz mermi
wizardBulletType = "shurikenbullet";
wizardMaxAmmo = 7;
wizardAmmo = wizardMaxAmmo;
wizardReloadTime = 2000;
tapFireCooldown = 750;
} else if (weapon.asset === "Lasergun") {
wizardBulletType = "lasergunbullet";
wizardMaxAmmo = 10;
wizardAmmo = wizardMaxAmmo;
wizardReloadTime = 1200;
tapFireCooldown = 300;
} else {
// Diğer silahlar için default ayarlar
wizardBulletType = null;
wizardMaxAmmo = 7;
wizardAmmo = wizardMaxAmmo;
wizardReloadTime = 2000;
tapFireCooldown = Math.max(100, 850 - speedUpgradeLevel * 150);
}
// Move health bar above new asset
// Health bar is now fixed in the GUI, no need to reposition here
// Feedback
LK.effects.flashObject(wizard, 0x2ecc40, 400);
// Update visuals for all shop items
for (var si = 0; si < shopItemButtons.length; si++) {
if (shopItemButtons[si].updateShopItemState) shopItemButtons[si].updateShopItemState();
}
} else {
LK.effects.flashObject(coinText, 0xe74c3c, 600);
}
};
// Attach state update helper for global update
shopItem.updateShopItemState = updateShopItemState;
})(weapon, shopItem, purchasedLabel, selectedLabel, priceCoin, itemText, updateShopItemState);
shopItem.x = 0;
shopItem.y = itemY;
shopWindow.addChild(shopItem);
shopItemButtons.push(shopItem);
},
weapon,
itemY,
shopItem,
itemIcon,
itemText,
priceCoin,
purchasedLabel,
selectedLabel;
for (var i = 0; i < weaponList.length; i++) {
_loop();
}
// BACK button
var backBtn = new Container();
// No background for back button
var backBtnText = new Text2("BACK", {
size: 90,
fill: "#fff"
});
backBtnText.anchor.set(0.5, 0.5);
backBtnText.x = 0;
backBtnText.y = 0;
backBtn.addChild(backBtnText);
backBtn.x = 0;
backBtn.y = itemStartY + weaponList.length * itemSpacing + 80;
shopWindow.addChild(backBtn);
backBtn.down = function () {
if (shopWindow && !shopWindow.destroyed) {
shopWindow.destroy();
shopWindow = null;
}
};
// Center window
shopWindow.x = 2048 / 2;
shopWindow.y = 2732 / 2;
game.addChild(shopWindow);
}
// Shop button interaction
shopButton.down = function (x, y, obj) {
if (shopWindow && !shopWindow.destroyed) return;
showShopWindow();
};
// Start button interaction
startButton.down = function (x, y, obj) {
if (gameStarted) return;
gameStarted = true;
// Remove start UI container (removes both start and upgrade buttons)
if (startUiContainer && !startUiContainer.destroyed) {
startUiContainer.destroy();
}
// --- RESET GAME STATE ---
// Remove all enemies, fireballs, coins from game and arrays
for (var i = enemies.length - 1; i >= 0; i--) {
if (enemies[i] && !enemies[i].destroyed) enemies[i].destroy();
enemies.splice(i, 1);
}
for (var i = fireballs.length - 1; i >= 0; i--) {
if (fireballs[i] && !fireballs[i].destroyed) fireballs[i].destroy();
fireballs.splice(i, 1);
}
for (var i = coins.length - 1; i >= 0; i--) {
if (coins[i] && !coins[i].destroyed) coins[i].destroy();
coins.splice(i, 1);
}
// Reset score and coin count
score = 0;
// coinCount is NOT reset here, so coins are preserved when starting a new game
scoreText.setText("Score: 0");
coinText.setText("" + coinCount);
// Center wizard
wizard.x = 2048 / 2;
wizard.y = 2732 / 2;
// Remove all children to ensure only one wizard asset
for (var i = wizard.children.length - 1; i >= 0; i--) {
wizard.removeChild(wizard.children[i]);
}
// Attach wizard asset if not present
var hasWizardSprite = false;
for (var i = 0; i < wizard.children.length; i++) {
hasWizardSprite = true;
break;
}
if (!hasWizardSprite) {
var newSprite = wizard.attachAsset(wizardAsset, {
anchorX: 0.5,
anchorY: 0.5
});
if (newSprite) {
newSprite.rotation = Math.PI;
}
} else if (wizard.children && wizard.children.length > 0) {
wizard.children[0].rotation = Math.PI; // face left
}
// Reset health
wizardHealth = maxWizardHealth;
updateHealthBar();
// Enable game input
game.move = originalGameMove;
game.down = originalGameDown;
game.up = originalGameUp;
};
// Save original handlers for restoration
var originalGameMove = function originalGameMove(x, y, obj) {
// Wizard is fixed; do nothing
// Calculate angle from wizard to pointer/touch and rotate wizard sprite
var dx = x - wizard.x;
var dy = y - wizard.y;
var angle = Math.atan2(dy, dx);
// Wizard's default asset faces left, so add Math.PI to rotate to correct direction
if (wizard.children && wizard.children.length > 0) {
wizard.children[0].rotation = angle + Math.PI;
}
// If firing, update direction for continuous fire
if (isFiring) {
lastFireX = x;
lastFireY = y;
}
};
var originalGameDown = function originalGameDown(x, y, obj) {
var now = Date.now();
if (now - lastTapFireTime < tapFireCooldown) {
// Too soon, ignore this tap for firing
return;
}
lastTapFireTime = now;
isFiring = true;
lastFireX = x;
lastFireY = y;
shootFireballAt(x, y);
if (fireInterval) LK.clearInterval(fireInterval);
fireInterval = LK.setInterval(function () {
if (isFiring) {
shootFireballAt(lastFireX, lastFireY);
}
}, tapFireCooldown); // fire every tapFireCooldown ms when holding down
};
var originalGameUp = function originalGameUp(x, y, obj) {
isFiring = false;
if (fireInterval) {
LK.clearInterval(fireInterval);
fireInterval = null;
}
};
// Array to hold all fireballs
var fireballs = [];
// Helper: get direction vector from wizard to (x, y)
function getDirection(fromX, fromY, toX, toY, speed) {
var dx = toX - fromX;
var dy = toY - fromY;
var len = Math.sqrt(dx * dx + dy * dy);
if (len === 0) return {
vx: 0,
vy: 0
};
return {
vx: dx / len * speed,
vy: dy / len * speed
};
}
// Dragging wizard with mouse/touch (disabled)
var dragging = false;
// Move handler: wizard does not move
game.move = function (x, y, obj) {
if (!gameStarted) return; // Only rotate wizard during gameplay
// Calculate angle from wizard to pointer/touch and rotate wizard sprite
var dx = x - wizard.x;
var dy = y - wizard.y;
var angle = Math.atan2(dy, dx);
// Wizard's default asset faces left, so add Math.PI to rotate to correct direction
if (wizard.children && wizard.children.length > 0) {
wizard.children[0].rotation = angle + Math.PI;
}
// If firing, update direction for continuous fire
if (isFiring) {
lastFireX = x;
lastFireY = y;
}
};
// Track if fire is being held
var isFiring = false;
var fireInterval = null;
var lastFireX = 0;
// --- Magazine system for wizard weapon ---
var wizardMaxAmmo = 7;
var wizardAmmo = wizardMaxAmmo;
var wizardReloading = false;
var wizardReloadTime = 2000; // ms
var wizardReloadTimeout = null;
// Hangi mermi asseti kullanılacak? (null: default, "shurikenbullet", "minigunbullet")
var wizardBulletType = null;
// Cooldown for tap-to-fire (now 850ms)
var lastTapFireTime = 0;
var tapFireCooldown = 850;
function shootFireballAt(x, y) {
// --- Magazine system: block fire if out of ammo or reloading ---
// For shuriken, skip ammo/reload logic (infinite ammo)
if (wizardAsset !== "shuriken") {
if (wizardReloading) {
// Can't shoot while reloading
return;
}
if (wizardAmmo <= 0) {
// Start reload if not already reloading
if (!wizardReloading) {
wizardReloading = true;
wizardReloadTimeout = LK.setTimeout(function () {
wizardAmmo = wizardMaxAmmo;
wizardReloading = false;
wizardReloadTimeout = null;
}, wizardReloadTime);
}
return;
}
// Decrease ammo
wizardAmmo--;
}
// Eğer wizardAsset shuriken ise shurikenbullet fırlat
if (wizardAsset === "shuriken") {
// Fire 3 shurikenbullets at -15, 0, +15 degrees from the main direction
var baseDir = getDirection(wizard.x, wizard.y, x, y, 8);
var baseAngle = Math.atan2(baseDir.vy, baseDir.vx);
var angles = [-15, 0, 15];
for (var i = 0; i < angles.length; i++) {
var angleRad = baseAngle + angles[i] * Math.PI / 180;
var vx = Math.cos(angleRad) * 8;
var vy = Math.sin(angleRad) * 8;
var fireball = new Fireball();
// Remove default fireball sprite, add shurikenbullet
if (fireball.children && fireball.children.length > 0) {
var oldSprite = fireball.children[0];
fireball.removeChild(oldSprite);
}
var shurikenBulletSprite = fireball.attachAsset('shurikenbullet', {
anchorX: 0.5,
anchorY: 0.5
});
fireball.x = wizard.x;
fireball.y = wizard.y;
fireball.vx = vx;
fireball.vy = vy;
if (fireball.children && fireball.children.length > 0) {
fireball.children[0].rotation = angleRad;
}
if (wizard.children && wizard.children.length > 0 && angles[i] === 0) {
wizard.children[0].rotation = baseAngle + Math.PI;
}
fireballs.push(fireball);
game.addChild(fireball);
}
LK.getSound('Minigun').play();
// Set shuriken fire interval to 750ms
tapFireCooldown = 750;
// No reload or ammo decrement for shuriken (infinite ammo)
} else {
// Minigun için özel asset ve ayarlar
if (wizardAsset === "minigun" || wizardBulletType === "minigunbullet") {
tapFireCooldown = 200;
// Fire 1 bullet per tap, but with random scatter in a 30-degree cone
var baseDir = getDirection(wizard.x, wizard.y, x, y, 12); // Minigun için daha hızlı mermi
var baseAngle = Math.atan2(baseDir.vy, baseDir.vx);
// 30-degree cone: -15 to +15 deg, random within
var scatterDeg = Math.random() * 30 - 15;
var scatterRad = scatterDeg * Math.PI / 180;
var angle = baseAngle + scatterRad;
var vx = Math.cos(angle) * 12;
var vy = Math.sin(angle) * 12;
var fireball = new Fireball();
fireball.x = wizard.x;
fireball.y = wizard.y;
fireball.vx = vx;
fireball.vy = vy;
// Default fireball asseti kaldır, minigunbullet ekle
if (fireball.children && fireball.children.length > 0) {
var oldSprite = fireball.children[0];
fireball.removeChild(oldSprite);
}
var minigunBulletSprite = fireball.attachAsset('minigunbullet', {
anchorX: 0.5,
anchorY: 0.5
});
if (fireball.children && fireball.children.length > 0) {
fireball.children[0].rotation = angle;
}
if (wizard.children && wizard.children.length > 0) {
wizard.children[0].rotation = Math.atan2(y - wizard.y, x - wizard.x) + Math.PI;
}
fireballs.push(fireball);
game.addChild(fireball);
LK.getSound('Minigun').play();
// Start reload if out of ammo after this shot
if (wizardAmmo <= 0 && !wizardReloading) {
wizardReloading = true;
wizardReloadTimeout = LK.setTimeout(function () {
wizardAmmo = wizardMaxAmmo;
wizardReloading = false;
wizardReloadTimeout = null;
}, wizardReloadTime);
}
} else if (wizardAsset === "Lasergun" || wizardBulletType === "lasergunbullet") {
tapFireCooldown = 300;
var fireball = new Fireball();
fireball.x = wizard.x;
fireball.y = wizard.y;
var dir = getDirection(wizard.x, wizard.y, x, y, 16);
fireball.vx = dir.vx;
fireball.vy = dir.vy;
var angle = Math.atan2(dir.vy, dir.vx);
// Remove default fireball sprite, add lasergunbullet
if (fireball.children && fireball.children.length > 0) {
var oldSprite = fireball.children[0];
fireball.removeChild(oldSprite);
}
var laserBulletSprite = fireball.attachAsset('lasergunbullet', {
anchorX: 0.5,
anchorY: 0.5
});
if (fireball.children && fireball.children.length > 0) {
fireball.children[0].rotation = angle;
}
if (wizard.children && wizard.children.length > 0) {
wizard.children[0].rotation = Math.atan2(y - wizard.y, x - wizard.x) + Math.PI;
}
fireballs.push(fireball);
game.addChild(fireball);
LK.getSound('plasma').play();
// Start reload if out of ammo after this shot
if (wizardAmmo <= 0 && !wizardReloading) {
wizardReloading = true;
wizardReloadTimeout = LK.setTimeout(function () {
wizardAmmo = wizardMaxAmmo;
wizardReloading = false;
wizardReloadTimeout = null;
}, wizardReloadTime);
}
} else {
// Restore tapFireCooldown to upgrade-based value for non-shuriken weapons
tapFireCooldown = Math.max(100, 850 - speedUpgradeLevel * 150);
var fireball = new Fireball();
fireball.x = wizard.x;
fireball.y = wizard.y;
var dir = getDirection(wizard.x, wizard.y, x, y, 8);
fireball.vx = dir.vx;
fireball.vy = dir.vy;
var angle = Math.atan2(dir.vy, dir.vx);
if (fireball.children && fireball.children.length > 0) {
fireball.children[0].rotation = angle;
}
if (wizard.children && wizard.children.length > 0) {
wizard.children[0].rotation = Math.atan2(y - wizard.y, x - wizard.x) + Math.PI;
}
fireballs.push(fireball);
game.addChild(fireball);
LK.getSound('fire').play();
// Start reload if out of ammo after this shot
if (wizardAmmo <= 0 && !wizardReloading) {
wizardReloading = true;
wizardReloadTimeout = LK.setTimeout(function () {
wizardAmmo = wizardMaxAmmo;
wizardReloading = false;
wizardReloadTimeout = null;
}, wizardReloadTime);
}
}
}
}
// Down handler: start firing repeatedly only if gameStarted
game.down = function (x, y, obj) {
if (!gameStarted) return;
var now = Date.now();
if (now - lastTapFireTime < tapFireCooldown) {
// Too soon, ignore this tap for firing
return;
}
lastTapFireTime = now;
isFiring = true;
lastFireX = x;
lastFireY = y;
shootFireballAt(x, y);
if (fireInterval) LK.clearInterval(fireInterval);
fireInterval = LK.setInterval(function () {
if (isFiring) {
shootFireballAt(lastFireX, lastFireY);
}
}, tapFireCooldown); // fire every tapFireCooldown ms when holding down
};
// Up handler: stop firing only if gameStarted
game.up = function (x, y, obj) {
if (!gameStarted) return;
isFiring = false;
if (fireInterval) {
LK.clearInterval(fireInterval);
fireInterval = null;
}
};
// Array to hold all enemies
var enemies = [];
// Import storage plugin for persistent coin saving
// Array to hold all coins
var coins = [];
// Wizard health system
var wizardHealth = 5;
var maxWizardHealth = 5;
// Health upgrade cost system
var healthUpgradeCost = 25;
var healthUpgradeBtnText = null;
var healthUpgradeLevel = 0;
// --- Per-weapon upgrade system ---
var weaponUpgradeDefaults = {
speedUpgradeLevel: 0,
speedUpgradeCost: 50,
damageUpgradeLevel: 0,
damageUpgradeCost: 60,
healthUpgradeLevel: 0,
healthUpgradeCost: 25,
maxWizardHealth: 5,
wizardHealth: 5,
fireballDamage: 1
};
// Helper to get upgrade key for a weapon
function getWeaponUpgradeKey(weaponAsset) {
return "weaponUpgrades_" + weaponAsset;
}
// Helper to get upgrades for a weapon (returns object)
function getWeaponUpgrades(weaponAsset) {
var key = getWeaponUpgradeKey(weaponAsset);
var upgrades = storage[key];
if (!upgrades) {
upgrades = {};
// Copy defaults
for (var k in weaponUpgradeDefaults) upgrades[k] = weaponUpgradeDefaults[k];
storage[key] = upgrades;
} else {
// Fill in any missing defaults
for (var k in weaponUpgradeDefaults) {
if (typeof upgrades[k] === "undefined") upgrades[k] = weaponUpgradeDefaults[k];
}
}
return upgrades;
}
// Helper to save upgrades for a weapon
function saveWeaponUpgrades(weaponAsset, upgrades) {
var key = getWeaponUpgradeKey(weaponAsset);
storage[key] = upgrades;
}
// --- Current weapon upgrades (populated on load and on weapon change) ---
var currentWeaponUpgrades = getWeaponUpgrades(wizardAsset);
var speedUpgradeLevel = currentWeaponUpgrades.speedUpgradeLevel;
var speedUpgradeCost = currentWeaponUpgrades.speedUpgradeCost;
var damageUpgradeLevel = currentWeaponUpgrades.damageUpgradeLevel;
var damageUpgradeCost = currentWeaponUpgrades.damageUpgradeCost;
var healthUpgradeLevel = currentWeaponUpgrades.healthUpgradeLevel;
var healthUpgradeCost = currentWeaponUpgrades.healthUpgradeCost;
var maxWizardHealth = currentWeaponUpgrades.maxWizardHealth;
var wizardHealth = currentWeaponUpgrades.wizardHealth;
var fireballDamage = currentWeaponUpgrades.fireballDamage;
// Health bar UI update
function updateHealthBar() {
if (typeof healthBarFill === "undefined" || typeof healthBarBg === "undefined") return;
var ratio = Math.max(0, Math.min(1, wizardHealth / maxWizardHealth));
healthBarFill.width = (healthBarBg.width - 8) * ratio;
// Keep bar anchored left
healthBarFill.x = healthBarBg.x - (healthBarBg.width - 8) * (1 - ratio) / 2;
}
// Score variable
var score = 0;
// Persistent total coins (stacked across games)
var totalCoins = storage.totalCoins || 0;
// --- Persistent Progress: Restore on load ---
var coinCount = typeof storage.coinCount === "number" ? storage.coinCount : 0;
var speedUpgradeLevel = typeof storage.speedUpgradeLevel === "number" ? storage.speedUpgradeLevel : 0;
var speedUpgradeCost = typeof storage.speedUpgradeCost === "number" ? storage.speedUpgradeCost : 50;
var damageUpgradeLevel = typeof storage.damageUpgradeLevel === "number" ? storage.damageUpgradeLevel : 0;
var damageUpgradeCost = typeof storage.damageUpgradeCost === "number" ? storage.damageUpgradeCost : 60;
var healthUpgradeLevel = typeof storage.healthUpgradeLevel === "number" ? storage.healthUpgradeLevel : 0;
var healthUpgradeCost = typeof storage.healthUpgradeCost === "number" ? storage.healthUpgradeCost : 25;
var maxWizardHealth = typeof storage.maxWizardHealth === "number" ? storage.maxWizardHealth : 5;
var wizardHealth = typeof storage.wizardHealth === "number" ? storage.wizardHealth : maxWizardHealth;
var fireballDamage = typeof storage.fireballDamage === "number" ? storage.fireballDamage : 1;
var shopPurchases = storage.shopPurchases || {};
var wizardAsset = storage.wizardAsset || "wizard";
// Score text
var scoreText = new Text2("Score: 0", {
size: 100,
fill: "#fff"
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// After scoreText and wizard are positioned, update startUiContainer position
if (typeof startUiContainer !== "undefined" && startUiContainer && typeof wizard !== "undefined" && wizard) {
// Place UI container between score and wizard, but not overlapping either
startUiContainer.x = 2048 / 2;
startUiContainer.y = wizard.y - 180;
}
// Coin icon and coin count text
var coinIcon = LK.getAsset('coin', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
var coinText = new Text2("" + coinCount, {
size: 90,
fill: 0xFFD700
});
coinText.anchor.set(0.5, 0);
// Add coin icon and text to the GUI, but position them below the score text
LK.gui.top.addChild(coinIcon);
LK.gui.top.addChild(coinText);
// --- Health Bar UI under coin asset ---
var healthBarWidth = 245;
var healthBarHeight = 57;
var healthBarBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: healthBarWidth,
height: healthBarHeight
});
healthBarBg.alpha = 0.35;
var healthBarFill = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: healthBarWidth - 8,
height: healthBarHeight - 8
});
healthBarFill.alpha = 0.85;
healthBarFill.tint = 0x2ecc40;
// Add white "HEALTH" label centered in the bar
var healthBarLabel = new Text2("HEALTH", {
size: 64,
// Increased font size
fill: "#fff"
});
healthBarLabel.anchor.set(0.5, 0.5);
LK.gui.top.addChild(healthBarBg);
LK.gui.top.addChild(healthBarFill);
LK.gui.top.addChild(healthBarLabel);
// --- Ammo Bar UI below health bar ---
var ammoBarWidth = healthBarWidth;
var ammoBarHeight = 36;
var ammoBarBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: ammoBarWidth,
height: ammoBarHeight
});
ammoBarBg.alpha = 0.28;
var ammoBarFill = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: ammoBarWidth - 8,
height: ammoBarHeight - 8
});
ammoBarFill.alpha = 0.92;
ammoBarFill.tint = 0x3498db; // blue for ammo
// Add dynamic ammo label centered in the bar
var ammoBarLabel = new Text2("", {
size: 36,
fill: "#fff"
});
ammoBarLabel.anchor.set(0.5, 0.5);
LK.gui.top.addChild(ammoBarBg);
LK.gui.top.addChild(ammoBarFill);
LK.gui.top.addChild(ammoBarLabel);
// Position coin icon and text below the score text in the start screen
coinIcon.x = scoreText.x;
coinIcon.y = scoreText.y + scoreText.height + coinIcon.height * 0.6;
// Place coinText 100px to the right and 50px above the coin icon
coinText.x = coinIcon.x + 100;
coinText.y = coinIcon.y - 50;
// Position health bar under coin asset
healthBarBg.x = coinIcon.x;
healthBarBg.y = coinIcon.y + coinIcon.height * 0.7 + healthBarHeight / 2 + 8;
healthBarFill.x = healthBarBg.x;
healthBarFill.y = healthBarBg.y;
// Center the label inside the health bar
if (typeof healthBarLabel !== "undefined") {
healthBarLabel.x = healthBarBg.x;
healthBarLabel.y = healthBarBg.y;
}
// Health bar update function
updateHealthBar();
// --- Restore wizard asset if changed (e.g. shuriken) ---
if (wizardAsset !== "wizard") {
// Remove all children to ensure only one wizard asset
for (var i = wizard.children.length - 1; i >= 0; i--) {
wizard.removeChild(wizard.children[i]);
}
var newSprite = wizard.attachAsset(wizardAsset, {
anchorX: 0.5,
anchorY: 0.5
});
}
// Helper: spawn an enemy at a random edge, moving toward wizard
function spawnEnemy() {
// Only allow certain types after certain scores
var canEnemy2 = score >= 10;
var canEnemy3 = score >= 20;
var canEnemy4 = score >= 30;
// Weighted random: 35% enemy1, 30% enemy2, 20% enemy3, 15% enemy4
// If a type is not available, its weight is 0 and weights are renormalized
var weights = [35,
// enemy1
canEnemy2 ? 30 : 0,
// enemy2
canEnemy3 ? 20 : 0,
// enemy3
canEnemy4 ? 15 : 0 // enemy4
];
var totalWeight = 0;
for (var i = 0; i < weights.length; i++) totalWeight += weights[i];
var r = Math.random() * totalWeight;
var acc = 0;
var enemyType = 1;
for (var i = 0; i < weights.length; i++) {
acc += weights[i];
if (r < acc) {
enemyType = i + 1;
break;
}
}
var enemy;
if (enemyType === 1) {
enemy = new Enemy();
} else if (enemyType === 2) {
enemy = new Enemy2();
} else if (enemyType === 3) {
enemy = new Enemy3();
} else {
enemy = new Enemy4();
}
// Randomly pick an edge: 0=top, 1=bottom, 2=left, 3=right
var edge = Math.floor(Math.random() * 4);
var ex, ey;
if (edge === 0) {
// top
ex = Math.random() * 2048;
ey = -50;
} else if (edge === 1) {
// bottom
ex = Math.random() * 2048;
ey = 2732 + 50;
} else if (edge === 2) {
// left
ex = -50;
ey = Math.random() * 2732;
} else {
// right
ex = 2048 + 50;
ey = Math.random() * 2732;
}
enemy.x = ex;
enemy.y = ey;
// Move toward wizard
var dir = getDirection(ex, ey, wizard.x, wizard.y, 2.5 + Math.random() * 1.5); // randomize speed a bit
enemy.vx = dir.vx;
enemy.vy = dir.vy;
enemies.push(enemy);
game.addChild(enemy);
}
// Enemy spawn timer
var enemySpawnStopped = false;
var bossSpawned = false;
var boss = null;
var enemySpawnTimer = LK.setInterval(function () {
// Stop enemy spawn at score 10 and spawn boss
if (!enemySpawnStopped && score >= 10) {
enemySpawnStopped = true;
// Stop spawning enemies
LK.clearInterval(enemySpawnTimer);
// Spawn boss
if (!bossSpawned) {
boss = new Boss();
// Spawn boss at top center
boss.x = 2048 / 2;
boss.y = -120;
game.addChild(boss);
bossSpawned = true;
}
return;
}
if (!enemySpawnStopped) {
spawnEnemy();
}
}, 1200);
// Game update: update wizard, fireballs, enemies, handle collisions, and scoring
game.update = function () {
// If game not started, only update startButton and wizard visuals
if (!gameStarted) {
// --- Reset magazine system on game over/start screen ---
// If minigun is selected, always set to 350 ammo at new game start
if (wizardAsset === "minigun") {
wizardMaxAmmo = 350;
wizardAmmo = 350;
tapFireCooldown = 500;
} else if (wizardAsset === "Lasergun") {
wizardMaxAmmo = 10;
wizardAmmo = wizardMaxAmmo;
tapFireCooldown = 300;
} else {
wizardAmmo = wizardMaxAmmo;
}
wizardReloading = false;
if (wizardReloadTimeout) {
LK.clearTimeout(wizardReloadTimeout);
wizardReloadTimeout = null;
}
if (wizard.update) wizard.update();
// Animate start button (pulse effect)
if (typeof startButton !== "undefined" && startButton && startButton.children && startButton.children.length > 0) {
var t = LK.ticks || Date.now();
var scale = 1 + 0.06 * Math.sin(t * 0.12);
startButton.scale.x = scale;
startButton.scale.y = scale;
}
return;
}
// Update wizard
if (wizard.update) wizard.update();
// Update fireballs and remove destroyed ones
for (var i = fireballs.length - 1; i >= 0; i--) {
var fb = fireballs[i];
if (fb.update) fb.update();
if (fb.destroyed) {
fireballs.splice(i, 1);
}
}
// Update coins and remove destroyed ones
for (var c = coins.length - 1; c >= 0; c--) {
var coin = coins[c];
// Move coin directly toward wizard
var dx = wizard.x - coin.x;
var dy = wizard.y - coin.y;
var dist = Math.sqrt(dx * dx + dy * dy);
var speed = 22; // Fast enough to feel instant, but visible
if (dist > 1) {
coin.x += dx / dist * Math.min(speed, dist);
coin.y += dy / dist * Math.min(speed, dist);
} else {
coin.x = wizard.x;
coin.y = wizard.y;
}
// Check collision with wizard (collect coin)
if (coin.lastWasIntersecting === undefined) coin.lastWasIntersecting = false;
var coinIntersecting = coin.intersects(wizard);
if (!coin.lastWasIntersecting && coinIntersecting) {
// Do not add to score when collecting coin
coinCount += 1;
coinText.setText("" + coinCount);
// Save coin count persistently
storage.coinCount = coinCount;
// Create gain effect (use gain asset instead of explosion)
var gainEffect = LK.getAsset('gain', {
anchorX: 0.5,
anchorY: 0.5,
x: coin.x,
y: coin.y,
scaleX: 1,
scaleY: 1,
alpha: 1
});
game.addChild(gainEffect);
// Animate gain effect: scale up and fade out, then destroy
(function (effect) {
var frames = 24;
var frame = 0;
effect.update = function () {
frame++;
effect.scale.x = 1 + 0.5 * (frame / frames);
effect.scale.y = 1 + 0.5 * (frame / frames);
effect.alpha = 1 - frame / frames;
if (frame >= frames) {
effect.destroy();
}
};
})(gainEffect);
// Create +N asset effect at wizard position
var plusAmount = 1;
if (coin.hasOwnProperty('amount')) {
plusAmount = coin.amount;
}
var plusText = new Text2("+" + plusAmount, {
size: 90,
fill: 0xFFD700
});
plusText.anchor.set(0.5, 0.5);
plusText.x = wizard.x;
plusText.y = wizard.y;
game.addChild(plusText);
// Animate +N asset: move up and fade out, then destroy
(function (txt) {
var startY = txt.y;
var frames = 36;
var frame = 0;
txt.alpha = 1;
txt.update = function () {
frame++;
txt.y = startY - frame * 2.2;
txt.alpha = 1 - frame / frames;
if (frame >= frames) {
txt.destroy();
}
};
})(plusText);
// Remove coin
coin.destroy();
coins.splice(c, 1);
continue;
}
coin.lastWasIntersecting = coinIntersecting;
}
// Position coin icon and text below the score text (centered)
if (scoreText.parent && coinIcon.parent && coinText.parent) {
// Place coin icon below the score text, centered
coinIcon.x = scoreText.x;
coinIcon.y = scoreText.y + scoreText.height + coinIcon.height * 0.6;
// Place coinText 100px to the right and 50px above the coin icon
coinText.x = coinIcon.x + 100;
coinText.y = coinIcon.y - 50;
// Position health bar under coin asset
if (typeof healthBarBg !== "undefined" && typeof healthBarFill !== "undefined") {
healthBarBg.x = coinIcon.x;
healthBarBg.y = coinIcon.y + coinIcon.height * 0.7 + healthBarBg.height / 2 + 8;
healthBarFill.x = healthBarBg.x - (healthBarBg.width - 8) * (1 - Math.max(0, Math.min(1, wizardHealth / maxWizardHealth))) / 2;
healthBarFill.y = healthBarBg.y;
// Keep label centered in bar
if (typeof healthBarLabel !== "undefined") {
healthBarLabel.x = healthBarBg.x;
healthBarLabel.y = healthBarBg.y;
}
}
updateHealthBar();
// --- Position and update ammo bar below health bar ---
if (typeof ammoBarBg !== "undefined" && typeof ammoBarFill !== "undefined") {
ammoBarBg.x = healthBarBg.x;
ammoBarBg.y = healthBarBg.y + healthBarBg.height / 2 + ammoBarBg.height / 2 + 10;
ammoBarFill.x = ammoBarBg.x;
ammoBarFill.y = ammoBarBg.y;
if (typeof ammoBarLabel !== "undefined") {
ammoBarLabel.x = ammoBarBg.x;
ammoBarLabel.y = ammoBarBg.y;
// Update ammo label text
if (wizardAsset === "shuriken") {
ammoBarLabel.setText("∞/∞");
} else if (typeof wizardAmmo !== "undefined" && typeof wizardMaxAmmo !== "undefined") {
ammoBarLabel.setText(wizardAmmo + "/" + wizardMaxAmmo);
} else {
ammoBarLabel.setText("");
}
}
// Update ammo bar fill width
var ammoRatio = 1;
if (wizardAsset === "shuriken") {
ammoRatio = 1; // always full for shuriken
} else if (typeof wizardAmmo !== "undefined" && typeof wizardMaxAmmo !== "undefined" && wizardMaxAmmo > 0) {
ammoRatio = Math.max(0, Math.min(1, wizardAmmo / wizardMaxAmmo));
}
ammoBarFill.width = (ammoBarBg.width - 8) * ammoRatio;
ammoBarFill.x = ammoBarBg.x - (ammoBarBg.width - 8) * (1 - ammoRatio) / 2;
}
}
// Update enemies and remove destroyed ones
for (var j = enemies.length - 1; j >= 0; j--) {
var enemy = enemies[j];
if (enemy.update) enemy.update();
if (enemy.destroyed) {
enemies.splice(j, 1);
continue;
}
// ... (rest of enemy collision code unchanged)
// Check collision with wizard (health system)
if (enemy.lastWasIntersecting === undefined) enemy.lastWasIntersecting = false;
var nowIntersecting = enemy.intersects(wizard);
if (!enemy.lastWasIntersecting && nowIntersecting) {
// Only decrease health if not already at 0
if (wizardHealth > 0) {
wizardHealth -= 1;
// Save wizard health
storage.wizardHealth = wizardHealth;
// Flash wizard red
if (wizard.children && wizard.children.length > 0) {
LK.effects.flashObject(wizard.children[0], 0xff0000, 400);
}
// Update health bar (no-op)
updateHealthBar();
// Remove enemy after hit
enemy.destroy();
enemies.splice(j, 1);
// If health reaches 0, trigger game over
if (wizardHealth <= 0) {
totalCoins += coinCount;
storage.totalCoins = totalCoins;
LK.effects.flashScreen(0xff0000, 1000);
// Instead of game over, reset to start screen
gameStarted = false;
// Recreate start UI if needed
if (!startUiContainer || startUiContainer.destroyed) {
startUiContainer = new Container();
startButton = new Container();
startButtonBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: startButtonWidth,
height: startButtonHeight,
color: 0x1e90ff
});
startButtonBg.alpha = 0.92;
startButton.addChild(startButtonBg);
startButtonText = new Text2("START GAME", {
size: 220,
fill: "#fff"
});
startButtonText.anchor.set(0.5, 0.5);
startButtonText.x = 0;
startButtonText.y = -120;
startButton.addChild(startButtonText);
upgradeButton = new Container();
upgradeButtonBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: upgradeButtonWidth,
height: upgradeButtonHeight,
color: 0x2ecc71
});
upgradeButtonBg.alpha = 0.92;
upgradeButton.addChild(upgradeButtonBg);
upgradeButtonText = new Text2("UPGRADE", {
size: 110,
// Half of recreated START GAME (220)
fill: "#fff"
});
upgradeButtonText.anchor.set(0.5, 0.5);
upgradeButtonText.x = 0;
upgradeButtonText.y = 0;
upgradeButton.addChild(upgradeButtonText);
startButton.x = 0;
startButton.y = -400;
upgradeButton.x = 0;
upgradeButton.y = startButton.y + startButtonHeight / 2 + 55 + upgradeButtonHeight / 2;
startUiContainer.addChild(startButton);
startUiContainer.addChild(upgradeButton);
startUiContainer.x = 2048 / 2;
startUiContainer.y = 2732 / 2;
game.addChild(startUiContainer);
// Re-attach handlers
upgradeButton.down = function (x, y, obj) {
if (upgradeWindow && !upgradeWindow.destroyed) return;
showUpgradeWindow();
};
startButton.down = function (x, y, obj) {
var now = Date.now();
if (now - lastTapFireTime < tapFireCooldown) {
// Too soon, ignore this tap for firing
return;
}
lastTapFireTime = now;
if (gameStarted) return;
gameStarted = true;
if (startUiContainer && !startUiContainer.destroyed) {
startUiContainer.destroy();
}
for (var i = enemies.length - 1; i >= 0; i--) {
if (enemies[i] && !enemies[i].destroyed) enemies[i].destroy();
enemies.splice(i, 1);
}
for (var i = fireballs.length - 1; i >= 0; i--) {
if (fireballs[i] && !fireballs[i].destroyed) fireballs[i].destroy();
fireballs.splice(i, 1);
}
for (var i = coins.length - 1; i >= 0; i--) {
if (coins[i] && !coins[i].destroyed) coins[i].destroy();
coins.splice(i, 1);
}
score = 0;
// coinCount is NOT reset here, so coins are preserved when starting a new game
scoreText.setText("Score: 0");
coinText.setText("" + coinCount);
wizard.x = 2048 / 2;
wizard.y = 2732 / 2;
// Load upgrades for selected weapon
currentWeaponUpgrades = getWeaponUpgrades(wizardAsset);
speedUpgradeLevel = currentWeaponUpgrades.speedUpgradeLevel;
speedUpgradeCost = currentWeaponUpgrades.speedUpgradeCost;
damageUpgradeLevel = currentWeaponUpgrades.damageUpgradeLevel;
damageUpgradeCost = currentWeaponUpgrades.damageUpgradeCost;
healthUpgradeLevel = currentWeaponUpgrades.healthUpgradeLevel;
healthUpgradeCost = currentWeaponUpgrades.healthUpgradeCost;
maxWizardHealth = currentWeaponUpgrades.maxWizardHealth;
wizardHealth = currentWeaponUpgrades.wizardHealth;
fireballDamage = currentWeaponUpgrades.fireballDamage;
// Remove all children to ensure only one wizard asset
for (var i = wizard.children.length - 1; i >= 0; i--) {
wizard.removeChild(wizard.children[i]);
}
// Attach wizard asset if not present
var hasWizardSprite = false;
for (var i = 0; i < wizard.children.length; i++) {
hasWizardSprite = true;
break;
}
if (!hasWizardSprite) {
var newSprite = wizard.attachAsset(wizardAsset, {
anchorX: 0.5,
anchorY: 0.5
});
if (newSprite) {
newSprite.rotation = Math.PI;
}
} else if (wizard.children && wizard.children.length > 0) {
wizard.children[0].rotation = Math.PI;
}
// Switch upgrades to selected weapon on restart
currentWeaponUpgrades = getWeaponUpgrades(wizardAsset);
speedUpgradeLevel = currentWeaponUpgrades.speedUpgradeLevel;
speedUpgradeCost = currentWeaponUpgrades.speedUpgradeCost;
damageUpgradeLevel = currentWeaponUpgrades.damageUpgradeLevel;
damageUpgradeCost = currentWeaponUpgrades.damageUpgradeCost;
healthUpgradeLevel = currentWeaponUpgrades.healthUpgradeLevel;
healthUpgradeCost = currentWeaponUpgrades.healthUpgradeCost;
maxWizardHealth = currentWeaponUpgrades.maxWizardHealth;
wizardHealth = currentWeaponUpgrades.wizardHealth;
fireballDamage = currentWeaponUpgrades.fireballDamage;
wizardHealth = maxWizardHealth;
storage.wizardHealth = wizardHealth;
storage.maxWizardHealth = maxWizardHealth;
storage.wizardHealth = wizardHealth;
storage.maxWizardHealth = maxWizardHealth;
updateHealthBar();
game.move = originalGameMove;
game.down = originalGameDown;
game.up = originalGameUp;
};
} else {
// If UI exists, just re-add it
if (startUiContainer.parent !== game) {
game.addChild(startUiContainer);
}
// Recreate shop button and handlers if needed
if (typeof shopButton === "undefined" || !shopButton || shopButton.destroyed) {
// --- SHOP BUTTON UI LOGIC (recreate) ---
shopButton = new Container();
shopButtonBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: shopButtonWidth,
height: shopButtonHeight
});
shopButtonBg.alpha = 0.92;
shopButton.addChild(shopButtonBg);
shopButtonText = new Text2("SHOP", {
size: 110,
fill: "#fff"
});
shopButtonText.anchor.set(0.5, 0.5);
shopButtonText.x = 0;
shopButtonText.y = 0;
shopButton.addChild(shopButtonText);
shopButton.x = 0;
shopButton.y = upgradeButton.y + upgradeButtonHeight / 2 + 40 + shopButtonHeight / 2;
startUiContainer.addChild(shopButton);
shopButton.down = function (x, y, obj) {
if (shopWindow && !shopWindow.destroyed) return;
showShopWindow();
};
}
}
// Block input until start is pressed
blockGameInput();
return;
}
}
}
enemy.lastWasIntersecting = nowIntersecting;
// Check collision with fireballs
for (var k = fireballs.length - 1; k >= 0; k--) {
var fb = fireballs[k];
if (enemy['fb' + k + '_lastIntersecting'] === undefined) enemy['fb' + k + '_lastIntersecting'] = false;
var fbIntersect = enemy.intersects(fb);
// Only allow collision if fireball is inside the visible screen
var fireballOnScreen = fb.x >= 0 && fb.x <= 2048 && fb.y >= 0 && fb.y <= 2732;
if (!enemy['fb' + k + '_lastIntersecting'] && fbIntersect && fireballOnScreen) {
// Decrease enemy health by fireballDamage (default 1, upgrades increase)
enemy.health -= fireballDamage;
// Destroy fireball
fb.destroy();
fireballs.splice(k, 1);
// If enemy health reaches 0, destroy enemy and increase score
if (enemy.health <= 0) {
// Spawn explosion at enemy position
var explosion = new Explosion();
explosion.x = enemy.x;
explosion.y = enemy.y;
game.addChild(explosion);
// Determine coin count and plus text based on enemy type
var coinAmount = 1;
if (enemy.type === 2) coinAmount = 2;
if (enemy.type === 3) coinAmount = 3;
if (enemy.type === 4) coinAmount = 4;
// Drop the correct number of coins
for (var cc = 0; cc < coinAmount; cc++) {
var coin = new Coin();
coin.x = enemy.x;
coin.y = enemy.y;
coin.vx = 0;
coin.vy = 0;
coin.gravity = 0;
// For multi-coin drops, only the first coin will show +N at wizard
if (cc === 0) {
coin.amount = coinAmount;
}
coins.push(coin);
game.addChild(coin);
}
// Play dead sound
LK.getSound('dead').play();
enemy.destroy();
enemies.splice(j, 1);
score += 1;
scoreText.setText("Score: " + score);
// (Removed: +N effect at enemy death. Now shown at wizard when coin is collected)
break;
}
}
enemy['fb' + k + '_lastIntersecting'] = fbIntersect;
}
}
// --- Boss update and boss fireball collision ---
if (boss && !boss.destroyed) {
if (boss.update) boss.update();
// Boss hit by fireballs
for (var k = fireballs.length - 1; k >= 0; k--) {
var fb = fireballs[k];
if (boss['fb' + k + '_lastIntersecting'] === undefined) boss['fb' + k + '_lastIntersecting'] = false;
var fbIntersect = boss.intersects(fb);
// Only allow collision if fireball is inside the visible screen
var fireballOnScreen = fb.x >= 0 && fb.x <= 2048 && fb.y >= 0 && fb.y <= 2732;
if (!boss['fb' + k + '_lastIntersecting'] && fbIntersect && fireballOnScreen) {
boss.health -= fireballDamage;
fb.destroy();
fireballs.splice(k, 1);
// Flash boss on hit
if (boss.children && boss.children.length > 0) {
LK.effects.flashObject(boss.children[0], 0xff0000, 200);
}
// Boss death
if (boss.health <= 0) {
// Spawn explosion at boss position
var explosion = new Explosion();
explosion.x = boss.x;
explosion.y = boss.y;
game.addChild(explosion);
// Drop 10 coins
for (var cc = 0; cc < 10; cc++) {
var coin = new Coin();
coin.x = boss.x;
coin.y = boss.y;
coin.vx = 0;
coin.vy = 0;
coin.gravity = 0;
if (cc === 0) coin.amount = 10;
coins.push(coin);
game.addChild(coin);
}
LK.getSound('dead').play();
boss.destroy();
boss = null;
// Award 10 score for boss
score += 10;
scoreText.setText("Score: " + score);
break;
}
}
boss['fb' + k + '_lastIntersecting'] = fbIntersect;
}
// BossBullet logic: handle collision with wizard and fireballs
for (var k = fireballs.length - 1; k >= 0; k--) {
var fb = fireballs[k];
// Only check boss bullets (bossbullet asset)
if (fb.children && fb.children.length > 0 && fb.children[0].texture && fb.children[0].texture.assetId === 'bossbullet') {
// --- Hit wizard ---
if (fb['lastHitWizard'] === undefined) fb['lastHitWizard'] = false;
var hitWizard = fb.intersects(wizard);
if (!fb['lastHitWizard'] && hitWizard) {
if (wizardHealth > 0) {
wizardHealth -= 1; // BossBullet does 1 damage
storage.wizardHealth = wizardHealth;
if (wizard.children && wizard.children.length > 0) {
LK.effects.flashObject(wizard.children[0], 0xff0000, 400);
}
updateHealthBar();
// Remove bossbullet
fb.destroy();
fireballs.splice(k, 1);
// Game over if health 0
if (wizardHealth <= 0) {
totalCoins += coinCount;
storage.totalCoins = totalCoins;
LK.effects.flashScreen(0xff0000, 1000);
gameStarted = false;
// (UI recreation code omitted for brevity, handled above)
}
}
}
fb['lastHitWizard'] = hitWizard;
// --- Hit by wizard fireballs ---
// Check collision with all wizard fireballs (not bossbullet)
for (var m = fireballs.length - 1; m >= 0; m--) {
if (m === k) continue;
var wfb = fireballs[m];
// Only check wizard fireballs (not bossbullet)
if (wfb.children && wfb.children.length > 0 && wfb.children[0].texture && wfb.children[0].texture.assetId !== 'bossbullet') {
if (fb['wfb' + m + '_lastIntersecting'] === undefined) fb['wfb' + m + '_lastIntersecting'] = false;
var hit = fb.intersects(wfb);
if (!fb['wfb' + m + '_lastIntersecting'] && hit) {
// BossBullet takes 1 hit
if (typeof fb.health === "undefined") fb.health = 3;
fb.health -= 1;
// Remove wizard fireball
wfb.destroy();
fireballs.splice(m, 1);
// Flash bossbullet on hit
if (fb.children && fb.children.length > 0) {
LK.effects.flashObject(fb.children[0], 0xff0000, 120);
}
// Destroy bossbullet if health <= 0
if (fb.health <= 0) {
// Small explosion
var explosion = new Explosion();
explosion.x = fb.x;
explosion.y = fb.y;
game.addChild(explosion);
fb.destroy();
fireballs.splice(k, 1);
break;
}
}
fb['wfb' + m + '_lastIntersecting'] = hit;
}
}
}
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -26,10 +26,28 @@
self.y += self.speed;
if (self.y >= 400) {
self.y = 400;
self.state = "fight";
+ // Initialize orbit parameters
+ self.orbitAngle = 0;
+ self.orbitRadius = 420;
+ self.orbitSpeed = 0.035 + Math.random() * 0.02; // radians per frame, randomize a bit
+ self.orbitDirection = Math.random() < 0.5 ? 1 : -1; // random direction
}
} else if (self.state === "fight") {
+ // Orbit around wizard
+ if (typeof self.orbitAngle === "undefined") self.orbitAngle = 0;
+ if (typeof self.orbitRadius === "undefined") self.orbitRadius = 420;
+ if (typeof self.orbitSpeed === "undefined") self.orbitSpeed = 0.04;
+ if (typeof self.orbitDirection === "undefined") self.orbitDirection = 1;
+ // Update orbit angle
+ self.orbitAngle += self.orbitSpeed * self.orbitDirection;
+ // Orbit center is wizard's current position
+ var centerX = wizard.x;
+ var centerY = wizard.y;
+ // Calculate boss position on orbit
+ self.x = centerX + Math.cos(self.orbitAngle) * self.orbitRadius;
+ self.y = centerY + Math.sin(self.orbitAngle) * self.orbitRadius;
// Always face wizard
var dx = wizard.x - self.x;
var dy = wizard.y - self.y;
var angle = Math.atan2(dy, dx);
@@ -41,9 +59,9 @@
if (self.fireCooldown <= 0) {
self.fireCooldown = self.fireInterval;
var bossBullet = new BossBullet();
bossBullet.x = self.x;
- bossBullet.y = self.y + 80;
+ bossBullet.y = self.y + 80 * Math.sin(self.orbitAngle); // fire from boss's "front"
var dir = getDirection(self.x, self.y, wizard.x, wizard.y, 5); // slow speed
bossBullet.vx = dir.vx;
bossBullet.vy = dir.vy;
if (bossBullet.children && bossBullet.children.length > 0) {
@@ -2638,18 +2656,11 @@
if (wfb.children && wfb.children.length > 0 && wfb.children[0].texture && wfb.children[0].texture.assetId !== 'bossbullet') {
if (fb['wfb' + m + '_lastIntersecting'] === undefined) fb['wfb' + m + '_lastIntersecting'] = false;
var hit = fb.intersects(wfb);
if (!fb['wfb' + m + '_lastIntersecting'] && hit) {
- // BossBullet takes 1 hit from any fireball
+ // BossBullet takes 1 hit
if (typeof fb.health === "undefined") fb.health = 3;
- // If hit by minigunbullet, count as 1 hit
- var isMinigunBullet = wfb.children[0].texture.assetId === 'minigunbullet';
- if (isMinigunBullet) {
- fb.health -= 1;
- } else {
- // Other fireballs also do 1 hit (default)
- fb.health -= 1;
- }
+ fb.health -= 1;
// Remove wizard fireball
wfb.destroy();
fireballs.splice(m, 1);
// Flash bossbullet on hit
get an enemy in the form of slime. In-Game asset. 2d. High contrast. No shadows
get an enemy in the form of slime. In-Game asset. 2d. High contrast. No shadows
Let there be a mini machine gun and let this gun be pixel shaped. In-Game asset. 2d. High contrast. No shadows
a bullet but yellow and pixel. In-Game asset. 2d. High contrast. No shadows
slime explosion. In-Game asset. 2d. High contrast. No shadows
Change eyes like red
+ gain coin effect. In-Game asset. 2d. High contrast. No shadows
Fast bullet upgrade. In-Game asset. 2d. High contrast. No shadows
Upgrade power bullet. In-Game asset. 2d. High contrast. No shadows
Health + icon pixels. In-Game asset. 2d. High contrast. No shadows
Handgun pixel its look left. In-Game asset. 2d. High contrast. No shadows
işaretli alanı siyaha boya
pixel shuriken but 8 edges. In-Game asset. 2d. High contrast. No shadows
shotgun pixel and look left side. In-Game asset. 2d. High contrast. No shadows
submachine gun look left. In-Game asset. 2d. High contrast. No shadows
mp5 gun pixel. In-Game asset. 2d. High contrast. No shadows
Minigun bullet pixel. In-Game asset. 2d. High contrast. No shadows
Eliptic neon laser bullet. In-Game asset. 2d. High contrast. No shadows. Pixel
slime but have metalic helmet. In-Game asset. 2d. High contrast. No shadows
a slime boss enemy very strict. In-Game asset. 2d. High contrast. No shadows
create mirror view a bit smaller
add a dragon baby on top of gun
a goblin slime which have backpack fully coins. In-Game asset. 2d. High contrast. No shadows
Disappear smoke pixel. In-Game asset. 2d. High contrast. No shadows
Coin pile pixel. In-Game asset. 2d. High contrast. No shadows
fire left to right pixel. In-Game asset. 2d. High contrast. No shadows
Slime enemy healer. In-Game asset. 2d. High contrast. No shadows
Healt restore pixel. In-Game asset. 2d. High contrast. No shadows
Ammo +1 upgrade. In-Game asset. 2d. High contrast. No shadows
Type SLOW bottom of the amblem
Fire ball pixel
boss slime but like fire and dangereous. In-Game asset. 2d. High contrast. No shadows
Add body of this slime