-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.rb
More file actions
63 lines (54 loc) · 1.67 KB
/
init.rb
File metadata and controls
63 lines (54 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require "gosu"
require "opengl"
require "texplay"
require_relative "map.rb"
require_relative "camera.rb"
Gosu::enable_undocumented_retrofication
class Window < Gosu::Window
attr_reader :camera, :map
def initialize
super(1280, 720, false)
self.caption = "Ruby FPS"
@map = Map.new( self,
"assets/map.png",
"assets/tileset.png",
"assets/walls.png" )
@camera = Camera.new(self)
@aim = Gosu::Image.new(self, "assets/aim.png", true)
@character_minimap = Gosu::Image.new(self, "assets/character_minimap.png", true)
@map_bg = Gosu::Image.new(self, "assets/map_bg.png", true)
end
def button_down(id)
exit if id == Gosu::KbEscape
end
def draw_minimap
chara_color = Gosu::Color.new(128, 0, 255, 0)
map_color = Gosu::Color.new(128, 255, 255, 255)
black_color = Gosu::Color.new(255, 255, 255, 255)
clip_to(0, 0, 160, 120) do
scale 6 do
@map_bg.draw(0, 0, 0, 1, 1, black_color)
x = @map.rect.width / 2
y = @map.rect.length / 2 - 3
z = 1
angle = @camera.horizontal_angle + 90.0
x_map = x - @camera.position.x - 0.1
y_map = y - @camera.position.z + 0.05
@map.map_texture.draw(x_map, y_map, 0, 1, 1, map_color)
@character_minimap.draw_rot(x, y, z, angle, 0.5, 0.8, 1, 1, chara_color)
end
end
end
def draw
gl do
@camera.look
@map.draw
end
@aim.draw((self.width / 2) - (@aim.width / 2), (self.height / 2) - (@aim.height / 2), 0, 0.8, 0.8)
draw_minimap
end
def update
@camera.update
end
end
Window.new.show