Game Development Reference
In-Depth Information
8 @initial_health = @health = health
9 @health_updated = true
10 end
11
12 def restore
13 @health = @initial_health
14 @health_updated = true
15 end
16
17 def dead?
18 @health < 1
19 end
20
21 def update
22 update_image
23 end
24
25 def inflict_damage (amount)
26 if @health > 0
27 @health_updated = true
28 @health = [ @health - amount . to_i, 0]. max
29 after_death if dead?
30 end
31 end
32
33 def draw (viewport)
34 returnunless draw?
35
@image && @image . draw(
x - @image . width / 2 ,
36
y - object . graphics . height / 2 -
37
@image . height, 100 )
38
39 end
40
41
protected
42
43 def draw?
44 $debug
45 end
46
47 def update_image
48 returnunless draw?
49 if @health_updated
50
text = @health . to_s
font_size = 18
51
@image = Gosu :: Image . from_text(
52
$window , text,
53
Search WWH ::




Custom Search