Skip to content

Commit 39364b2

Browse files
authored
Merge pull request #349 from lxgr-linux/feat/visual_effects
Feat/visual effects
2 parents 237679c + ae3266c commit 39364b2

File tree

3 files changed

+71
-14
lines changed

3 files changed

+71
-14
lines changed

src/pokete/classes/animations.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def transition(_map, poke):
4545

4646

4747
def fight_intro(height, width):
48-
"""Intro animation for fight
48+
"""Intro animation for fight with enhanced visual effect
4949
ARGS:
5050
height: Height of the animation
5151
width: Width of the animation"""
@@ -57,17 +57,24 @@ def fight_intro(height, width):
5757
for i in vec_list:
5858
i.add(fancymap, int(width / 2), int((height - 1) / 2))
5959
fancymap.show()
60+
61+
chars = ["-", "=", "-"]
62+
char_idx = 0
6063
for i, _l in zip(
6164
list(zip(*[j.obs for j in vec_list])),
6265
list(zip(*[list(2 * " ") + k for k in [j.obs for j in vec_list]])),
6366
):
6467
for j in i:
65-
j.rechar("-")
68+
j.rechar(chars[char_idx % len(chars)])
6669
for j in _l:
6770
if j != " ":
6871
j.rechar(" ")
72+
char_idx += 1
6973
fancymap.show()
70-
time.sleep(SPEED_OF_TIME * 0.005)
74+
time.sleep(SPEED_OF_TIME * 0.008)
75+
76+
time.sleep(SPEED_OF_TIME * 0.15)
77+
7178
for i in vec_list:
7279
i.remove()
7380
del fancymap

src/pokete/classes/health_bar.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@ def make(self, oldhp):
2828
self.rechar(bar_num * "#", esccode)
2929

3030
def update(self, oldhp):
31-
"""Updates the healthbar in steps
31+
"""Updates the healthbar in steps with easing effect
3232
ARGS:
3333
oldhp: The pokes former hp"""
34+
diff = abs(oldhp - self.poke.hp)
35+
step = 0
3436
while oldhp != self.poke.hp and oldhp > 0:
3537
oldhp += -1 if oldhp > self.poke.hp else 1
38+
step += 1
3639
self.poke.text_hp.rechar(f"HP:{oldhp}", esccode=Color.yellow)
3740
self.make(oldhp)
38-
time.sleep(SPEED_OF_TIME * 0.1)
41+
# Easing: starts fast, slows down towards end
42+
progress = step / max(diff, 1)
43+
delay = 0.03 + (0.12 * progress * progress)
44+
time.sleep(SPEED_OF_TIME * delay)
3945
self.poke.ico.map.show()
4046
self.poke.text_hp.rechar(f"HP:{oldhp}")
4147
time.sleep(SPEED_OF_TIME * 0.1)

src/pokete/classes/moves.py

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,40 @@ def attack(self):
2525
)
2626
self.poke.ico.map.show()
2727
time.sleep(SPEED_OF_TIME * _t)
28+
self.impact()
29+
30+
def impact(self):
31+
"""Brief flash effect on enemy when attack lands"""
32+
if self.poke.enem == self.poke:
33+
return
34+
enem_ico = self.poke.enem.ico
35+
flash_chars = ["*", "X", "*"]
36+
flash = se.Text(flash_chars[0], esccode=Color.thicc + Color.yellow)
37+
flash.add(
38+
enem_ico.map,
39+
*(
40+
(enem_ico.x, enem_ico.y + enem_ico.height)
41+
if self.poke.player
42+
else (
43+
enem_ico.x + enem_ico.width,
44+
enem_ico.y,
45+
)
46+
),
47+
)
48+
for char in flash_chars:
49+
flash.rechar(char, esccode=Color.thicc + Color.yellow)
50+
enem_ico.map.show()
51+
time.sleep(SPEED_OF_TIME * 0.1)
52+
flash.remove()
53+
enem_ico.map.show()
2854

