diff options
| author | _Tradam <[email protected]> | 2021-12-16 19:22:26 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-12-16 19:22:26 -0500 |
| commit | 5954b9beb4d4a3b4f248d72d1851195f030558a8 (patch) | |
| tree | fecd8aa840a25afdb502915b0fdb4d03b7ed339a /samples/02_input_basics | |
| parent | 2f845281f133849256b57bb08fd3e9ae57600784 (diff) | |
| parent | eaa29e72939f5edf61735ccbb73c36ee89369f65 (diff) | |
| download | dragonruby-game-toolkit-contrib-master.tar.gz dragonruby-game-toolkit-contrib-master.zip | |
Diffstat (limited to 'samples/02_input_basics')
| -rw-r--r-- | samples/02_input_basics/01_keyboard/app/main.rb | 51 | ||||
| -rw-r--r-- | samples/02_input_basics/01_moving_a_sprite/app/main.rb | 30 | ||||
| -rw-r--r-- | samples/02_input_basics/01_moving_a_sprite/license-for-sample.txt | 9 | ||||
| -rw-r--r-- | samples/02_input_basics/01_moving_a_sprite/replay.txt | 73 | ||||
| -rw-r--r-- | samples/02_input_basics/01_moving_a_sprite/sprites/square/green.png | bin | 0 -> 283 bytes | |||
| -rw-r--r-- | samples/02_input_basics/02_mouse/app/main.rb | 14 | ||||
| -rw-r--r-- | samples/02_input_basics/03_mouse_point_to_rect/app/main.rb | 14 | ||||
| -rw-r--r-- | samples/02_input_basics/04_mouse_rect_to_rect/app/main.rb | 18 | ||||
| -rw-r--r-- | samples/02_input_basics/05_controller/app/main.rb | 68 | ||||
| -rw-r--r-- | samples/02_input_basics/06_touch/app/main.rb | 11 |
10 files changed, 191 insertions, 97 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 diff --git a/samples/02_input_basics/01_moving_a_sprite/app/main.rb b/samples/02_input_basics/01_moving_a_sprite/app/main.rb new file mode 100644 index 0000000..da699a0 --- /dev/null +++ b/samples/02_input_basics/01_moving_a_sprite/app/main.rb @@ -0,0 +1,30 @@ +def tick args + # create a player and set default values + # for the player's x, y, w (width), and h (height) + args.state.player.x ||= 100 + args.state.player.y ||= 100 + args.state.player.w ||= 50 + args.state.player.h ||= 50 + + # render the player to the screen + args.outputs.sprites << { x: args.state.player.x, + y: args.state.player.y, + w: args.state.player.w, + h: args.state.player.h, + path: 'sprites/square/green.png' } + + # move the player around using the keyboard + if args.inputs.up + args.state.player.y += 10 + elsif args.inputs.down + args.state.player.y -= 10 + end + + if args.inputs.left + args.state.player.x -= 10 + elsif args.inputs.right + args.state.player.x += 10 + end +end + +$gtk.reset diff --git a/samples/02_input_basics/01_moving_a_sprite/license-for-sample.txt b/samples/02_input_basics/01_moving_a_sprite/license-for-sample.txt new file mode 100644 index 0000000..100dcec --- /dev/null +++ b/samples/02_input_basics/01_moving_a_sprite/license-for-sample.txt @@ -0,0 +1,9 @@ +Copyright 2019 DragonRuby LLC + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/samples/02_input_basics/01_moving_a_sprite/replay.txt b/samples/02_input_basics/01_moving_a_sprite/replay.txt new file mode 100644 index 0000000..1ec5f3a --- /dev/null +++ b/samples/02_input_basics/01_moving_a_sprite/replay.txt @@ -0,0 +1,73 @@ +replay_version 2.0 +stopped_at 442 +seed 100 +recorded_at 2021-11-20 11:06:58 -0600 +[:mouse_button_up, 1, 0, 1, 1, 5] +[:key_down_raw, 1073741903, 0, 2, 2, 147] +[:key_down_raw, 1073741903, 0, 2, 3, 162] +[:key_down_raw, 1073741903, 0, 2, 4, 164] +[:key_down_raw, 1073741903, 0, 2, 5, 166] +[:key_down_raw, 1073741903, 0, 2, 6, 168] +[:key_down_raw, 1073741903, 0, 2, 7, 170] +[:key_down_raw, 1073741903, 0, 2, 8, 172] +[:key_down_raw, 1073741906, 0, 2, 9, 172] +[:key_down_raw, 1073741905, 0, 2, 10, 182] +[:key_up_raw, 1073741903, 0, 2, 11, 185] +[:key_up_raw, 1073741906, 0, 2, 12, 188] +[:key_down_raw, 1073741904, 0, 2, 13, 195] +[:key_up_raw, 1073741905, 0, 2, 14, 202] +[:key_up_raw, 1073741904, 0, 2, 15, 208] +[:key_down_raw, 1073741903, 0, 2, 16, 210] +[:key_down_raw, 1073741903, 0, 2, 17, 225] +[:key_down_raw, 1073741903, 0, 2, 18, 227] +[:key_down_raw, 1073741903, 0, 2, 19, 229] +[:key_down_raw, 1073741903, 0, 2, 20, 231] +[:key_down_raw, 1073741903, 0, 2, 21, 233] +[:key_down_raw, 1073741903, 0, 2, 22, 235] +[:key_down_raw, 1073741903, 0, 2, 23, 237] +[:key_down_raw, 1073741903, 0, 2, 24, 239] +[:key_down_raw, 1073741903, 0, 2, 25, 241] +[:key_down_raw, 1073741903, 0, 2, 26, 243] +[:key_down_raw, 1073741903, 0, 2, 27, 245] +[:key_down_raw, 1073741903, 0, 2, 28, 247] +[:key_down_raw, 1073741903, 0, 2, 29, 249] +[:key_down_raw, 1073741903, 0, 2, 30, 251] +[:key_down_raw, 1073741903, 0, 2, 31, 253] +[:key_down_raw, 1073741903, 0, 2, 32, 255] +[:key_down_raw, 1073741903, 0, 2, 33, 257] +[:key_down_raw, 1073741903, 0, 2, 34, 259] +[:key_down_raw, 1073741903, 0, 2, 35, 261] +[:key_down_raw, 1073741903, 0, 2, 36, 263] +[:key_down_raw, 1073741903, 0, 2, 37, 265] +[:key_down_raw, 1073741903, 0, 2, 38, 267] +[:key_down_raw, 1073741903, 0, 2, 39, 269] +[:key_down_raw, 1073741903, 0, 2, 40, 271] +[:key_down_raw, 1073741906, 0, 2, 41, 271] +[:key_up_raw, 1073741903, 0, 2, 42, 282] +[:key_down_raw, 1073741906, 0, 2, 43, 286] +[:key_down_raw, 1073741906, 0, 2, 44, 288] +[:key_down_raw, 1073741906, 0, 2, 45, 290] +[:key_down_raw, 1073741906, 0, 2, 46, 292] +[:key_down_raw, 1073741906, 0, 2, 47, 294] +[:key_down_raw, 1073741906, 0, 2, 48, 296] +[:key_down_raw, 1073741906, 0, 2, 49, 298] +[:key_down_raw, 1073741906, 0, 2, 50, 301] +[:key_down_raw, 1073741905, 0, 2, 51, 302] +[:key_up_raw, 1073741906, 0, 2, 52, 313] +[:key_down_raw, 1073741904, 0, 2, 53, 315] +[:key_up_raw, 1073741905, 0, 2, 54, 322] +[:key_down_raw, 1073741904, 0, 2, 55, 330] +[:key_down_raw, 1073741904, 0, 2, 56, 332] +[:key_down_raw, 1073741904, 0, 2, 57, 334] +[:key_down_raw, 1073741904, 0, 2, 58, 336] +[:key_down_raw, 1073741904, 0, 2, 59, 338] +[:key_down_raw, 1073741904, 0, 2, 60, 340] +[:key_down_raw, 1073741904, 0, 2, 61, 342] +[:key_down_raw, 1073741904, 0, 2, 62, 344] +[:key_down_raw, 1073741904, 0, 2, 63, 346] +[:key_down_raw, 1073741904, 0, 2, 64, 348] +[:key_down_raw, 1073741904, 0, 2, 65, 350] +[:key_up_raw, 1073741904, 0, 2, 66, 351] +[:key_down_raw, 96, 0, 2, 67, 359] +[:key_up_raw, 96, 0, 2, 68, 364] +[:key_down_raw, 13, 0, 2, 69, 442] diff --git a/samples/02_input_basics/01_moving_a_sprite/sprites/square/green.png b/samples/02_input_basics/01_moving_a_sprite/sprites/square/green.png Binary files differnew file mode 100644 index 0000000..5ef7f75 --- /dev/null +++ b/samples/02_input_basics/01_moving_a_sprite/sprites/square/green.png diff --git a/samples/02_input_basics/02_mouse/app/main.rb b/samples/02_input_basics/02_mouse/app/main.rb index 43217f5..23cb619 100644 --- a/samples/02_input_basics/02_mouse/app/main.rb +++ b/samples/02_input_basics/02_mouse/app/main.rb @@ -32,7 +32,7 @@ Reminder: # Use args.inputs.mouse.click.created_at # To see how many frames its been since the click occurred -# Use args.inputs.mouse.click.creat_at_elapsed +# Use args.inputs.mouse.click.created_at_elapsed # Saving the click in args.state can be quite useful @@ -61,11 +61,7 @@ def small_label args, x, row, message # This method effectively combines the row_to_px and small_font methods # It changes the given row value to a DragonRuby pixel value # and adds the customization parameters - [x, row_to_px(args, row), message, small_font] -end - -def small_font - [-2, 0, 0, 0, 0, 255] + { x: x, y: row_to_px(args, row), text: message, alignment_enum: -2 } end def row_to_px args, row_number @@ -81,7 +77,7 @@ 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 diff --git a/samples/02_input_basics/03_mouse_point_to_rect/app/main.rb b/samples/02_input_basics/03_mouse_point_to_rect/app/main.rb index 7dd627f..7d4394c 100644 --- a/samples/02_input_basics/03_mouse_point_to_rect/app/main.rb +++ b/samples/02_input_basics/03_mouse_point_to_rect/app/main.rb @@ -42,7 +42,7 @@ def tick args args.outputs.labels << small_label(args, x, 15, "Click inside the blue box maybe ---->") - box = [785, 370, 50, 50, 0, 0, 170] + box = { x: 785, y: 370, w: 50, h: 50, r: 0, g: 0, b: 170 } args.outputs.borders << box # Saves the most recent click into args.state @@ -64,11 +64,7 @@ def tick args end def small_label args, x, row, message - [x, row_to_px(args, row), message, small_font] -end - -def small_font - [-2, 0, 0, 0, 0, 255] + { x: x, y: row_to_px(args, row), text: message, size_enum: -2 } end def row_to_px args, row_number @@ -84,7 +80,7 @@ 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 diff --git a/samples/02_input_basics/04_mouse_rect_to_rect/app/main.rb b/samples/02_input_basics/04_mouse_rect_to_rect/app/main.rb index 1a00a41..8250598 100644 --- a/samples/02_input_basics/04_mouse_rect_to_rect/app/main.rb +++ b/samples/02_input_basics/04_mouse_rect_to_rect/app/main.rb @@ -42,9 +42,15 @@ def tick args # They are stored in game so that they do not get reset every tick if args.inputs.mouse.click if !args.state.box_collision_one - args.state.box_collision_one = [args.inputs.mouse.click.point.x - 25, args.inputs.mouse.click.point.y - 25, 125, 125, 180, 0, 0, 180] + args.state.box_collision_one = { x: args.inputs.mouse.click.point.x - 25, + y: args.inputs.mouse.click.point.y - 25, + w: 125, h: 125, + r: 180, g: 0, b: 0, a: 180 } elsif !args.state.box_collision_two - args.state.box_collision_two = [args.inputs.mouse.click.point.x - 25, args.inputs.mouse.click.point.y - 25, 125, 125, 0, 0, 180, 180] + args.state.box_collision_two = { x: args.inputs.mouse.click.point.x - 25, + y: args.inputs.mouse.click.point.y - 25, + w: 125, h: 125, + r: 0, g: 0, b: 180, a: 180 } else args.state.box_collision_one = nil args.state.box_collision_two = nil @@ -71,15 +77,11 @@ def tick args end def small_label args, x, row, message - [x, row_to_px(args, row), message, small_font] -end - -def small_font - [-2, 0, 0, 0, 0, 255] + { x: x, y: row_to_px(args, row), text: message, size_enum: -2 } end def row_to_px args, row_number - args.grid.top.shift_down(5).shift_down(20 * row_number) + args.grid.top - 5 - (20 * row_number) end def tick_instructions args, text, y = 715 diff --git a/samples/02_input_basics/05_controller/app/main.rb b/samples/02_input_basics/05_controller/app/main.rb index c986fa9..0ca4bbb 100644 --- a/samples/02_input_basics/05_controller/app/main.rb +++ b/samples/02_input_basics/05_controller/app/main.rb @@ -7,6 +7,8 @@ If there is more than one controller being used, they can be differentiated by using names like controller_one and controller_two. + For a full listing of buttons, take a look at mygame/documentation/08-controllers.md. + Reminder: - args.state.PROPERTY: The state property on args is a dynamic @@ -40,57 +42,51 @@ class ControllerDemo def process_inputs state.buttons = [] - state.buttons << [100, 500, inputs.controller_one.key_held.l1, "L1"] - state.buttons << [100, 600, inputs.controller_one.key_held.l2, "L2"] - - state.buttons << [1100, 500, inputs.controller_one.key_held.r1, "R1"] - state.buttons << [1100, 600, inputs.controller_one.key_held.r2, "R2"] - - state.buttons << [540, 450, inputs.controller_one.key_held.select, "Select"] - state.buttons << [660, 450, inputs.controller_one.key_held.start, "Start"] - - state.buttons << [200, 300, inputs.controller_one.key_held.left, "Left"] - state.buttons << [300, 400, inputs.controller_one.key_held.up, "Up"] - state.buttons << [400, 300, inputs.controller_one.key_held.right, "Right"] - state.buttons << [300, 200, inputs.controller_one.key_held.down, "Down"] - - state.buttons << [800, 300, inputs.controller_one.key_held.x, "X"] - state.buttons << [900, 400, inputs.controller_one.key_held.y, "Y"] - state.buttons << [1000, 300, inputs.controller_one.key_held.a, "A"] - state.buttons << [900, 200, inputs.controller_one.key_held.b, "B"] - - state.buttons << [450 + inputs.controller_one.left_analog_x_perc * 100, - 100 + inputs.controller_one.left_analog_y_perc * 100, - inputs.controller_one.key_held.l3, - "L3"] - - state.buttons << [750 + inputs.controller_one.right_analog_x_perc * 100, - 100 + inputs.controller_one.right_analog_y_perc * 100, - inputs.controller_one.key_held.r3, - "R3"] + state.buttons << { x: 100, y: 500, active: inputs.controller_one.key_held.l1, text: "L1"} + state.buttons << { x: 100, y: 600, active: inputs.controller_one.key_held.l2, text: "L2"} + state.buttons << { x: 1100, y: 500, active: inputs.controller_one.key_held.r1, text: "R1"} + state.buttons << { x: 1100, y: 600, active: inputs.controller_one.key_held.r2, text: "R2"} + state.buttons << { x: 540, y: 450, active: inputs.controller_one.key_held.select, text: "Select"} + state.buttons << { x: 660, y: 450, active: inputs.controller_one.key_held.start, text: "Start"} + state.buttons << { x: 200, y: 300, active: inputs.controller_one.key_held.left, text: "Left"} + state.buttons << { x: 300, y: 400, active: inputs.controller_one.key_held.up, text: "Up"} + state.buttons << { x: 400, y: 300, active: inputs.controller_one.key_held.right, text: "Right"} + state.buttons << { x: 300, y: 200, active: inputs.controller_one.key_held.down, text: "Down"} + state.buttons << { x: 800, y: 300, active: inputs.controller_one.key_held.x, text: "X"} + state.buttons << { x: 900, y: 400, active: inputs.controller_one.key_held.y, text: "Y"} + state.buttons << { x: 1000, y: 300, active: inputs.controller_one.key_held.a, text: "A"} + state.buttons << { x: 900, y: 200, active: inputs.controller_one.key_held.b, text: "B"} + state.buttons << { x: 450 + inputs.controller_one.left_analog_x_perc * 100, + y: 100 + inputs.controller_one.left_analog_y_perc * 100, + active: inputs.controller_one.key_held.l3, + text: "L3" } + state.buttons << { x: 750 + inputs.controller_one.right_analog_x_perc * 100, + y: 100 + inputs.controller_one.right_analog_y_perc * 100, + active: inputs.controller_one.key_held.r3, + text: "R3" } end # Gives each button a square shape. # If the button is being pressed or held (which means it is considered active), # the square is filled in. Otherwise, the button simply has a border. def render - state.buttons.each do |x, y, active, text| - rect = [x, y, 75, 75] + state.buttons.each do |b| + rect = { x: b.x, y: b.y, w: 75, h: 75 } - if active # if button is pressed + if b.active # if button is pressed outputs.solids << rect # rect is output as solid (filled in) else outputs.borders << rect # otherwise, output as border end # Outputs the text of each button using labels. - outputs.labels << [x, y + 95, text] # add 95 to place label above button + outputs.labels << { x: b.x, y: b.y + 95, text: b.text } # add 95 to place label above button end - outputs.labels << [10, 60, "Left Analog x: #{inputs.controller_one.left_analog_x_raw} (#{inputs.controller_one.left_analog_x_perc * 100}%)"] - outputs.labels << [10, 30, "Left Analog y: #{inputs.controller_one.left_analog_y_raw} (#{inputs.controller_one.left_analog_y_perc * 100}%)"] - outputs.labels << [900, 60, "Right Analog x: #{inputs.controller_one.right_analog_x_raw} (#{inputs.controller_one.right_analog_x_perc * 100}%)"] - outputs.labels << [900, 30, "Right Analog y: #{inputs.controller_one.right_analog_y_raw} (#{inputs.controller_one.right_analog_y_perc * 100}%)"] + outputs.labels << { x: 10, y: 60, text: "Left Analog x: #{inputs.controller_one.left_analog_x_raw} (#{inputs.controller_one.left_analog_x_perc * 100}%)" } + outputs.labels << { x: 10, y: 30, text: "Left Analog y: #{inputs.controller_one.left_analog_y_raw} (#{inputs.controller_one.left_analog_y_perc * 100}%)" } + outputs.labels << { x: 900, y: 60, text: "Right Analog x: #{inputs.controller_one.right_analog_x_raw} (#{inputs.controller_one.right_analog_x_perc * 100}%)" } + outputs.labels << { x: 900, y: 30, text: "Right Analog y: #{inputs.controller_one.right_analog_y_raw} (#{inputs.controller_one.right_analog_y_perc * 100}%)" } end end diff --git a/samples/02_input_basics/06_touch/app/main.rb b/samples/02_input_basics/06_touch/app/main.rb index 8b006c7..501fa74 100644 --- a/samples/02_input_basics/06_touch/app/main.rb +++ b/samples/02_input_basics/06_touch/app/main.rb @@ -11,10 +11,12 @@ def tick args # the next new touch will be finger_one again, but until then, new touches # don't fill in earlier slots. if !args.inputs.finger_one.nil? - args.outputs.primitives << [640, 650, "Finger #1 is touching at (#{args.inputs.finger_one.x}, #{args.inputs.finger_one.y}).", 5, 1, 255, 255, 255].label + args.outputs.primitives << { x: 640, y: 650, text: "Finger #1 is touching at (#{args.inputs.finger_one.x}, #{args.inputs.finger_one.y}).", + size_enum: 5, alignment_enum: 1, r: 255, g: 255, b: 255 }.label! end if !args.inputs.finger_two.nil? - args.outputs.primitives << [640, 600, "Finger #2 is touching at (#{args.inputs.finger_two.x}, #{args.inputs.finger_two.y}).", 5, 1, 255, 255, 255].label + args.outputs.primitives << { x: 640, y: 600, text: "Finger #2 is touching at (#{args.inputs.finger_two.x}, #{args.inputs.finger_two.y}).", + size_enum: 5, alignment_enum: 1, r: 255, g: 255, b: 255 }.label! end # Here's the more flexible interface: this will report as many simultaneous @@ -35,8 +37,7 @@ def tick args r = (color & 0xFF0000) >> 16 g = (color & 0x00FF00) >> 8 b = (color & 0x0000FF) - args.outputs.primitives << [v.x - (size / 2), v.y + (size / 2), size, size, r, g, b, 255].solid - args.outputs.primitives << [v.x, v.y + size, k.to_s, 0, 1, 0, 0, 0].label + args.outputs.primitives << { x: v.x - (size / 2), y: v.y + (size / 2), w: size, h: size, r: r, g: g, b: b, a: 255 }.solid! + args.outputs.primitives << { x: v.x, y: v.y + size, text: k.to_s, alignment_enum: 1 }.label! } end - |
