chingu 0.7.6.6 → 0.7.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. data/chingu.gemspec +9 -2
  2. data/examples/example11_animation.rb +2 -5
  3. data/examples/example17_gosu_tutorial.rb +2 -2
  4. data/examples/example18_animation_trait.rb +2 -2
  5. data/examples/example19_edit_viewport.rb +6 -3
  6. data/examples/example21.yml +283 -291
  7. data/examples/example21_sidescroller_with_edit.rb +22 -16
  8. data/examples/example22_text.rb +5 -1
  9. data/examples/example23_chipmunk.rb +25 -0
  10. data/examples/example3_parallax.rb +1 -0
  11. data/examples/example4_gamestates.rb +20 -5
  12. data/examples/game1.rb +13 -40
  13. data/lib/chingu.rb +2 -1
  14. data/lib/chingu/assets.rb +2 -2
  15. data/lib/chingu/basic_game_object.rb +1 -23
  16. data/lib/chingu/game_object.rb +21 -0
  17. data/lib/chingu/game_object_map.rb +96 -0
  18. data/lib/chingu/game_states/debug.rb +60 -14
  19. data/lib/chingu/game_states/edit.rb +5 -1
  20. data/lib/chingu/game_states/fade_to.rb +1 -1
  21. data/lib/chingu/helpers/input_client.rb +13 -5
  22. data/lib/chingu/helpers/input_dispatcher.rb +13 -8
  23. data/lib/chingu/helpers/options_setter.rb +33 -0
  24. data/lib/chingu/input.rb +5 -5
  25. data/lib/chingu/rect.rb +2 -0
  26. data/lib/chingu/text.rb +7 -9
  27. data/lib/chingu/traits/animation.rb +1 -0
  28. data/lib/chingu/traits/bounding_box.rb +1 -5
  29. data/lib/chingu/traits/bounding_circle.rb +1 -6
  30. data/lib/chingu/traits/effect.rb +4 -4
  31. data/lib/chingu/traits/retrofy.rb +1 -1
  32. data/lib/chingu/traits/sprite.rb +234 -0
  33. data/lib/chingu/traits/velocity.rb +22 -11
  34. data/lib/chingu/traits/viewport.rb +2 -2
  35. data/lib/chingu/viewport.rb +32 -21
  36. data/lib/chingu/window.rb +6 -5
  37. data/spec/chingu/helpers/options_setter_spec.rb +39 -0
  38. data/spec/spec_helper.rb +3 -0
  39. metadata +12 -5
@@ -59,8 +59,11 @@ module Chingu
59
59
  # Sets X and Y velocity with one single call. Takes an Array-argument with 2 values.
60
60
  #
61
61
  def velocity=(value)
62
- @velocity_x, @velocity_y = value && return if value.is_a? Array
63
- @velocity_x, @velocity_y = value, value
62
+ if value.is_a? Array
63
+ @velocity_x, @velocity_y = value
64
+ else
65
+ @velocity_x, @velocity_y = value, value
66
+ end
64
67
  end
65
68
 
66
69
  def velocity; [@velocity_x, @velocity_y]; end
@@ -69,8 +72,11 @@ module Chingu
69
72
  # Sets X and Y acceleration with one single call. Takes an Array-argument with 2 values.
70
73
  #
71
74
  def acceleration=(value)
72
- @acceleration_x, @acceleration_y = value && return if value.is_a? Array
73
- @acceleration_x, @acceleration_y = value, value
75
+ if value.is_a? Array
76
+ @acceleration_x, @acceleration_y = value
77
+ else
78
+ @acceleration_x, @acceleration_y = value, value
79
+ end
74
80
  end
75
81
 
76
82
  def acceleration; [@acceleration_x, @acceleration_y]; end
@@ -92,20 +98,25 @@ module Chingu
92
98
  @velocity_x += @acceleration_x if (@velocity_x + @acceleration_x).abs < @max_velocity_x
93
99
  @velocity_y += @acceleration_y if (@velocity_y + @acceleration_y).abs < @max_velocity_y
94
100
 
95
- @previous_x = @x
96
- @previous_y = @y
101
+ @previous_x = self.x
102
+ @previous_y = self.y
97
103
 