2955
def pound(self):
3056
"""Pound move"""
3157
for i in [-1, 1]:
3258
self.poke.ico.move(0, i)
3359
self.poke.ico.map.show()
3460
time.sleep(SPEED_OF_TIME * 0.3)
61+
self.impact()
3562

3663
def bomb(self):
3764
"""Bomb move"""
@@ -82,7 +109,7 @@ def bomb(self):
82109
text.add(
83110
_map, round((_map.width - 11) / 2), round((_map.height - 9) / 2)
84111
)
85-
self.throw(Color.thicc + Color.blue + "o" + Color.reset, 0.5)
112+
self.__throw(Color.thicc + Color.blue + "o" + Color.reset, 0.5)
86113
for i in frames:
87114
text.rechar(i)
88115
self.poke.ico.map.show()
@@ -114,12 +141,17 @@ def arch(self):
114141
line.remove()
115142
del line
116143

117-
def throw(self, txt="#", factor=1.0, num=1):
118-
"""Throw move
144+
def throw(self):
145+
self.__throw()
146+
self.impact()
147+
148+
def __throw(self, txt="#", factor=1.0, num=1, trail=True):
149+
"""Throw move with trail effect
119150
ARGS:
120151
txt: The char that moves across the screen
121152
factor: Scalar to stretch the vector
122-
num: The number of chars thrown"""
153+
num: The number of chars thrown
154+
trail: Whether to show a fading trail behind projectile"""
123155
if self.poke.enem == self.poke:
124156
return
125157
line = se.Line(
@@ -139,24 +171,36 @@ def throw(self, txt="#", factor=1.0, num=1):
139171
self.poke.ico.y + 1,
140172
)
141173
self.poke.ico.map.show()
174+
trail_char = Color.white + "." + Color.reset
175+
trail_len = 3 if trail else 0
142176
for i in range(len(line.obs) + num * 5 - 1):
143177
for j in range(0, num * 5, 5):
144178
if len(line.obs) > i - j >= 0:
145179
line.obs[i - j].rechar(txt)
146-
if len(line.obs) >= i - j > 0:
147-
line.obs[i - j - 1].rechar(line.char)
180+
# Trail effect: show fading dots behind projectile
181+
if trail:
182+
for t in range(1, trail_len + 1):
183+
trail_idx = i - j - t
184+
if 0 <= trail_idx < len(line.obs):
185+
line.obs[trail_idx].rechar(trail_char)
186+
# Clear old trail
187+
clear_idx = i - j - trail_len - 1 if trail else i - j - 1
188+
if len(line.obs) > clear_idx >= 0:
189+
line.obs[clear_idx].rechar(line.char)
148190
time.sleep(SPEED_OF_TIME * 0.05)
149191
self.poke.ico.map.show()
150192
line.remove()
151193
del line
152194

153195
def gun(self):
154196
"""Gun move"""
155-
self.throw(txt=Color.thicc + Color.blue + "o" + Color.reset, num=4)
197+
self.__throw(txt=Color.thicc + Color.blue + "o" + Color.reset, num=4)
198+
self.impact()
156199

157200
def fireball(self):
158201
"""Fireball move"""
159-
self.throw(txt=Color.thicc + Color.red + "*" + Color.reset)
202+
self.__throw(txt=Color.thicc + Color.red + "*" + Color.reset)
203+
self.impact()
160204

161205
def shine(self, ico=Color.thicc + Color.green + "*" + Color.reset):
162206
"""Shine Move"""
@@ -217,7 +261,7 @@ def rain(self):
217261
random.choice(range(2)) + cloud.y + 3,
218262
)
219263
_map.show()
220-
time.sleep(0.05)
264+
time.sleep(SPEED_OF_TIME * 0.05)
221265
drops.append(rain)
222266
cloud.remove()
223267
for drop in drops:

0 commit comments

Comments
 (0)