forked from oahassan/way-of-the-stick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playtool.py
82 lines (65 loc) · 2.83 KB
/
playtool.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
import sys
import pygame
from testplayer import TestPlayer
import animation
import EditorTools
import gamestate
import stage
class PlayTool(EditorTools.Tool):
_SYMBOL_LINE_THICKNESS = 2
def __init__(self):
"""creates a new play tool"""
EditorTools.Tool.__init__(
self,
'play',
'Play the animation.'
)
self.symbol = EditorTools.Symbol()
self.symbol.draw = PlayTool.draw_symbol
self.animation_type = None
self.animation = None
def draw_symbol(self, surface):
"""draws the symbol of the play tool
surface: the surface to draw the play tool's symbol on"""
point1 = (self.button_center()[0] - 6, self.button_center()[1] - 6)
point2 = (self.button_center()[0] - 6, self.button_center()[1] + 6)
point3 = (self.button_center()[0] + 6, self.button_center()[1])
pygame.draw.polygon(surface, \
self.symbol.color, \
(point1, point2, point3), \
PlayTool._SYMBOL_LINE_THICKNESS)
def init_state(self, animation):
EditorTools.Tool.init_state(self, animation)
gamestate.frame_rate = 100
gamestate.drawing_mode = gamestate.DrawingModes.DIRTY_RECTS
gamestate.stage = stage.load_play_tool_stage()
gamestate.screen.blit(gamestate.stage.background_image, (0,0))
gamestate.new_dirty_rects.append(pygame.Rect((0,0),(gamestate._WIDTH, gamestate._HEIGHT)))
self.test_player = TestPlayer()
self.test_player.init_state()
self.test_player.load_action(self.animation_type, self.animation)
def clear_state(self):
"""clears the state of this tool"""
self.animation.frame_index = len(self.animation.frames) - 1
EditorTools.Tool.clear_state(self)
gamestate.drawing_mode = gamestate.DrawingModes.UPDATE_ALL
gamestate.frame_rate = 20
def handle_events(self, \
surface, \
mousePos, \
mouseButtonsPressed, \
events):
event_types = []
for event in events:
event_types.append(event.type)
if pygame.QUIT in event_types:
sys.exit()
else:
for rect in gamestate.old_dirty_rects:
rect_surface = pygame.Surface((rect.width,rect.height))
rect_surface.blit(gamestate.stage.background_image,((-rect.left,-rect.top)))
gamestate.screen.blit(rect_surface,rect.topleft)
self.test_player.handle_events()
#self.animation.frame_index += 1
#if self.animation.frame_index >= len(self.animation.frames):
# self.animation.frame_index = 0