summaryrefslogtreecommitdiffhomepage
path: root/samples/01_rendering_basics/02_lines
diff options
context:
space:
mode:
authorAmir Rajan <[email protected]>2020-09-11 02:02:01 -0500
committerAmir Rajan <[email protected]>2020-09-11 02:02:57 -0500
commit33ec37b141e896b47ed642923fd33b0c658ae9fb (patch)
treea40d3e5d41beeb06508200078f6f26b0ee57d6a4 /samples/01_rendering_basics/02_lines
parent958cf43779d2bf528869e80511c4c4f2a433b2db (diff)
downloaddragonruby-game-toolkit-contrib-33ec37b141e896b47ed642923fd33b0c658ae9fb.tar.gz
dragonruby-game-toolkit-contrib-33ec37b141e896b47ed642923fd33b0c658ae9fb.zip
synced samples
Diffstat (limited to 'samples/01_rendering_basics/02_lines')
-rw-r--r--samples/01_rendering_basics/02_lines/app/main.rb54
-rw-r--r--samples/01_rendering_basics/02_lines/license-for-sample.txt9
2 files changed, 63 insertions, 0 deletions
diff --git a/samples/01_rendering_basics/02_lines/app/main.rb b/samples/01_rendering_basics/02_lines/app/main.rb
new file mode 100644
index 0000000..fd0781f
--- /dev/null
+++ b/samples/01_rendering_basics/02_lines/app/main.rb
@@ -0,0 +1,54 @@
+=begin
+
+APIs listing that haven't been encountered in a previous sample apps:
+
+- args.outputs.lines: An array. Values in this array generate lines on
+ the screen.
+- args.state.tick_count: This property contains an integer value that
+ represents the current frame. GTK renders at 60 FPS. A value of 0
+ for args.state.tick_count represents the initial load of the game.
+
+=end
+
+# The parameters required for lines are:
+# 1. The initial point (x, y)
+# 2. The end point (x2, y2)
+# 3. The rgba values for the color and transparency (r, g, b, a)
+
+# An example of creating a line would be:
+# args.outputs.lines << [100, 100, 300, 300, 255, 0, 255, 255]
+
+# This would create a line from (100, 100) to (300, 300)
+# The RGB code (255, 0, 255) would determine its color, a purple
+# It would have an Alpha value of 255, making it completely opaque
+
+def tick args
+ tick_instructions args, "Sample app shows how to create lines."
+
+ args.outputs.labels << [480, 620, "Lines (x, y, x2, y2, r, g, b, a)"]
+
+ # Some simple lines
+ args.outputs.lines << [380, 450, 675, 450]
+ args.outputs.lines << [380, 410, 875, 410]
+
+ # These examples utilize args.state.tick_count to change the length of the lines over time
+ # args.state.tick_count is the ticks that have occurred in the game
+ # This is accomplished by making either the starting or ending point based on the args.state.tick_count
+ args.outputs.lines << [380, 370, 875, 370, args.state.tick_count % 255, 0, 0, 255]
+ args.outputs.lines << [380, 330 - args.state.tick_count % 25, 875, 330, 0, 0, 0, 255]
+ args.outputs.lines << [380 + args.state.tick_count % 400, 290, 875, 290, 0, 0, 0, 255]
+end
+
+def tick_instructions args, text, y = 715
+ return if args.state.key_event_occurred
+ if args.inputs.mouse.click ||
+ args.inputs.keyboard.directional_vector ||
+ args.inputs.keyboard.key_down.enter ||
+ args.inputs.keyboard.key_down.escape
+ 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
+end
diff --git a/samples/01_rendering_basics/02_lines/license-for-sample.txt b/samples/01_rendering_basics/02_lines/license-for-sample.txt
new file mode 100644
index 0000000..100dcec
--- /dev/null
+++ b/samples/01_rendering_basics/02_lines/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.