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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
// 魔法锅类
class MagicPot {
    constructor(x, y) {
        this.x = x;
        this.y = y;
        this.width = 120;
        this.height = 100;
        this.state = 'idle'; // idle, activated, cooking, overflowing
        
        // 动画属性
        this.animationTime = 0;
        this.glowIntensity = 0;
        this.shakeAmount = 0;
        this.lidOffset = 0;
        this.steamParticles = [];
        
        // 颜色配置
        this.colors = {
            pot: '#8B4513',
            potHighlight: '#CD853F',
            potShadow: '#654321',
            lid: '#A0522D',
            lidHighlight: '#DEB887',
            glow: '#FFD700',
            steam: '#FFFFFF',
            magic: '#FF69B4'
        };
        
        // 食物和动物素材
        this.foodImage = null;
        this.animalImage = null;
        this.currentFood = null;
        
        // 魔法锅图片
        this.potImage = null;
        this.imageLoaded = false;
        this.loadPotImage();
    }
    
    update(deltaTime) {
        this.animationTime += deltaTime * 0.001;
        
        // 根据状态更新动画
        switch (this.state) {
            case 'idle':
                this.updateIdleAnimation();
                break;
            case 'activated':
                this.updateActivatedAnimation();
                break;
            case 'cooking':
                this.updateCookingAnimation();
                break;
            case 'overflowing':
                this.updateOverflowingAnimation();
                break;
        }
        
        // 更新蒸汽粒子
        this.updateSteamParticles(deltaTime);
    }
    
    updateIdleAnimation() {
        // 轻微的呼吸效果
        this.glowIntensity = Math.sin(this.animationTime * 0.5) * 0.1 + 0.1;
        this.shakeAmount = 0;
        this.lidOffset = 0;
    }
    
    updateActivatedAnimation() {
        // 发光效果
        this.glowIntensity = Math.sin(this.animationTime * 2) * 0.3 + 0.5;
        this.shakeAmount = 0;
        this.lidOffset = 0;
        
        // 生成魔法粒子
        if (Math.random() < 0.1) {
            this.createMagicParticle();
        }
    }
    
    updateCookingAnimation() {
        // 强烈的发光和轻微震动
        this.glowIntensity = Math.sin(this.animationTime * 3) * 0.4 + 0.6;
        this.shakeAmount = Math.sin(this.animationTime * 8) * 2;
        this.lidOffset = Math.sin(this.animationTime * 4) * 3;
        
        // 生成蒸汽
        if (Math.random() < 0.3) {
            this.createSteamParticle();
        }
        
        // 生成魔法粒子
        if (Math.random() < 0.2) {
            this.createMagicParticle();
        }
    }
    
    updateOverflowingAnimation() {
        // 剧烈震动,锅盖被顶开
        this.glowIntensity = 1;
        this.shakeAmount = Math.sin(this.animationTime * 15) * 5;
        this.lidOffset = -20 + Math.sin(this.animationTime * 10) * 5;
        
        // 大量蒸汽
        if (Math.random() < 0.8) {
            this.createSteamParticle();
        }
        
        // 魔法粒子
        if (Math.random() < 0.5) {
            this.createMagicParticle();
        }
    }
    
    createSteamParticle() {
        const particle = {
            x: this.x + (Math.random() - 0.5) * this.width * 0.8,
            y: this.y - this.height * 0.3,
            vx: (Math.random() - 0.5) * 20,
            vy: -Math.random() * 50 - 30,
            size: Math.random() * 8 + 4,
            opacity: 0.8,
            life: 1,
            maxLife: Math.random() * 2 + 1
        };
        
        this.steamParticles.push(particle);
    }
    
    createMagicParticle() {
        const angle = Math.random() * Math.PI * 2;
        const radius = this.width * 0.6;
        
        const particle = {
            x: this.x + Math.cos(angle) * radius,
            y: this.y + Math.sin(angle) * radius * 0.5,
            vx: Math.cos(angle) * 30,
            vy: Math.sin(angle) * 30 - 20,
            size: Math.random() * 4 + 2,
            opacity: 1,
            life: 1,
            maxLife: Math.random() * 1.5 + 0.5,
            color: Math.random() < 0.5 ? '#FFD700' : '#FF69B4'
        };
        
        this.steamParticles.push(particle);
    }
    
    updateSteamParticles(deltaTime) {
        for (let i = this.steamParticles.length - 1; i >= 0; i--) {
            const particle = this.steamParticles[i];
            
            // 更新位置
            particle.x += particle.vx * deltaTime * 0.001;
            particle.y += particle.vy * deltaTime * 0.001;
            
            // 更新生命周期
            particle.life -= deltaTime * 0.001 / particle.maxLife;
            particle.opacity = particle.life;
            
            // 蒸汽粒子逐渐变大
            if (!particle.color) {
                particle.size += deltaTime * 0.002;
            }
            
            // 移除死亡的粒子
            if (particle.life <= 0) {
                this.steamParticles.splice(i, 1);
            }
        }
    }
    
