chingu 0.6 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -55,6 +55,7 @@ examples/media/spaceship.png
55
55
  examples/media/stickfigure.bmp
56
56
  examples/media/stickfigure.png
57
57
  examples/media/video_games.png
58
+ examples/media/wood.png
58
59
  lib/chingu.rb
59
60
  lib/chingu/animation.rb
60
61
  lib/chingu/assets.rb
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{chingu}
5
- s.version = "0.6"
5
+ s.version = "0.6.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-11-21}
9
+ s.date = %q{2009-11-22}
10
10
  s.description = %q{OpenGL accelerated 2D game framework for Ruby.
11
11
  Builds on the awesome Gosu (Ruby/C++) which provides all the core functionality.
12
12
  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.}
13
13
  s.email = ["ippa@rubylicio.us"]
14
14
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "benchmarks/README.txt"]
15
- s.files = ["History.txt", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "benchmarks/README.txt", "benchmarks/benchmark.rb", "benchmarks/benchmark3.rb", "benchmarks/benchmark4.rb", "benchmarks/benchmark5.rb", "benchmarks/benchmark6.rb", "benchmarks/meta_benchmark.rb", "benchmarks/meta_benchmark2.rb", "chingu.gemspec", "examples/example1.rb", "examples/example10.rb", "examples/example11.rb", "examples/example12.rb", "examples/example13.rb", "examples/example14.rb", "examples/example2.rb", "examples/example3.rb", "examples/example4.rb", "examples/example5.rb", "examples/example6.rb", "examples/example7.rb", "examples/example8.rb", "examples/example9.rb", "examples/game1.rb", "examples/high_score_list.yml", "examples/media/Parallax-scroll-example-layer-0.png", "examples/media/Parallax-scroll-example-layer-1.png", "examples/media/Parallax-scroll-example-layer-2.png", "examples/media/Parallax-scroll-example-layer-3.png", "examples/media/background1.png", "examples/media/bullet.png", "examples/media/bullet_hit.wav", "examples/media/city1.csv", "examples/media/city1.png", "examples/media/city2.png", "examples/media/droid.bmp", "examples/media/enemy_bullet.png", "examples/media/explosion.wav", "examples/media/fire_bullet.png", "examples/media/fireball.png", "examples/media/laser.wav", "examples/media/particle.png", "examples/media/plane.csv", "examples/media/plane.png", "examples/media/ruby.png", "examples/media/saucer.csv", "examples/media/saucer.gal", "examples/media/saucer.png", "examples/media/spaceship.png", "examples/media/stickfigure.bmp", "examples/media/stickfigure.png", "examples/media/video_games.png", "lib/chingu.rb", "lib/chingu/animation.rb", "lib/chingu/assets.rb", "lib/chingu/basic_game_object.rb", "lib/chingu/core_extensions.rb", "lib/chingu/fpscounter.rb", "lib/chingu/game_object.rb", "lib/chingu/game_object_list.rb", "lib/chingu/game_state.rb", "lib/chingu/game_state_manager.rb", "lib/chingu/game_states/debug.rb", "lib/chingu/game_states/edit.rb", "lib/chingu/game_states/fade_to.rb", "lib/chingu/game_states/pause.rb", "lib/chingu/helpers/game_object.rb", "lib/chingu/helpers/game_state.rb", "lib/chingu/helpers/gfx.rb", "lib/chingu/helpers/input_client.rb", "lib/chingu/helpers/input_dispatcher.rb", "lib/chingu/helpers/rotation_center.rb", "lib/chingu/high_score_list.rb", "lib/chingu/inflector.rb", "lib/chingu/input.rb", "lib/chingu/named_resource.rb", "lib/chingu/parallax.rb", "lib/chingu/particle.rb", "lib/chingu/rect.rb", "lib/chingu/require_all.rb", "lib/chingu/text.rb", "lib/chingu/traits/bounding_box.rb", "lib/chingu/traits/collision_detection.rb", "lib/chingu/traits/effect.rb", "lib/chingu/traits/radius.rb", "lib/chingu/traits/retrofy.rb", "lib/chingu/traits/timer.rb", "lib/chingu/traits/velocity.rb", "lib/chingu/window.rb"]
15
+ s.files = ["History.txt", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "benchmarks/README.txt", "benchmarks/benchmark.rb", "benchmarks/benchmark3.rb", "benchmarks/benchmark4.rb", "benchmarks/benchmark5.rb", "benchmarks/benchmark6.rb", "benchmarks/meta_benchmark.rb", "benchmarks/meta_benchmark2.rb", "chingu.gemspec", "examples/example1.rb", "examples/example10.rb", "examples/example11.rb", "examples/example12.rb", "examples/example13.rb", "examples/example14.rb", "examples/example2.rb", "examples/example3.rb", "examples/example4.rb", "examples/example5.rb", "examples/example6.rb", "examples/example7.rb", "examples/example8.rb", "examples/example9.rb", "examples/game1.rb", "examples/high_score_list.yml", "examples/media/Parallax-scroll-example-layer-0.png", "examples/media/Parallax-scroll-example-layer-1.png", "examples/media/Parallax-scroll-example-layer-2.png", "examples/media/Parallax-scroll-example-layer-3.png", "examples/media/background1.png", "examples/media/bullet.png", "examples/media/bullet_hit.wav", "examples/media/city1.csv", "examples/media/city1.png", "examples/media/city2.png", "examples/media/droid.bmp", "examples/media/enemy_bullet.png", "examples/media/explosion.wav", "examples/media/fire_bullet.png", "examples/media/fireball.png", "examples/media/laser.wav", "examples/media/particle.png", "examples/media/plane.csv", "examples/media/plane.png", "examples/media/ruby.png", "examples/media/saucer.csv", "examples/media/saucer.gal", "examples/media/saucer.png", "examples/media/spaceship.png", "examples/media/stickfigure.bmp", "examples/media/stickfigure.png", "examples/media/video_games.png", "examples/media/wood.png", "lib/chingu.rb", "lib/chingu/animation.rb", "lib/chingu/assets.rb", "lib/chingu/basic_game_object.rb", "lib/chingu/core_extensions.rb", "lib/chingu/fpscounter.rb", "lib/chingu/game_object.rb", "lib/chingu/game_object_list.rb", "lib/chingu/game_state.rb", "lib/chingu/game_state_manager.rb", "lib/chingu/game_states/debug.rb", "lib/chingu/game_states/edit.rb", "lib/chingu/game_states/fade_to.rb", "lib/chingu/game_states/pause.rb", "lib/chingu/helpers/game_object.rb", "lib/chingu/helpers/game_state.rb", "lib/chingu/helpers/gfx.rb", "lib/chingu/helpers/input_client.rb", "lib/chingu/helpers/input_dispatcher.rb", "lib/chingu/helpers/rotation_center.rb", "lib/chingu/high_score_list.rb", "lib/chingu/inflector.rb", "lib/chingu/input.rb", "lib/chingu/named_resource.rb", "lib/chingu/parallax.rb", "lib/chingu/particle.rb", "lib/chingu/rect.rb", "lib/chingu/require_all.rb", "lib/chingu/text.rb", "lib/chingu/traits/bounding_box.rb", "lib/chingu/traits/collision_detection.rb", "lib/chingu/traits/effect.rb", "lib/chingu/traits/radius.rb", "lib/chingu/traits/retrofy.rb", "lib/chingu/traits/timer.rb", "lib/chingu/traits/velocity.rb", "lib/chingu/window.rb"]
16
16
  s.homepage = %q{http://github.com/ippa/chingu/tree/master}
17
17
  s.rdoc_options = ["--main", "README.rdoc"]
18
18
  s.require_paths = ["lib"]
@@ -8,29 +8,34 @@ include Gosu
8
8
  #
9
9
  class Game < Chingu::Window
10
10
  def initialize
11
- super(600,200)
12
- self.input = { :holding_left => :camera_left,
11
+ super(600,200)
12
+ self.caption = "Chingu::Parallax example. Scroll with left/right arrows. Space for new parallax example!"
13
+ switch_game_state(Wood)
14
+ end
15
+ end
16
+
17
+ class Scroller < Chingu::GameState
18
+ def initialize(options)
19
+ super
20
+ @text_color = Color.new(0xFF000000)
21
+ end
22
+
23
+ def setup
24
+ self.input = { :holding_left => :camera_left,
13
25
  :holding_right => :camera_right,
14
26
  :holding_up => :camera_up,
15
27
  :holding_down => :camera_down,
16
- :escape => :exit }
17
-
18
- self.caption = "Chingu::Parallax example. Scroll with left/right arrows."
19
-
20
- @parallax = Chingu::Parallax.create(:x => 0, :y => 0, :center_x => 0, :center_y => 0)
21
-
22
- #
23
- # If no :zorder is given to @parallax.add_layer it defaults to first added -> lowest zorder
24
- # Everywhere the :image argument is used, theese 2 values are the Same:
25
- # 1) Image["foo.png"] 2) "foo.png"
26
- #
27
- # Notice we add layers to the parallax scroller in 3 different ways.
28
- # They all end up as ParallaxLayer-instances internally
29
- #
30
- @parallax.add_layer(:image => "Parallax-scroll-example-layer-0.png", :damping => 100, :center => 0)
31
- @parallax.add_layer(:image => "Parallax-scroll-example-layer-1.png", :damping => 10, :center => 0)
32
- @parallax << Chingu::ParallaxLayer.new(:image => "Parallax-scroll-example-layer-2.png", :damping => 5, :center => 0)
33
- @parallax << {:image => "Parallax-scroll-example-layer-3.png", :damping => 1, :center => 0} # you can also add like this
28
+ :space => :next_game_state,
29
+ :escape => :exit
30
+ }
31
+ end
32
+
33
+ def next_game_state
34
+ if current_game_state.class == Wood
35
+ switch_game_state(Jungle)
36
+ else
37
+ switch_game_state(Wood)
38
+ end
34
39
  end
35
40
 
36
41
  def camera_left
@@ -51,8 +56,38 @@ class Game < Chingu::Window
51
56
  def camera_down
52
57
  # This is essentially the same as @parallax.y -= 2
53
58
  @parallax.camera_y += 2
59
+ end
60
+ end
61
+
62
+ class Wood < Scroller
63
+ def initialize(options = {})
64
+ super
65
+ @parallax = Chingu::Parallax.create(:x => 0, :y => 0, :rotation_center => :top_left)
66
+ @parallax << { :image => "wood.png", :repeat_x => true, :repeat_y => true}
67
+ Chingu::Text.create("82x64 image with repeat_x and repeat_y set to TRUE", :x => 0, :y => 0, :size => 30, :color => @text_color)
54
68
  end
69
+ end
55
70
 
71
+ class Jungle < Scroller
72
+ def initialize(options = {})
73
+ super
74
+ @parallax = Chingu::Parallax.create(:x => 0, :y => 0, :rotation_center => :top_left)
75
+
76
+ #
77
+ # If no :zorder is given to @parallax.add_layer it defaults to first added -> lowest zorder
78
+ # Everywhere the :image argument is used, theese 2 values are the Same:
79
+ # 1) Image["foo.png"] 2) "foo.png"
80
+ #
81
+ # Notice we add layers to the parallax scroller in 3 different ways.
82
+ # They all end up as ParallaxLayer-instances internally
83
+ #
84
+ @parallax.add_layer(:image => "Parallax-scroll-example-layer-0.png", :damping => 100)
85
+ @parallax.add_layer(:image => "Parallax-scroll-example-layer-1.png", :damping => 10)
86
+ @parallax << Chingu::ParallaxLayer.new(:image => "Parallax-scroll-example-layer-2.png", :damping => 5, :parallax => @parallax)
87
+ @parallax << {:image => "Parallax-scroll-example-layer-3.png", :damping => 1}
88
+
89
+ Chingu::Text.create("Multiple layers with repeat_x set to TRUE", :x => 0, :y => 0, :size => 30, :color => @text_color)
90
+ end
56
91
  end
57
92
 
58
93
  Game.new.show
Binary file
@@ -28,7 +28,7 @@ require File.join(CHINGU_ROOT,"chingu","require_all") # Thanks to http://github.
28
28
  require_all "#{CHINGU_ROOT}/chingu"
29
29
 
30
30
  module Chingu
31
- VERSION = "0.6"
31
+ VERSION = "0.6.1"
32
32
 
33
33
  DEBUG_COLOR = Gosu::Color.new(0xFFFF0000)
34
34
  DEBUG_ZORDER = 9999
@@ -28,7 +28,7 @@ module Chingu
28
28
  #
29
29
  class GameObject < Chingu::BasicGameObject
30
30
  attr_accessor :image, :x, :y, :angle, :center_x, :center_y, :factor_x, :factor_y, :color, :mode, :zorder
31
- attr_reader :factor, :center
31
+ attr_reader :factor, :center#, :rotation_center
32
32
 
33
33
  include Chingu::Helpers::InputClient # Adds input and input=
34
34
  include Chingu::Helpers::RotationCenter # Adds easy and verbose modification of @center_x and @center_y
@@ -48,13 +48,16 @@ module Chingu
48
48
  @y = options[:y] || 0
49
49
  @angle = options[:angle] || 0
50
50
 
51
-
52
51
  self.factor = options[:factor] || 1.0
53
52
  @factor_x = options[:factor_x] if options[:factor_x]
54
53
  @factor_y = options[:factor_y] if options[:factor_y]
55
54
 
56
- self.center = options[:center] || 0.5
55
+ self.center = options[:center] || 0.5
56
+
57
+
58
+ @rotation_center = options[:rotation_center]
57
59
  self.rotation_center(options[:rotation_center]) if options[:rotation_center]
60
+
58
61
  @center_x = options[:center_x] if options[:center_x]
59
62
  @center_y = options[:center_y] if options[:center_y]
60
63
 
@@ -40,7 +40,9 @@ module Chingu
40
40
  #
41
41
  def initialize(options = {})
42
42
  super(options)
43
- @repeat = options[:repeat] || true
43
+ @repeat_x = options[:repeat_x] || true
44
+ @repeat_y = options[:repeat_y] || false
45
+
44
46
  @layers = Array.new
45
47
  end
46
48
 
@@ -50,7 +52,7 @@ module Chingu
50
52
  # @parallax << {:image => "landscape.png", :damping => 1}
51
53
  #
52
54
  def add_layer(arg)
53
- @layers << (arg.is_a?(ParallaxLayer) ? arg : ParallaxLayer.new(arg))
55
+ @layers << (arg.is_a?(ParallaxLayer) ? arg : ParallaxLayer.new(arg.merge({:parallax => self})))
54
56
  end
55
57
  alias << add_layer
56
58
 
@@ -108,7 +110,10 @@ module Chingu
108
110
  layer.y = @y / layer.damping
109
111
 
110
112
  # This is the magic that repeats the layer to the left and right
111
- layer.x -= layer.image.width while layer.x > 0
113
+ layer.x -= layer.image.width while (layer.repeat_x && layer.x > 0)
114
+
115
+ # This is the magic that repeats the layer to the left and right
116
+ layer.y -= layer.image.height while (layer.repeat_y && layer.y > 0)
112
117
  end
113
118
  end
114
119
 
@@ -119,14 +124,29 @@ module Chingu
119
124
  @layers.each do |layer|
120
125
  layer.draw
121
126
 
122
- save_x = layer.x
127
+ save_x, save_y = layer.x, layer.y
123
128
 
124
- ## If layer lands inside our screen, repeat it
125
- while (layer.x + layer.image.width) < $window.width
129
+ # If layer lands inside our window and repeat_x is true (defaults to true), draw it until window ends
130
+ while layer.repeat_x && layer.x < $window.width
131
+ while layer.repeat_y && layer.y < $window.height
132
+ layer.y += layer.image.height
133
+ layer.draw
134
+ end
135
+ layer.y = save_y
136
+
126
137
  layer.x += layer.image.width
127
138
  layer.draw
128
139
  end
129
-
140
+
141
+ # Special loop for when repeat_y is set but not repeat_x
142
+ if layer.repeat_y && !layer.repeat_x
143
+ while layer.repeat_y && layer.y < $window.height
144
+ layer.y += layer.image.height
145
+ layer.draw
146
+ end
147
+ end
148
+
149
+
130
150
  layer.x = save_x
131
151
  end
132
152
  self
@@ -143,17 +163,33 @@ module Chingu
143
163
  class ParallaxLayer < Chingu::GameObject
144
164
  @@zorder_counter = 0
145
165
  attr_reader :damping
166
+ attr_accessor :repeat_x, :repeat_y
146
167
 
147
- def initialize(options)
168
+ def initialize(options)
169
+ @parallax = options[:parallax]
148
170
  # No auto update/draw, the parentclass Parallax takes care of that!
149
171
  options.merge!(:visible => false, :paused => true)
172
+
173
+ options = {:rotation_center => @parallax.options[:rotation_center]}.merge(options) if @parallax
174
+
175
+ #
176
+ # Default arguments for repeat_x and repeat_y
177
+ # If no zorder is given, use a global incrementing counter.
178
+ # First added, furthest behind when drawn.
179
+ #
180
+ options = {
181
+ :repeat_x => true,
182
+ :repeat_y => false,
183
+ :zorder => (@@zorder_counter+=1)
184
+ }.merge(options)
185
+
150
186
 
151
- # If no zorder is given, use a global incrementing counter. First added, furthest behind when drawn.
152
- options.merge!(:zorder => (@@zorder_counter+=1)) if options[:zorder].nil?
187
+ @repeat_x = options[:repeat_x]
188
+ @repeat_y = options[:repeat_y]
153
189
 
154
190
  super(options)
155
191
 
156
- @damping = options[:damping] || 10
192
+ @damping = options[:damping] || 1
157
193
  end
158
194
 
159
195
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chingu
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.6"
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ippa
@@ -30,7 +30,7 @@ cert_chain:
30
30
  hxtMlw==
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2009-11-21 00:00:00 +01:00
33
+ date: 2009-11-22 00:00:00 +01:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
@@ -115,6 +115,7 @@ files:
115
115
  - examples/media/stickfigure.bmp
116
116
  - examples/media/stickfigure.png
117
117
  - examples/media/video_games.png
118
+ - examples/media/wood.png
118
119
  - lib/chingu.rb
119
120
  - lib/chingu/animation.rb
120
121
  - lib/chingu/assets.rb
metadata.gz.sig CHANGED
Binary file