-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectorbar.rb
113 lines (85 loc) · 3.17 KB
/
selectorbar.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
class SelectorBar
attr_reader :current_image, :x, :moving
def initialize(size, *paths)
@size = size
@spacing = 120
@border = 3
@names = []
@current_image = 0
@next_image = 0
paths.each { |name| @names << name }
@x = ($game.settings.default_width - @size) / 2
@y = 0
@next_x = @x
@moving = false
end
def update
if @next_image == @current_image
@moving = false
if button_down?(KB_RIGHT) && @current_image < @names.size - 1
@next_image = @current_image + 1
@next_x = @x - (@size + @spacing)
elsif button_down?(KB_LEFT) && @current_image > 0
@next_image = @current_image - 1
@next_x = @x + (@size + @spacing)
end
else
@moving = true
if @next_x < @x
@x -= 15
if @next_x > @x
@x = @next_x
@current_image = @next_image
end
elsif @next_x > @x
@x += 15
if @next_x < @x
@x = @next_x
@current_image = @next_image
end
end
end
end
def draw
# Draw the selection square
Gosu.draw_rect(($game.settings.default_width - @size * 1.2) / 2,
($game.settings.default_height - @size * 1.2) / 2,
@size * 1.2,
@size * 1.2,
Color::YELLOW,
500)
Gosu.draw_rect(($game.settings.default_width - @size * 1.2) / 2 + @border,
($game.settings.default_height - @size * 1.2) / 2 + @border,
@size * 1.2 - @border * 2,
@size * 1.2 - @border * 2,
Color.new(220, 0, 0, 0),
500)
# Draw spaceship
i = 0
@names.each do |name|
SpriteManager.get_image(name).draw(@x + i * (@size + @spacing),
($game.settings.default_height - @size) / 2,
500,
@size / SpriteManager.get_image(name).width.to_f,
@size / SpriteManager.get_image(name).width.to_f) if @x + i * (@size + @spacing) + @size > 0 and
@x + i * (@size + @spacing) < $game.settings.default_width
$font.draw(name,
@x + i * (@size + @spacing) + (@size - $font.text_width(name, 0.35))/2,
($game.settings.default_height - @size) / 2 + @size + 25,
500,
0.35,
0.35)
i += 1
end
end
def reset
@x = ($game.settings.default_width - @size) / 2
@y = 0
@current_image = 0
@next_image = 0
@next_x = @x
end
def current_element
return @names.to_a[@current_image]
end
end