chingu 0.8rc2 → 0.8rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/README.rdoc +66 -19
  2. data/benchmarks/arrays_bench.rb +22 -0
  3. data/benchmarks/game_objects_benchmark.rb +29 -35
  4. data/chingu.gemspec +16 -2
  5. data/examples/example18_animation_trait.rb +14 -9
  6. data/examples/example19.yml +305 -561
  7. data/examples/example19_edit_viewport.rb +3 -1
  8. data/examples/example1_basics.rb +4 -4
  9. data/examples/example21.yml +62 -54
  10. data/examples/example21_sidescroller_with_edit.rb +13 -21
  11. data/examples/example4_gamestates.rb +0 -2
  12. data/examples/example7_gfx_helpers.rb +1 -1
  13. data/examples/example8_traits.rb +1 -2
  14. data/examples/example9_collision_detection.rb +1 -1
  15. data/examples/game1.rb +1 -1
  16. data/lib/chingu.rb +1 -2
  17. data/lib/chingu/animation.rb +13 -5
  18. data/lib/chingu/assets.rb +2 -2
  19. data/lib/chingu/basic_game_object.rb +33 -30
  20. data/lib/chingu/game_object.rb +0 -5
  21. data/lib/chingu/game_object_list.rb +34 -21
  22. data/lib/chingu/game_states/edit.rb +2 -5
  23. data/lib/chingu/game_states/fade_to.rb +0 -1
  24. data/lib/chingu/game_states/pause.rb +1 -1
  25. data/lib/chingu/helpers/game_object.rb +0 -1
  26. data/lib/chingu/parallax.rb +3 -9
  27. data/lib/chingu/simple_menu.rb +7 -8
  28. data/lib/chingu/traits/animation.rb +2 -4
  29. data/lib/chingu/traits/sprite.rb +16 -13
  30. data/lib/chingu/window.rb +1 -1
  31. data/spec/chingu/animation_spec.rb +88 -0
  32. data/spec/chingu/assets_spec.rb +58 -0
  33. data/spec/chingu/basic_game_object_spec.rb +111 -0
  34. data/spec/chingu/game_object_list_spec.rb +78 -0
  35. data/spec/chingu/game_object_spec.rb +50 -14
  36. data/spec/chingu/game_state_manager_spec.rb +105 -0
  37. data/spec/chingu/helpers/input_client_spec.rb +4 -0
  38. data/spec/chingu/helpers/input_dispatcher_spec.rb +4 -0
  39. data/spec/chingu/images/droid_11x15.bmp +0 -0
  40. data/spec/chingu/parallax_spec.rb +25 -16
  41. data/spec/chingu/window_spec.rb +55 -0
  42. data/spec/spec_helper.rb +1 -5
  43. metadata +17 -3
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ module Chingu
4
+ describe GameStateManager do
5
+ before :each do
6
+ @game = Chingu::Window.new
7
+ end
8
+
9
+ after :each do
10
+ @game.close
11
+ end
12
+
13
+ describe "initial configuration" do
14
+ it "$window should have a game_state_manager" do
15
+ @game.game_state_manager.should_not be_nil
16
+ end
17
+ it "should have 0 game states" do
18
+ @game.game_state_manager.game_states.count.should == 0
19
+ end
20
+ end
21
+
22
+ describe "push_game_state" do
23
+ before :each do
24
+ @game.push_game_state(Chingu::GameStates::Pause)
25
+ @game.push_game_state(Chingu::GameStates::Edit)
26
+ end
27
+
28
+ it "should change current game state" do
29
+ @game.current_game_state.class.should == Chingu::GameStates::Edit
30
+ end
31
+
32
+ it "should keep last game state" do
33
+ @game.game_state_manager.previous_game_state.class.should == Chingu::GameStates::Pause
34
+ @game.current_game_state.class.should == Chingu::GameStates::Edit
35
+ end
36
+
37
+ it "should increment total # of game states" do
38
+ @game.game_states.count.should == 2
39
+ end
40
+
41
+ end
42
+
43
+ describe "pop_game_state" do
44
+ before :each do
45
+ @game.push_game_state(Chingu::GameStates::Pause)
46
+ @game.push_game_state(Chingu::GameStates::Edit)
47
+ end
48
+
49
+ it "should replace current game state with last one" do
50
+ @game.pop_game_state
51
+ @game.current_game_state.class.should == Chingu::GameStates::Pause
52
+ end
53
+
54
+ it "should decrement total # of game states" do
55
+ @game.pop_game_state
56
+ @game.game_states.count.should == 1
57
+ end
58
+ end
59
+
60
+ describe "switch_game_state" do
61
+ before :each do
62
+ @game.push_game_state(Chingu::GameStates::Pause)
63
+ @game.switch_game_state(Chingu::GameStates::Edit)
64
+ end
65
+
66
+ it "should replace current game state" do
67
+ @game.current_game_state.class.should == Chingu::GameStates::Edit
68
+ end
69
+
70
+ it "should not change the total amount of game states" do
71
+ @game.game_states.count.should == 1
72
+ end
73
+ end
74
+
75
+ describe "clear_game_states" do
76
+ it "should clear all game states" do
77
+ @game.push_game_state(Chingu::GameStates::Pause)
78
+ @game.switch_game_state(Chingu::GameStates::Edit)
79
+ @game.clear_game_states
80
+ @game.game_states.count.should == 0
81
+ end
82
+ end
83
+
84
+ describe "transitional_game_state" do
85
+ before :each do
86
+ @game.transitional_game_state(Chingu::GameStates::FadeTo)
87
+ @game.push_game_state(Chingu::GameStates::Pause)
88
+ @game.push_game_state(Chingu::GameStates::Edit)
89
+ end
90
+
91
+ #it "should get back to the last game state after popping" do
92
+ # @game.pop_game_state
93
+ # @game.update
94
+ # sleep 4
95
+ # @game.update
96
+ # @game.current_game_state.class.should == Chingu::GameStates::Pause
97
+ #end
98
+
99
+ it "keep track of amount of created game states" do
100
+ @game.game_states.count.should == 2
101
+ end
102
+ end
103
+
104
+ end
105
+ end
@@ -13,6 +13,10 @@ module Chingu
13
13
  @handler2 = @subject.method :handler2
