1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from fortuneengine.GameEngine import GameEngine
17
18
19
20
21
23 """
24 The GameEngineElement is a helper object that can be extended by
25 other classes. When the class is extended, it will automatically
26 register its self for the event and draw loops with the game engine.
27 """
28
29 - def __init__(self, has_draw=True, has_event=True):
30 """
31 Default constructor for GameEngineElement
32
33 @param has_draw: boolean to signify if element should be drawn
34 @param has_event: boolean to signify whether the element should be
35 given events from the queue
36 """
37 self.__has_draw = has_draw
38 self.__has_event = has_event
39 self.__in_engine = False
40 self.game_engine = GameEngine.instance
41 self.__ddo_list = []
42
44 """
45 Returns true if object has been registered with the game engine.
46 """
47 return self.__in_engine
48
50 """
51 Adds some objects to the DynamicDrawableObject list and the
52 game engine's scene.
53
54 @param objects: A list of DynamicDrawableObjects
55 """
56
57 self.game_engine.get_scene().addObjects(objects)
58 self.__ddo_list += objects
59
61 """
62 Registers the object with the game engine. Registers draw and event
63 call backs separately if they were set to true in the constructor.
64 """
65 if not self.__in_engine:
66 self.__in_engine = True
67
68 if self.__has_draw:
69 self.game_engine.add_draw_callback(self.draw)
70
71 if self.__has_event:
72 self.game_engine.add_event_callback(self.event_handler)
73
75 """
76 Removes the object from the correct queues in the engine
77 """
78 if self.__in_engine:
79 self.__in_engine = False
80
81 if self.__has_draw:
82 self.game_engine.remove_draw_callback(self.draw)
83
84 if self.__has_event:
85 self.game_engine.remove_event_callback(self.event_handler)
86
87 if not (self.__ddo_list == []):
88 for object in self.__ddo_list:
89 self.game_engine.get_scene().removeObject(object)
90
91
93 """
94 This method should be overridden by the user-specified class that
95 extends this GameEngineElement class. This method specifies how that
96 class will handle events given to it by the engine.
97
98 @return: true if the user wants to prevent the event from
99 continuing down the queue
100 """
101 pass
102
103 - def draw(self, screen):
104 """
105 This method should be overridden by the user-specified class that
106 extends this GameEngineElement class. This method specifies how the
107 class will be drawn.
108 """
109 pass
110