    render(ctx) {
        const currentX = this.x + (Math.random() - 0.5) * this.shakeAmount;
        const currentY = this.y + (Math.random() - 0.5) * this.shakeAmount;
        
        // 绘制发光效果
        if (this.glowIntensity > 0) {
            this.renderGlow(ctx, currentX, currentY);
        }
        
        // 绘制魔法锅(图片或默认绘制)
        if (this.imageLoaded && this.potImage) {
            this.renderPotImage(ctx, currentX, currentY);
        } else {
            // 备用绘制方案
            this.renderPotBody(ctx, currentX, currentY);
            this.renderPotLid(ctx, currentX, currentY + this.lidOffset);
        }
        
        // 绘制蒸汽和魔法粒子
        this.renderParticles(ctx);
        
        // 绘制装饰
        this.renderDecorations(ctx, currentX, currentY);
    }
    
    renderPotImage(ctx, x, y) {
        ctx.save();
        
        // 如果有发光效果,添加阴影
        if (this.glowIntensity > 0) {
            ctx.shadowBlur = this.glowIntensity * 30;
            ctx.shadowColor = '#FFD700';
        }
        
        // 计算图片尺寸和位置
        const imageWidth = this.width * 1.5; // 稍微放大一点
        const imageHeight = this.height * 1.5;
        const imageX = x - imageWidth / 2;
        const imageY = y - imageHeight / 2 + this.lidOffset * 0.3; // 锅盖偏移效果
        
        // 绘制魔法锅图片
        ctx.drawImage(
            this.potImage,
            imageX,
            imageY,
            imageWidth,
            imageHeight
        );
        
        ctx.restore();
    }
    
    renderGlow(ctx, x, y) {
        const glowRadius = this.width * 0.8 * this.glowIntensity;
        const gradient = ctx.createRadialGradient(x, y, 0, x, y, glowRadius);
        
        gradient.addColorStop(0, `rgba(255, 215, 0, ${this.glowIntensity * 0.3})`);
        gradient.addColorStop(0.5, `rgba(255, 105, 180, ${this.glowIntensity * 0.2})`);
        gradient.addColorStop(1, 'rgba(255, 215, 0, 0)');
        
        ctx.fillStyle = gradient;
        ctx.beginPath();
        ctx.arc(x, y, glowRadius, 0, Math.PI * 2);
        ctx.fill();
    }
    
    renderPotBody(ctx, x, y) {
        const potWidth = this.width;
        const potHeight = this.height;
        
        // 锅身主体
        ctx.fillStyle = this.colors.pot;
        ctx.beginPath();
        ctx.ellipse(x, y + potHeight * 0.3, potWidth * 0.5, potHeight * 0.4, 0, 0, Math.PI * 2);
        ctx.fill();
        
        // 锅身侧面
        ctx.fillStyle = this.colors.potShadow;
        ctx.fillRect(x - potWidth * 0.5, y - potHeight * 0.2, potWidth, potHeight * 0.5);
        
        // 锅身高光
        ctx.fillStyle = this.colors.potHighlight;
        ctx.beginPath();
        ctx.ellipse(x - potWidth * 0.2, y - potHeight * 0.1, potWidth * 0.15, potHeight * 0.1, 0, 0, Math.PI * 2);
        ctx.fill();
        
        // 锅把手
        this.renderHandles(ctx, x, y);
    }
    
    renderHandles(ctx, x, y) {
        ctx.strokeStyle = this.colors.potShadow;
        ctx.lineWidth = 8;
        ctx.lineCap = 'round';
        
        // 左把手
        ctx.beginPath();
        ctx.arc(x - this.width * 0.6, y, this.width * 0.15, -Math.PI * 0.3, Math.PI * 0.3);
        ctx.stroke();
        
        // 右把手
        ctx.beginPath();
        ctx.arc(x + this.width * 0.6, y, this.width * 0.15, Math.PI * 0.7, Math.PI * 1.3);
        ctx.stroke();
    }
    
    renderPotLid(ctx, x, y) {
        const lidWidth = this.width * 0.9;
        const lidHeight = this.height * 0.2;
        
        // 锅盖主体
        ctx.fillStyle = this.colors.lid;
        ctx.beginPath();
        ctx.ellipse(x, y - this.height * 0.3, lidWidth * 0.5, lidHeight * 0.5, 0, 0, Math.PI * 2);
        ctx.fill();
        
        // 锅盖高光
        ctx.fillStyle = this.colors.lidHighlight;
        ctx.beginPath();
        ctx.ellipse(x - lidWidth * 0.1, y - this.height * 0.35, lidWidth * 0.3, lidHeight * 0.3, 0, 0, Math.PI * 2);
        ctx.fill();
        
        // 锅盖把手
        ctx.fillStyle = this.colors.potShadow;
        ctx.beginPath();
        ctx.ellipse(x, y - this.height * 0.45, 8, 12, 0, 0, Math.PI * 2);
        ctx.fill();
        
        ctx.fillStyle = this.colors.lidHighlight;
        ctx.beginPath();
        ctx.ellipse(x - 2, y - this.height * 0.48, 4, 6, 0, 0, Math.PI * 2);
        ctx.fill();
    }
    
