Game Development Reference
In-Depth Information
update and draw methods would cycle through @components and delegate those calls
to each of them in a sequence. It is important to update all components first, and only
then draw them. Keep in mind that @components array order has significance. First
elements will always be updated and drawn before last ones.
We will also provide removable? method that would return true for objects that
mark_for_removal was invoked on. This way we will be able to weed out old bullets
and explosions and feed them to GC.
Next up, base Component class:
05-refactor/entities/components/component.rb
1 class Component
2 def initialize (game_object = nil )
3 self . object = game_object
4 end
5
6 def update
7 # override
8 end
9
10 def draw (viewport)
11 # override
12 end
13
14
protected
15
16 def object = (obj)
17 if obj
18 @object = obj
19 obj . components << self
20 end
21 end
22
23 def x
24 @object . x
25 end
26
27 def y
28 @object . y
29 end
30
31 def object
32
@object
Search WWH ::




Custom Search