User prompt
Ekrana bastığımda ateş etme efektini her bastığımda değil belirli bir süreyle ateş etmesini sağla bu süreyi 1 saniye olarak ayarla yani ekrana iki defa ard arda 1 saniyeden az bi sürede basarsam ateş etmesin
User prompt
Bu durumu oyun başladığındada yap
User prompt
Ekrana bastığımda ateşler arasında 540 ms bekleme süresi koy
User prompt
Wizard assetinin konumunu 150 piksel aşağı taşı fakat fireball sabit kalsın
User prompt
Wizard assetinin konumunu 350 piksel aşağı taşı
User prompt
Wizardın konumunu 150 piksel aşağı taşı
User prompt
Karakterin görselini 150 birim aşağıya taşı
User prompt
Ateş efecktini karakterden bir miktar y ekseninde 150 birim aşağıda yapsın
User prompt
Ateş efecktini karakterden bir miktar y ekseninde 15 birim aşağıda yapsın
User prompt
Ateş efecktini karakterden bir miktar y ekseninde yukarıda yapsın
User prompt
atış hızını üç kat düşür
User prompt
Back butonu health butonu arasındaki mesafeveyi 500 piksel yap
User prompt
Back butonu health butonu arasındaki mesafeveyi 250piksel yap
User prompt
Geri butonunun ismini BACK olarak değiştir ve health le arasında olan mesafeyi 150 birim yap
User prompt
Geri butonun ismini BACK olarak değiştir ve ekranda en alta yerleştir
User prompt
Power speed ve health butonları arasındaki mesafeyi 50 birim artır
User prompt
Upgrade ekranındaki butonların aralarındaki mesafeyi 15 artır
User prompt
Start game yazısı bold olsun
User prompt
Upgrade ekranındaki butonların aralarını 5 birim artır
User prompt
Upgrade yazısını start game yazısının yarısı kadar yap
User prompt
Start game yazısını yarı yarıya küçült
User prompt
Start Game yazısının boyutunu 4 katına çıkar ve yukarıya doğru taşı
User prompt
Upgrade yazısı başla yazısının altında olsun. Başla yazısını Start Game olarak değiştir ve büyüt
User prompt
Upgrade ekranındaki assetler ekranın en üst layerinde yer alsın
User prompt
Health upgrade health assetini kullansın
/****
* Plugins
****/
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
// 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;
});
// 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;
// Always keep health bar below wizard in case of movement
if (self.children && self.children.length > 0 && typeof healthBarBg !== "undefined" && typeof healthBar !== "undefined") {
healthBarBg.y = self.children[0].height / 2 + 10;
healthBar.x = 0;
healthBarBg.x = 0;
healthBar.y = healthBarBg.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,
color: 0x1e90ff
});
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,
color: 0x2ecc71
});
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 and upgrade buttons in the UI container
startButton.x = 0;
startButton.y = -400; //{36} // Moved much higher
upgradeButton.x = 0;
upgradeButton.y = startButton.y + startButtonHeight / 2 + 40 + upgradeButtonHeight / 2; //{38} // Just below start button
// Add both buttons to the UI container
startUiContainer.addChild(startButton);
startUiContainer.addChild(upgradeButton);
// 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,
winH = 1100;
var winBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: winW,
height: winH,
color: 0x222244
});
winBg.alpha = 0.97;
upgradeWindow.addChild(winBg);
// Decorative background asset (e.g. gain asset, semi-transparent, behind everything)
var decoBg = LK.getAsset('gain', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0,
scaleX: 6,
scaleY: 6,
alpha: 0.10
});
upgradeWindow.addChild(decoBg);
// Title
var title = new Text2("UPGRADE", {
size: 110,
fill: "#fff"
});
title.anchor.set(0.5, 0);
title.x = 0;
title.y = -winH / 2 + 70;
upgradeWindow.addChild(title);
// Button helper with icon
function makeUpgradeBtn(label, y, color, iconAsset, iconColor) {
var btn = new Container();
var btnBg = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: 700,
height: 180,
color: color
});
btnBg.alpha = 0.93;
btn.addChild(btnBg);
// Icon asset (left side of button)
var icon = null;
if (iconAsset) {
icon = LK.getAsset(iconAsset, {
anchorX: 0.5,
anchorY: 0.5,
x: -260,
y: 0,
scaleX: 1.2,
scaleY: 1.2,
color: iconColor !== undefined ? iconColor : color
});
// If using a shape, set tint/color if provided
if (iconColor !== undefined && icon && icon.tint !== undefined) {
icon.tint = iconColor;
}
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 = 230;
var btns = [];
// Use fast, power, background assets for each upgrade (background as health icon)
var btnLabels = [{
label: "SPEED",
color: 0x3498db,
iconAsset: 'fast',
iconColor: 0x3498db
}, {
label: "POWER",
color: 0xe67e22,
iconAsset: 'power',
iconColor: 0xe67e22
}, {
label: "HEALTH",
color: 0xe74c3c,
iconAsset: 'health',
// Use health asset as the health icon
iconColor: 0xe74c3c
}];
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);
}
// HEALTH upgrade logic: cost 20 coins, +2 max health, +2 current health
btns[2].down = function () {
if (coinCount >= 20) {
coinCount -= 20;
coinText.setText("" + coinCount);
maxWizardHealth += 2;
wizardHealth += 2;
updateHealthBar();
// Optional: feedback effect
LK.effects.flashObject(healthBar, 0x2ecc40, 600);
} else {
// Optional: feedback for not enough coins
LK.effects.flashObject(coinText, 0xe74c3c, 600);
}
};
// Geri button with icon (use coin as a back icon for fun)
var geriBtn = makeUpgradeBtn("GERİ", 520, 0x888888, 'coin', 0x888888);
upgradeWindow.addChild(geriBtn);
// Geri 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();
};
// 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;
if (wizard.children && wizard.children.length > 0) {
wizard.children[0].rotation = Math.PI; // face left
}
// Reposition health bar below wizard after centering
if (wizard.children && wizard.children.length > 0) {
healthBarBg.y = wizard.children[0].height / 2 + 10;
healthBar.x = 0;
healthBarBg.x = 0;
healthBar.y = healthBarBg.y;
}
// 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) {
isFiring = true;
lastFireX = x;
lastFireY = y;
shootFireballAt(x, y);
if (fireInterval) LK.clearInterval(fireInterval);
fireInterval = LK.setInterval(function () {
if (isFiring) {
shootFireballAt(lastFireX, lastFireY);
}
}, 180);
};
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) {
// 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;
}
};
// Track if fire is being held
var isFiring = false;
var fireInterval = null;
var lastFireX = 0;
var lastFireY = 0;
// Helper to shoot a fireball toward (x, y)
function shootFireballAt(x, y) {
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();
}
// Down handler: start firing repeatedly
game.down = function (x, y, obj) {
isFiring = true;
lastFireX = x;
lastFireY = y;
shootFireballAt(x, y);
if (fireInterval) LK.clearInterval(fireInterval);
fireInterval = LK.setInterval(function () {
if (isFiring) {
shootFireballAt(lastFireX, lastFireY);
}
}, 180); // fire every 180ms (about 5.5 shots/sec)
};
// Up handler: stop firing
game.up = function (x, y, obj) {
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 bar UI (smaller, positioned just below wizard)
var healthBarWidth = 180;
var healthBarHeight = 18;
var healthBarYOffset = 90; // vertical offset below wizard
var healthBarBg = LK.getAsset('background', {
anchorX: 0.5,
// center horizontally
anchorY: 0,
// top edge
width: healthBarWidth,
height: healthBarHeight,
color: 0x222222
});
var healthBar = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0,
width: healthBarWidth,
height: healthBarHeight,
color: 0x2ecc40
});
// Add health bar as children of wizard so it follows wizard position
wizard.addChild(healthBarBg);
wizard.addChild(healthBar);
// Position health bar just below wizard sprite
healthBarBg.x = 0;
healthBarBg.y = wizard.children[0] ? wizard.children[0].height / 2 + 10 : healthBarYOffset;
healthBar.x = 0;
healthBar.y = healthBarBg.y;
// Health bar update function
function updateHealthBar() {
var percent = Math.max(0, wizardHealth) / maxWizardHealth;
healthBar.width = healthBarBg.width * percent;
// Color changes as health drops
if (percent > 0.6) {
healthBar.tint = 0x2ecc40; // green
} else if (percent > 0.3) {
healthBar.tint = 0xffc107; // yellow
} else {
healthBar.tint = 0xe74c3c; // red
}
}
updateHealthBar();
// Score variable
var score = 0;
// Persistent total coins (stacked across games)
var totalCoins = storage.totalCoins || 0;
// 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 coinCount = 0;
var coinText = new Text2("0", {
size: 90,
fill: 0xFFD700
});
coinText.anchor.set(0, 0);
// Position coin icon and text to the right of the score
// We'll update their position after first render in game.update
LK.gui.top.addChild(coinIcon);
LK.gui.top.addChild(coinText);
// Helper: spawn an enemy at a random edge, moving toward wizard
function spawnEnemy() {
// Determine which enemy types are available based on score
var availableTypes = [1];
if (score >= 10) availableTypes.push(2);
if (score >= 20) availableTypes.push(3);
// Randomly pick an available type
var typeIdx = Math.floor(Math.random() * availableTypes.length);
var enemyType = availableTypes[typeIdx];
var enemy;
if (enemyType === 1) {
enemy = new Enemy();
} else if (enemyType === 2) {
enemy = new Enemy2();
} else {
enemy = new Enemy3();
}
// 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 enemySpawnTimer = LK.setInterval(function () {
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) {
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);
// 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 next to score text (right side)
if (scoreText.parent && coinIcon.parent && coinText.parent) {
// Get scoreText bounds in GUI coordinates
var scoreBounds = scoreText.getBounds();
// Place coin icon to the right of score text, with a small gap
coinIcon.x = scoreText.x + scoreBounds.width / 2 + coinIcon.width * 0.7;
coinIcon.y = scoreText.y + coinIcon.height * 0.45;
// Place coinText to the right of coin icon
coinText.x = coinIcon.x + coinIcon.width * 0.7;
coinText.y = scoreText.y + coinIcon.height * 0.1;
}
// 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;
}
// 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;
// Flash wizard red
if (wizard.children && wizard.children.length > 0) {
LK.effects.flashObject(wizard.children[0], 0xff0000, 400);
}
// Update health bar
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 + 40 + 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) {
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;
if (wizard.children && wizard.children.length > 0) {
wizard.children[0].rotation = Math.PI;
}
if (wizard.children && wizard.children.length > 0) {
healthBarBg.y = wizard.children[0].height / 2 + 10;
healthBar.x = 0;
healthBarBg.x = 0;
healthBar.y = healthBarBg.y;
}
wizardHealth = 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);
}
}
// 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
enemy.health -= 1;
// 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;
// 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;
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -283,9 +283,10 @@
});
upgradeButtonBg.alpha = 0.92;
upgradeButton.addChild(upgradeButtonBg);
var upgradeButtonText = new Text2("UPGRADE", {
- size: 60,
+ size: 110,
+ // Half of START GAME (220)
fill: "#fff"
});
upgradeButtonText.anchor.set(0.5, 0.5);
upgradeButtonText.x = 0;
@@ -933,9 +934,10 @@
});
upgradeButtonBg.alpha = 0.92;
upgradeButton.addChild(upgradeButtonBg);
upgradeButtonText = new Text2("UPGRADE", {
- size: 60,
+ size: 110,
+ // Half of recreated START GAME (220)
fill: "#fff"
});
upgradeButtonText.anchor.set(0.5, 0.5);
upgradeButtonText.x = 0;
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