add skin manager

This commit is contained in:
jakciehan
2026-04-10 23:05:26 +08:00
parent cc2e7b9bb0
commit 0e321bcea6
9 changed files with 421 additions and 46 deletions
+31 -15
View File
@@ -79,6 +79,7 @@ const GameScene = {
// Revive ad state
_reviveAdUsed: false,
_reviveCount: 0, // Track revive count for escalating cost
_showingReviveDialog: false,
_reviveDialogButtons: null,
@@ -97,6 +98,7 @@ const GameScene = {
this._gameOverDelay = 0;
this._cachedBasePos = null;
this._reviveAdUsed = false;
this._reviveCount = 0;
this._showingReviveDialog = false;
this._reviveDialogButtons = null;
@@ -138,6 +140,11 @@ const GameScene = {
});
this._playerTank.activateShield(3000); // spawn protection
// Apply equipped skin colors to player tank
if (GameGlobal.skinManager) {
this._playerTank._skinColors = GameGlobal.skinManager.getCurrentSkinColors();
}
// Safety: ensure player spawn area is clear of blocking terrain
this._clearSpawnArea(levelData.playerSpawn.col, levelData.playerSpawn.row);
@@ -471,14 +478,15 @@ const GameScene = {
ctx.fillText(t('ad.watchAd') || '📺 Watch Ad (Free)', btns.watchAd.x + btns.watchAd.w / 2, btns.watchAd.y + btns.watchAd.h / 2);
}
// Gold Revive button (orange)
// Gold Revive button (orange) - show escalating cost
if (btns.goldRevive) {
const hasGold = GameGlobal.currencyManager && GameGlobal.currencyManager.hasGold(200);
const reviveCost = this._getReviveCost();
const hasGold = GameGlobal.currencyManager && GameGlobal.currencyManager.hasGold(reviveCost);
ctx.fillStyle = hasGold ? '#FF9800' : '#555555';
ctx.fillRect(btns.goldRevive.x, btns.goldRevive.y, btns.goldRevive.w, btns.goldRevive.h);
ctx.fillStyle = '#FFFFFF';
ctx.font = 'bold 13px Arial';
ctx.fillText(t('ad.goldRevive') || '🪙 Gold Revive (200)', btns.goldRevive.x + btns.goldRevive.w / 2, btns.goldRevive.y + btns.goldRevive.h / 2);
ctx.fillText(`🪙 ${t('ad.goldRevive') || 'Gold Revive'} (${reviveCost})`, btns.goldRevive.x + btns.goldRevive.w / 2, btns.goldRevive.y + btns.goldRevive.h / 2);
}
// Give Up button (gray)
@@ -680,13 +688,8 @@ const GameScene = {
const hasLives = this._playerTank.die();
if (!hasLives) {
// Check if revive ad is available and not yet used this level
if (!this._reviveAdUsed) {
// Always show revive dialog (with ad and/or gold options)
this._showReviveAdDialog();
} else {
this._triggerGameOver();
}
// Always show revive dialog (escalating cost each time)
this._showReviveAdDialog();
}
},
@@ -701,6 +704,18 @@ const GameScene = {
return GameGlobal.adManager.canShowScene(AdManager.AD_SCENE.REVIVE);
},
/**
* Get the current revive gold cost based on revive count (escalating).
* 1st revive: 200, 2nd: 400, 3rd+: 800
* @returns {number}
* @private
*/
_getReviveCost() {
if (this._reviveCount === 0) return 200;
if (this._reviveCount === 1) return 400;
return 800;
},
/**
* Show the revive dialog overlay with dual options.
* Pauses the game and presents watch-ad / gold-revive / give-up options.
@@ -736,17 +751,18 @@ const GameScene = {
},
/**
* Handle the player choosing to revive with gold (200 gold).
* Handle the player choosing to revive with gold (escalating cost).
* @private
*/
_onGoldRevive() {
const cost = this._getReviveCost();
const cm = GameGlobal.currencyManager;
if (cm && cm.spendGold(200)) {
if (cm && cm.spendGold(cost)) {
this._showingReviveDialog = false;
this._reviveDialogButtons = null;
this._reviveAdUsed = true;
this._reviveCount++;
this._revivePlayer();
console.log('[GameScene] Player revived via gold (200)');
console.log(`[GameScene] Player revived via gold (${cost}), revive #${this._reviveCount}`);
}
},
@@ -762,7 +778,7 @@ const GameScene = {
this._showingReviveDialog = false;
this._reviveDialogButtons = null;
if (completed) {
this._reviveAdUsed = true;
this._reviveCount++;
this._revivePlayer();
} else {
this._triggerGameOver();