File size: 5,979 Bytes
81b3c3b
 
5207761
81b3c3b
 
 
5207761
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81b3c3b
 
5207761
 
 
 
 
81b3c3b
5207761
 
 
 
 
 
 
 
81b3c3b
 
5207761
 
 
 
 
 
 
 
 
81b3c3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
<script lang="ts">
  import { fade } from 'svelte/transition';
  import { onMount } from 'svelte';

  export let effects: Array<{type: string, emoji: string, duration: number}> = [];
  export let flash: boolean = false;
  
  // GBA-style flicker animation parameters
  const flickerCount = 19;
  const frameDelay = 2;
  const flickerDuration = 600; // milliseconds
  
  // Flicker state management
  let isFlickering = false;
  let flickerVisible = true;
  let flickerFrame = 0;
  let flickerInterval: number;
  
  // Watch for flash changes to trigger flicker animation
  $: if (flash && !isFlickering) {
    startFlickerAnimation();
  }
  
  function startFlickerAnimation() {
    isFlickering = true;
    flickerFrame = 0;
    
    // Calculate frame duration based on total duration and frame count
    const totalFrames = flickerCount * (frameDelay + 1);
    const frameDuration = flickerDuration / totalFrames;
    
    flickerInterval = setInterval(() => {
      if (flickerFrame >= totalFrames) {
        // Animation finished, always visible
        clearInterval(flickerInterval);
        isFlickering = false;
        flickerVisible = true;
        return;
      }
      
      // Toggle visibility every frameDelay frames
      const flickerCycle = Math.floor(flickerFrame / (frameDelay + 1));
      flickerVisible = flickerCycle % 2 === 0;
      
      flickerFrame++;
    }, frameDuration);
  }
  
  onMount(() => {
    return () => {
      if (flickerInterval) {
        clearInterval(flickerInterval);
      }
    };
  });
</script>

<!-- Effects wrapper with relative positioning for particles -->
<div class="effects-wrapper">
  <!-- GBA-style flicker effect -->
  <div class="effects-container" style="opacity: {(flash && isFlickering) ? (flickerVisible ? 1 : 0) : 1};">
    <slot />
  </div>

  <!-- Particle effects -->
  {#each effects as effect (effect)}
    <div class="effect-particle {effect.type}" style="animation-duration: {effect.duration}ms">
      <span class="effect-emoji">{effect.emoji}</span>
    </div>
  {/each}
</div>

<style>
  .effects-wrapper {
    position: relative;
    display: inline-block;
  }
  
  .effects-container {
    position: relative;
    display: inline-block;
    transition: opacity 0.05s ease;
  }
  
  .effect-particle {
    position: absolute;
    pointer-events: none;
    z-index: 5;
    animation-fill-mode: forwards;
  }
  
  .effect-emoji {
    font-size: 24px;
    display: block;
    filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.3));
  }
  
  /* Damage and status effects */
  .effect-particle.burn,
  .effect-particle.poison,
  .effect-particle.paralyze,
  .effect-particle.sleep,
  .effect-particle.freeze {
    top: 20%;
    left: 50%;
    animation: statusEffect linear;
  }
  
  /* Stat changes */
  .effect-particle.attackUp,
  .effect-particle.defenseUp,
  .effect-particle.speedUp,
  .effect-particle.accuracyUp {
    bottom: 30%;
    left: 50%;
    animation: statIncrease ease-out;
  }
  
  .effect-particle.attackDown,
  .effect-particle.defenseDown,
  .effect-particle.speedDown,
  .effect-particle.accuracyDown {
    top: 30%;
    left: 50%;
    animation: statDecrease ease-out;
  }
  
  /* Special effects */
  .effect-particle.critical,
  .effect-particle.superEffective {
    top: 10%;
    left: 50%;
    animation: criticalEffect ease-out;
  }
  
  .effect-particle.notVeryEffective,
  .effect-particle.miss {
    top: 40%;
    left: 50%;
    animation: missEffect ease-out;
  }
  
  .effect-particle.heal {
    bottom: 20%;
    left: 50%;
    animation: healEffect ease-out;
  }
  
  /* Animations */
  @keyframes statusEffect {
    0% {
      transform: translate(-50%, 0) scale(0.5);
      opacity: 0;
    }
    20% {
      transform: translate(-50%, -10px) scale(1.2);
      opacity: 1;
    }
    40% {
      transform: translate(-50%, -5px) scale(1);
      opacity: 1;
    }
    100% {
      transform: translate(-50%, -20px) scale(0.8);
      opacity: 0;
    }
  }
  
  @keyframes statIncrease {
    0% {
      transform: translate(-50%, 0) scale(0.5);
      opacity: 0;
    }
    30% {
      transform: translate(-50%, -30px) scale(1.3);
      opacity: 1;
    }
    70% {
      transform: translate(-50%, -40px) scale(1.1);
      opacity: 1;
    }
    100% {
      transform: translate(-50%, -60px) scale(0.7);
      opacity: 0;
    }
  }
  
  @keyframes statDecrease {
    0% {
      transform: translate(-50%, 0) scale(0.5);
      opacity: 0;
    }
    30% {
      transform: translate(-50%, 20px) scale(1.3);
      opacity: 1;
    }
    70% {
      transform: translate(-50%, 30px) scale(1.1);
      opacity: 1;
    }
    100% {
      transform: translate(-50%, 50px) scale(0.7);
      opacity: 0;
    }
  }
  
  @keyframes criticalEffect {
    0% {
      transform: translate(-50%, 0) scale(0.3) rotate(-10deg);
      opacity: 0;
    }
    20% {
      transform: translate(-50%, -20px) scale(1.5) rotate(5deg);
      opacity: 1;
    }
    40% {
      transform: translate(-50%, -15px) scale(1.3) rotate(-2deg);
      opacity: 1;
    }
    60% {
      transform: translate(-50%, -25px) scale(1.4) rotate(1deg);
      opacity: 1;
    }
    100% {
      transform: translate(-50%, -40px) scale(0.8) rotate(0deg);
      opacity: 0;
    }
  }
  
  @keyframes missEffect {
    0% {
      transform: translate(-50%, 0) scale(1);
      opacity: 0;
    }
    20% {
      transform: translate(-50%, 0) scale(1.2);
      opacity: 0.7;
    }
    80% {
      transform: translate(-50%, 0) scale(1.1);
      opacity: 0.3;
    }
    100% {
      transform: translate(-50%, 0) scale(1);
      opacity: 0;
    }
  }
  
  @keyframes healEffect {
    0% {
      transform: translate(-50%, 20px) scale(0.5);
      opacity: 0;
    }
    30% {
      transform: translate(-50%, -10px) scale(1.2);
      opacity: 1;
    }
    70% {
      transform: translate(-50%, -30px) scale(1);
      opacity: 1;
    }
    100% {
      transform: translate(-50%, -50px) scale(0.6);
      opacity: 0;
    }
  }
</style>