summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTom Black <[email protected]>2016-10-10 17:51:05 -0400
committerTom Black <[email protected]>2016-10-10 17:51:05 -0400
commitc4439b1dd462d408004bf5b02fa4547f4db1cb5f (patch)
tree0ce7b55b10b4bbe61448d3bbb2d372a12bccc617
parentad85619dbc7591121ed0100938a9c10778ccd73b (diff)
downloadruby2d-c4439b1dd462d408004bf5b02fa4547f4db1cb5f.tar.gz
ruby2d-c4439b1dd462d408004bf5b02fa4547f4db1cb5f.zip
Update tests to reflect current API
-rw-r--r--Rakefile2
-rw-r--r--tests/input.rb40
-rw-r--r--tests/testcard.rb37
3 files changed, 61 insertions, 18 deletions
diff --git a/Rakefile b/Rakefile
index e3c43a6..de363c0 100644
--- a/Rakefile
+++ b/Rakefile
@@ -23,7 +23,7 @@ def run_cmd(cmd)
end
def run_test(file)
- print "\n==> ".blue, "running tests/#{file}.rb".bold, "\n"
+ print "\n==> ".blue, "running tests/#{file}.rb".bold, "\n\n"
system "( cd tests/ ; ruby #{file}.rb )"
end
diff --git a/tests/input.rb b/tests/input.rb
index 31f1527..fbf0530 100644
--- a/tests/input.rb
+++ b/tests/input.rb
@@ -3,11 +3,41 @@ require 'ruby2d'
set width: 200, height: 100, title: "Ruby 2D – Input"
on key: 'a' do
- puts "a key"
+ puts "on key: 'a'"
end
-on key_down: 's' do
- puts "s key down"
+on key_up: 's' do
+ puts "on key_up: 's'"
+end
+
+on key_down: 'd' do
+ puts "on key_down: 'd'"
+end
+
+on key: 'any' do
+ puts "on key: 'any'"
+end
+
+on key_down: 'any' do
+ puts "on key_down: 'any'"
+end
+
+on key_up: 'any' do
+ puts "on key_up: 'any'"
+end
+
+on_key do |key|
+ puts "on_key: #{key}"
+end
+
+on_controller do |which, is_axis, axis, val, is_btn, btn|
+ puts "=== Controller Pressed ===",
+ "which: which",
+ "is_axis: #{is_axis}",
+ "axis: #{axis}",
+ "val: #{val}",
+ "is_btn: #{is_btn}",
+ "btn: #{btn}"
end
on mouse: 'left' do
@@ -30,4 +60,8 @@ on mouse: 'any' do
puts "mouse any"
end
+on key: 'escape' do
+ close
+end
+
show
diff --git a/tests/testcard.rb b/tests/testcard.rb
index 95a6d28..4245653 100644
--- a/tests/testcard.rb
+++ b/tests/testcard.rb
@@ -1,10 +1,9 @@
require 'ruby2d'
-set width: 700, height: 500, title: "Ruby 2D – Testcard"
+set width: 700, height: 500, title: "Ruby 2D – Test Card"
# Read window attributes
-puts "
-=== Window Attributes ===
+puts "=== Window Attributes ===
Title: #{get :title}
Width: #{get :width}
Height: #{get :height}
@@ -55,7 +54,6 @@ Rectangle.new(650, 0, 50, 50,
Rectangle.new(600, 50, 50, 50, 'random')
Rectangle.new(650, 50, 50, 50, 'random')
-
# White to black gradient
Rectangle.new(0, 100, 700, 25,
[
@@ -93,7 +91,7 @@ Triangle.new(175, 200, 200, 250, 150, 250,
[0, 1.0, 0, 1.0],
[0, 0, 1.0, 1.0]
])
-Rectangle.new(200, 200, 50, 50, 'gray') # add background for transparancy
+Rectangle.new(200, 200, 50, 50, [0.5, 0.5, 0.5, 1.0]) # add background for transparancy
Triangle.new(225, 200, 250, 250, 200, 250,
[
[1.0, 1.0, 1.0, 1.0],
@@ -132,18 +130,29 @@ Quad.new(
Image.new(590, 180, "media/image.png")
Image.new(590, 290, "media/image.jpg")
Image.new(590, 400, "media/image.bmp")
+img_r = Image.new(350, 200, "media/colors.png")
+# img_r.width, img_r.height = 50, 50
+# img_r.color = [1.0, 0.3, 0.3, 1.0]
+img_g = Image.new(400, 200, "media/colors.png")
+# img_g.width, img_g.height = 50, 50
+# img_g.color = [0.3, 1.0, 0.3, 1.0]
+img_b = Image.new(450, 200, "media/colors.png")
+# img_b.width, img_b.height = 50, 50
+# img_b.color = [0.3, 0.3, 1.0, 1.0]
# Text
-Text.new(0, 250) # Default message
-t1 = Text.new(0, 275, 30, "Hello Ruby 2D!", "media/bitstream_vera/vera.ttf")
-t1.color = 'red' # Doesn't work yet
-t2 = Text.new(0, 325, 20) # Default message
-t2.text = "Text can be changed"
-fps = Text.new(0, 375, 20)
+txt_r = Text.new( 44, 202, 20, "R", "media/bitstream_vera/vera.ttf")
+# txt_r.color = [1.0, 0.0, 0.0, 1.0]
+txt_g = Text.new( 92, 202, 20, "G", "media/bitstream_vera/vera.ttf")
+# txt_g.color = [0.0, 1.0, 0.0, 1.0]
+txt_b = Text.new(144, 202, 20, "B", "media/bitstream_vera/vera.ttf")
+# txt_b.color = [0.0, 0.0, 1.0, 1.0]
+# Frames per second
+fps = Text.new(10, 470, 20, "media/bitstream_vera/vera.ttf")
# Sprites
-s1 = Sprite.new(350, 200, "media/sprite_sheet.png")
+s1 = Sprite.new(500, 200, "media/sprite_sheet.png")
s1.add(forwards: [
[ 0, 0, 50, 50, 30],
[ 50, 0, 50, 50, 40],
@@ -154,7 +163,7 @@ s1.add(forwards: [
# Pointer for mouse
pointer = Square.new(0, 0, 10, 'white')
-on key: "escape" do
+on key: 'escape' do
close
end
@@ -162,7 +171,7 @@ update do
pointer.x = (get :mouse_x) - 5
pointer.y = (get :mouse_y) - 7
s1.animate(:forwards)
- fps.text = "FPS: #{get :fps}"
+ fps.text = "FPS: #{(get :fps).round(3)}"
end
show