-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowerup.js
108 lines (97 loc) · 2.87 KB
/
powerup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
class Powerup {
constructor(x, y, type) {
this.x = x;
this.y = y;
this.type = type; // 0: speed, 1: damage, 2: multishot, 3: health
this.radius = 10;
this.duration = 5; // seconds
// Animation
this.angle = 0;
this.rotationSpeed = Math.PI; // radians per second
}
draw(ctx) {
ctx.save();
ctx.translate(this.x, this.y);
ctx.rotate(this.angle);
// Draw power-up
ctx.beginPath();
switch(this.type) {
case 0: // Speed (lightning bolt)
ctx.fillStyle = '#ffff00';
ctx.strokeStyle = '#ffa500';
this.drawLightning(ctx);
break;
case 1: // Damage (sword)
ctx.fillStyle = '#ff4444';
ctx.strokeStyle = '#cc0000';
this.drawSword(ctx);
break;
case 2: // Multishot (three dots)
ctx.fillStyle = '#44ff44';
ctx.strokeStyle = '#00cc00';
this.drawMultishot(ctx);
break;
case 3: // Health (heart)
ctx.fillStyle = '#ff4444';
ctx.strokeStyle = '#cc0000';
this.drawHeart(ctx);
break;
}
ctx.restore();
// Update rotation
this.angle += this.rotationSpeed / 60; // Assuming 60 FPS
}
drawLightning(ctx) {
ctx.beginPath();
ctx.moveTo(-5, -10);
ctx.lineTo(2, -2);
ctx.lineTo(-2, 2);
ctx.lineTo(5, 10);
ctx.lineWidth = 3;
ctx.stroke();
}
drawSword(ctx) {
ctx.beginPath();
ctx.moveTo(0, -10);
ctx.lineTo(0, 10);
ctx.moveTo(-5, -5);
ctx.lineTo(5, 5);
ctx.lineWidth = 3;
ctx.stroke();
}
drawMultishot(ctx) {
for (let i = -1; i <= 1; i++) {
ctx.beginPath();
ctx.arc(i * 6, 0, 2, 0, Math.PI * 2);
ctx.fill();
ctx.stroke();
}
}
drawHeart(ctx) {
ctx.beginPath();
ctx.moveTo(0, 5);
ctx.bezierCurveTo(-5, 0, -10, 5, 0, 10);
ctx.bezierCurveTo(10, 5, 5, 0, 0, 5);
ctx.fill();
ctx.stroke();
}
apply(player) {
switch(this.type) {
case 0: // Speed boost
player.speed = 400;
player.speedBoostTimer = this.duration;
break;
case 1: // Damage boost
player.damage = 40;
player.damageBoostTimer = this.duration;
break;
case 2: // Multishot
player.multishot = 3;
player.multishotTimer = this.duration;
break;
case 3: // Health
player.heal(50);
break;
}
}
}