chingu 0.7.7.5 → 0.8rc1
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.
- data/History.txt +1 -1
- data/Rakefile +4 -2
- data/chingu.gemspec +25 -10
- data/examples/example10_traits_retrofy.rb +3 -2
- data/examples/example11_animation.rb +3 -2
- data/examples/example12_trait_timer.rb +3 -2
- data/examples/example13_high_scores.rb +3 -2
- data/examples/example14_bounding_box_circle.rb +6 -5
- data/examples/example15_trait_timer2.rb +3 -2
- data/examples/example16_online_high_scores.rb +3 -2
- data/examples/example17_gosu_tutorial.rb +104 -103
- data/examples/example18_animation_trait.rb +3 -2
- data/examples/example19_edit_viewport.rb +3 -2
- data/examples/example1_basics.rb +3 -2
- data/examples/example20_trait_inheritence_test.rb +3 -2
- data/examples/example21.yml +306 -306
- data/examples/example21_sidescroller_with_edit.rb +3 -2
- data/examples/example22_text.rb +3 -2
- data/examples/example23_chipmunk.rb +3 -2
- data/examples/example24_enter_name.rb +19 -0
- data/examples/example24_input_codes.rb +41 -0
- data/examples/example25.yml +625 -0
- data/examples/example25_fibers_state_machine.rb +167 -0
- data/examples/example2_gamestate_basics.rb +3 -2
- data/examples/example3_parallax.rb +3 -2
- data/examples/example4_gamestates.rb +3 -2
- data/examples/example5_gamestates_in_pure_gosu.rb +3 -2
- data/examples/example6_transitional_game_state.rb +3 -2
- data/examples/example7_gfx_helpers.rb +3 -2
- data/examples/example8_traits.rb +3 -2
- data/examples/example9_collision_detection.rb +3 -2
- data/examples/game1.rb +3 -2
- data/examples/game_of_life.rb +291 -290
- data/lib/chingu.rb +6 -1
- data/lib/chingu/animation.rb +3 -2
- data/lib/chingu/game_object.rb +7 -1
- data/lib/chingu/game_object_map.rb +6 -12
- data/lib/chingu/game_states/edit.rb +63 -66
- data/lib/chingu/game_states/enter_name.rb +97 -0
- data/lib/chingu/helpers/game_object.rb +10 -21
- data/lib/chingu/input.rb +2 -0
- data/lib/chingu/online_high_score_list.rb +1 -4
- data/lib/chingu/rect.rb +2 -1
- data/lib/chingu/window.rb +10 -1
- data/spec/chingu/game_object_spec.rb +22 -22
- data/spec/chingu/input_spec.rb +22 -0
- metadata +48 -22
- data/spec/chingu/rect_20x20.png +0 -0
@@ -29,7 +29,6 @@ module Chingu
|
|
29
29
|
module GameObject
|
30
30
|
|
31
31
|
def add_game_object(object)
|
32
|
-
# puts "#{self.to_s} add_game_object(#{object.to_s})"
|
33
32
|
@game_objects.add_game_object(object)
|
34
33
|
end
|
35
34
|
|
@@ -86,10 +85,16 @@ module Chingu
|
|
86
85
|
# :game_objects - an Array, game objects to save
|
87
86
|
# :classes - an Array, save only game objects of theese classes
|
88
87
|
#
|
88
|
+
# NOTE: To save a color do: :color => game_object.color.argb
|
89
|
+
#
|
89
90
|
def save_game_objects(options = {})
|
91
|
+
#
|
92
|
+
# TODO: Move this to GameObjectList#save ?
|
93
|
+
#
|
90
94
|
file = options[:file] || "#{self.class.to_s.downcase}.yml"
|
91
95
|
game_objects = options[:game_objects]
|
92
96
|
classes = options[:classes]
|
97
|
+
attributes = options[:attributes] || [:x, :y, :angle, :zorder, :factor_x, :factor_y, :alpha]
|
93
98
|
|
94
99
|
require 'yaml'
|
95
100
|
objects = []
|
@@ -97,30 +102,14 @@ module Chingu
|
|
97
102
|
# Only save specified classes, if given.
|
98
103
|
next if classes and !classes.empty? and !classes.include?(game_object.class)
|
99
104
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
:y => game_object.y,
|
104
|
-
:angle => game_object.angle,
|
105
|
-
:zorder => game_object.zorder,
|
106
|
-
:factor_x => game_object.factor_x,
|
107
|
-
:factor_y => game_object.factor_y,
|
108
|
-
:color => game_object.color.argb,
|
109
|
-
#:color => sprintf("0x%x",game_object.color.argb)
|
110
|
-
#:center_x => game_object.center_x,
|
111
|
-
#:center_y => game_object.center_y,
|
112
|
-
}
|
113
|
-
}
|
105
|
+
attr_hash = {}
|
106
|
+
attributes.each { |attr| attr_hash[attr] = game_object.send(attr) }
|
107
|
+
objects << {game_object.class.to_s => attr_hash}
|
114
108
|
end
|
115
109
|
|
116
|
-
|
117
|
-
#Marshal.dump(previous_game_state.game_objects, File.open(@filename, "w"))
|
118
|
-
File.open(file, 'w') do |out|
|
119
|
-
YAML.dump(objects, out)
|
120
|
-
end
|
110
|
+
File.open(file, 'w') { |out| YAML.dump(objects, out) }
|
121
111
|
end
|
122
112
|
|
123
|
-
|
124
113
|
end
|
125
114
|
|
126
115
|
end
|
data/lib/chingu/input.rb
CHANGED
@@ -51,6 +51,7 @@ module Chingu
|
|
51
51
|
KbLeftAlt => [:left_alt, :lalt],
|
52
52
|
KbLeftControl => [:left_control, :left_ctrl, :lctrl],
|
53
53
|
KbLeftShift => [:left_shift, :lshift],
|
54
|
+
KbLeftMeta => [:left_meta, :lmeta],
|
54
55
|
|
55
56
|
|
56
57
|
KbNumpadAdd => [:"+", :add, :plus],
|
@@ -65,6 +66,7 @@ module Chingu
|
|
65
66
|
KbRightAlt => [:right_alt, :ralt],
|
66
67
|
KbRightControl => [:right_control, :right_ctrl, :rctrl],
|
67
68
|
KbRightShift => [:right_shift, :rshift],
|
69
|
+
KbRightMeta => [:right_meta, :rmeta],
|
68
70
|
KbSpace => [:" ", :space],
|
69
71
|
KbTab => [:tabulator, :tab],
|
70
72
|
KbUp => [:up_arrow, :up],
|
@@ -26,7 +26,7 @@ module Chingu
|
|
26
26
|
# - fetch high scores, add new ones
|
27
27
|
# - Iterate through highscores with each and each_with_index
|
28
28
|
#
|
29
|
-
#
|
29
|
+
# This class is the reason for the 'crack' and 'rest_client' dependencies.
|
30
30
|
#
|
31
31
|
class OnlineHighScoreList
|
32
32
|
attr_reader :resource, :high_scores
|
@@ -37,9 +37,6 @@ module Chingu
|
|
37
37
|
@login = options[:login] || options[:user]
|
38
38
|
@password = options[:password]
|
39
39
|
@game_id = options[:game_id]
|
40
|
-
|
41
|
-
require 'rest_client'
|
42
|
-
require 'crack/xml'
|
43
40
|
@resource = RestClient::Resource.new("http://api.gamercv.com/games/#{@game_id}/high_scores",
|
44
41
|
:user => @login, :password => @password, :timeout => 20, :open_timeout => 5)
|
45
42
|
|
data/lib/chingu/rect.rb
CHANGED
@@ -189,6 +189,7 @@ class Rect < Array
|
|
189
189
|
end
|
190
190
|
|
191
191
|
# Return the x coordinate of the right side of the Rect.
|
192
|
+
# def right; return self.at(0)+self.at(2)-1; end
|
192
193
|
def right; return self.at(0)+self.at(2); end
|
193
194
|
|
194
195
|
# Set the x coordinate of the right side of the Rect by translating the
|
@@ -199,6 +200,7 @@ class Rect < Array
|
|
199
200
|
alias r= right=;
|
200
201
|
|
201
202
|
# Return the y coordinate of the bottom side of the Rect.
|
203
|
+
#def bottom; return self.at(1)+self.at(3)-1; end
|
202
204
|
def bottom; return self.at(1)+self.at(3); end
|
203
205
|
|
204
206
|
# Set the y coordinate of the bottom side of the Rect by translating the
|
@@ -616,5 +618,4 @@ class Rect < Array
|
|
616
618
|
|
617
619
|
end # class Rect
|
618
620
|
|
619
|
-
|
620
621
|
end # module Chingu
|
data/lib/chingu/window.rb
CHANGED
@@ -39,7 +39,7 @@ module Chingu
|
|
39
39
|
include Chingu::Helpers::InputClient # Window has its own inputmap
|
40
40
|
|
41
41
|
attr_reader :root, :game_state_manager, :game_objects, :milliseconds_since_last_tick
|
42
|
-
attr_accessor :factor
|
42
|
+
attr_accessor :factor, :cursor
|
43
43
|
|
44
44
|
def initialize(width = 800, height = 600, fullscreen = false, update_interval = 16.666666)
|
45
45
|
fullscreen ||= ARGV.include?("--fullscreen")
|
@@ -59,10 +59,19 @@ module Chingu
|
|
59
59
|
@game_state_manager = GameStateManager.new
|
60
60
|
@milliseconds_since_last_tick = 0
|
61
61
|
@factor = 1
|
62
|
+
@cursor = false
|
62
63
|
|
63
64
|
setup
|
64
65
|
end
|
65
66
|
|
67
|
+
#
|
68
|
+
# If this returns true, GOSU will show a cursor
|
69
|
+
# Chingu solves this with the $window.cursor = [true|false] accessor
|
70
|
+
#
|
71
|
+
def needs_cursor?
|
72
|
+
@cursor
|
73
|
+
end
|
74
|
+
|
66
75
|
# Placeholder to be overwritten
|
67
76
|
def setup; end;
|
68
77
|
|
@@ -3,9 +3,11 @@ require 'spec_helper'
|
|
3
3
|
module Chingu
|
4
4
|
|
5
5
|
describe GameObject do
|
6
|
-
|
7
|
-
before(:all) do
|
6
|
+
before :all do
|
8
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')
|
9
11
|
end
|
10
12
|
|
11
13
|
it { should respond_to(:x) }
|
@@ -19,11 +21,7 @@ module Chingu
|
|
19
21
|
it { should respond_to(:mode) }
|
20
22
|
it { should respond_to(:color) }
|
21
23
|
|
22
|
-
|
23
|
-
before do
|
24
|
-
subject { GameObject.new }
|
25
|
-
end
|
26
|
-
|
24
|
+
context "when created with defaults" do
|
27
25
|
it "should have default values" do
|
28
26
|
subject.angle.should == 0
|
29
27
|
subject.x.should == 0
|
@@ -55,32 +53,34 @@ module Chingu
|
|
55
53
|
subject.alpha = 1000
|
56
54
|
subject.alpha.should == 255
|
57
55
|
end
|
58
|
-
|
59
56
|
end
|
60
57
|
|
61
|
-
|
58
|
+
it "should raise an exception if the image fails to load" do
|
59
|
+
lambda { described_class.new(:image => "monkey_with_a_nuclear_tail.png") }.should raise_error Exception
|
60
|
+
end
|
62
61
|
|
63
|
-
|
62
|
+
context "when created with an image named in a string" do
|
63
|
+
subject { described_class.new(:image => "rect_20x20.png") }
|
64
64
|
|
65
65
|
it "should have width,height & size" do
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
subject.height.should == 20
|
67
|
+
subject.width.should == 20
|
68
|
+
subject.size.should == [20,20]
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should adapt width,height & size to scaling" do
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
subject.factor = 2
|
73
|
+
subject.height.should == 40
|
74
|
+
subject.width.should == 40
|
75
|
+
subject.size.should == [40,40]
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should adapt factor_x/factor_y to new size" do
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
subject.size = [10,40] # half the width, double the height
|
80
|
+
subject.width.should == 10
|
81
|
+
subject.height.should == 40
|
82
|
+
subject.factor_x.should == 0.5
|
83
|
+
subject.factor_y.should == 2
|
84
84
|
end
|
85
85
|
|
86
86
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chingu::Input do
|
4
|
+
it "should map all defined Gosu input constants to Chinu symbols" do
|
5
|
+
# Simpler if all the inputs are in a big hash.
|
6
|
+
input_names = Gosu.constants.select {|constant| constant =~ /^(?:Kb|Ms|Gp)/ }
|
7
|
+
input_names.delete_if {|name| name.to_s =~ /Range(?:Start|End)|Num$/ } # Special entries.
|
8
|
+
gosu_inputs = input_names.inject({}) {|hash, name| hash[name] = Gosu.const_get name; hash }
|
9
|
+
|
10
|
+
gosu_inputs.each_value do |code|
|
11
|
+
symbols = described_class::CONSTANT_TO_SYMBOL[code]
|
12
|
+
symbols.should_not be_empty
|
13
|
+
symbols.each {|s| s.should be_kind_of Symbol }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should map all Chingu symbols to Gosu input codes" do
|
18
|
+
described_class::CONSTANT_TO_SYMBOL.values.flatten.uniq.each do |symbol|
|
19
|
+
described_class::SYMBOL_TO_CONSTANT[symbol].should be_kind_of Fixnum
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chingu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
4
|
+
prerelease: true
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
- 5
|
11
|
-
version: 0.7.7.5
|
7
|
+
- 8rc1
|
8
|
+
version: 0.8rc1
|
12
9
|
platform: ruby
|
13
10
|
authors:
|
14
11
|
- ippa
|
@@ -16,7 +13,7 @@ autorequire:
|
|
16
13
|
bindir: bin
|
17
14
|
cert_chain: []
|
18
15
|
|
19
|
-
date: 2010-
|
16
|
+
date: 2010-11-14 00:00:00 +01:00
|
20
17
|
default_executable:
|
21
18
|
dependencies:
|
22
19
|
- !ruby/object:Gem::Dependency
|
@@ -27,12 +24,11 @@ dependencies:
|
|
27
24
|
requirements:
|
28
25
|
- - ">="
|
29
26
|
- !ruby/object:Gem::Version
|
30
|
-
hash: 47
|
31
27
|
segments:
|
32
28
|
- 0
|
33
29
|
- 7
|
34
|
-
-
|
35
|
-
version: 0.7.
|
30
|
+
- 24
|
31
|
+
version: 0.7.24
|
36
32
|
type: :runtime
|
37
33
|
version_requirements: *id001
|
38
34
|
- !ruby/object:Gem::Dependency
|
@@ -43,14 +39,11 @@ dependencies:
|
|
43
39
|
requirements:
|
44
40
|
- - ">="
|
45
41
|
- !ruby/object:Gem::Version
|
46
|
-
hash: -744372164
|
47
42
|
segments:
|
48
43
|
- 2
|
49
44
|
- 0
|
50
45
|
- 0
|
51
|
-
|
52
|
-
- 12
|
53
|
-
version: 2.0.0.beta.12
|
46
|
+
version: 2.0.0
|
54
47
|
type: :development
|
55
48
|
version_requirements: *id002
|
56
49
|
- !ruby/object:Gem::Dependency
|
@@ -61,7 +54,6 @@ dependencies:
|
|
61
54
|
requirements:
|
62
55
|
- - ">="
|
63
56
|
- !ruby/object:Gem::Version
|
64
|
-
hash: 3
|
65
57
|
segments:
|
66
58
|
- 0
|
67
59
|
version: "0"
|
@@ -75,12 +67,37 @@ dependencies:
|
|
75
67
|
requirements:
|
76
68
|
- - ">="
|
77
69
|
- !ruby/object:Gem::Version
|
78
|
-
hash: 3
|
79
70
|
segments:
|
80
71
|
- 0
|
81
72
|
version: "0"
|
82
73
|
type: :development
|
83
74
|
version_requirements: *id004
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rest_client
|
77
|
+
prerelease: false
|
78
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
type: :development
|
87
|
+
version_requirements: *id005
|
88
|
+
- !ruby/object:Gem::Dependency
|
89
|
+
name: crack
|
90
|
+
prerelease: false
|
91
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
type: :development
|
100
|
+
version_requirements: *id006
|
84
101
|
description: OpenGL accelerated 2D game framework for Ruby. Builds on Gosu (Ruby/C++) which provides all the core functionality. Chingu adds simple yet powerful game states, prettier input handling, deployment safe asset-handling, a basic re-usable game object and stackable game logic.
|
85
102
|
email: ippa@rubylicio.us
|
86
103
|
executables: []
|
@@ -124,6 +141,10 @@ files:
|
|
124
141
|
- examples/example21_sidescroller_with_edit.rb
|
125
142
|
- examples/example22_text.rb
|
126
143
|
- examples/example23_chipmunk.rb
|
144
|
+
- examples/example24_enter_name.rb
|
145
|
+
- examples/example24_input_codes.rb
|
146
|
+
- examples/example25.yml
|
147
|
+
- examples/example25_fibers_state_machine.rb
|
127
148
|
- examples/example2_gamestate_basics.rb
|
128
149
|
- examples/example3_parallax.rb
|
129
150
|
- examples/example4_gamestates.rb
|
@@ -191,6 +212,7 @@ files:
|
|
191
212
|
- lib/chingu/game_state_manager.rb
|
192
213
|
- lib/chingu/game_states/debug.rb
|
193
214
|
- lib/chingu/game_states/edit.rb
|
215
|
+
- lib/chingu/game_states/enter_name.rb
|
194
216
|
- lib/chingu/game_states/fade_to.rb
|
195
217
|
- lib/chingu/game_states/pause.rb
|
196
218
|
- lib/chingu/game_states/popup.rb
|
@@ -233,7 +255,7 @@ files:
|
|
233
255
|
- spec/chingu/helpers/options_setter_spec.rb
|
234
256
|
- spec/chingu/images/rect_20x20.png
|
235
257
|
- spec/chingu/inflector_spec.rb
|
236
|
-
- spec/chingu/
|
258
|
+
- spec/chingu/input_spec.rb
|
237
259
|
- spec/chingu/text_spec.rb
|
238
260
|
- spec/spec_helper.rb
|
239
261
|
- specs.watchr
|
@@ -251,19 +273,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
251
273
|
requirements:
|
252
274
|
- - ">="
|
253
275
|
- !ruby/object:Gem::Version
|
254
|
-
hash: 3
|
255
276
|
segments:
|
256
277
|
- 0
|
257
278
|
version: "0"
|
258
279
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
259
280
|
none: false
|
260
281
|
requirements:
|
261
|
-
- - "
|
282
|
+
- - ">"
|
262
283
|
- !ruby/object:Gem::Version
|
263
|
-
hash: 3
|
264
284
|
segments:
|
265
|
-
-
|
266
|
-
|
285
|
+
- 1
|
286
|
+
- 3
|
287
|
+
- 1
|
288
|
+
version: 1.3.1
|
267
289
|
requirements: []
|
268
290
|
|
269
291
|
rubyforge_project: chingu
|
@@ -278,6 +300,7 @@ test_files:
|
|
278
300
|
- spec/chingu/helpers/input_dispatcher_spec.rb
|
279
301
|
- spec/chingu/helpers/options_setter_spec.rb
|
280
302
|
- spec/chingu/inflector_spec.rb
|
303
|
+
- spec/chingu/input_spec.rb
|
281
304
|
- spec/chingu/text_spec.rb
|
282
305
|
- spec/spec_helper.rb
|
283
306
|
- examples/example10_traits_retrofy.rb
|
@@ -295,6 +318,9 @@ test_files:
|
|
295
318
|
- examples/example21_sidescroller_with_edit.rb
|
296
319
|
- examples/example22_text.rb
|
297
320
|
- examples/example23_chipmunk.rb
|
321
|
+
- examples/example24_enter_name.rb
|
322
|
+
- examples/example24_input_codes.rb
|
323
|
+
- examples/example25_fibers_state_machine.rb
|
298
324
|
- examples/example2_gamestate_basics.rb
|
299
325
|
- examples/example3_parallax.rb
|
300
326
|
- examples/example4_gamestates.rb
|
data/spec/chingu/rect_20x20.png
DELETED
Binary file
|