chingu 0.7.7.3 → 0.7.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/chingu.gemspec +2 -2
- data/examples/example6_transitional_game_state.rb +1 -1
- data/lib/chingu.rb +1 -1
- data/lib/chingu/game_object_map.rb +46 -23
- data/lib/chingu/game_state_manager.rb +3 -9
- data/lib/chingu/game_states/fade_to.rb +8 -2
- data/lib/chingu/helpers/game_state.rb +0 -4
- data/lib/chingu/traits/bounding_box.rb +5 -3
- data/lib/chingu/traits/collision_detection.rb +14 -0
- metadata +5 -5
data/chingu.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{chingu}
|
8
|
-
s.version = "0.7.7.
|
8
|
+
s.version = "0.7.7.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["ippa"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-22}
|
13
13
|
s.description = %q{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.}
|
14
14
|
s.email = %q{ippa@rubylicio.us}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -14,7 +14,7 @@ class Game < Chingu::Window
|
|
14
14
|
switch_game_state(State1)
|
15
15
|
self.input = {:space => :push, :return => :switch, :esc => :exit}
|
16
16
|
self.caption = "Example of transitional game state FadeTo when switchin between two game states"
|
17
|
-
transitional_game_state(Chingu::GameStates::FadeTo, :speed =>
|
17
|
+
transitional_game_state(Chingu::GameStates::FadeTo, {:speed => 5, :debug => true})
|
18
18
|
end
|
19
19
|
|
20
20
|
def push
|
data/lib/chingu.rb
CHANGED
@@ -53,35 +53,40 @@ module Chingu
|
|
53
53
|
|
54
54
|
@game_objects.each do |game_object|
|
55
55
|
puts "#{game_object.class} @ #{game_object.x} / #{game_object.y}" if @debug
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
56
|
+
insert(game_object)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# Insert game_object into the map
|
62
|
+
#
|
63
|
+
def insert(game_object)
|
64
|
+
start_x = ( game_object.bb.left / @grid[0] ).to_i
|
65
|
+
stop_x = ( (game_object.bb.right) / @grid[0] ).to_i
|
65
66
|
|
67
|
+
#if game_object.zorder == 80
|
68
|
+
# puts "x: #{game_object.x}, y: #{game_object.y}"
|
69
|
+
# puts "width: #{game_object.width}, height: #{game_object.height}"
|
70
|
+
# puts "start_x: #{start_x}, stop_x: #{stop_x}"
|
71
|
+
#end
|
66
72
|
|
67
|
-
|
68
|
-
|
69
|
-
|
73
|
+
(start_x ... stop_x).each do |x|
|
74
|
+
start_y = (game_object.bb.top / @grid[1] ).to_i
|
75
|
+
stop_y = ( (game_object.bb.bottom) / @grid[1] ).to_i
|
70
76
|
|
71
|
-
|
77
|
+
@game_object_positions[game_object] = [(start_x ... stop_x), (start_y ... stop_y)]
|
72
78
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
79
|
+
@map[x] ||= []
|
80
|
+
(start_y ... stop_y).each do |y|
|
81
|
+
@map[x][y] = game_object
|
77
82
|
end
|
78
|
-
end
|
83
|
+
end
|
79
84
|
end
|
80
|
-
|
85
|
+
|
81
86
|
#
|
82
87
|
# Removes a specific game object from the map
|
83
88
|
#
|
84
|
-
def
|
89
|
+
def delete(game_object)
|
85
90
|
range_x, range_y = @game_object_positions[game_object]
|
86
91
|
|
87
92
|
range_x.each do |x|
|
@@ -90,6 +95,7 @@ module Chingu
|
|
90
95
|
end
|
91
96
|
end
|
92
97
|
end
|
98
|
+
alias :clear_game_object :delete
|
93
99
|
|
94
100
|
#
|
95
101
|
# Clear game object from the array-map on a certain X/Y
|
@@ -113,17 +119,34 @@ module Chingu
|
|
113
119
|
start_x = (game_object.bb.left / @grid[0]).to_i
|
114
120
|
stop_x = (game_object.bb.right / @grid[0]).to_i
|
115
121
|
|
116
|
-
(start_x
|
122
|
+
(start_x ... stop_x).each do |x|
|
117
123
|
start_y = (game_object.bb.top / @grid[1]).to_i
|
118
124
|
stop_y = (game_object.bb.bottom / @grid[1]).to_i
|
119
125
|
|
120
|
-
(start_y
|
126
|
+
(start_y ... stop_y).each do |y|
|
121
127
|
return @map[x][y] if @map[x] && @map[x][y]
|
122
128
|
end
|
123
129
|
|
124
130
|
end
|
125
131
|
return nil
|
126
132
|
end
|
127
|
-
|
133
|
+
|
134
|
+
#
|
135
|
+
# Yields each object in the map colliding with the given game object
|
136
|
+
#
|
137
|
+
def each_collision(game_object)
|
138
|
+
start_x = (game_object.bb.left / @grid[0]).to_i
|
139
|
+
stop_x = (game_object.bb.right / @grid[0]).to_i
|
140
|
+
|
141
|
+
(start_x ... stop_x).each do |x|
|
142
|
+
start_y = (game_object.bb.top / @grid[1]).to_i
|
143
|
+
stop_y = (game_object.bb.bottom / @grid[1]).to_i
|
144
|
+
|
145
|
+
(start_y ... stop_y).each do |y|
|
146
|
+
yield @map[x][y] if @map[x] && @map[x][y] && @map[x][y] != game_object # Don't yield collisions with itself
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
128
151
|
end
|
129
152
|
end
|
@@ -49,7 +49,6 @@ module Chingu
|
|
49
49
|
@game_states = []
|
50
50
|
@transitional_game_state = nil
|
51
51
|
@transitional_game_state_options = {}
|
52
|
-
@previous_game_state = nil
|
53
52
|
end
|
54
53
|
|
55
54
|
#
|
@@ -101,8 +100,6 @@ module Chingu
|
|
101
100
|
#
|
102
101
|
def switch_game_state(state, options = {})
|
103
102
|
options = {:setup => true, :finalize => true, :transitional => true}.merge(options)
|
104
|
-
|
105
|
-
@previous_game_state = current_game_state
|
106
103
|
|
107
104
|
new_state = game_state_instance(state)
|
108
105
|
|
@@ -124,7 +121,7 @@ module Chingu
|
|
124
121
|
# If we have a transitional, switch to that instead, with new_state as first argument
|
125
122
|
transitional_game_state = @transitional_game_state.new(new_state, @transitional_game_state_options)
|
126
123
|
transitional_game_state.game_state_manager = self
|
127
|
-
self.
|
124
|
+
self.push_game_state(transitional_game_state, :transitional => false)
|
128
125
|
else
|
129
126
|
if current_game_state.nil?
|
130
127
|
@game_states << new_state
|
@@ -147,8 +144,6 @@ module Chingu
|
|
147
144
|
#
|
148
145
|
def push_game_state(state, options = {})
|
149
146
|
options = {:setup => true, :finalize => true, :transitional => true}.merge(options)
|
150
|
-
|
151
|
-
@previous_game_state = current_game_state
|
152
147
|
|
153
148
|
new_state = game_state_instance(state)
|
154
149
|
|
@@ -195,7 +190,6 @@ module Chingu
|
|
195
190
|
# Give the soon-to-be-disabled state a chance to clean up by calling finalize() on it.
|
196
191
|
#
|
197
192
|
current_game_state.finalize if current_game_state.respond_to?(:finalize) && options[:finalize]
|
198
|
-
@previous_game_state = current_game_state
|
199
193
|
|
200
194
|
#
|
201
195
|
# Activate the game state "bellow" current one with a simple Array.pop
|
@@ -213,7 +207,7 @@ module Chingu
|
|
213
207
|
# If we have a transitional, push that instead, with new_state as first argument
|
214
208
|
transitional_game_state = @transitional_game_state.new(current_game_state, @transitional_game_state_options)
|
215
209
|
transitional_game_state.game_state_manager = self
|
216
|
-
self.
|
210
|
+
self.push_game_state(transitional_game_state, :transitional => false)
|
217
211
|
end
|
218
212
|
|
219
213
|
## MOVED: self.inside_state = current_game_state
|
@@ -225,7 +219,7 @@ module Chingu
|
|
225
219
|
# Returns the previous game state. Shortcut: "previous"
|
226
220
|
#
|
227
221
|
def previous_game_state
|
228
|
-
|
222
|
+
current_game_state.previous_game_state
|
229
223
|
end
|
230
224
|
alias :previous previous_game_state
|
231
225
|
|
@@ -36,6 +36,7 @@ module Chingu
|
|
36
36
|
class FadeTo < Chingu::GameState
|
37
37
|
|
38
38
|
def initialize(new_game_state, options = {})
|
39
|
+
super(options)
|
39
40
|
@options = {:speed => 3, :zorder => INFINITY}.merge(options)
|
40
41
|
|
41
42
|
@new_game_state = new_game_state
|
@@ -45,11 +46,12 @@ module Chingu
|
|
45
46
|
|
46
47
|
def setup
|
47
48
|
@color = Gosu::Color.new(0,0,0,0)
|
48
|
-
|
49
49
|
if previous_game_state
|
50
|
+
p "* Setup: fading out" if options[:debug]
|
50
51
|
@fading_in = false
|
51
52
|
@alpha = 0.0
|
52
53
|
else
|
54
|
+
p "* Setup: fading in" if options[:debug]
|
53
55
|
@fading_in = true
|
54
56
|
@alpha = 255.0
|
55
57
|
end
|
@@ -62,7 +64,11 @@ module Chingu
|
|
62
64
|
@alpha = 0 if @alpha < 0
|
63
65
|
@alpha = 255 if @alpha > 255
|
64
66
|
|
65
|
-
|
67
|
+
if @alpha == 255
|
68
|
+
@fading_in = true
|
69
|
+
p "* Update: fading in" if options[:debug]
|
70
|
+
end
|
71
|
+
|
66
72
|
@color.alpha = @alpha.to_i
|
67
73
|
@drawn = false
|
68
74
|
end
|
@@ -58,9 +58,11 @@ module Chingu
|
|
58
58
|
|
59
59
|
width, height = self.size
|
60
60
|
|
61
|
-
if trait_options[:bounding_box][:scale]
|
62
|
-
|
63
|
-
|
61
|
+
if scale = trait_options[:bounding_box][:scale]
|
62
|
+
width_scale, height_scale = scale, scale
|
63
|
+
width_scale, height_scale = scale[0], scale[1] if scale.is_a? Array
|
64
|
+
width *= width_scale
|
65
|
+
height *= height_scale
|
64
66
|
end
|
65
67
|
|
66
68
|
x = self.x - width * self.center_x
|
@@ -154,6 +154,20 @@ module Chingu
|
|
154
154
|
|
155
155
|
|
156
156
|
module ClassMethods
|
157
|
+
#
|
158
|
+
# Yield all objects of this class that is colliding with point x,y
|
159
|
+
#
|
160
|
+
# Example:
|
161
|
+
# Enemy.each_at(sword.x, sword.y) { |enemy| enemy.die }
|
162
|
+
#
|
163
|
+
def each_at(x,y)
|
164
|
+
self.all.each do |object|
|
165
|
+
next unless object.collidable
|
166
|
+
yield object if object.respond_to?(:bb) && object.bb.collide_point?(x,y)
|
167
|
+
yield object if object.respond_to?(:radius) && Gosu.distance(object.x, object.y, x, y) < object.radius
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
157
171
|
#
|
158
172
|
# Works like each_collision but with inline-code for speedups
|
159
173
|
#
|
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:
|
4
|
+
hash: 99
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
9
|
- 7
|
10
|
-
-
|
11
|
-
version: 0.7.7.
|
10
|
+
- 4
|
11
|
+
version: 0.7.7.4
|
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-08-
|
19
|
+
date: 2010-08-22 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:
|
46
|
+
hash: 859163661
|
47
47
|
segments:
|
48
48
|
- 2
|
49
49
|
- 0
|