Game Development Reference
In-Depth Information
33
cam_x
=
@camera
.
x
34
cam_y
=
@camera
.
y
35
off_x
=
$window
.
width
/ 2 -
cam_x
36
off_y
=
$window
.
height
/ 2 -
cam_y
37
viewport
=
@camera
.
viewport
38
$window
.
translate(off_x, off_y)
do
39
zoom
=
@camera
.
zoom
40
$window
.
scale(zoom, zoom, cam_x, cam_y)
do
41
@map
.
draw(viewport)
42
@object_pool
.
objects
.
map {
|
o
|
o
.
draw(viewport) }
43
end
44
end
45
@camera
.
draw_crosshair
46
end
47
48
def
button_down
(
id
)
49
if
id
==
Gosu
::
KbQ
50
leave
51
$window
.
close
52
end
53
if
id
==
Gosu
::
KbEscape
54
GameState
.
switch(
MenuState
.
instance)
55
end
56
end
57
58
private
59
60
def
update_caption
61
now
=
Gosu
.
milliseconds
62
if
now
-
(
@caption_updated_at
|| 0
)
> 1000
63
$window
.
caption
=
'Tanks Prototype. '
<<
64
"[FPS:
#{
Gosu
.
fps
}
. "
<<
65
"Tank @
#{
@tank
.
x
.
round
}
:
#{
@tank
.
y
.
round
}
]"
66
@caption_updated_at
=
now
67
end
68
end
69
end
Implementation of
PlayState
is now also a little simpler. It doesn't update
@tank
or
@bullets
individually anymore. Instead, it uses
ObjectPool
and does all object
operations in bulk.
Other Improvements
05-refactor/main.rb