summaryrefslogtreecommitdiffhomepage
path: root/test/key.rb
diff options
context:
space:
mode:
authorTom Black <[email protected]>2017-04-08 23:17:18 -0400
committerTom Black <[email protected]>2017-04-13 15:22:05 -0400
commit10d9acbe39a6e649e8752c3d06d1157d43b6e73a (patch)
tree0da91cd30d4e900d4b1d5c4d0e5b0d656997811e /test/key.rb
parent193315380ed9c714e5f78b7d1b1224cfc68ccaaa (diff)
downloadruby2d-10d9acbe39a6e649e8752c3d06d1157d43b6e73a.tar.gz
ruby2d-10d9acbe39a6e649e8752c3d06d1157d43b6e73a.zip
Add mouse events, introduce event structs
Diffstat (limited to 'test/key.rb')
-rw-r--r--test/key.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/key.rb b/test/key.rb
new file mode 100644
index 0000000..3c2c8e6
--- /dev/null
+++ b/test/key.rb
@@ -0,0 +1,30 @@
+require 'ruby2d'
+
+set title: "Ruby 2D — Key", width: 300, height: 200
+
+s1 = Square.new(5, 5, 50, [1, 1, 1, 1])
+s2 = Square.new(60, 5, 50, [1, 1, 1, 1])
+
+on :key do |event|
+ puts event
+end
+
+on :key_down do |event|
+ s1.color = [1, 0, 0, 1]
+end
+
+on :key_held do |event|
+ s2.color = [0, 1, 0, 1]
+end
+
+on :key_up do |event|
+ s1.color = [1, 1, 1, 1]
+ s2.color = [1, 1, 1, 1]
+end
+
+
+on :key_down do |event|
+ close if event.key == 'escape'
+end
+
+show