Game Development Reference
In-Depth Information
attr_accessor
:x
,
:y
,
:zoom
35
36
37
def
initialize
38
@x
=
@y
= 0
39
@zoom
= 1
40
end
41
42
def
can_view?
(x, y, obj)
43
x0, x1, y0, y1
=
viewport
(x0
-
obj
.
width
.
.x1)
.
include?(x)
&&
44
(y0
-
obj
.
height
.
.y1)
.
include?(y)
45
46
end
47
48
def
viewport
49
x0
=
@x
-
(
$window
.
width
/ 2
)
/
@zoom
50
x1
=
@x
+
(
$window
.
width
/ 2
)
/
@zoom
51
y0
=
@y
-
(
$window
.
height
/ 2
)
/
@zoom
52
y1
=
@y
+
(
$window
.
height
/ 2
)
/
@zoom
53
[
x0, x1, y0, y1
]
54
end
55
56
def
to_s
57
"FPS:
#{
Gosu
.
fps
}
. "
<<
"
#{
@x
}
:
#{
@y
}
@
#{
'%.2f'
%
@zoom
}
. "
<<
58
'WASD to move, arrows to zoom.'
59
60
end
61
62
def
draw_crosshair
63
$window
.
draw_line(
@x
- 10
,
@y
,
Gosu
::
Color
::
YELLOW
,
64
@x
+ 10
,
@y
,
Gosu
::
Color
::
YELLOW
,
100
)
65
$window
.
draw_line(
66
@x
,
@y
- 10
,
Gosu
::
Color
::
YELLOW
,
67
@x
,
@y
+ 10
,
Gosu
::
Color
::
YELLOW
,
100
)
68
69
end
70
end
71
72
73
class
GameWindow
<
Gosu
::
Window
74
SPEED
= 10
75
76
def
initialize
77
super
(
800
,
600
,
false
)
78
$window
=
self
@map
=
WorldMap
.
new(
2048
,
1024
)
79
@camera
=
Camera
.
new
80