Game Development Reference
In-Depth Information
26
@current_frame
= 0
27
end
28
29
def
update
30
@current_frame
+= 1
if
frame_expired?
31
end
32
33
def
draw
34
returnif
done?
35
image
=
current_frame
image
.
draw(
36
@x
-
image
.
width
/ 2.0
,
37
@y
-
image
.
height
/ 2.0
,
38
0
)
39
40
end
41
42
def
done?
43
@done
||=
@current_frame
==
@animation
.
size
44
end
45
46
def
sound
47
@sound
.
play
48
end
49
50
private
51
52
def
current_frame
53
@animation
[
@current_frame
%
@animation
.
size
]
54
end
55
56
def
frame_expired?
57
now
=
Gosu
.
milliseconds
58
@last_frame
||=
now
59
if
(now
-
@last_frame
)
>
FRAME_DELAY
60
@last_frame
=
now
61
end
62
end
63
end
64
65
class
GameWindow
<
Gosu
::
Window
66
BACKGROUND
=
media_path(
'country_field.png'
)
67
68
def
initialize
(width
=800
, height
=600
, fullscreen
=
false
)
69
super
70
self
.
caption
=
'Hello Animation'
@background
=
Gosu
::
Image
.
new(
71