98
104
  #
99
105
  # if option :apply is false, just calculate velocities, don't apply them to x/y
100
106
  #
101
- unless trait_options[:velocity][:apply] == false
102
- self.x += @velocity_x
103
- self.y += @velocity_y
104
- end
107
+ move(@velocity_x, @velocity_y) unless trait_options[:velocity][:apply] == false
105
108
 
106
109
  super
107
110
  end
108
111
 
112
+ #
113
+ # Move game object
114
+ #
115
+ def move(x, y)
116
+ self.x += x
117
+ self.y += y
118
+ end
119
+
109
120
  #
110
121
  # Setts velocity_x and velocity_y to 0, stopping the game object
111
122
  # Note it doesn't reset the acceleration!
@@ -127,7 +138,7 @@ module Chingu
127
138
  # Did game object move last tick
128
139
  #
129
140
  def moved?
130
- @x != @previous_x || @y != @previous_y
141
+ self.x != @previous_x || self.y != @previous_y
131
142
  end
132
143
  end
133
144
  end
@@ -69,8 +69,8 @@ module Chingu
69
69
  # It only draws game objects inside the viewport. (GOSU does no such optimizations)
70
70
  #
71
71
  def draw
72
- self.game_objects.draw_relative(-@viewport.x, -@viewport.y)
73
- #@viewport.apply { super }
72
+ #self.game_objects.draw_relative(-@viewport.x, -@viewport.y)
73
+ @viewport.apply { super }
74
74
  end
75
75
  end
76
76
  end
@@ -21,7 +21,11 @@
21
21
 
22
22
  module Chingu
23
23
  #
24
- # A basic viewport class
24
+ # A basic viewport class. Coordinates X and Y are relative to game
25
+ # area that can be specified by any arguments acceptable by
26
+ # Chingu::Rect#new method. By default, the game_area is the same
27
+ # as window and thus the vieport has no effect.
28
+ #
25
29
  #
26
30
  # TODO:
27
31
  # Implement use of viewports angle, center_x, center_y, factor_x, factor_y
@@ -32,11 +36,11 @@ module Chingu
32
36
  def initialize(options = {})
33
37
  @x = options[:x] || 0
34
38
  @y = options[:y] || 0
35
- @x_target = options[:x_target]
36
- @y_target = options[:y_target]
39
+ @x_target = options[:x_target] || @x
40
+ @y_target = options[:y_target] || @y
37
41
  @x_lag = options[:x_lag] || 0
38
42
  @y_lag = options[:y_lag] || 0
39
- @game_area = Chingu::Rect.new(options[:game_area]||[@x, @y, $window.width, $window.height])
43
+ @game_area = Chingu::Rect.new(options[:game_area] || [@x, @y, $window.width, $window.height])
40
44
  end
41
45
 
42
46
  #
@@ -68,11 +72,7 @@ module Chingu
68
72
  # The game objects image will be the rectangle the viewport can move within.
69
73
  #
70
74
  def game_area_object=(game_object)
71
- image = (game_object.is_a? Gosu::Image) ? game_object : game_object.image
72
- @game_area = Rect.new(0,0,
73
- (image.width*$window.factor) - $window.width,
74
- (image.height*$window.factor) - $window.height
75
- )
75
+ @game_area = Rect.new(0, 0, game_object.width, game_object.height)
76
76
  end
77
77
 
78
78
  #
@@ -83,7 +83,7 @@ module Chingu
83
83
  # height,width,factor_x,factor_y,center_x,center_y as well...
84
84
  #
85
85
  def inside?(object, y = nil)
86
- x, y = y ? [object,y] : [object.x, object.y]
86
+ x, y = y ? [object,y] : [object.x, object.y]
87
87
  x >= @x && x <= (@x + $window.width) &&
88
88
  y >= @y && y <= (@y + $window.height)
89
89
  end
@@ -99,8 +99,8 @@ module Chingu
99
99
  # The viewport can't show anything outside the game area
100
100
  #
101
101
  def inside_game_area?(object)
