-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameWindow.rb
135 lines (109 loc) · 4.35 KB
/
GameWindow.rb
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
module GameWindow
@@debug = true
@@pause = false
UI_draw_order = 500
UI_draw_font_order = 1200
Debug_draw_order = 500
Debug_draw_font_order = 1200
Game_draw_order = 200
Game_draw_font_order = 1000
UI_Font = Fonts::Middle
UI_color = [255, 0, 0, 80]
UI_Side_width = 230
UI = {:side=>{
:left=>{
:x=>0,:y=>0,:image=>Image.new( UI_Side_width, Window.height, UI_color)
},
:right=>{
:x=>Window.width - UI_Side_width, :y=>0, :image=>Image.new( UI_Side_width, Window.height, UI_color)
}
},
:under=>{
:x=>0, :y=>Window.height - Fonts::Large.size, :image=>Image.new( Window.width, Fonts::Large.size, UI_color)
},
:pause=>{
:x=>Window.width / 2 - UI_Font.get_width("pause Restart to [ESC].") / 2, :y=>Window.height / 2, :string=>"pause Restart to [ESC]."
},
:gameover=>{
:x=>Window.width / 2 - UI_Font.get_width("Game Over") / 2, :y=>Window.height / 2, :string=>"Game Over"
}
}
def self.draw_start_title()
title_font = UI_Font
start_title = ["Welcome to Test Ruby Game.", "Please Start to [Space] Key."]
Window.draw_font( (Window.width / 2 - title_font.get_width(start_title[0]) / 2),
(Window.height / 2 - title_font.size / 2), start_title[0], title_font )
Window.draw_font( (Window.width / 2 - title_font.get_width(start_title[1]) / 2),
(Window.height / 2 + title_font.size / 2), start_title[1], title_font )
end
def self.chengePause()
@@pause = !@@pause
end
def self.pause?()
return @@pause
end
def self.debug=(enable)
@@debug = enable
end
def self.debug_draw( x, y, image, z=0)
Window.draw( x, y, image, Debug_draw_font_order) if @@debug && z<=0
Window.draw( x, y, image, z) if @@debug && z>0
end
def self.debug_draw_font( x, y, string, font, option={})
option.store(:z,Debug_draw_font_order) if option[:z] == nil
Window.draw_font( x, y, string, font, option) if @@debug
end
def self.debug?()
return @@debug
end
def self.draw( x, y, image, z=0)
Window.draw( x, y, image, Game_draw_order) if z<=0
Window.draw( x, y, image, z) if z>0
end
def self.draw_alpha( x, y, image, alpha, z=0)
Window.draw_alpha( x, y, image, alpha, Game_draw_order) if z<=0
Window.draw_alpha( x, y, image, alpha, z) if z>0
end
def self.draw_rot(x, y, image, angle, center_x=nil, center_y=nil, z=0)
Window.draw_rot( x, y, image, angle, center_x, center_y, Game_draw_order) if z<=0
Window.draw_rot( x, y, image, angle, center_x, center_y, z) if z>0
end
def self.draw_sprite( sprite,z=0)
draw( sprite.x, sprite.y, sprite.image) if z <= 0
draw( sprite.x, sprite.y, sprite.image, z) if z > 0
end
def self.draw_font( x, y, string, font, option={})
option.store(:z,Game_draw_font_order) if option[:z] == nil
Window.draw_font( x, y, string, font, option)
end
def self.x()
return UI[:side][:left][:x] + UI[:side][:left][:image].width
end
def self.center_horizontal
return Window.width / 2
end
def self.width()
return UI[:side][:right][:x]
end
def self.y()
return 0
end
def self.center_vertical
return Window.height / 2
end
def self.height()
return UI[:under][:y]
end
def self.debug()
GameWindow.debug_draw_font( GameWindow.width, GameWindow.y, "FPS: " + Window.fps.to_s, Fonts::Middle)
end
def self.draw_gameover()
Window.draw_font( UI[:gameover][:x], UI[:gameover][:y], UI[:gameover][:string], Fonts::Large, option={:z=>UI_draw_font_order})
end
def self.draw_ui()
Window.draw( UI[:side][:left][:x], UI[:side][:left][:y], UI[:side][:left][:image], UI_draw_order)
Window.draw( UI[:side][:right][:x], UI[:side][:right][:y], UI[:side][:right][:image], UI_draw_order)
Window.draw( UI[:under][:x], UI[:under][:y], UI[:under][:image], UI_draw_order)
Window.draw_font( UI[:pause][:x], UI[:pause][:y], UI[:pause][:string], UI_Font, option={:z=>UI_draw_font_order}) if @@pause
end
end