-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.rb
More file actions
120 lines (100 loc) · 2.84 KB
/
Copy pathoptions.rb
File metadata and controls
120 lines (100 loc) · 2.84 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
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
class Options < State
def initialize game
@game = game
@screen = game.screen
@queue = game.queue
@pong = Text.new 0, 35, "Options", 100
@line = GameObject.new(0, 150, Rubygame::Surface.new([@screen.width,10]).fill([255,255,255]))
@winning_score = List.new 0, 200, 48, "Winning Score: ", :winning_score, [-1, 3, 5, 7, 9]
@ball_speed = List.new 0, 250, 48, "Ball Speed: ", :ball_speed, [3,4,5,6,7,8,9,10]
@music = OnOff.new 0, 300, 48, "Music: ", :music
@fx = OnOff.new 0, 350, 48, "FX: ", :fx
@reset = Reset.new 0, 400, 48
@options = [@winning_score, @ball_speed, @music, @fx, @reset]
@reset.options = @options
@select = Selector.new 0, *@options
@objs = [@pong, @line, *@options]
@objs.each { |obj| obj.center_x @screen.width }
@objs += [@select]
end
def update
@select.update
@queue.each do |ev|
@select.handle_event ev
case ev
when Rubygame::KeyDownEvent
if ev.key == Rubygame::K_ESCAPE
@game.switch_state Title.new(@game)
end
if ev.key == Rubygame::K_RETURN
@options[@select.choice].cycle
end
end
end
end
def draw
@screen.fill [0, 0, 0]
@objs.each { |obj| obj.draw @screen }
@screen.flip
end
end
class OnOff < Text
def initialize x, y, size, prefix, value
@value = value
@prefix = prefix
super x, y, gen_text, size
end
def cycle
Conf[@value] = !Conf[@value]
self.text= gen_text
Conf.save
end
def gen_text
if Conf[@value] == true
return @prefix + "On"
else
return @prefix + "Off"
end
end
def reset
self.text= gen_text
end
end
class List < Text
def initialize x, y, size, prefix, value, choices
@prefix = prefix
@value = value
@choices = choices
@choice = @choices.index(Conf[@value])
super x, y, gen_text, size
end
def cycle
@choice += 1
@choice = 0 if @choices[@choice] == nil
Conf[@value] = @choices[@choice]
self.text= gen_text
Conf.save
end
def gen_text
return @prefix + Conf[@value].to_s
end
def reset
@choice = @choices.index(Conf[@value])
self.text= gen_text
end
end
class Reset < Text
attr_writer :options
def initialize x, y, size
super x, y, "Reset", size
end
def cycle
Conf.reset
Conf.save
@options.each do |opt|
opt.reset
end
end
def reset
end
end