ippa-chingu 0.5.5 → 0.5.5.1
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/README.rdoc +1 -1
- data/chingu.gemspec +2 -2
- data/examples/example10.rb +0 -2
- data/examples/example9.rb +3 -4
- data/lib/chingu.rb +1 -1
- data/lib/chingu/animation.rb +1 -1
- data/lib/chingu/basic_game_object.rb +18 -8
- data/lib/chingu/game_object.rb +2 -3
- data/lib/chingu/game_object_list.rb +2 -0
- data/lib/chingu/traits/collision_detection.rb +15 -5
- data/lib/chingu/traits/effect.rb +2 -2
- data/lib/chingu/traits/velocity.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -65,7 +65,7 @@ For example, inside game state Menu you call push_game_state(Level). When Level
|
|
65
65
|
=== Traits
|
66
66
|
Traits are extensions (or plugins if you so will) to BasicGameObjects.
|
67
67
|
The aim is so encapsulate common behaivor into modules for easy inclusion in your game classes.
|
68
|
-
Making a trait is easy, just an ordinary module with the methods setup_trait(),
|
68
|
+
Making a trait is easy, just an ordinary module with the methods setup_trait(), update_trait() and/or draw_trait().
|
69
69
|
It currently has to be namespaced to Chingu::Traits for "has_trait" to work inside GameObject-classes.
|
70
70
|
|
71
71
|
== OTHER CLASSES / HELPERS
|
data/chingu.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{chingu}
|
5
|
-
s.version = "0.5.5"
|
5
|
+
s.version = "0.5.5.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["ippa"]
|
9
|
-
s.date = %q{2009-09-
|
9
|
+
s.date = %q{2009-09-26}
|
10
10
|
s.description = %q{Game framework built on top of the OpenGL accelerated game lib Gosu.
|
11
11
|
It adds simple yet powerful game states, prettier input handling, deployment safe asset-handling, a basic re-usable game object and automation of common task.}
|
12
12
|
s.email = ["ippa@rubylicio.us"]
|
data/examples/example10.rb
CHANGED
data/examples/example9.rb
CHANGED
@@ -11,7 +11,7 @@ class Game < Chingu::Window
|
|
11
11
|
super(800,800)
|
12
12
|
self.input = {:esc => :exit}
|
13
13
|
self.caption = "Example of game object traits 'velocity' and 'effect'"
|
14
|
-
push_game_state(
|
14
|
+
push_game_state(ParticleState)
|
15
15
|
end
|
16
16
|
|
17
17
|
def next_effect; pop_game_state; end
|
@@ -30,7 +30,7 @@ class FireCube < Chingu::GameObject
|
|
30
30
|
attr_accessor :color, :radius
|
31
31
|
|
32
32
|
def initialize(options)
|
33
|
-
super
|
33
|
+
super
|
34
34
|
@mode = :additive
|
35
35
|
|
36
36
|
# initialize with a rightwards velocity with some damping to look more realistic
|
@@ -51,7 +51,6 @@ class FireCube < Chingu::GameObject
|
|
51
51
|
|
52
52
|
def update
|
53
53
|
@color = @blue
|
54
|
-
super
|
55
54
|
end
|
56
55
|
|
57
56
|
def collides?(object2)
|
@@ -64,7 +63,7 @@ class FireCube < Chingu::GameObject
|
|
64
63
|
|
65
64
|
end
|
66
65
|
|
67
|
-
class
|
66
|
+
class ParticleState < Chingu::GameState
|
68
67
|
def setup
|
69
68
|
self.input = { :space => :new_fire_cube }
|
70
69
|
100.times { new_fire_cube }
|
data/lib/chingu.rb
CHANGED
data/lib/chingu/animation.rb
CHANGED
@@ -36,6 +36,13 @@ module Chingu
|
|
36
36
|
def initialize(options = {})
|
37
37
|
@options = options
|
38
38
|
|
39
|
+
#
|
40
|
+
# A GameObject either belong to a GameState or our mainwindow ($window)
|
41
|
+
#
|
42
|
+
if $window && $window.respond_to?(:game_state_manager)
|
43
|
+
@parent = $window.game_state_manager.inside_state || $window
|
44
|
+
end
|
45
|
+
|
39
46
|
# This will call #setup_trait on the latest trait mixed in
|
40
47
|
# which then will pass it on to the next setup_trait() with a super-call.
|
41
48
|
setup_trait(options)
|
@@ -53,13 +60,9 @@ module Chingu
|
|
53
60
|
instance = self.new(options)
|
54
61
|
|
55
62
|
#
|
56
|
-
#
|
63
|
+
# Add to parents list of game objects
|
57
64
|
#
|
58
|
-
if
|
59
|
-
if (instance.parent = $window.game_state_manager.inside_state || $window)
|
60
|
-
instance.parent.add_game_object(instance)
|
61
|
-
end
|
62
|
-
end
|
65
|
+
instance.parent.add_game_object(instance) if instance.parent
|
63
66
|
|
64
67
|
return instance
|
65
68
|
end
|
@@ -67,12 +70,19 @@ module Chingu
|
|
67
70
|
def setup_trait(options)
|
68
71
|
end
|
69
72
|
|
70
|
-
def
|
73
|
+
def update_trait
|
71
74
|
end
|
72
75
|
|
73
|
-
def
|
76
|
+
def draw_trait
|
74
77
|
end
|
75
78
|
|
79
|
+
def update
|
80
|
+
end
|
81
|
+
|
82
|
+
def draw
|
83
|
+
end
|
84
|
+
|
85
|
+
|
76
86
|
#
|
77
87
|
# Returns an array with all objects of current class.
|
78
88
|
# BasicGameObject#all is state aware so only objects belonging to the current state will be returned.
|
data/lib/chingu/game_object.rb
CHANGED
@@ -81,8 +81,8 @@ module Chingu
|
|
81
81
|
end
|
82
82
|
|
83
83
|
# Quick way of setting both center_x and center_y
|
84
|
-
def center=(
|
85
|
-
@center_x = @center_y =
|
84
|
+
def center=(center)
|
85
|
+
@center_x = @center_y = center
|
86
86
|
end
|
87
87
|
|
88
88
|
# Returns true if object is inside the game window, false if outside
|
@@ -101,7 +101,6 @@ module Chingu
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def draw
|
104
|
-
super
|
105
104
|
@image.draw_rot(@x, @y, @zorder, @angle, @center_x, @center_y, @factor_x, @factor_y, @color, @mode)
|
106
105
|
end
|
107
106
|
end
|
@@ -67,10 +67,12 @@ module Chingu
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def draw
|
70
|
+
@game_objects.each { |object| object.draw_trait }
|
70
71
|
@game_objects.each { |object| object.draw }
|
71
72
|
end
|
72
73
|
|
73
74
|
def update
|
75
|
+
@game_objects.each { |object| object.update_trait }
|
74
76
|
@game_objects.each { |object| object.update }
|
75
77
|
end
|
76
78
|
|
@@ -87,7 +87,7 @@ module Chingu
|
|
87
87
|
#
|
88
88
|
# Have bounding box follow game objects x/y
|
89
89
|
#
|
90
|
-
def
|
90
|
+
def update_trait
|
91
91
|
if defined?(@bounding_box) && @bounding_box.is_a?(Rect)
|
92
92
|
@bounding_box.x = self.x
|
93
93
|
@bounding_box.y = self.y
|
@@ -103,13 +103,23 @@ module Chingu
|
|
103
103
|
def each_collision(klasses = [])
|
104
104
|
Array(klasses).each do |klass|
|
105
105
|
klass.all.each do |object|
|
106
|
-
if object
|
107
|
-
|
108
|
-
|
106
|
+
yield(self, object) if collides?(object)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# Works like each_collsion but with inline-code for speedups
|
113
|
+
#
|
114
|
+
def each_radius_collision(klasses = [])
|
115
|
+
Array(klasses).each do |klass|
|
116
|
+
klass.all.each do |object|
|
117
|
+
yield(self, object) if distance(@x, @y, object.x, object.y) < @radius
|
109
118
|
end
|
110
119
|
end
|
111
120
|
end
|
112
121
|
|
122
|
+
|
113
123
|
|
114
124
|
module ClassMethods
|
115
125
|
|
@@ -126,7 +136,7 @@ module Chingu
|
|
126
136
|
yield object1, object2 if distance(object1.x, object1.y, object2.x, object2.y) < object1.radius
|
127
137
|
end
|
128
138
|
end
|
129
|
-
end
|
139
|
+
end
|
130
140
|
end
|
131
141
|
|
132
142
|
#
|
data/lib/chingu/traits/effect.rb
CHANGED
@@ -55,12 +55,12 @@ module Chingu
|
|
55
55
|
super
|
56
56
|
end
|
57
57
|
|
58
|
-
def
|
58
|
+
def draw_trait
|
59
59
|
puts "Effect#draw" if @effect_options[:debug]
|
60
60
|
super
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
63
|
+
def update_trait
|
64
64
|
puts "Effect#update" if @effect_options[:debug]
|
65
65
|
|
66
66
|
rotate(@rotating) if @rotating
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ippa-chingu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.5
|
4
|
+
version: 0.5.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ippa
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-26 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|