diff options
| author | Amir Rajan <[email protected]> | 2021-12-10 00:09:48 -0600 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2021-12-10 00:09:48 -0600 |
| commit | eaa29e72939f5edf61735ccbb73c36ee89369f65 (patch) | |
| tree | c310fac2e39bd799bf7fc1f73d35c12bcc5187b7 /samples/07_advanced_rendering | |
| parent | 33dfdde9ae03e3218b4796f3595d3b727f626587 (diff) | |
| download | dragonruby-game-toolkit-contrib-eaa29e72939f5edf61735ccbb73c36ee89369f65.tar.gz dragonruby-game-toolkit-contrib-eaa29e72939f5edf61735ccbb73c36ee89369f65.zip | |
Synced with DragonRuby Game Toolkit v3.2.
Diffstat (limited to 'samples/07_advanced_rendering')
4 files changed, 231 insertions, 17 deletions
diff --git a/samples/07_advanced_rendering/00_labels_with_wrapped_text/app/main.rb b/samples/07_advanced_rendering/00_labels_with_wrapped_text/app/main.rb new file mode 100644 index 0000000..71eefa9 --- /dev/null +++ b/samples/07_advanced_rendering/00_labels_with_wrapped_text/app/main.rb @@ -0,0 +1,88 @@ +def tick args + # defaults + args.state.scroll_location ||= 0 + args.state.textbox.messages ||= [] + args.state.textbox.scroll ||= 0 + + # render + args.outputs.background_color = [0, 0, 0, 255] + render_messages args + render_instructions args + + # inputs + if args.inputs.keyboard.key_down.one + queue_message args, "Hello there neighbour! my name is mark, how is your day today?" + end + + if args.inputs.keyboard.key_down.two + queue_message args, "I'm doing great sir, actually I'm having a picnic today" + end + + if args.inputs.keyboard.key_down.three + queue_message args, "Well that sounds wonderful!" + end + + if args.inputs.keyboard.key_down.home + args.state.scroll_location = 1 + end + + if args.inputs.keyboard.key_down.delete + clear_message_queue args + end +end + +def queue_message args, msg + args.state.textbox.messages.concat msg.wrapped_lines 50 +end + +def clear_message_queue args + args.state.textbox.messages = nil + args.state.textbox.scroll = 0 +end + +def render_messages args + args.outputs[:textbox].w = 400 + args.outputs[:textbox].h = 720 + + args.outputs.primitives << args.state.textbox.messages.each_with_index.map do |s, idx| + { + x: 0, + y: 20 * (args.state.textbox.messages.size - idx) + args.state.textbox.scroll * 20, + text: s, + size_enum: -3, + alignment_enum: 0, + r: 255, g:255, b: 255, a: 255 + } + end + + args.outputs[:textbox].labels << args.state.textbox.messages.each_with_index.map do |s, idx| + { + x: 0, + y: 20 * (args.state.textbox.messages.size - idx) + args.state.textbox.scroll * 20, + text: s, + size_enum: -3, + alignment_enum: 0, + r: 255, g:255, b: 255, a: 255 + } + end + + args.outputs[:textbox].borders << [0, 0, args.outputs[:textbox].w, 720] + + args.state.textbox.scroll += args.inputs.mouse.wheel.y unless args.inputs.mouse.wheel.nil? + + if args.state.scroll_location > 0 + args.state.textbox.scroll = 0 + args.state.scroll_location = 0 + end + + args.outputs.sprites << [900, 0, args.outputs[:textbox].w, 720, :textbox] +end + +def render_instructions args + args.outputs.labels << [30, + 30.from_top, + "press 1, 2, 3 to display messages, MOUSE WHEEL to scroll, HOME to go to top, BACKSPACE to delete.", + 0, 255, 255] + + args.outputs.primitives << [0, 55.from_top, 1280, 30, :pixel, 0, 255, 0, 0, 0].sprite +end diff --git a/samples/07_advanced_rendering/00_labels_with_wrapped_text/replay.txt b/samples/07_advanced_rendering/00_labels_with_wrapped_text/replay.txt new file mode 100644 index 0000000..8153881 --- /dev/null +++ b/samples/07_advanced_rendering/00_labels_with_wrapped_text/replay.txt @@ -0,0 +1,93 @@ +replay_version 2.0 +stopped_at 461 +seed 100 +recorded_at 2021-11-20 11:11:30 -0600 +[:mouse_button_up, 1, 0, 1, 1, 5] +[:mouse_move, 789, 84, 2, 2, 33] +[:mouse_move, 790, 84, 2, 3, 35] +[:mouse_move, 791, 84, 2, 4, 37] +[:key_down_raw, 49, 0, 2, 5, 72] +[:key_up_raw, 49, 0, 2, 6, 78] +[:key_down_raw, 50, 0, 2, 7, 90] +[:key_up_raw, 50, 0, 2, 8, 97] +[:mouse_move, 789, 85, 2, 9, 108] +[:mouse_move, 784, 86, 2, 10, 109] +[:mouse_move, 780, 88, 2, 11, 110] +[:mouse_move, 780, 89, 2, 12, 112] +[:mouse_move, 780, 90, 2, 13, 114] +[:mouse_move, 780, 91, 2, 14, 115] +[:key_down_raw, 49, 0, 2, 15, 123] +[:key_up_raw, 49, 0, 2, 16, 131] +[:key_down_raw, 49, 0, 2, 17, 150] +[:key_up_raw, 49, 0, 2, 18, 157] +[:key_down_raw, 50, 0, 2, 19, 161] +[:key_up_raw, 50, 0, 2, 20, 169] +[:key_down_raw, 51, 0, 2, 21, 179] +[:key_up_raw, 51, 0, 2, 22, 186] +[:mouse_move, 780, 92, 2, 23, 186] +[:mouse_move, 781, 92, 2, 24, 187] +[:mouse_move, 777, 92, 2, 25, 225] +[:mouse_move, 769, 94, 2, 26, 226] +[:mouse_move, 761, 96, 2, 27, 227] +[:mouse_move, 759, 97, 2, 28, 228] +[:mouse_move, 760, 99, 2, 29, 231] +[:mouse_move, 762, 101, 2, 30, 232] +[:mouse_move, 768, 112, 2, 31, 233] +[:mouse_move, 769, 112, 2, 32, 234] +[:mouse_wheel, 0, 1, 2, 33, 234] +[:mouse_move, 769, 113, 2, 34, 234] +[:mouse_wheel, 0, 2, 2, 35, 235] +[:mouse_move, 770, 114, 2, 36, 235] +[:mouse_wheel, 0, 4, 2, 37, 236] +[:mouse_move, 771, 115, 2, 38, 237] +[:mouse_wheel, 0, 6, 2, 39, 237] +[:mouse_move, 771, 116, 2, 40, 239] +[:mouse_wheel, 0, 7, 2, 41, 239] +[:mouse_move, 772, 119, 2, 42, 240] +[:mouse_move, 773, 120, 2, 43, 241] +[:mouse_move, 773, 121, 2, 44, 242] +[:mouse_move, 774, 121, 2, 45, 243] +[:mouse_move, 774, 122, 2, 46, 244] +[:mouse_move, 775, 124, 2, 47, 246] +[:mouse_move, 780, 132, 2, 48, 247] +[:mouse_move, 784, 142, 2, 49, 248] +[:mouse_move, 788, 149, 2, 50, 249] +[:mouse_move, 789, 150, 2, 51, 250] +[:mouse_move, 789, 151, 2, 52, 251] +[:mouse_move, 790, 151, 2, 53, 252] +[:mouse_move, 790, 152, 2, 54, 262] +[:mouse_wheel, 0, 1, 2, 55, 273] +[:mouse_wheel, 0, 1, 2, 56, 274] +[:mouse_wheel, 0, 4, 2, 57, 275] +[:mouse_wheel, 0, 6, 2, 58, 277] +[:mouse_move, 790, 151, 2, 59, 288] +[:mouse_wheel, 0, -1, 2, 60, 297] +[:mouse_wheel, 0, -1, 2, 61, 299] +[:mouse_wheel, 0, -4, 2, 62, 300] +[:mouse_wheel, 0, -6, 2, 63, 301] +[:mouse_wheel, 0, -1, 2, 64, 317] +[:mouse_wheel, 0, -1, 2, 65, 318] +[:mouse_wheel, 0, -4, 2, 66, 319] +[:mouse_wheel, 0, -6, 2, 67, 320] +[:mouse_wheel, 0, -7, 2, 68, 321] +[:mouse_move, 791, 151, 2, 69, 322] +[:key_down_raw, 49, 0, 2, 70, 339] +[:key_up_raw, 49, 0, 2, 71, 343] +[:mouse_move, 791, 150, 2, 72, 343] +[:key_down_raw, 49, 0, 2, 73, 348] +[:key_up_raw, 49, 0, 2, 74, 351] +[:key_down_raw, 49, 0, 2, 75, 356] +[:key_up_raw, 49, 0, 2, 76, 361] +[:key_down_raw, 96, 0, 2, 77, 388] +[:mouse_move, 792, 150, 2, 78, 389] +[:key_up_raw, 96, 0, 2, 79, 392] +[:mouse_move, 792, 149, 2, 80, 394] +[:mouse_move, 787, 157, 2, 81, 418] +[:mouse_move, 776, 165, 2, 82, 419] +[:mouse_move, 768, 168, 2, 83, 420] +[:mouse_move, 766, 168, 2, 84, 421] +[:mouse_move, 767, 168, 2, 85, 424] +[:mouse_move, 772, 168, 2, 86, 425] +[:mouse_move, 777, 168, 2, 87, 426] +[:mouse_move, 778, 168, 2, 88, 427] +[:key_down_raw, 13, 0, 2, 89, 461] diff --git a/samples/07_advanced_rendering/00_rotating_label/app/main.rb b/samples/07_advanced_rendering/00_rotating_label/app/main.rb new file mode 100644 index 0000000..8b21fb8 --- /dev/null +++ b/samples/07_advanced_rendering/00_rotating_label/app/main.rb @@ -0,0 +1,32 @@ +def tick args + # set the render target width and height to match the label + args.outputs[:scene].w = 220 + args.outputs[:scene].h = 30 + + + # make the background transparent + args.outputs[:scene].background_color = [255, 255, 255, 0] + + # set the blendmode of the label to 0 (no blending) + # center it inside of the scene + # set the vertical_alignment_enum to 1 (center) + args.outputs[:scene].labels << { x: 0, + y: 15, + text: "label in render target", + blendmode_enum: 0, + vertical_alignment_enum: 1 } + + # add a border to the render target + args.outputs[:scene].borders << { x: 0, + y: 0, + w: args.outputs[:scene].w, + h: args.outputs[:scene].h } + + # add the rendertarget to the main output as a sprite + args.outputs.sprites << { x: 640 - args.outputs[:scene].w.half, + y: 360 - args.outputs[:scene].h.half, + w: args.outputs[:scene].w, + h: args.outputs[:scene].h, + angle: args.state.tick_count, + path: :scene } +end diff --git a/samples/07_advanced_rendering/08_splitscreen_camera/app/main.rb b/samples/07_advanced_rendering/08_splitscreen_camera/app/main.rb index 9b08e1e..9d22918 100644 --- a/samples/07_advanced_rendering/08_splitscreen_camera/app/main.rb +++ b/samples/07_advanced_rendering/08_splitscreen_camera/app/main.rb @@ -6,7 +6,7 @@ class CameraMovement def serialize {state: state, inputs: inputs, outputs: outputs, grid: grid } end - + def inspect serialize.to_s end @@ -76,12 +76,12 @@ class CameraMovement default_player(0, 0, 64, 64, "sprites/player/player_#{state.player_cyan.orientation}_standing.png") end - + def new_player_magenta default_player(64, 0, 64, 64, "sprites/player/player_#{state.player_magenta.orientation}_standing.png") end - + def new_camera_magenta default_camera(0,0,720,720) end @@ -93,7 +93,8 @@ class CameraMovement def new_camera_center default_camera(0,0,1280,720) end - + + def new_room default_floor_tile(0,0,1024,1024,'sprites/rooms/camera_room.png') end @@ -118,7 +119,7 @@ class CameraMovement state.player_cyan.x += state.player_cyan.dx state.player_cyan.y += state.player_cyan.dy end - + def calc_player_magenta state.player_magenta.x += state.player_magenta.dx state.player_magenta.y += state.player_magenta.dy @@ -133,7 +134,7 @@ class CameraMovement state.camera_center.x += (targetX - state.camera_center.x) * 0.1 * timeScale state.camera_center.y += (targetY - state.camera_center.y) * 0.1 * timeScale end - + def calc_camera_magenta timeScale = 1 @@ -170,7 +171,7 @@ class CameraMovement def calc_trauma_decay state.trauma = state.trauma * 0.9 end - + def calc_random_float_range(min, max) rand * (max-min) + min end @@ -198,7 +199,7 @@ class CameraMovement g: 255, b: 255} end - + def render_player_magenta outputs[:scene].sprites << {x: state.player_magenta.x, y: state.player_magenta.y, @@ -244,16 +245,16 @@ class CameraMovement render_camera_magenta_scene render_camera_cyan_scene - angle = Math.atan((state.player_magenta.y - state.player_cyan.y)/(state.player_magenta.x- state.player_cyan.x)) * 180/Math::PI + angle = Math.atan((state.player_magenta.y - state.player_cyan.y)/(state.player_magenta.x- state.player_cyan.x)) * 180/Math::PI output_split_camera angle - + end def render_camera_magenta_scene zoomFactor = 1 offsetX = 32 offsetY = 32 - + outputs[:scene_magenta].sprites << {x: (-state.camera_magenta.x*2), y: (-state.camera_magenta.y), w: outputs[:scene].width*2, @@ -279,7 +280,7 @@ class CameraMovement outputs.labels << [128,64,"#{quadrant}",8,2,255,0,255,255] if quadrant == 1 set_camera_attributes(w: 640, h: 720, m_x: 640, m_y: 0, c_x: 0, c_y: 0) - + elsif quadrant == 2 set_camera_attributes(w: 1280, h: 360, m_x: 0, m_y: 360, c_x: 0, c_y: 0) @@ -297,7 +298,7 @@ class CameraMovement state.camera_cyan.h = h + 64 outputs[:scene_cyan].width = (w) * 2 outputs[:scene_cyan].height = h - + state.camera_magenta.w = w + 64 state.camera_magenta.h = h + 64 outputs[:scene_magenta].width = (w) * 2 @@ -309,7 +310,7 @@ class CameraMovement path: :scene_magenta} outputs.sprites << {x: c_x, y: c_y, - w: w, + w: w, h: h, path: :scene_cyan} end @@ -317,7 +318,7 @@ class CameraMovement def add_trauma amount state.trauma = [state.trauma + amount, 1.0].min end - + def remove_trauma amount state.trauma = [state.trauma - amount, 0.0].max end @@ -357,7 +358,7 @@ class CameraMovement outputs.labels << [128,512,"#{state.player_cyan.x.round()}",8,2,0,255,255,255] outputs.labels << [128,480,"#{state.player_cyan.y.round()}",8,2,0,255,255,255] end - + def input_move_magenta if inputs.keyboard.key_held.w state.player_magenta.dy = 5 @@ -391,5 +392,5 @@ def tick args $camera_movement.outputs = args.outputs $camera_movement.state = args.state $camera_movement.grid = args.grid - $camera_movement.tick + $camera_movement.tick end |