    renderParticles(ctx) {
        this.steamParticles.forEach(particle => {
            ctx.save();
            ctx.globalAlpha = particle.opacity;
            
            if (particle.color) {
                // 魔法粒子
                ctx.fillStyle = particle.color;
                ctx.shadowBlur = 10;
                ctx.shadowColor = particle.color;
            } else {
                // 蒸汽粒子
                ctx.fillStyle = this.colors.steam;
            }
            
            ctx.beginPath();
            ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
            ctx.fill();
            
            ctx.restore();
        });
    }
    
    renderDecorations(ctx, x, y) {
        // 绘制魔法符文(如果激活)
        if (this.state !== 'idle') {
            this.renderMagicRunes(ctx, x, y);
        }
        
        // 绘制食物图标(如果正在烹饪)
        if (this.state === 'cooking' && this.currentFood) {
            this.renderFoodIcon(ctx, x, y);
        }
    }
    
    renderMagicRunes(ctx, x, y) {
        const runeRadius = this.width * 0.8;
        const runeCount = 6;
        const time = this.animationTime * 2;
        
        ctx.strokeStyle = this.colors.magic;
        ctx.lineWidth = 2;
        ctx.globalAlpha = this.glowIntensity * 0.5;
        
        for (let i = 0; i < runeCount; i++) {
            const angle = (i / runeCount) * Math.PI * 2 + time;
            const runeX = x + Math.cos(angle) * runeRadius;
            const runeY = y + Math.sin(angle) * runeRadius * 0.5;
            
            // 绘制简单的符文形状
            ctx.beginPath();
            ctx.moveTo(runeX - 5, runeY - 5);
            ctx.lineTo(runeX + 5, runeY + 5);
            ctx.moveTo(runeX + 5, runeY - 5);
            ctx.lineTo(runeX - 5, runeY + 5);
            ctx.stroke();
        }
        
        ctx.globalAlpha = 1;
    }
    
    renderFoodIcon(ctx, x, y) {
        // 在锅上方显示食物图标
        const iconY = y - this.height * 0.8;
        
        ctx.fillStyle = '#FFD700';
        ctx.font = '24px Arial';
        ctx.textAlign = 'center';
        ctx.fillText(this.getFoodEmoji(this.currentFood), x, iconY);
    }
    
    getFoodEmoji(foodName) {
        const emojiMap = {
            'apple': '🍎',
            'banana': '🍌',
            'orange': '🍊',
            'strawberry': '🍓',
            'watermelon': '🍉',
            'grape': '🍇',
            'pizza': '🍕',
            'burger': '🍔',
            'cake': '🍰',
            'cookie': '🍪',
            'bread': '🍞',
            'cheese': '🧀',
            'fish': '🐟',
            'chicken': '🍗',
            'rice': '🍚',
            'noodles': '🍜'
        };
        
        return emojiMap[foodName] || '🍽️';
    }
    
    // 状态控制方法
    activate() {
        this.state = 'activated';
        this.animationTime = 0;
    }
    
    startCooking(foodName) {
        this.state = 'cooking';
        this.currentFood = foodName;
        this.animationTime = 0;
    }
    
    startOverflowing() {
        this.state = 'overflowing';
        this.animationTime = 0;
    }
    
    stopOverflowing() {
        this.state = 'activated';
        this.lidOffset = 0;
        this.shakeAmount = 0;
    }
    
    reset() {
        this.state = 'idle';
        this.currentFood = null;
        this.animationTime = 0;
        this.glowIntensity = 0;
        this.shakeAmount = 0;
        this.lidOffset = 0;
        this.steamParticles = [];
    }
    
    setFoodAssets(foodImage, animalImage) {
        this.foodImage = foodImage;
        this.animalImage = animalImage;
    }
    
    // 碰撞检测
    contains(x, y) {
        const dx = x - this.x;
        const dy = y - this.y;
        const distance = Math.sqrt(dx * dx + dy * dy);
        return distance < this.width * 0.5;
    }
    
    // 获取锅的边界
    getBounds() {
        return {
            left: this.x - this.width * 0.5,
            right: this.x + this.width * 0.5,
            top: this.y - this.height * 0.5,
            bottom: this.y + this.height * 0.5
        };
    }
    
    // 加载魔法锅图片
    loadPotImage() {
        this.potImage = new Image();
        this.potImage.onload = () => {
            this.imageLoaded = true;
            console.log('魔法锅图片加载成功');
        };
        this.potImage.onerror = () => {
            console.warn('魔法锅图片加载失败,使用默认绘制');
            this.imageLoaded = false;
        };
        this.potImage.src = 'assets/images/magic_pot.png';
    }
}