Game Development Reference
In-Depth Information
private
40
41
42
def
current_frame
43
@animation
[
@current_frame
%
@animation
.
size
]
44
end
45
46
def
frame_expired?
47
now
=
Gosu
.
milliseconds
48
@last_frame
||=
now
49
if
(now
-
@last_frame
)
>
FRAME_DELAY
50
@last_frame
=
now
51
end
52
end
53
end
54
55
class
GameWindow
<
Gosu
::
Window
56
BACKGROUND
=
media_path(
'country_field.png'
)
57
58
def
initialize
(width
=800
, height
=600
, fullscreen
=
false
)
59
super
60
self
.
caption
=
'Hello Animation'
61
@background
=
Gosu
::
Image
.
new(
62
self
,
BACKGROUND
,
false
)
63
@animation
=
Explosion
.
load_animation(
self
)
64
@explosions
= []
65
end
66
67
def
update
68
@explosions
.
reject!(
&
:done?
)
69
@explosions
.
map(
&
:update
)
70
end
71
72
def
button_down
(
id
)
73
close
if
id
==
Gosu
::
KbEscape
74
if
id
==
Gosu
::
MsLeft
75
@explosions
.
push(
Explosion
.
new(
76
@animation
, mouse_x, mouse_y))
77
78
end
79
end
80
81
def
needs_cursor?
82
true
83
end
84
85
def
needs_redraw?