102
- object.x >= @game_area.x && object.x <= (@game_area.width + $window.width) &&
103
- object.y >= @game_area.x && object.y <= (@game_area.height + $window.height)
102
+ object.x >= @game_area.x && object.x <= @game_area.width &&
103
+ object.y >= @game_area.x && object.y <= @game_area.height
104
104
  end
105
105
 
106
106
  # Returns true object is outside the game area
@@ -130,25 +130,36 @@ module Chingu
130
130
  def x=(x)
131
131
  @x = x
132
132
  if @game_area
133
- @x = @game_area.x if @x < @game_area.x
134
- @x = @game_area.width if @x > @game_area.width
133
+ @x = @game_area.x if @x < @game_area.x
134
+ @x = @game_area.width-$window.width if @x > @game_area.width-$window.width
135
135
  end
136
136
  end
137
137
 
138
- #
139
- # Viewports Y setter with boundschecking
140
- #
138
+ #
139
+ # Viewports Y setter with boundschecking
140
+ #
141
141
  def y=(y)
142
142
  @y = y
143
143
  if @game_area
144
- @y = @game_area.y if @y < @game_area.y
145
- @y = @game_area.height if @y > @game_area.height
144
+ @y = @game_area.y if @y < @game_area.y
145
+ @y = @game_area.height-$window.height if @y > @game_area.height-$window.height
146
146
  end
147
147
  end
148
148
 
149
149
  def apply(&block)
150
150
  $window.translate(-@x, -@y, &block)
151
- end
151
+ end
152
+
153
+ def to_s
154
+ a = @game_area
155
+ %/
156
+ Vieport
157
+ Position: #{@x}, #{y}
158
+ Game area: #{a.x},#{a.y},#{a.width},#{a.height}"
159
+ Target: #{@target_x}, #{@target_y}
160
+ /
161
+ end
162
+
152
163
 
153
164
  end
154
- end
165
+ end
@@ -46,11 +46,12 @@ module Chingu
46
46
  $window = super(width, height, fullscreen, update_interval)
47
47
 
48
48
  @root = File.dirname(File.expand_path($0))
49
- Chingu::Asset.autoload_dirs = [".", File.join(@root, "assets"), File.join(@root, "media")]
50
- Gosu::Image.autoload_dirs = [".", File.join(@root, "images"), File.join(@root, "gfx"), File.join(@root, "media")]
51
- Gosu::Sample.autoload_dirs = [".", File.join(@root, "sounds"), File.join(@root, "sfx"), File.join(@root, "media")]
52
- Gosu::Song.autoload_dirs = [".", File.join(@root, "songs"), File.join(@root, "sounds"), File.join(@root, "sfx"), File.join(@root, "media")]
53
-
49
+
50
+ Chingu::Asset.autoload_dirs += [".", File.join(@root, "assets"), File.join(@root, "media")]
51
+ Gosu::Image.autoload_dirs += [".", File.join(@root, "images"), File.join(@root, "gfx"), File.join(@root, "media")]
52
+ Gosu::Sample.autoload_dirs += [".", File.join(@root, "sounds"), File.join(@root, "sfx"), File.join(@root, "media")]
53
+ Gosu::Song.autoload_dirs += [".", File.join(@root, "songs"), File.join(@root, "sounds"), File.join(@root, "sfx"), File.join(@root, "media")]
54
+
54
55
  @game_objects = GameObjectList.new
55
56
  @input_clients = Array.new
56
57
 
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ class Car
4
+ include Chingu::Helpers::OptionsSetter
5
+
6
+ attr_accessor :angle, :speed
7
+ attr_reader :color
8
+
9
+ def initialize(params)
10
+ set_options(params, { :angle => 11, :speed => 22 })
11
+ end
12
+ end
13
+
14
+
15
+ module Chingu
16
+ module Helpers
17
+ describe OptionsSetter do
18
+
19
+ describe "using without defaults" do
20
+ before do
21
+ @car = Car.new(:angle => 44)
22
+ end
23
+
24
+ it "should set angle from options" do
25
+ @car.angle.should == 44
26
+ end
27
+
28
+ it "should set speed from defaults" do
29
+ @car.speed.should == 22
30
+ end
31
+
32
+ it "should handle attribute without writer" do
33
+ Car.new(:color => :green).color.should == :green
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -1,11 +1,14 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
 
