Game Development Reference
In-Depth Information
97
def
choose_tile
(val)
98
case
val
99
when
0.0.
.
0.3
# 30% chance
100
@water
101
when
0.3.
.
0.45
# 15% chance, water edges
102
@sand
103
else
# 55% chance
104
@grass
105
end
106
end
Here we could go crazy if we had more different tiles to use. We could add deep waters
at
0.0..0.1
, mountains at
0.9..0.95
and snow caps at
0.95..1.0
. And all this
would have beautiful transitions.
Player Movement With Keyboard And Mouse
We have learned to draw maps, but we need a protagonist to explore them. It will be a tank
that you can move around the island with WASD keys and use your mouse to target it's gun
at things. The tank will be drawn on top of our island map, and it will be above ground, but
below tree layer, so it can sneak behind palm trees. That's as close to real deal as it gets!
02-warmup/player_movement.rb
1
require
'gosu'
2
require
'gosu_tiled'
3
require
'gosu_texture_packer'
4
5
class
Tank
6
attr_accessor
:x
,
:y
,
:body_angle
,
:gun_angle
7
8
def
initialize
(window, body, shadow, gun)
9
@x
=
window
.
width
/ 2
10
@y
=
window
.
height
/ 2
11
@window
=
window
12
@body
=
body
13
@shadow
=
shadow
14
@gun
=
gun
15
@body_angle
= 0.0
16
@gun_angle
= 0.0
17
end
18
19
def
update
20
atan
=
Math
.
atan2(
320 -
@window
.
mouse_x,
240 -
@window
.
mouse_y)
21