14
14
  end
15
15
 
16
+ after :each do
17
+ $window = nil
18
+ end
19
+
16
20
  describe "#holding?" do
17
21
  it "should be true if that key is being held down" do
18
22
  $window.should_receive(:button_down?).with(Gosu::KbSpace).and_return(true)
@@ -33,6 +33,10 @@ describe Chingu::Helpers::InputDispatcher do
33
33
  $window.stub!(:button_down?).and_return(false)
34
34
  end
35
35
 
36
+ after :each do
37
+ $window = nil
38
+ end
39
+
36
40
  it "should dispatch if a key is being held" do
37
41
  @client.should_receive(:handler).with(no_args)
38
42
  $window.stub!(:button_down?).with(Gosu::KbA).and_return(true)
@@ -1,34 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Chingu
4
-
5
4
  describe Parallax do
6
- before :all do
5
+ before :each do
7
6
  @game = Chingu::Window.new
8
7
 
9
8
  # Gosu uses the paths based on where rspec is, not where this file is, so we need to do it manually!
10
9
  Gosu::Image::autoload_dirs.unshift File.join(File.dirname(File.expand_path(__FILE__)), 'images')
11
10
  end
11
+
12
+ after :each do
13
+ @game.close
14
+ end
12
15
 
13
- context "layers" do
14
- before :all do
15
- @parallax = Parallax.new
16
- @parallax << {:image => "rect_20x20.png", :repeat_x => true, :repeat_y => true}
17
- @parallax.add_layer(:image => "rect_20x20.png", :repeat_x => true, :repeat_y => true)
18
- @parallax << ParallaxLayer.new(:image => "rect_20x20.png", :repeat_x => true, :repeat_y => true)
19
- end
20
-
16
+ describe "layers" do
21
17
  it "should have 3 different ways of adding layers" do
22
- @parallax.layers.count.should == 3
18
+ subject << {:image => "rect_20x20.png", :repeat_x => true, :repeat_y => true}
19
+ subject.add_layer(:image => "rect_20x20.png", :repeat_x => true, :repeat_y => true)
20
+ subject << ParallaxLayer.new(:image => "rect_20x20.png", :repeat_x => true, :repeat_y => true)
21
+
22
+ subject.layers.count.should equal 3
23
23
  end
24
24
 
25
25
  it "should have incrementing zorder" do
26
- @parallax.layers[0].zorder == 0
27
- @parallax.layers[1].zorder == 1
28
- @parallax.layers[2].zorder == 2
26
+ 3.times do
27
+ subject.add_layer(:image => "rect_20x20.png")
28
+ end
29
+ subject.layers[1].zorder.should equal (subject.layers[0].zorder + 1)
30
+ subject.layers[2].zorder.should equal (subject.layers[0].zorder + 2)
29
31
  end
32
+
33
+ it "should start incrementing zorder in layers from Parallax-instance zorder if available" do
34
+ parallax = Parallax.new(:zorder => 2000)
35
+ 3.times { parallax.add_layer(:image => "rect_20x20.png") }
36
+ parallax.layers[0].zorder.should == 2000
37
+ parallax.layers[1].zorder.should == 2001
38
+ parallax.layers[2].zorder.should == 2002
39
+ end
40
+
30
41
  end
31
-
32
42
  end
33
-
34
43
  end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ module Chingu
