Game Development Reference
In-Depth Information
7
end
8
9
class
GameWindow
<
Gosu
::
Window
10
WIDTH
= 800
HEIGHT
= 600
11
TILE_SIZE
= 128
12
13
14
def
initialize
15
super
(
WIDTH
,
HEIGHT
,
false
)
16
self
.
caption
=
'Random Map'
17
@tileset
=
Gosu
::
TexturePacker
.
load_json(
18
self
, media_path(
'ground.json'
),
:precise
)
19
@redraw
=
true
20
end
21
22
def
button_down
(
id
)
23
close
if
id
==
Gosu
::
KbEscape
24
@redraw
=
true
if
id
==
Gosu
::
KbSpace
25
end
26
27
def
needs_redraw?
28
@redraw
29
end
30
31
def
draw
32
@redraw
=
false
(
0.
.
WIDTH
/
TILE_SIZE
)
.
each
do
|
x
|
33
(
0.
.
HEIGHT
/
TILE_SIZE
)
.
each
do
|
y
|
34
@tileset
.
frame(
35
@tileset
.
frame_list
.
sample)
.
draw(
36
x
*
(
TILE_SIZE
),
37
y
*
(
TILE_SIZE
),
38
0
)
39
40
end
41
end
42
end
43
end
44
45
window
=
GameWindow
.
new
46
window
.
show
Run it, then press spacebar to refill the screen with random tiles.
$
ruby 02-warmup/random_map.rb