Skip to content

Commit 6f8e98f

Browse files
committedMar 22, 2023
Add difficulty setting menu item
1 parent fbd9550 commit 6f8e98f

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ run
66
publish
77

88
logs/
9+
10+
.DS_Store

‎app/constants.rb

+2
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@
3232
FP_DUAL = :dual
3333
FP_TRI = :tri
3434
FP_QUAD = :quad
35+
36+
DIFFICULTY = [:easy, :normal, :hard]

‎app/game_setting.rb

+3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ def load_settings(args)
3333
v = true
3434
elsif v == "false"
3535
v = false
36+
else
37+
v = v.to_sym
3638
end
3739
args.state.setting[k.to_sym] = v
3840
end
3941
else
4042
args.state.setting.sfx = true
4143
args.state.setting.fullscreen = false
44+
args.state.setting.difficulty = :normal
4245
end
4346

4447
if args.state.setting.fullscreen

‎app/menu.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def text_for_setting_val(val)
9999
when false
100100
text(:off)
101101
else
102-
val
102+
text(val) || val
103103
end
104104
end
105105
end

‎app/scenes/settings.rb

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ def tick_settings(args)
55
a_s = args.state
66

77
options = [
8+
{
9+
key: :difficulty,
10+
kind: :toggle,
11+
setting_val: a_s.setting.difficulty,
12+
on_select: -> (args) do
13+
current_index = DIFFICULTY.index(a_s.setting.difficulty)
14+
current_index = (current_index + 1) % DIFFICULTY.length
15+
GameSetting.save_after(args) do |args|
16+
a_s.setting.difficulty = DIFFICULTY[current_index]
17+
end
18+
end
19+
},
820
{
921
key: :sfx,
1022
kind: :toggle,

‎app/text.rb

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
sfx: "Sound Effects",
4141
start: "Start",
4242
win: "You Win!",
43+
difficulty: "Difficulty",
44+
easy: "Grandma's House",
45+
normal: "The Real World",
46+
hard: "The Hunger Games",
4347
}
4448

4549
# Gets the text for the passed in `key`. Raises if it does not exist. We don't

0 commit comments

Comments
 (0)
Please sign in to comment.