-
Notifications
You must be signed in to change notification settings - Fork 4
/
animation.py
88 lines (71 loc) · 3.28 KB
/
animation.py
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
from console import console
from graphic import GraphicChar
import icon
import settings
class InstantAnimation(object):
def __init__(self, game_state):
self.game_state = game_state
def run_animation(self):
pass
class MissileAnimation(InstantAnimation):
def __init__(self, game_state, symbol, color_fg, path):
super(MissileAnimation, self).__init__(game_state)
self.symbol = symbol
self.color_fg = color_fg
self.path = path
self.camera = game_state.camera
self.player = game_state.player
def run_animation(self):
for point in self.path:
if not self.player.dungeon_mask.can_see_point(point):
continue
self.game_state.prepare_draw()
self.draw_missile_at_point(point)
for _ in range(settings.MISSILE_ANIMATION_DELAY):
console.flush()
def draw_missile_at_point(self, point):
x, y = self.camera.dungeon_to_screen_position(point)
console.set_color_fg((x, y), self.color_fg)
console.set_symbol((x, y), self.symbol)
def animate_flight(game_state, path, symbol_char, color_fg):
flight_animation = MissileAnimation(game_state, symbol_char, color_fg, path)
flight_animation.run_animation()
def animate_point(game_state, position, graphic_chars):
if not game_state.player.dungeon_mask.can_see_point(position):
return
camera = game_state.camera
x, y = camera.dungeon_to_screen_position(position)
for graphic_char in graphic_chars:
game_state.prepare_draw()
console.set_color_fg((x, y), graphic_char.color_fg)
console.set_symbol((x, y), graphic_char.icon)
for _ in range(settings.MISSILE_ANIMATION_DELAY):
console.flush()
def animate_fall_sync(target_entity):
color_fg = target_entity.graphic_char.color_fg
target_entity.game_state.value.force_draw()
graphic_chars = [target_entity.graphic_char,
GraphicChar(None, color_fg, icon.BIG_CENTER_DOT),
GraphicChar(None, color_fg, "*"),
GraphicChar(None, color_fg, "+"),
GraphicChar(None, color_fg, icon.CENTER_DOT)]
animate_point(target_entity.game_state.value, target_entity.position.value, graphic_chars)
def animate_fall(target_entity, animation_target_piece):
color_fg = target_entity.graphic_char.color_fg
target_entity.game_state.value.force_draw()
graphic_chars = [target_entity.graphic_char,
GraphicChar(None, color_fg, icon.BIG_CENTER_DOT),
GraphicChar(None, color_fg, "*"),
GraphicChar(None, color_fg, "+"),
GraphicChar(None, color_fg, icon.CENTER_DOT)]
animation_target_piece.char_printer.append_graphic_char_temporary_frames(graphic_chars)
def animate_path(game_state, path, graphic_char):
path = [p for p in path if game_state.player.dungeon_mask.can_see_point(p)]
camera = game_state.camera
for _ in range(settings.MISSILE_ANIMATION_DELAY):
game_state.prepare_draw()
for position in path:
x, y = camera.dungeon_to_screen_position(position)
console.set_color_fg((x, y), graphic_char.color_fg)
console.set_symbol((x, y), graphic_char.icon)
console.flush()