4
+
4
5
  # encoding: utf-8
5
6
  require 'rubygems'
6
7
  require 'rspec'
8
+ require 'require_all'
7
9
 
8
10
  require 'chingu'
11
+ require 'chingu/helpers/options_setter'
9
12
 
10
13
  def media_path(file)
11
14
  File.join($window.root, "..", "..", "examples", "media", file)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chingu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 99
4
+ hash: 97
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
9
  - 6
10
- - 6
11
- version: 0.7.6.6
10
+ - 7
11
+ version: 0.7.6.7
12
12
  platform: ruby
13
13
  authors:
14
14
  - ippa
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-06-24 00:00:00 +02:00
19
+ date: 2010-08-11 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -43,7 +43,7 @@ dependencies:
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- hash: -1054406665
46
+ hash: -389188292
47
47
  segments:
48
48
  - 2
49
49
  - 0
@@ -123,6 +123,7 @@ files:
123
123
  - examples/example21.yml
124
124
  - examples/example21_sidescroller_with_edit.rb
125
125
  - examples/example22_text.rb
126
+ - examples/example23_chipmunk.rb
126
127
  - examples/example2_gamestate_basics.rb
127
128
  - examples/example3_parallax.rb
128
129
  - examples/example4_gamestates.rb
@@ -185,6 +186,7 @@ files:
185
186
  - lib/chingu/fpscounter.rb
186
187
  - lib/chingu/game_object.rb
187
188
  - lib/chingu/game_object_list.rb
189
+ - lib/chingu/game_object_map.rb
188
190
  - lib/chingu/game_state.rb
189
191
  - lib/chingu/game_state_manager.rb
190
192
  - lib/chingu/game_states/debug.rb
@@ -198,6 +200,7 @@ files:
198
200
  - lib/chingu/helpers/gfx.rb
199
201
  - lib/chingu/helpers/input_client.rb
200
202
  - lib/chingu/helpers/input_dispatcher.rb
203
+ - lib/chingu/helpers/options_setter.rb
201
204
  - lib/chingu/helpers/rotation_center.rb
202
205
  - lib/chingu/high_score_list.rb
203
206
  - lib/chingu/inflector.rb
@@ -215,6 +218,7 @@ files:
215
218
  - lib/chingu/traits/collision_detection.rb
216
219
  - lib/chingu/traits/effect.rb
217
220
  - lib/chingu/traits/retrofy.rb
221
+ - lib/chingu/traits/sprite.rb
218
222
  - lib/chingu/traits/timer.rb
219
223
  - lib/chingu/traits/velocity.rb
220
224
  - lib/chingu/traits/viewport.rb
@@ -222,6 +226,7 @@ files:
222
226
  - lib/chingu/window.rb
223
227
  - spec/chingu/fpscounter_spec.rb
224
228
  - spec/chingu/game_object_spec.rb
229
+ - spec/chingu/helpers/options_setter_spec.rb
225
230
  - spec/chingu/inflector_spec.rb
226
231
  - spec/chingu/rect_20x20.png
227
232
  - spec/chingu/text_spec.rb
@@ -264,6 +269,7 @@ summary: OpenGL accelerated 2D game framework for Ruby
264
269
  test_files:
265
270
  - spec/chingu/fpscounter_spec.rb
266
271
  - spec/chingu/game_object_spec.rb
272
+ - spec/chingu/helpers/options_setter_spec.rb
267
273
  - spec/chingu/inflector_spec.rb
268
274
  - spec/chingu/text_spec.rb
269
275
  - spec/spec_helper.rb
@@ -281,6 +287,7 @@ test_files:
281
287
  - examples/example20_trait_inheritence_test.rb
282
288
  - examples/example21_sidescroller_with_edit.rb
283
289
  - examples/example22_text.rb
290
+ - examples/example23_chipmunk.rb
284
291
  - examples/example2_gamestate_basics.rb
285
292
  - examples/example3_parallax.rb
286
293
  - examples/example4_gamestates.rb