chingu 0.8rc1 → 0.8rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -3
- data/chingu.gemspec +201 -198
- data/examples/example21.yml +39 -39
- data/examples/example26_splash_screen.rb +48 -0
- data/examples/example3_parallax.rb +6 -10
- data/examples/game1.rb +4 -3
- data/examples/game_of_life.rb +11 -9
- data/examples/{example24_input_codes.rb → tool1_input_codes.rb} +1 -1
- data/lib/chingu.rb +1 -1
- data/lib/chingu/assets.rb +58 -0
- data/lib/chingu/basic_game_object.rb +15 -3
- data/lib/chingu/classic_game_object.rb +267 -0
- data/lib/chingu/game_object.rb +6 -234
- data/lib/chingu/game_states/debug.rb +1 -1
- data/lib/chingu/game_states/pause.rb +1 -1
- data/lib/chingu/helpers/rotation_center.rb +1 -2
- data/lib/chingu/inflector.rb +7 -0
- data/lib/chingu/named_resource.rb +258 -254
- data/lib/chingu/parallax.rb +6 -4
- data/lib/chingu/text.rb +4 -2
- data/lib/chingu/traits/sprite.rb +22 -19
- data/lib/chingu/window.rb +17 -0
- data/spec/chingu/game_object_spec.rb +69 -1
- data/spec/chingu/parallax_spec.rb +34 -0
- metadata +25 -21
- data/.gitignore +0 -6
data/lib/chingu/parallax.rb
CHANGED
@@ -123,8 +123,6 @@ module Chingu
|
|
123
123
|
#
|
124
124
|
def draw
|
125
125
|
@layers.each do |layer|
|
126
|
-
#layer.draw
|
127
|
-
|
128
126
|
save_x, save_y = layer.x, layer.y
|
129
127
|
|
130
128
|
# If layer lands inside our window and repeat_x is true (defaults to true), draw it until window ends
|
@@ -183,15 +181,19 @@ module Chingu
|
|
183
181
|
:zorder => (@@zorder_counter+=1)
|
184
182
|
}.merge(options)
|
185
183
|
|
186
|
-
|
187
184
|
@repeat_x = options[:repeat_x]
|
188
185
|
@repeat_y = options[:repeat_y]
|
189
|
-
|
186
|
+
|
190
187
|
super(options)
|
191
188
|
|
192
189
|
@damping = options[:damping] || 1
|
193
190
|
end
|
194
191
|
|
192
|
+
def draw
|
193
|
+
super
|
194
|
+
#p "draw @ #{x} / #{y}: #{image} - #{zorder} - #{color}"
|
195
|
+
end
|
196
|
+
|
195
197
|
#
|
196
198
|
# Gets pixel from layers image
|
197
199
|
# The pixel is from the window point of view, so coordinates are converted:
|
data/lib/chingu/text.rb
CHANGED
@@ -65,18 +65,20 @@ module Chingu
|
|
65
65
|
text = nil
|
66
66
|
end
|
67
67
|
|
68
|
+
# We remove the :size param so it doesn't get to GameObject where it means something else
|
69
|
+
@size = options.delete(:size) || options.delete(:height) || @@size || 15
|
70
|
+
|
68
71
|
super(options)
|
69
72
|
|
70
73
|
@text = text || options[:text] || "-No text specified-"
|
71
74
|
@font = options[:font] || @@font || Gosu::default_font_name()
|
72
|
-
@size = options[:size] || options[:height] || @@size || 15
|
73
75
|
@line_spacing = options[:line_spacing] || 1
|
74
76
|
@align = options[:align] || :left
|
75
77
|
@max_width = options[:max_width]
|
76
78
|
@padding = options[:padding] || @@padding
|
77
79
|
self.rotation_center = :top_left
|
78
80
|
|
79
|
-
@gosu_font = Gosu::Font
|
81
|
+
@gosu_font = Gosu::Font[@font, @size]
|
80
82
|
create_image unless @image
|
81
83
|
|
82
84
|
if options[:background]
|
data/lib/chingu/traits/sprite.rb
CHANGED
@@ -28,8 +28,8 @@ module Chingu
|
|
28
28
|
# :x, :y, :angle, :factor_x, :factor_y, :center_x, :center_y, :zorder, :mode, :visible
|
29
29
|
#
|
30
30
|
module Sprite
|
31
|
-
|
32
31
|
include Chingu::Helpers::OptionsSetter
|
32
|
+
include Chingu::Helpers::RotationCenter # Adds easy and verbose modification of @center_x and @center_y
|
33
33
|
|
34
34
|
module ClassMethods
|
35
35
|
def initialize_trait(options = {})
|
@@ -37,19 +37,23 @@ module Chingu
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
attr_accessor :x, :y, :angle, :factor_x, :factor_y, :center_x, :center_y, :zorder, :mode, :visible
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
40
|
+
attr_accessor :x, :y, :angle, :factor_x, :factor_y, :center_x, :center_y, :zorder, :mode, :visible, :color
|
41
|
+
attr_reader :factor, :center, :height, :width, :image
|
42
|
+
|
43
|
+
def setup_trait(object_options = {})
|
44
|
+
# default settings for all variables unless set in constructor
|
45
|
+
defaults = {
|
46
|
+
:x => 0, :y => 0, :angle => 0,
|
47
|
+
:factor => ($window.factor||1.0),
|
48
|
+
:zorder => 100, :center_x => 0.5, :center_y => 0.5,
|
49
|
+
:mode => :default, :color => nil
|
50
|
+
}
|
51
|
+
|
52
|
+
# if user specs :image take care of it first since width, height etc depends on it.
|
53
|
+
self.image = object_options.delete(:image) if object_options[:image]
|
54
|
+
|
55
|
+
set_options(trait_options[:sprite].merge(object_options), defaults)
|
56
|
+
|
53
57
|
super
|
54
58
|
end
|
55
59
|
|
@@ -139,14 +143,13 @@ module Chingu
|
|
139
143
|
[self.width, self.height]
|
140
144
|
end
|
141
145
|
|
142
|
-
|
143
146
|
# Quick way of setting both factor_x and factor_y
|
144
147
|
def factor=(factor)
|
145
|
-
@factor_x = @factor_y = factor
|
148
|
+
@factor = @factor_x = @factor_y = factor
|
146
149
|
end
|
147
150
|
alias scale= factor=
|
148
|
-
|
149
|
-
|
151
|
+
alias scale factor
|
152
|
+
|
150
153
|
# Quick way of setting both center_x and center_y
|
151
154
|
def center=(center)
|
152
155
|
@center_x = @center_y = center
|
@@ -220,7 +223,7 @@ module Chingu
|
|
220
223
|
# Works as #draw() but takes offsets for all draw_rot()-arguments. Used among others by the viewport-trait.
|
221
224
|
#
|
222
225
|
def draw_relative(x=0, y=0, zorder=0, angle=0, center_x=0, center_y=0, factor_x=0, factor_y=0)
|
223
|
-
@image.draw_rot(@x+x, @y+y, @zorder+zorder, @angle+angle, @center_x+center_x, @center_y+center_y, @factor_x+factor_x, @factor_y+factor_y, @color, @mode)
|
226
|
+
@image.draw_rot(@x+x, @y+y, @zorder+zorder, @angle+angle, @center_x+center_x, @center_y+center_y, @factor_x+factor_x, @factor_y+factor_y, @color, @mode)
|
224
227
|
end
|
225
228
|
|
226
229
|
#
|
data/lib/chingu/window.rb
CHANGED
@@ -42,6 +42,8 @@ module Chingu
|
|
42
42
|
attr_accessor :factor, :cursor
|
43
43
|
|
44
44
|
def initialize(width = 800, height = 600, fullscreen = false, update_interval = 16.666666)
|
45
|
+
raise "Cannot create a new #{self.class} before the old one has been closed" if $window
|
46
|
+
|
45
47
|
fullscreen ||= ARGV.include?("--fullscreen")
|
46
48
|
$window = super(width, height, fullscreen, update_interval)
|
47
49
|
|
@@ -51,6 +53,7 @@ module Chingu
|
|
51
53
|
Gosu::Image.autoload_dirs += [".", File.join(@root, "images"), File.join(@root, "gfx"), File.join(@root, "media")]
|
52
54
|
Gosu::Sample.autoload_dirs += [".", File.join(@root, "sounds"), File.join(@root, "sfx"), File.join(@root, "media")]
|
53
55
|
Gosu::Song.autoload_dirs += [".", File.join(@root, "songs"), File.join(@root, "sounds"), File.join(@root, "sfx"), File.join(@root, "media")]
|
56
|
+
Gosu::Font.autoload_dirs += [".", File.join(@root, "fonts"), File.join(@root, "media")]
|
54
57
|
|
55
58
|
@game_objects = GameObjectList.new
|
56
59
|
@input_clients = Array.new
|
@@ -198,5 +201,19 @@ module Chingu
|
|
198
201
|
@input_clients.each { |object| dispatch_button_down(id, object) unless object.paused? }
|
199
202
|
@game_state_manager.button_down(id)
|
200
203
|
end
|
204
|
+
|
205
|
+
#
|
206
|
+
# Close the window when it is no longer required. Ensure this is done before a new window is initialized.
|
207
|
+
#
|
208
|
+
def close
|
209
|
+
super
|
210
|
+
|
211
|
+
# Clear out all assets, tied to this $window, so that a new instance can create more.
|
212
|
+
[Gosu::Image, Gosu::Song, Gosu::Font, Gosu::Sample].each do |asset|
|
213
|
+
asset.clear
|
214
|
+
end
|
215
|
+
|
216
|
+
$window = nil
|
217
|
+
end
|
201
218
|
end
|
202
219
|
end
|
@@ -20,6 +20,10 @@ module Chingu
|
|
20
20
|
it { should respond_to(:zorder) }
|
21
21
|
it { should respond_to(:mode) }
|
22
22
|
it { should respond_to(:color) }
|
23
|
+
it { should respond_to(:attributes) }
|
24
|
+
it { should respond_to(:draw) }
|
25
|
+
it { should respond_to(:draw_at) }
|
26
|
+
it { should respond_to(:draw_relative) }
|
23
27
|
|
24
28
|
context "when created with defaults" do
|
25
29
|
it "should have default values" do
|
@@ -54,10 +58,55 @@ module Chingu
|
|
54
58
|
subject.alpha.should == 255
|
55
59
|
end
|
56
60
|
end
|
61
|
+
|
62
|
+
it "should have the same value for self.alpha as self.color.alpha" do
|
63
|
+
subject.alpha.should == subject.color.alpha
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should have a corrent filename created from class name" do
|
67
|
+
subject.filename.should == "game_object"
|
68
|
+
end
|
57
69
|
|
58
70
|
it "should raise an exception if the image fails to load" do
|
59
71
|
lambda { described_class.new(:image => "monkey_with_a_nuclear_tail.png") }.should raise_error Exception
|
60
72
|
end
|
73
|
+
|
74
|
+
context "position" do
|
75
|
+
it "inside_window?" do
|
76
|
+
subject.x = 1
|
77
|
+
subject.y = 1
|
78
|
+
subject.inside_window?.should == true
|
79
|
+
subject.outside_window?.should == false
|
80
|
+
end
|
81
|
+
it "outside_window?" do
|
82
|
+
subject.x = @game.width + 1
|
83
|
+
subject.y = @game.height + 1
|
84
|
+
subject.inside_window?.should == false
|
85
|
+
subject.outside_window?.should == true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "setters" do
|
90
|
+
it "factor should set both factor_x and factor_y" do
|
91
|
+
subject.factor = 4
|
92
|
+
subject.factor_x.should == 4
|
93
|
+
subject.factor_y.should == 4
|
94
|
+
end
|
95
|
+
|
96
|
+
it "scale should work as alias for factor" do
|
97
|
+
subject.scale = 5
|
98
|
+
subject.factor.should == 5
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "visibility" do
|
103
|
+
it "should hide/show object on self.hide! and self.show!" do
|
104
|
+
subject.hide!
|
105
|
+
subject.visible?.should == false
|
106
|
+
subject.show!
|
107
|
+
subject.visible?.should == true
|
108
|
+
end
|
109
|
+
end
|
61
110
|
|
62
111
|
context "when created with an image named in a string" do
|
63
112
|
subject { described_class.new(:image => "rect_20x20.png") }
|
@@ -81,9 +130,28 @@ module Chingu
|
|
81
130
|
subject.height.should == 40
|
82
131
|
subject.factor_x.should == 0.5
|
83
132
|
subject.factor_y.should == 2
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "when created with multiple arguments" do
|
137
|
+
subject { described_class.new(:image => "rect_20x20.png", :size => [10, 10]) }
|
138
|
+
it "should initialize values correclty" do
|
139
|
+
subject.width.should == 10
|
140
|
+
subject.height.should == 10
|
84
141
|
end
|
85
|
-
|
86
142
|
end
|
143
|
+
|
144
|
+
#context "when there's a global factor/scale" do
|
145
|
+
# $window = Chingu::Window.new
|
146
|
+
# $window.factor = 2
|
147
|
+
# subject { described_class.new(:image => "rect_20x20.png") }
|
148
|
+
# it "should use global factor/scale" do
|
149
|
+
# subject.factor_x.should == 2
|
150
|
+
# subject.factor_y.should == 2
|
151
|
+
# subject.width.should == 40
|
152
|
+
# subject.height.should == 40
|
153
|
+
# end
|
154
|
+
#end
|
87
155
|
|
88
156
|
after(:all) do
|
89
157
|
$window.close
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Chingu
|
4
|
+
|
5
|
+
describe Parallax do
|
6
|
+
before :all do
|
7
|
+
@game = Chingu::Window.new
|
8
|
+
|
9
|
+
# Gosu uses the paths based on where rspec is, not where this file is, so we need to do it manually!
|
10
|
+
Gosu::Image::autoload_dirs.unshift File.join(File.dirname(File.expand_path(__FILE__)), 'images')
|
11
|
+
end
|
12
|
+
|
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
|
+
|
21
|
+
it "should have 3 different ways of adding layers" do
|
22
|
+
@parallax.layers.count.should == 3
|
23
|
+
end
|
24
|
+
|
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
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: true
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
version: 0.
|
7
|
+
- 8rc2
|
8
|
+
version: 0.8rc2
|
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-
|
16
|
+
date: 2010-11-17 00:00:00 +01:00
|
17
17
|
default_executable:
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
@@ -27,8 +27,8 @@ dependencies:
|
|
27
27
|
segments:
|
28
28
|
- 0
|
29
29
|
- 7
|
30
|
-
-
|
31
|
-
version: 0.7.
|
30
|
+
- 25
|
31
|
+
version: 0.7.25
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
34
|
- !ruby/object:Gem::Dependency
|
@@ -41,9 +41,9 @@ dependencies:
|
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
segments:
|
43
43
|
- 2
|
44
|
+
- 1
|
44
45
|
- 0
|
45
|
-
|
46
|
-
version: 2.0.0
|
46
|
+
version: 2.1.0
|
47
47
|
type: :development
|
48
48
|
version_requirements: *id002
|
49
49
|
- !ruby/object:Gem::Dependency
|
@@ -108,7 +108,6 @@ extra_rdoc_files:
|
|
108
108
|
- LICENSE
|
109
109
|
- README.rdoc
|
110
110
|
files:
|
111
|
-
- .gitignore
|
112
111
|
- .rspec
|
113
112
|
- History.txt
|
114
113
|
- LICENSE
|
@@ -142,9 +141,9 @@ files:
|
|
142
141
|
- examples/example22_text.rb
|
143
142
|
- examples/example23_chipmunk.rb
|
144
143
|
- examples/example24_enter_name.rb
|
145
|
-
- examples/example24_input_codes.rb
|
146
144
|
- examples/example25.yml
|
147
145
|
- examples/example25_fibers_state_machine.rb
|
146
|
+
- examples/example26_splash_screen.rb
|
148
147
|
- examples/example2_gamestate_basics.rb
|
149
148
|
- examples/example3_parallax.rb
|
150
149
|
- examples/example4_gamestates.rb
|
@@ -199,10 +198,12 @@ files:
|
|
199
198
|
- examples/media/tube.png
|
200
199
|
- examples/media/video_games.png
|
201
200
|
- examples/media/wood.png
|
201
|
+
- examples/tool1_input_codes.rb
|
202
202
|
- lib/chingu.rb
|
203
203
|
- lib/chingu/animation.rb
|
204
204
|
- lib/chingu/assets.rb
|
205
205
|
- lib/chingu/basic_game_object.rb
|
206
|
+
- lib/chingu/classic_game_object.rb
|
206
207
|
- lib/chingu/core_ext/array.rb
|
207
208
|
- lib/chingu/fpscounter.rb
|
208
209
|
- lib/chingu/game_object.rb
|
@@ -256,6 +257,7 @@ files:
|
|
256
257
|
- spec/chingu/images/rect_20x20.png
|
257
258
|
- spec/chingu/inflector_spec.rb
|
258
259
|
- spec/chingu/input_spec.rb
|
260
|
+
- spec/chingu/parallax_spec.rb
|
259
261
|
- spec/chingu/text_spec.rb
|
260
262
|
- spec/spec_helper.rb
|
261
263
|
- specs.watchr
|
@@ -264,8 +266,8 @@ homepage: http://github.com/ippa/chingu
|
|
264
266
|
licenses: []
|
265
267
|
|
266
268
|
post_install_message:
|
267
|
-
rdoc_options:
|
268
|
-
|
269
|
+
rdoc_options: []
|
270
|
+
|
269
271
|
require_paths:
|
270
272
|
- lib
|
271
273
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -294,15 +296,6 @@ signing_key:
|
|
294
296
|
specification_version: 3
|
295
297
|
summary: OpenGL accelerated 2D game framework for Ruby
|
296
298
|
test_files:
|
297
|
-
- spec/chingu/fpscounter_spec.rb
|
298
|
-
- spec/chingu/game_object_spec.rb
|
299
|
-
- spec/chingu/helpers/input_client_spec.rb
|
300
|
-
- spec/chingu/helpers/input_dispatcher_spec.rb
|
301
|
-
- spec/chingu/helpers/options_setter_spec.rb
|
302
|
-
- spec/chingu/inflector_spec.rb
|
303
|
-
- spec/chingu/input_spec.rb
|
304
|
-
- spec/chingu/text_spec.rb
|
305
|
-
- spec/spec_helper.rb
|
306
299
|
- examples/example10_traits_retrofy.rb
|
307
300
|
- examples/example11_animation.rb
|
308
301
|
- examples/example12_trait_timer.rb
|
@@ -319,8 +312,8 @@ test_files:
|
|
319
312
|
- examples/example22_text.rb
|
320
313
|
- examples/example23_chipmunk.rb
|
321
314
|
- examples/example24_enter_name.rb
|
322
|
-
- examples/example24_input_codes.rb
|
323
315
|
- examples/example25_fibers_state_machine.rb
|
316
|
+
- examples/example26_splash_screen.rb
|
324
317
|
- examples/example2_gamestate_basics.rb
|
325
318
|
- examples/example3_parallax.rb
|
326
319
|
- examples/example4_gamestates.rb
|
@@ -331,3 +324,14 @@ test_files:
|
|
331
324
|
- examples/example9_collision_detection.rb
|
332
325
|
- examples/game1.rb
|
333
326
|
- examples/game_of_life.rb
|
327
|
+
- examples/tool1_input_codes.rb
|
328
|
+
- spec/chingu/fpscounter_spec.rb
|
329
|
+
- spec/chingu/game_object_spec.rb
|
330
|
+
- spec/chingu/helpers/input_client_spec.rb
|
331
|
+
- spec/chingu/helpers/input_dispatcher_spec.rb
|
332
|
+
- spec/chingu/helpers/options_setter_spec.rb
|
333
|
+
- spec/chingu/inflector_spec.rb
|
334
|
+
- spec/chingu/input_spec.rb
|
335
|
+
- spec/chingu/parallax_spec.rb
|
336
|
+
- spec/chingu/text_spec.rb
|
337
|
+
- spec/spec_helper.rb
|