ippa-chingu 0.5.3 → 0.5.4
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/LICENSE +504 -0
- data/Manifest.txt +6 -2
- data/README.rdoc +7 -6
- data/benchmarks/benchmark5.rb +29 -0
- data/chingu.gemspec +3 -3
- data/examples/example10.rb +71 -0
- data/examples/example9.rb +25 -14
- data/lib/chingu.rb +24 -47
- data/lib/chingu/basic_game_object.rb +6 -50
- data/lib/chingu/core_extensions.rb +22 -0
- data/lib/chingu/effects.rb +22 -0
- data/lib/chingu/fpscounter.rb +22 -0
- data/lib/chingu/game_object.rb +24 -1
- data/lib/chingu/game_state.rb +22 -0
- data/lib/chingu/game_state_manager.rb +22 -0
- data/lib/chingu/game_states/debug.rb +22 -0
- data/lib/chingu/game_states/fade_to.rb +22 -0
- data/lib/chingu/game_states/pause.rb +23 -0
- data/lib/chingu/gfx_helpers.rb +22 -0
- data/lib/chingu/helpers.rb +22 -0
- data/lib/chingu/inflector.rb +22 -0
- data/lib/chingu/require_all.rb +133 -0
- data/lib/chingu/traits/collision_detection.rb +98 -5
- data/lib/chingu/traits/effect.rb +89 -56
- data/lib/chingu/traits/effect_module.rb +86 -0
- data/lib/chingu/traits/input.rb +23 -0
- data/lib/chingu/traits/rotation_center.rb +22 -0
- data/lib/chingu/traits/velocity.rb +52 -44
- data/lib/chingu/traits/velocity_module.rb +44 -0
- data/lib/chingu/window.rb +1 -1
- metadata +8 -4
- data/lib/chingu/traits/deprecated_module_visual.rb +0 -108
- data/lib/chingu/traits/deprecated_visual.rb +0 -100
data/lib/chingu/traits/effect.rb
CHANGED
@@ -1,6 +1,28 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# Chingu -- Game framework built on top of the opengl accelerated gamelib Gosu
|
4
|
+
# Copyright (C) 2009 ippa / ippa@rubylicio.us
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License as published by the Free Software Foundation; either
|
9
|
+
# version 2.1 of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This library is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this library; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
#
|
20
|
+
#++
|
21
|
+
|
22
|
+
|
1
23
|
module Chingu
|
2
24
|
module Traits
|
3
|
-
|
25
|
+
module Effect
|
4
26
|
#
|
5
27
|
# Adds .rotating .fading and .zooming to any GameObject.
|
6
28
|
#
|
@@ -12,69 +34,80 @@ module Chingu
|
|
12
34
|
# factor <-> growth? scale? automatic_zoom?
|
13
35
|
# alpha <-> fade
|
14
36
|
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
37
|
+
attr_accessor :rotating, :fading, :zooming
|
38
|
+
|
39
|
+
#def self.initialize_trait(options)
|
40
|
+
# @effect_options = {:debug => false}.merge(options)
|
41
|
+
# puts "Effect#initialize" if @effect_options[:debug]
|
42
|
+
# super
|
43
|
+
#end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Setup
|
47
|
+
#
|
48
|
+
def setup_trait(options)
|
49
|
+
@effect_options = {:debug => false}.merge(options)
|
50
|
+
puts "Effect#setup" if @effect_options[:debug]
|
51
|
+
|
52
|
+
@rotating = options[:rotating] || nil
|
53
|
+
@zooming = options[:zooming] || nil
|
54
|
+
@fading = options[:fading] || nil
|
55
|
+
super
|
56
|
+
end
|
57
|
+
|
58
|
+
def draw
|
59
|
+
puts "Effect#draw" if @effect_options[:debug]
|
60
|
+
super
|
61
|
+
end
|
62
|
+
|
63
|
+
def update
|
64
|
+
puts "Effect#update" if @effect_options[:debug]
|
65
|
+
|
66
|
+
rotate(@rotating) if @rotating
|
67
|
+
fade(@fading) if @fading
|
68
|
+
zoom(@zooming) if @zooming
|
69
|
+
super
|
70
|
+
end
|
71
|
+
|
72
|
+
# Zoom - increase @factor_x and @factor_y at the same time.
|
73
|
+
def zoom(amount = 0.1)
|
74
|
+
@factor_x += amount
|
75
|
+
@factor_y += amount
|
76
|
+
end
|
25
77
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
78
|
+
# Zoom Out - decrease @factor_x and @factor_y at the same time.
|
79
|
+
def zoom_out(amount = 0.1)
|
80
|
+
@factor_x -= amount
|
81
|
+
@factor_y -= amount
|
82
|
+
end
|
31
83
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
84
|
+
# Rotate object 'amount' degrees
|
85
|
+
def rotate(amount = 1)
|
86
|
+
@angle += amount
|
87
|
+
end
|
36
88
|
|
37
|
-
|
38
|
-
|
39
|
-
|
89
|
+
# Fade object by decreasing/increasing color.alpha
|
90
|
+
def fade(amount = 1)
|
91
|
+
return if amount == 0
|
40
92
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Fade out objects color by decreasing color.alpha
|
50
|
-
def fade_out(amount = 1)
|
51
|
-
fade(-amount)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Fade in objects color by increasing color.alpha
|
55
|
-
def fade_in(amount = 1)
|
56
|
-
fade(amount)
|
57
|
-
end
|
93
|
+
new_alpha = @color.alpha + amount
|
94
|
+
if amount < 0
|
95
|
+
@color.alpha = [0, new_alpha].max
|
96
|
+
else
|
97
|
+
@color.alpha = [0, new_alpha].min
|
58
98
|
end
|
59
99
|
end
|
60
|
-
|
61
|
-
#
|
62
|
-
|
63
|
-
|
64
|
-
def setup(parent_instance, options)
|
65
|
-
@parent_instance = parent_instance
|
66
|
-
@parent_instance.instance_eval do
|
67
|
-
@rotating = options[:rotating] || nil
|
68
|
-
@zooming = options[:zooming] || nil
|
69
|
-
@fading = options[:fading] || nil
|
70
|
-
end
|
100
|
+
|
101
|
+
# Fade out objects color by decreasing color.alpha
|
102
|
+
def fade_out(amount = 1)
|
103
|
+
fade(-amount)
|
71
104
|
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
parent.zoom(parent.zooming) if parent.zooming
|
105
|
+
|
106
|
+
# Fade in objects color by increasing color.alpha
|
107
|
+
def fade_in(amount = 1)
|
108
|
+
fade(amount)
|
77
109
|
end
|
110
|
+
|
78
111
|
end
|
79
112
|
end
|
80
113
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Chingu
|
2
|
+
module Traits
|
3
|
+
module Effect
|
4
|
+
#
|
5
|
+
# Adds .rotating .fading and .zooming to any GameObject.
|
6
|
+
#
|
7
|
+
# TODO: better naming? suggestions:
|
8
|
+
#
|
9
|
+
# basic gosu unit <-> automation name
|
10
|
+
# ==============================================
|
11
|
+
# angle <-> rotation? rotating? automatic_angle?
|
12
|
+
# factor <-> growth? scale? automatic_zoom?
|
13
|
+
# alpha <-> fade
|
14
|
+
#
|
15
|
+
attr_accessor :rotating, :fading, :zooming
|
16
|
+
|
17
|
+
def initialize(options)
|
18
|
+
puts "Effect#initialize"
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
# Zoom - increase @factor_x and @factor_y at the same time.
|
23
|
+
def zoom(amount = 0.1)
|
24
|
+
@factor_x += amount
|
25
|
+
@factor_y += amount
|
26
|
+
end
|
27
|
+
|
28
|
+
# Zoom Out - decrease @factor_x and @factor_y at the same time.
|
29
|
+
def zoom_out(amount = 0.1)
|
30
|
+
@factor_x -= amount
|
31
|
+
@factor_y -= amount
|
32
|
+
end
|
33
|
+
|
34
|
+
# Rotate object 'amount' degrees
|
35
|
+
def rotate(amount = 1)
|
36
|
+
@angle += amount
|
37
|
+
end
|
38
|
+
|
39
|
+
# Fade object by decreasing/increasing color.alpha
|
40
|
+
def fade(amount = 1)
|
41
|
+
return if amount == 0
|
42
|
+
|
43
|
+
new_alpha = @color.alpha + amount
|
44
|
+
if amount < 0
|
45
|
+
@color.alpha = [0, new_alpha].max
|
46
|
+
else
|
47
|
+
@color.alpha = [0, new_alpha].min
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Fade out objects color by decreasing color.alpha
|
52
|
+
def fade_out(amount = 1)
|
53
|
+
fade(-amount)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Fade in objects color by increasing color.alpha
|
57
|
+
def fade_in(amount = 1)
|
58
|
+
fade(amount)
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Setup
|
63
|
+
#
|
64
|
+
def setup(options)
|
65
|
+
puts "Effect#setup"
|
66
|
+
@rotating = options[:rotating] || nil
|
67
|
+
@zooming = options[:zooming] || nil
|
68
|
+
@fading = options[:fading] || nil
|
69
|
+
super
|
70
|
+
end
|
71
|
+
|
72
|
+
def draw
|
73
|
+
puts "Effect#draw"
|
74
|
+
super
|
75
|
+
end
|
76
|
+
|
77
|
+
def update
|
78
|
+
puts "Effect#update"
|
79
|
+
rotate(@rotating) if @rotating
|
80
|
+
fade(@fading) if @fading
|
81
|
+
zoom(@zooming) if @zooming
|
82
|
+
super
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/chingu/traits/input.rb
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# Chingu -- Game framework built on top of the opengl accelerated gamelib Gosu
|
4
|
+
# Copyright (C) 2009 ippa / ippa@rubylicio.us
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License as published by the Free Software Foundation; either
|
9
|
+
# version 2.1 of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This library is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this library; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
#
|
20
|
+
#++
|
21
|
+
|
22
|
+
|
1
23
|
module Chingu
|
2
24
|
module Traits
|
3
25
|
module Input
|
@@ -10,6 +32,7 @@ module Chingu
|
|
10
32
|
def input
|
11
33
|
@input
|
12
34
|
end
|
35
|
+
|
13
36
|
end
|
14
37
|
end
|
15
38
|
end
|
@@ -1,3 +1,25 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# Chingu -- Game framework built on top of the opengl accelerated gamelib Gosu
|
4
|
+
# Copyright (C) 2009 ippa / ippa@rubylicio.us
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License as published by the Free Software Foundation; either
|
9
|
+
# version 2.1 of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This library is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this library; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
#
|
20
|
+
#++
|
21
|
+
|
22
|
+
|
1
23
|
module Chingu
|
2
24
|
module Traits
|
3
25
|
module RotationCenter
|
@@ -1,59 +1,67 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# Chingu -- Game framework built on top of the opengl accelerated gamelib Gosu
|
4
|
+
# Copyright (C) 2009 ippa / ippa@rubylicio.us
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License as published by the Free Software Foundation; either
|
9
|
+
# version 2.1 of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This library is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this library; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
#
|
20
|
+
#++
|
21
|
+
|
22
|
+
|
1
23
|
module Chingu
|
2
24
|
module Traits
|
3
25
|
#
|
4
|
-
# A chingu
|
26
|
+
# A chingu trait providing velocity and acceleration logic.
|
5
27
|
#
|
6
|
-
|
28
|
+
module Velocity
|
29
|
+
attr_accessor :velocity_x, :velocity_y, :acceleration_x, :acceleration_y, :max_velocity
|
7
30
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@parent_instance.instance_eval do
|
25
|
-
@velocity_x = options[:velocity_x] || 0
|
26
|
-
@velocity_y = options[:velocity_y] || 0
|
27
|
-
@acceleration_x = options[:acceleration_x] || 0
|
28
|
-
@acceleration_y = options[:acceleration_y] || 0
|
29
|
-
@max_velocity = options[:max_velocity] || 1000
|
30
|
-
end
|
31
|
+
#def self.initialize_trait(options)
|
32
|
+
# @velocity_options = {:debug => false}.merge(options)
|
33
|
+
# puts "Velocity#initialize" if @velocity_options[:debug]
|
34
|
+
# super
|
35
|
+
#end
|
36
|
+
|
37
|
+
def setup_trait(options)
|
38
|
+
@velocity_options = {:debug => false}.merge(options)
|
39
|
+
puts "Velocity#setup" if @velocity_options[:debug]
|
40
|
+
|
41
|
+
@velocity_x = options[:velocity_x] || 0
|
42
|
+
@velocity_y = options[:velocity_y] || 0
|
43
|
+
@acceleration_x = options[:acceleration_x] || 0
|
44
|
+
@acceleration_y = options[:acceleration_y] || 0
|
45
|
+
@max_velocity = options[:max_velocity] || 1000
|
46
|
+
super
|
31
47
|
end
|
32
48
|
|
33
49
|
#
|
34
50
|
# Modifies X & Y of parent
|
35
51
|
#
|
36
|
-
def update
|
37
|
-
#
|
38
|
-
# This is slower oddly enough?
|
39
|
-
#
|
40
|
-
#parent.velocity_y += parent.acceleration_y if (parent.velocity_y + parent.acceleration_y).abs < parent.max_velocity
|
41
|
-
#parent.velocity_x += parent.acceleration_x if (parent.velocity_x + parent.acceleration_x).abs < parent.max_velocity
|
42
|
-
#parent.y += parent.velocity_y
|
43
|
-
#parent.x += parent.velocity_x
|
52
|
+
def update
|
53
|
+
puts "Velocity#update" if @velocity_options[:debug]
|
44
54
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
#vel_x = (@velocity_x + @acceleration_x).abs
|
51
|
-
#@velocity_x = vel_x if vel_x < @max_velocity
|
52
|
-
|
53
|
-
@y += @velocity_y
|
54
|
-
@x += @velocity_x
|
55
|
-
end
|
55
|
+
@velocity_y += @acceleration_y if (@velocity_y + @acceleration_y).abs < @max_velocity
|
56
|
+
@velocity_x += @acceleration_x if (@velocity_x + @acceleration_x).abs < @max_velocity
|
57
|
+
@y += @velocity_y
|
58
|
+
@x += @velocity_x
|
59
|
+
super
|
56
60
|
end
|
61
|
+
|
62
|
+
def stop
|
63
|
+
@acceleration_y = @acceleration_x = @velocity_y = @acceleration_y = 0
|
64
|
+
end
|
57
65
|
end
|
58
66
|
end
|
59
67
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Chingu
|
2
|
+
module Traits
|
3
|
+
#
|
4
|
+
# A chingu component providing velocity and acceleration logic.
|
5
|
+
#
|
6
|
+
module Velocity
|
7
|
+
attr_accessor :velocity_x, :velocity_y, :acceleration_x, :acceleration_y, :max_velocity
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
puts "Velocity#initialize"
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def stop
|
15
|
+
@acceleration_y = @acceleration_x = @velocity_y = @acceleration_y = 0
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Setup
|
20
|
+
#
|
21
|
+
def setup(options)
|
22
|
+
puts "Velocity#setup"
|
23
|
+
@velocity_x = options[:velocity_x] || 0
|
24
|
+
@velocity_y = options[:velocity_y] || 0
|
25
|
+
@acceleration_x = options[:acceleration_x] || 0
|
26
|
+
@acceleration_y = options[:acceleration_y] || 0
|
27
|
+
@max_velocity = options[:max_velocity] || 1000
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Modifies X & Y of parent
|
33
|
+
#
|
34
|
+
def update
|
35
|
+
puts "Velocity#update"
|
36
|
+
@velocity_y += @acceleration_y if (@velocity_y + @acceleration_y).abs < @max_velocity
|
37
|
+
@velocity_x += @acceleration_x if (@velocity_x + @acceleration_x).abs < @max_velocity
|
38
|
+
@y += @velocity_y
|
39
|
+
@x += @velocity_x
|
40
|
+
super
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|