chingu 0.5.7.1 → 0.5.8

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.tar.gz.sig CHANGED
Binary file
@@ -35,6 +35,7 @@ examples/media/bullet_hit.wav
35
35
  examples/media/city1.csv
36
36
  examples/media/city1.png
37
37
  examples/media/city2.png
38
+ examples/media/droid.bmp
38
39
  examples/media/enemy_bullet.png
39
40
  examples/media/explosion.wav
40
41
  examples/media/fire_bullet.png
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{chingu}
5
- s.version = "0.5.7.1"
5
+ s.version = "0.5.8"
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-10-15}
9
+ s.date = %q{2009-10-18}
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"]
13
13
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "benchmarks/README.txt"]
14
- 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/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/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/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/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/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/collision_detection.rb", "lib/chingu/traits/effect.rb", "lib/chingu/traits/retrofy.rb", "lib/chingu/traits/timer.rb", "lib/chingu/traits/velocity.rb", "lib/chingu/window.rb"]
14
+ 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/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/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/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/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/collision_detection.rb", "lib/chingu/traits/effect.rb", "lib/chingu/traits/retrofy.rb", "lib/chingu/traits/timer.rb", "lib/chingu/traits/velocity.rb", "lib/chingu/window.rb"]
15
15
  s.homepage = %q{http://github.com/ippa/chingu/tree/master}
16
16
  s.rdoc_options = ["--main", "README.rdoc"]
17
17
  s.require_paths = ["lib"]
@@ -52,7 +52,7 @@ class Thing < Chingu::GameObject
52
52
 
53
53
 
54
54
  self.factor = 8
55
- self.rotating = 2
55
+ self.rotation_rate = 2
56
56
  self.velocity_x = 2
57
57
  end
58
58
 
@@ -60,7 +60,7 @@ class Thing < Chingu::GameObject
60
60
  puts "Thing#update"
61
61
  if outside_window?
62
62
  @velocity_x = -@velocity_x
63
- @rotating = -@rotating
63
+ self.rotation_rate = -self.rotation_rate
64
64
  end
65
65
  end
66
66
 
@@ -1,51 +1,92 @@
1
1
  require 'rubygems'
2
+ require 'opengl'
2
3
  require File.join(File.dirname($0), "..", "lib", "chingu")
3
4
  include Gosu
5
+ include Chingu
4
6
 
5
7
  #
6
- # Parallax-example
7
- # Images from http://en.wikipedia.org/wiki/Parallax_scrolling
8
+ # Animation / retrofy example
8
9
  #
9
10
  class Game < Chingu::Window
11
+ attr_reader :factor
12
+
10
13
  def initialize
11
14
  super
12
- self.input = { :holding_left => :scroll_left,
13
- :holding_right => :scroll_right,
14
- :holding_up => :scroll_up,
15
- :holding_down => :scroll_down,
16
- :escape => :exit }
17
-
18
- self.caption = "Chingu::Parallax example. Scroll with left/right arrows."
15
+ @factor = 6
16
+ self.input = { :escape => :exit }
17
+ self.caption = "Chingu::Animation / retrofy example. Move with arrows!"
18
+ Droid.create(:x => $window.width/@factor/2, :y => $window.height/@factor/2)
19
+ end
20
+ end
21
+
22
+ class Droid < Chingu::GameObject
23
+ has_trait :retrofy # modifies draw(),
24
+
25
+ def initialize(options = {})
26
+ super
19
27
 
20
- @parallax = Chingu::Parallax.create(:x => 0, :y => 0, :center_x => 0, :center_y => 0)
28
+ self.input = { :holding_left => :left,
29
+ :holding_right => :right,
30
+ :holding_up => :up,
31
+ :holding_down => :down }
21
32
 
22
- #
23
- # If no :zorder is given to @parallax.add_background 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
- # TODO: scrolling to left borks outm, fix. + get rid of center_x / center_y args in a clean way.
28
- @parallax << {:image => "paralaxx2", :damping => 100, :center => 0)
29
- @parallax << {:image => "parallax-scroll-example-layer-1.png", :damping => 10, :center => 0)
30
- @parallax << {:image => "paralaxx2.png", :damping => 5, :center => 0)
33
+ # Load the full animation from tile-file media/droid.bmp
34
+ @full_animation = Chingu::Animation.new(:file => "droid.bmp", :size => [11,16]).retrofy
35
+
36
+ # Create new animations from specific frames and stuff them into easy to access hash
37
+ @animations = {}
38
+ @animations[:scan] = @full_animation[0..5]
39
+ @animations[:up] = @full_animation[6..7]
40
+ @animations[:down] = @full_animation[8..9]
41
+ @animations[:left] = @full_animation[10..11]
42
+ @animations[:right] = @full_animation[12..13]
43
+
44
+ # Start out by animation frames 0-5 (contained by @animations[:scan])
45
+ @animation = @animations[:scan]
46
+
47
+ self.factor = $window.factor
48
+ @last_x, @last_y = @x, @y
49
+ update
31
50
  end
32
-
33
- def scroll_left
34
- @parallax.x -= 2
51
+
52
+ def left
53
+ @x -= 1
54
+ @animation = @animations[:left]
35
55
  end
36
-
37
- def scroll_right
38
- @parallax.x += 2
39
- end
40
-
41
- def scroll_up
42
- @parallax.y -= 2
56
+
57
+ def right
58
+ @x += 1
59
+ @animation = @animations[:right]
60
+ end
61
+
62
+ def up
63
+ @y -= 1
64
+ @animation = @animations[:up]
65
+ end
66
+
67
+ def down
68
+ @y += 1
69
+ @animation = @animations[:down]
70
+ end
71
+
72
+ # We don't need to call super() in update().
73
+ # By default GameObject#update is empty since it doesn't contain any gamelogic to speak of.
74
+ def update
75
+
76
+ # Move the animation forward by fetching the next frame and putting it into @image
77
+ # @image is drawn by default by GameObject#draw
78
+ @image = @animation.next
79
+
80
+ #
81
+ # If droid stands still, use the scanning animation
82
+ #
83
+ if @x == @last_x && @y == @last_y
84
+ @animation = @animations[:scan]
85
+ end
86
+
87
+ @x, @y = @last_x, @last_y if outside_window? # return to previous coordinates if outside window
88
+ @last_x, @last_y = @x, @y # save current coordinates for possible use next time
43
89
  end
44
-
45
- def scroll_down
46
- @parallax.y += 2
47
- end
48
-
49
90
  end
50
91
 
51
92
  Game.new.show
@@ -1,5 +1,4 @@
1
1
  require 'rubygems'
2
- require 'devil'
3
2
  require File.join(File.dirname($0), "..", "lib", "chingu")
4
3
  include Gosu
5
4
 
@@ -90,9 +90,9 @@ class Particles < Chingu::GameState
90
90
  Chingu::Particle.create( :x => 100,
91
91
  :y => @ground_y,
92
92
  :animation => @fireball_animation,
93
- :zooming => +0.05,
94
- :fading => -10,
95
- :rotating => +1,
93
+ :scale_rate => +0.05,
94
+ :fade_rate => -10,
95
+ :rotation_rate => +1,
96
96
  :mode => :default
97
97
  )
98
98
 
@@ -102,9 +102,9 @@ class Particles < Chingu::GameState
102
102
  Chingu::Particle.create( :x => 300,
103
103
  :y => @ground_y,
104
104
  :animation => @fireball_animation,
105
- :zooming => +0.2,
106
- :fading => -4,
107
- :rotating => +3,
105
+ :scale_rate => +0.2,
106
+ :fade_rate => -4,
107
+ :rotation_rate => +3,
108
108
  :mode => :default
109
109
  )
110
110
  #
@@ -4,7 +4,7 @@ include Gosu
4
4
  include Chingu
5
5
 
6
6
  #
7
- # Demonstrating domponents "velocity" and "effect"
7
+ # Demonstrating traits "velocity" and "effect"
8
8
  #
9
9
  class Game < Chingu::Window
10
10
  def initialize
@@ -19,7 +19,8 @@ class Game < Chingu::Window
19
19
  end
20
20
 
21
21
  class Plasma < Chingu::GameObject
22
- has_traits :velocity, :effect
22
+ has_traits :velocity
23
+ attr_accessor :fade_rate
23
24
 
24
25
  def initialize(options)
25
26
  super
@@ -32,7 +33,11 @@ class Plasma < Chingu::GameObject
32
33
 
33
34
  # Simulate gravity
34
35
  @acceleration_y = 0.4
35
- end
36
+ end
37
+
38
+ def update
39
+ self.alpha -= @fade_rate if defined?(@fade_rate)
40
+ end
36
41
  end
37
42
 
38
43
  class Particles < Chingu::GameState
@@ -85,7 +90,7 @@ class Particles < Chingu::GameState
85
90
  end
86
91
 
87
92
  # 3) Start fading the alphachannel
88
- particle.fading = -3
93
+ particle.fade_rate = 3
89
94
  end
90
95
  end
91
96
 
@@ -4,7 +4,7 @@ include Gosu
4
4
  include Chingu
5
5
 
6
6
  #
7
- # Demonstrating domponents "velocity" and "effect"
7
+ # Demonstrating traits "velocity" and "collision_detection"
8
8
  #
9
9
  class Game < Chingu::Window
10
10
  def initialize
@@ -19,7 +19,6 @@ end
19
19
 
20
20
  class FireCube < Chingu::GameObject
21
21
  has_trait :velocity
22
- has_trait :effect
23
22
  has_trait :collision_detection
24
23
  #
25
24
  # TODO:
Binary file
@@ -20,6 +20,7 @@
20
20
  #++
21
21
 
22
22
  CHINGU_ROOT = File.dirname(File.expand_path(__FILE__))
23
+ ROOT = File.dirname(File.expand_path($0))
23
24
 
24
25
  require 'rubygems' unless RUBY_VERSION =~ /1\.9/
25
26
  require 'gosu'
@@ -27,5 +28,5 @@ require File.join(CHINGU_ROOT,"chingu","require_all") # Thanks to http://github.
27
28
  require_all "#{CHINGU_ROOT}/chingu"
28
29
 
29
30
  module Chingu
30
- VERSION = "0.5.7.1"
31
+ VERSION = "0.5.8"
31
32
  end
@@ -16,7 +16,8 @@ module Chingu
16
16
  # - file: Tile-file to cut up animation frames from.
17
17
  # - width: width of each frame in the tileanimation
18
18
  # - height: width of each frame in the tileanimation
19
- #
19
+ # - size: [x,y] specify width/height with 1 argument (an array)
20
+ # - delay: milliseconds between each frame
20
21
  #
21
22
  def initialize(options)
22
23
  options = {:loop => true, :bounce => false, :width => 32, :height => 32, :index => 0, :delay => 100}.merge(options)
@@ -35,6 +36,8 @@ module Chingu
35
36
  @height = options[:size][1]
36
37
  end
37
38
 
39
+ @file = media_path(@file) unless File.exist?(@file)
40
+
38
41
  @frame_actions = []
39
42
  @frames = Gosu::Image.load_tiles($window, @file, @width, @height, true)
40
43
  @step = 1
@@ -96,9 +99,9 @@ module Chingu
96
99
 
97
100
  #
98
101
  # Propelles the animation forward. Usually called in #update within the class which holds the animation.
99
- # #next! will look at bounce and loop flags to always return a correct frame (a Gosu#Image)
102
+ # Animation#next() will look at bounce and loop flags to always return a correct frame (a Gosu#Image)
100
103
  #
101
- def next!
104
+ def next
102
105
  if (@dt += $window.milliseconds_since_last_tick) > @delay
103
106
  @dt = 0
104
107
  @previous_index = @index
@@ -119,7 +122,8 @@ module Chingu
119
122
  end
120
123
  @frames[@index]
121
124
  end
122
-
125
+ alias :next! :next
126
+
123
127
  #
124
128
  # Initialize non-blurry zoom on frames in animation
125
129
  #
@@ -5,18 +5,18 @@
5
5
  #
6
6
  module Chingu
7
7
  def media_path(file)
8
- File.join($window.root, "media", file)
8
+ File.join(ROOT, "media", file)
9
9
  end
10
10
 
11
11
  def image_path(file)
12
- File.join($window.root, "gfx", file)
12
+ File.join(ROOT, "gfx", file)
13
13
  end
14
14
 
15
- class ImagePath
15
+ class Asset
16
16
  include Chingu::NamedResource
17
17
 
18
18
  def self.autoload(name)
19
- find_file(name)
19
+ find_file(name)
20
20
  end
21
21
  end
22
22
  end
@@ -75,30 +75,47 @@ module Chingu
75
75
  end
76
76
 
77
77
  #
78
- # Disable auto-updating of traits
78
+ # Disable automatic calling of update() and update_trait() each game loop
79
79
  #
80
80
  def pause!
81
81
  @paused = true
82
82
  end
83
+
83
84
  #
84
- # Enable auto-update of traits
85
+ # Enable automatic calling of update() and update_trait() each game loop
85
86
  #
86
87
  def unpause!
87
88
  @paused = false
88
89
  end
90
+
89
91
  #
90
- # Disable auto-drawing of object
92
+ # Disable automatic calling of draw and draw_trait each game loop
91
93
  #
92
94
  def hide!
93
95
  @visible = false
94
96
  end
97
+
95
98
  #
96
- # Enable auto-drawing of object
99
+ # Enable automatic calling of draw and draw_trait each game loop
97
100
  #
98
101
  def show!
99
102
  @visible = true
100
103
  end
101
104
 
105
+ #
106
+ # Returns true if paused
107
+ #
108
+ def paused?
109
+ @paused == true
110
+ end
111
+
112
+ #
113
+ # Returns true if visible (not hidden)
114
+ #
115
+ def visible?
116
+ @visible == true
117
+ end
118
+
102
119
  def setup_trait(options)
103
120
  end
104
121
 
@@ -24,8 +24,7 @@
24
24
  # Core extensions to GOSU
25
25
  # Some of these require the gem 'texplay'
26
26
  #
27
- module Gosu
28
-
27
+ module Gosu
29
28
  class Image
30
29
  #
31
30
  # Returns true if the pixel at x, y is 100% transperant (good for collisiondetection)
@@ -77,6 +77,20 @@ module Chingu
77
77
  @center = center
78
78
  @center_x = @center_y = center
79
79
  end
80
+
81
+ # Get objects alpha-value (internally stored in @color.alpha)
82
+ def alpha
83
+ @color.alpha
84
+ end
85
+
86
+ # Set objects alpha-value (internally stored in @color.alpha)
87
+ # If out of range, set to closest working value. this makes fading simpler.
88
+ def alpha=(value)
89
+ value = 0 if value < 0
90
+ value = 255 if value > 255
91
+ @color.alpha = value
92
+ end
93
+
80
94
 
81
95
  # Returns true if object is inside the game window, false if outside
82
96
  def inside_window?(x = @x, y = @y)
@@ -88,5 +88,33 @@ module Chingu
88
88
  def select
89
89
  @game_objects.select { |object| yield object }
90
90
  end
91
+
92
+ #
93
+ # Disable automatic calling of update() and update_trait() each game loop for all game objects
94
+ #
95
+ def pause!
96
+ @game_objects.each { |object| object.pause! }
97
+ end
98
+
99
+ #
100
+ # Enable automatic calling of update() and update_trait() each game loop for all game objects
101
+ #
102
+ def unpause!
103
+ @game_objects.each { |object| object.unpause! }
104
+ end
105
+
106
+ #
107
+ # Disable automatic calling of draw and draw_trait each game loop for all game objects
108
+ #
109
+ def hide!
110
+ @game_objects.each { |object| object.hide! }
111
+ end
112
+
113
+ #
114
+ # Enable automatic calling of draw and draw_trait each game loop for all game objects
115
+ #
116
+ def show!
117
+ @game_objects.each { |object| object.show! }
118
+ end
91
119
  end
92
120
  end
@@ -22,26 +22,28 @@
22
22
 
23
23
  module Chingu
24
24
  module Traits
25
+
26
+ #
27
+ # Adds methods:
28
+ # rotate(amount) # modifies @angle
29
+ # scale(amount) # modifies @factor_x and @factor_y
30
+ # fade(amount) # modifies @color.alpha
31
+ #
32
+ # Also adds attributes
33
+ # rotation_rate=amount # adds amount to @angle each game loop
34
+ # scale_rate=amount # adds amount to @factor_x and @factor_y each game loop
35
+ # fade_rate=amount # adds amount to @color.alpha each game loop
36
+ #
37
+ #
38
+ # WARNING, I'm very close to deprecating this trait, it doesn't do much and still introduces new names to learn.
39
+ # After a long discussion in #gosu I feel it's just better to use the accessors angle=, alpha= and factor=
40
+ #
41
+ # BasicGameObject#alpha= contains the most important logic this trait had now anyhow.
42
+ #
43
+
25
44
  module Effect
26
- #
27
- # Adds .rotating .fading and .zooming to any GameObject.
28
- #
29
- # TODO: better naming? suggestions:
30
- #
31
- # basic gosu unit <-> automation name
32
- # ==============================================
33
- # angle <-> rotation? rotating? automatic_angle?
34
- # factor <-> growth? scale? automatic_zoom?
35
- # alpha <-> fade
36
- #
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
+ attr_accessor :rotation_rate, :fade_rate, :scale_rate
46
+
45
47
  #
46
48
  # Setup
47
49
  #
@@ -49,63 +51,58 @@ module Chingu
49
51
  @effect_options = {:debug => false}.merge(options)
50
52
  puts "Effect#setup" if @effect_options[:debug]
51
53
 
52
- @rotating = options[:rotating] || nil
53
- @zooming = options[:zooming] || nil
54
- @fading = options[:fading] || nil
54
+ @rotation_rate = options[:rotation_rate] || nil
55
+ @scale_rate = options[:scale_rate] || nil
56
+ @fade_rate = options[:fade_rate] || nil
55
57
  super
56
58
  end
57
59
 
58
60
  def draw_trait
59
- puts "Effect#draw" if @effect_options[:debug]
60
61
  super
61
62
  end
62
63
 
63
64
  def update_trait
64
65
  puts "Effect#update" if @effect_options[:debug]
65
66
 
66
- rotate(@rotating) if @rotating
67
- fade(@fading) if @fading
68
- zoom(@zooming) if @zooming
67
+ rotate(@rotation_rate) if @rotation_rate
68
+ fade(@fade_rate) if @fade_rate
69
+ scale(@scale_rate) if @scale_rate
69
70
  super
70
71
  end
71
72
 
72
- # Zoom - increase @factor_x and @factor_y at the same time.
73
- def zoom(amount = 0.1)
73
+ # Increase @factor_x and @factor_y at the same time.
74
+ def scale(amount = 0.1)
74
75
  @factor_x += amount
75
76
  @factor_y += amount
76
77
  end
78
+ alias :zoom :scale
77
79
 
78
- # Zoom Out - decrease @factor_x and @factor_y at the same time.
79
- def zoom_out(amount = 0.1)
80
+ # Ddecrease @factor_x and @factor_y at the same time.
81
+ def scale_out(amount = 0.1)
80
82
  @factor_x -= amount
81
83
  @factor_y -= amount
82
84
  end
83
-
85
+ alias :zoom_out :scale_out
86
+
84
87
  # Rotate object 'amount' degrees
85
88
  def rotate(amount = 1)
86
- @angle += amount
89
+ self.angle += amount
87
90
  end
88
91
 
89
92
  # Fade object by decreasing/increasing color.alpha
90
93
  def fade(amount = 1)
91
94
  return if amount == 0
92
-
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
98
- end
95
+ self.alpha += amount
99
96
  end
100
97
 
101
98
  # Fade out objects color by decreasing color.alpha
102
99
  def fade_out(amount = 1)
103
- fade(-amount)
100
+ self.alpha -= amount
104
101
  end
105
102
 
106
103
  # Fade in objects color by increasing color.alpha
107
104
  def fade_in(amount = 1)
108
- fade(amount)
105
+ self.alpha += amount
109
106
  end
110
107
 
111
108
  end
@@ -52,6 +52,18 @@ module Chingu
52
52
  (@y * self.factor).to_i
53
53
  end
54
54
 
55
+ # Returns true if object is inside the game window, false if outside
56
+ # this special version takes @factor into consideration
57
+ def inside_window?
58
+ @x >= 0 && @x <= $window.width/self.factor && @y >= 0 && @y <= $window.height/self.factor
59
+ end
60
+
61
+ # Returns true object is outside the game window
62
+ # this special version takes @factor into consideration
63
+ def outside_window?
64
+ not inside_window?
65
+ end
66
+
55
67
  def draw
56
68
  @image.draw_rot(self.screen_x, self.screen_y, @zorder, @angle, @center_x, @center_y, @factor_x, @factor_y, @color, @mode)
57
69
  end
@@ -24,6 +24,7 @@ module Chingu
24
24
  $window = super(width, height, fullscreen, update_interval)
25
25
 
26
26
  @root = File.dirname(File.expand_path($0))
27
+ Chingu::Asset.autoload_dirs = [".", File.join(@root, "gfx"), File.join(@root, "media"), File.join(@root, "sfx")]
27
28
  Gosu::Image.autoload_dirs = [".", File.join(@root, "gfx"), File.join(@root, "media")]
28
29
  Gosu::Sample.autoload_dirs = [".", File.join(@root, "sound"), File.join(@root, "media")]
29
30
  Gosu::Tile.autoload_dirs = [".", File.join(@root, "gfx"), File.join(@root, "media")]
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.5.7.1
4
+ version: 0.5.8
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-10-15 00:00:00 +02:00
33
+ date: 2009-10-18 00:00:00 +02:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
@@ -94,6 +94,7 @@ files:
94
94
  - examples/media/city1.csv
95
95
  - examples/media/city1.png
96
96
  - examples/media/city2.png
97
+ - examples/media/droid.bmp
97
98
  - examples/media/enemy_bullet.png
98
99
  - examples/media/explosion.wav
99
100
  - examples/media/fire_bullet.png
metadata.gz.sig CHANGED
Binary file