summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorTom Black <[email protected]>2018-01-30 00:23:34 -0800
committerTom Black <[email protected]>2018-05-06 15:41:06 -0700
commit7d3cff5e5d6d53d7f4def94a9dc831e099e03e67 (patch)
treec3fc81f0ee676208dee1530ff5935f1b88692677 /test
parent2e07255723428d09eab38ad1a5fde11fc9a287d8 (diff)
downloadruby2d-7d3cff5e5d6d53d7f4def94a9dc831e099e03e67.tar.gz
ruby2d-7d3cff5e5d6d53d7f4def94a9dc831e099e03e67.zip
Sprite class redesign
See #33 for discussion
Diffstat (limited to 'test')
m---------test/media0
-rw-r--r--test/sprite.rb99
-rw-r--r--test/sprite_spec.rb6
3 files changed, 103 insertions, 2 deletions
diff --git a/test/media b/test/media
-Subproject 0d54e768f8da2217203649cb270f4d0add82328
+Subproject 44ae8c4a971e3ba6520ad9953fb4dd12eb36d2c
diff --git a/test/sprite.rb b/test/sprite.rb
new file mode 100644
index 0000000..713375a
--- /dev/null
+++ b/test/sprite.rb
@@ -0,0 +1,99 @@
+require 'ruby2d'
+
+if RUBY_ENGINE == 'opal'
+ media = "../test/media"
+else
+ media = "media"
+end
+
+set title: "Ruby 2D — Sprite", width: 350, height: 150
+
+
+coin = Sprite.new(
+ "#{media}/coin.png",
+ clip_width: 84,
+ time: 300,
+ loop: true
+)
+
+coin.play
+
+boom = Sprite.new(
+ "#{media}/boom.png",
+ x: 109,
+ clip_width: 127,
+ time: 75
+)
+
+hero = Sprite.new(
+ "#{media}/hero.png",
+ x: 261,
+ clip_width: 78,
+ time: 250,
+ animations: {
+ walk: 1..2,
+ climb: 3..4,
+ cheer: 5..6
+ }
+)
+
+atlas = Sprite.new(
+ "#{media}/texture_atlas.png",
+ x: 10, y: 100,
+ animations: {
+ count: [
+ {
+ x: 0, y: 0,
+ width: 35, height: 41,
+ time: 300
+ },
+ {
+ x: 26, y: 46,
+ width: 35, height: 38,
+ time: 400
+ },
+ {
+ x: 65, y: 10,
+ width: 32, height: 41,
+ time: 500
+ },
+ {
+ x: 10, y: 99,
+ width: 32, height: 38,
+ time: 600
+ },
+ {
+ x: 74, y: 80,
+ width: 32, height: 38,
+ time: 700
+ }
+ ]
+ }
+)
+
+atlas.play :count, :loop
+
+
+on :key_down do |e|
+ close if e.key == 'escape'
+
+ case e.key
+ when 'p'
+ coin.play
+ boom.play
+ atlas.play :count
+ when 's'
+ coin.stop
+ hero.stop
+ atlas.stop
+ when 'right'
+ hero.play :walk, :loop
+ when 'up'
+ hero.play :climb, :loop
+ when 'down'
+ hero.play :cheer
+ end
+end
+
+
+show
diff --git a/test/sprite_spec.rb b/test/sprite_spec.rb
index e44ea62..a9cbf31 100644
--- a/test/sprite_spec.rb
+++ b/test/sprite_spec.rb
@@ -3,13 +3,15 @@ require 'ruby2d'
RSpec.describe Ruby2D::Sprite do
describe '#new' do
+
it "raises exception if file doesn't exist" do
- expect { Sprite.new(0, 0, "bad_sprite_sheet.png") }.to raise_error(Ruby2D::Error)
+ expect { Sprite.new("bad_sprite_sheet.png") }.to raise_error(Ruby2D::Error)
end
it 'creates a new sprite' do
- Sprite.new(0, 0, "test/media/sprite_sheet.png")
+ Sprite.new("test/media/coin.png")
end
+
end
end