4
+
5
+ describe "Window" do
6
+ before :each do
7
+ @game = Chingu::Window.new
8
+ end
9
+
10
+ after :each do
11
+ @game.close
12
+ end
13
+
14
+ it { @game.should respond_to :close }
15
+ it { @game.should respond_to :fps }
16
+ it { @game.should respond_to :update }
17
+ it { @game.should respond_to :draw }
18
+ it { @game.should respond_to :root }
19
+ it { @game.should respond_to :game_state_manager }
20
+ it { @game.should respond_to :factor }
21
+ it { @game.should respond_to :cursor }
22
+ it { @game.should respond_to :root }
23
+ it { @game.should respond_to :milliseconds_since_last_tick }
24
+
25
+ context "a new Chingu::Window" do
26
+
27
+ it "should return itself as current scope" do
28
+ @game.current_scope.should == @game
29
+ end
30
+
31
+ it "should have 0 game objects" do
32
+ @game.game_objects.size.should == 0
33
+ end
34
+ end
35
+
36
+ context "each game iteration" do
37
+ it "$window.update() should call update() on all unpaused game objects" do
38
+ GameObject.create.should_receive(:update)
39
+ GameObject.create(:paused => true).should_not_receive(:update)
40
+ @game.update
41
+ end
42
+
43
+ it "$window.draw() should call draw() on all visible game objects" do
44
+ GameObject.create.should_receive(:draw)
45
+ @game.draw
46
+ end
47
+
48
+ it "$window.draw() should not call draw() on invisible game objects" do
49
+ GameObject.create(:visible => false).should_not_receive(:draw)
50
+ @game.game_objects.first.visible?.should == false
51
+ @game.draw
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,23 +1,19 @@
1
+ # encoding: utf-8
1
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
3
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
4
 
4
-
5
- # encoding: utf-8
6
5
  require 'rubygems'
7
6
  require 'rspec'
8
7
  require 'chingu/require_all'
9
8
 
10
9
  require 'chingu'
11
- require 'chingu/helpers/options_setter'
12
10
 
13
11
  def media_path(file)
14
12
  File.join($window.root, "..", "..", "examples", "media", file)
15
13
  end
16
14
 
17
15
  if defined?(Rcov)
18
-
19
16
  # all_app_files = Dir.glob('lib/**/*.rb')
20
17
  # all_app_files.each{|rb| require rb}
21
-
22
18
  end
23
19
 
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: true
5
5
  segments:
6
6
  - 0
7
- - 8rc2
8
- version: 0.8rc2
7
+ - 8rc3
8
+ version: 0.8rc3
9
9
  platform: ruby
10
10
  authors:
11
11
  - ippa
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2010-11-17 00:00:00 +01:00
16
+ date: 2010-12-12 00:00:00 +01:00
17
17
  default_executable:
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
@@ -114,6 +114,7 @@ files:
114
114
  - README.rdoc
115
115
  - Rakefile
116
116
  - benchmarks/README.txt
117
+ - benchmarks/arrays_bench.rb
117
118
  - benchmarks/benchmark.rb
118
119
  - benchmarks/benchmark3.rb
119
120
  - benchmarks/benchmark4.rb
@@ -249,16 +250,23 @@ files:
249
250
  - lib/chingu/traits/viewport.rb
250
251
  - lib/chingu/viewport.rb
251
252
  - lib/chingu/window.rb
253
+ - spec/chingu/animation_spec.rb
254
+ - spec/chingu/assets_spec.rb
255
+ - spec/chingu/basic_game_object_spec.rb
252
256
  - spec/chingu/fpscounter_spec.rb
257
+ - spec/chingu/game_object_list_spec.rb
253
258
  - spec/chingu/game_object_spec.rb
259
+ - spec/chingu/game_state_manager_spec.rb
254
260
  - spec/chingu/helpers/input_client_spec.rb
255
261
  - spec/chingu/helpers/input_dispatcher_spec.rb
256
262
  - spec/chingu/helpers/options_setter_spec.rb
263
+ - spec/chingu/images/droid_11x15.bmp
257
264
  - spec/chingu/images/rect_20x20.png
258
265
  - spec/chingu/inflector_spec.rb
259
266
  - spec/chingu/input_spec.rb
260
267
  - spec/chingu/parallax_spec.rb
261
268
  - spec/chingu/text_spec.rb
269
+ - spec/chingu/window_spec.rb
262
270
  - spec/spec_helper.rb
263
271
  - specs.watchr
264
272
  has_rdoc: true
@@ -325,8 +333,13 @@ test_files:
325
333
  - examples/game1.rb
326
334
  - examples/game_of_life.rb
327
335
  - examples/tool1_input_codes.rb
336
+ - spec/chingu/animation_spec.rb
337
+ - spec/chingu/assets_spec.rb
338
+ - spec/chingu/basic_game_object_spec.rb
328
339
  - spec/chingu/fpscounter_spec.rb
340
+ - spec/chingu/game_object_list_spec.rb
329
341
  - spec/chingu/game_object_spec.rb
342
+ - spec/chingu/game_state_manager_spec.rb
330
343
  - spec/chingu/helpers/input_client_spec.rb
331
344
  - spec/chingu/helpers/input_dispatcher_spec.rb
332
345
  - spec/chingu/helpers/options_setter_spec.rb
@@ -334,4 +347,5 @@ test_files:
334
347
  - spec/chingu/input_spec.rb
335
348
  - spec/chingu/parallax_spec.rb
336
349
  - spec/chingu/text_spec.rb
350
+ - spec/chingu/window_spec.rb
337
351
  - spec/spec_helper.rb