summaryrefslogtreecommitdiffhomepage
path: root/samples/02_input_basics/01_keyboard
diff options
context:
space:
mode:
author_Tradam <[email protected]>2021-12-16 19:22:26 -0500
committerGitHub <[email protected]>2021-12-16 19:22:26 -0500
commit5954b9beb4d4a3b4f248d72d1851195f030558a8 (patch)
treefecd8aa840a25afdb502915b0fdb4d03b7ed339a /samples/02_input_basics/01_keyboard
parent2f845281f133849256b57bb08fd3e9ae57600784 (diff)
parenteaa29e72939f5edf61735ccbb73c36ee89369f65 (diff)
downloaddragonruby-game-toolkit-contrib-master.tar.gz
dragonruby-game-toolkit-contrib-master.zip
Merge branch 'DragonRuby:master' into masterHEADmaster
Diffstat (limited to 'samples/02_input_basics/01_keyboard')
-rw-r--r--samples/02_input_basics/01_keyboard/app/main.rb51
1 files changed, 21 insertions, 30 deletions
diff --git a/samples/02_input_basics/01_keyboard/app/main.rb b/samples/02_input_basics/01_keyboard/app/main.rb
index 3c5e1b4..f97c134 100644
--- a/samples/02_input_basics/01_keyboard/app/main.rb
+++ b/samples/02_input_basics/01_keyboard/app/main.rb
@@ -4,7 +4,8 @@ APIs listing that haven't been encountered in a previous sample apps:
- args.inputs.keyboard.key_up.KEY: The value of the properties will be set
to the frame that the key_up event occurred (the frame correlates
- to args.state.tick_count). Otherwise the value will be nil.
+ to args.state.tick_count). Otherwise the value will be nil. For a
+ full listing of keys, take a look at mygame/documentation/06-keyboard.md.
- args.state.PROPERTY: The state property on args is a dynamic
structure. You can define ANY property here with ANY type of
arbitrary nesting. Properties defined on args.state will be retained
@@ -24,9 +25,9 @@ APIs listing that haven't been encountered in a previous sample apps:
def tick args
tick_instructions args, "Sample app shows how keyboard events are registered and accessed.", 360
# Notice how small_font accounts for all the remaining parameters
- args.outputs.labels << [460, row_to_px(args, 0), "Current game time: #{args.state.tick_count}", small_font]
- args.outputs.labels << [460, row_to_px(args, 2), "Keyboard input: args.inputs.keyboard.key_up.h", small_font]
- args.outputs.labels << [460, row_to_px(args, 3), "Press \"h\" on the keyboard.", small_font]
+ args.outputs.labels << { x: 460, y: row_to_px(args, 0), text: "Current game time: #{args.state.tick_count}", size_enum: -1 }
+ args.outputs.labels << { x: 460, y: row_to_px(args, 2), text: "Keyboard input: args.inputs.keyboard.key_up.h", size_enum: -1 }
+ args.outputs.labels << { x: 460, y: row_to_px(args, 3), text: "Press \"h\" on the keyboard.", size_enum: -1 }
# Input on a specifc key can be found through args.inputs.keyboard.key_up followed by the key
if args.inputs.keyboard.key_up.h
@@ -37,27 +38,19 @@ def tick args
args.state.h_pressed_at ||= false
if args.state.h_pressed_at
- args.outputs.labels << [460, row_to_px(args, 4), "\"h\" was pressed at time: #{args.state.h_pressed_at}", small_font]
+ args.outputs.labels << { x: 460, y: row_to_px(args, 4), text: "\"h\" was pressed at time: #{args.state.h_pressed_at}", size_enum: -1 }
else
- args.outputs.labels << [460, row_to_px(args, 4), "\"h\" has never been pressed.", small_font]
+ args.outputs.labels << { x: 460, y: row_to_px(args, 4), text: "\"h\" has never been pressed.", size_enum: -1 }
end
tick_help_text args
end
-def small_font
- # This method provides some values for the construction of labels
- # Specifically, Size, Alignment, & RGBA
- # This makes it so that custom parameters don't have to be repeatedly typed.
- # Additionally "small_font" provides programmers with more information than some numbers
- [-2, 0, 0, 0, 0, 255]
-end
-
-def row_to_px args, row_number
+def row_to_px args, row_number, y_offset = 20
# This takes a row_number and converts it to pixels DragonRuby understands.
# Row 0 starts 5 units below the top of the grid
# Each row afterward is 20 units lower
- args.grid.top.shift_down(5).shift_down(20 * row_number)
+ args.grid.top - 5 - (y_offset * row_number)
end
# Don't worry about understanding the code within this method just yet.
@@ -87,17 +80,17 @@ def tick_help_text args
end
end
- args.outputs.labels << [10, row_to_px(args, 6), "Advanced Help:", small_font]
+ args.outputs.labels << { x: 10, y: row_to_px(args, 6), text: "This is the api for the keys you've pressed:", size_enum: -1, r: 180 }
if !args.state.help_available
args.outputs.labels << [10, row_to_px(args, 7), "Press a key and I'll show code to access the key and what value will be returned if you used the code.", small_font]
return
end
- args.outputs.labels << [10 , row_to_px(args, 7), "args.inputs.keyboard", small_font]
- args.outputs.labels << [330, row_to_px(args, 7), "args.inputs.keyboard.key_down", small_font]
- args.outputs.labels << [650, row_to_px(args, 7), "args.inputs.keyboard.key_held", small_font]
- args.outputs.labels << [990, row_to_px(args, 7), "args.inputs.keyboard.key_up", small_font]
+ args.outputs.labels << { x: 10 , y: row_to_px(args, 7), text: "args.inputs.keyboard", size_enum: -2 }
+ args.outputs.labels << { x: 330, y: row_to_px(args, 7), text: "args.inputs.keyboard.key_down", size_enum: -2 }
+ args.outputs.labels << { x: 650, y: row_to_px(args, 7), text: "args.inputs.keyboard.key_held", size_enum: -2 }
+ args.outputs.labels << { x: 990, y: row_to_px(args, 7), text: "args.inputs.keyboard.key_up", size_enum: -2 }
fill_history args, :key_value_history, :down_or_held, nil
fill_history args, :key_down_value_history, :down, :key_down
@@ -143,12 +136,8 @@ def render_help_labels args, history_key, state_key, keyboard_method, x
end
idx += 2
[
- [x, row_to_px(args, idx - 2),
- " .#{k} is #{current_value || "nil"}",
- small_font],
- [x, row_to_px(args, idx - 1),
- " was #{v}",
- small_font]
+ { x: x, y: row_to_px(args, idx + 0, 16), text: " .#{k} is #{current_value || "nil"}", size_enum: -2 },
+ { x: x, y: row_to_px(args, idx + 1, 16), text: " was #{v}", size_enum: -2 }
]
end
end
@@ -163,7 +152,9 @@ def tick_instructions args, text, y = 715
args.state.key_event_occurred = true
end
- args.outputs.debug << [0, y - 50, 1280, 60].solid
- args.outputs.debug << [640, y, text, 1, 1, 255, 255, 255].label
- args.outputs.debug << [640, y - 25, "(click to dismiss instructions)" , -2, 1, 255, 255, 255].label
+ args.outputs.debug << { x: 0, y: y - 50, w: 1280, h: 60 }.solid!
+ args.outputs.debug << { x: 640, y: y, text: text,
+ size_enum: 1, alignment_enum: 1, r: 255, g: 255, b: 255 }.label!
+ args.outputs.debug << { x: 640, y: y - 25, text: "(click to dismiss instructions)",
+ size_enum: -2, alignment_enum: 1, r: 255, g: 255, b: 255 }.label!
end