ippa-chingu 0.4.4 → 0.4.5

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/History.txt CHANGED
@@ -1,7 +1,15 @@
1
- === 0.0.3 / 2009-08-14
1
+ === 0.4.5 / 2009-08-27
2
+ Tons of small fixes across the board.
3
+ Started on GFX Helpers (fill, fill_rect, fill_gradient so far).
4
+ A basic particle system (see example7.rb)
5
+
6
+ === 0.4.0 / 2009-08-19
7
+ Alot of game state love. Now also works stand alone with pure gosu.
8
+
9
+ === 0.3.0 / 2009-08-14
2
10
  Too much to list. remade inputsystem. gamestates are better. window.rb is cleaner. lots of small bugfixes. Bigger readme.
3
11
 
4
- === 0.0.2 / 2009-08-10
12
+ === 0.2.0 / 2009-08-10
5
13
  tons of new stuff and fixes. complete keymap. gamestate system. moreexamples/docs. better game_object.
6
14
 
7
15
  === 0.0.1 / 2009-08-05
data/Manifest.txt CHANGED
@@ -7,28 +7,39 @@ examples/example1.rb
7
7
  examples/example2.rb
8
8
  examples/example3.rb
9
9
  examples/example4.rb
10
+ examples/example5.rb
11
+ examples/example6.rb
12
+ examples/example7.rb
10
13
  examples/media/Parallax-scroll-example-layer-0.png
11
14
  examples/media/Parallax-scroll-example-layer-1.png
12
15
  examples/media/Parallax-scroll-example-layer-2.png
13
16
  examples/media/Parallax-scroll-example-layer-3.png
14
17
  examples/media/background1.png
15
18
  examples/media/fire_bullet.png
19
+ examples/media/fireball.png
20
+ examples/media/particle.png
21
+ examples/media/ruby.png
16
22
  examples/media/spaceship.png
17
23
  examples/media/stickfigure.bmp
18
24
  examples/media/stickfigure.png
25
+ examples/media/video_games.png
19
26
  lib/chingu.rb
20
27
  lib/chingu/animation.rb
21
28
  lib/chingu/assets.rb
22
- lib/chingu/chipmunk_object.rb
23
- lib/chingu/data_structures.rb
29
+ lib/chingu/core_extensions.rb
30
+ lib/chingu/effects.rb
24
31
  lib/chingu/fpscounter.rb
25
32
  lib/chingu/game_object.rb
26
33
  lib/chingu/game_state.rb
27
34
  lib/chingu/game_state_manager.rb
35
+ lib/chingu/game_states/fade_to.rb
36
+ lib/chingu/game_states/pause.rb
37
+ lib/chingu/gfx_helpers.rb
28
38
  lib/chingu/helpers.rb
29
39
  lib/chingu/input.rb
30
40
  lib/chingu/named_resource.rb
31
41
  lib/chingu/parallax.rb
42
+ lib/chingu/particle.rb
32
43
  lib/chingu/rect.rb
33
44
  lib/chingu/text.rb
34
45
  lib/chingu/window.rb
data/README.rdoc CHANGED
@@ -432,7 +432,7 @@ See http://www.libgosu.org/rdoc/classes/Gosu/Window.html for a full set of metho
432
432
  == TODO:
433
433
  * (done) Complete the input-definitions with all possible inputs (keyboard, gamepad, mouse)!
434
434
  * (done) Complete input-stuff with released-states etc
435
- * More gfx effects, for example: fade in/out to a specific color (black makes sense between levels).
435
+ * (done) More gfx effects, for example: fade in/out to a specific color (black makes sense between levels).
436
436
  * (posted request on forums) Summon good proven community gosu snippets into Chingu
437
437
  * (done) Generate docs @ ippa.github.com- http://rdoc.info/projects/ippa/chingu !
438
438
  * (done) A good scene-manager to manage welcome screens, levels and game flow- GameStateManager / GameState !
@@ -448,7 +448,7 @@ See http://www.libgosu.org/rdoc/classes/Gosu/Window.html for a full set of metho
448
448
  * (done) Streamline fps / tick code
449
449
  * (done) Encapsulate Font.new / draw_rot with a "class Text < GameObject"
450
450
  * (10% done) Make it possible for ppl to use the parts of Chingu they like
451
- * At least make GameStateManager really easy to use with pure Gosu / Document it!
451
+ * (done) At least make GameStateManager really easy to use with pure Gosu / Document it!
452
452
  * A more robust game state <-> game_object system to connect them together.
453
453
  * (50% done) Get better at styling rdocs
454
454
  * (done) all �gamestate� ? �game state� ? it's "game state"
data/Rakefile CHANGED
@@ -15,5 +15,5 @@ end
15
15
  desc "Build a working gemspec"
16
16
  task :gemspec do
17
17
  system "rake git:manifest"
18
- system "rake debug_gem | grep -v \"(in \" > chingu.gemspec"
18
+ system "rake debug_gem | grep -v \"(in \" | grep -v \"erik\" > chingu.gemspec"
19
19
  end
data/chingu.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{chingu}
5
- s.version = "0.4.4"
5
+ s.version = "0.4.5"
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-08-21}
9
+ s.date = %q{2009-08-27}
10
10
  s.description = %q{Game framework built on top of the OpenGL accelerated game lib Gosu. It adds simple yet powerfull game states, prettier inputhandling, deploymentsafe asset-handling, a basic re-usable game object and automation of common task.}
11
11
  s.email = ["ippa@rubylicio.us"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt"]
13
- s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "chingu.gemspec", "examples/example1.rb", "examples/example2.rb", "examples/example3.rb", "examples/example4.rb", "examples/example5.rb", "examples/example6.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/fire_bullet.png", "examples/media/ruby.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/chipmunk_object.rb", "lib/chingu/data_structures.rb", "lib/chingu/fpscounter.rb", "lib/chingu/game_object.rb", "lib/chingu/game_state.rb", "lib/chingu/game_state_manager.rb", "lib/chingu/helpers.rb", "lib/chingu/input.rb", "lib/chingu/named_resource.rb", "lib/chingu/parallax.rb", "lib/chingu/rect.rb", "lib/chingu/text.rb", "lib/chingu/window.rb"]
13
+ s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "chingu.gemspec", "examples/example1.rb", "examples/example2.rb", "examples/example3.rb", "examples/example4.rb", "examples/example5.rb", "examples/example6.rb", "examples/example7.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/fire_bullet.png", "examples/media/fireball.png", "examples/media/particle.png", "examples/media/ruby.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/core_extensions.rb", "lib/chingu/effects.rb", "lib/chingu/fpscounter.rb", "lib/chingu/game_object.rb", "lib/chingu/game_state.rb", "lib/chingu/game_state_manager.rb", "lib/chingu/game_states/fade_to.rb", "lib/chingu/game_states/pause.rb", "lib/chingu/gfx_helpers.rb", "lib/chingu/helpers.rb", "lib/chingu/input.rb", "lib/chingu/named_resource.rb", "lib/chingu/parallax.rb", "lib/chingu/particle.rb", "lib/chingu/rect.rb", "lib/chingu/text.rb", "lib/chingu/window.rb"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/ippa/chingu/tree/master}
16
16
  s.rdoc_options = ["--main", "README.rdoc"]
@@ -0,0 +1,132 @@
1
+ require 'rubygems'
2
+ require File.join(File.dirname($0), "..", "lib", "chingu")
3
+ include Gosu
4
+
5
+ #
6
+ # GFXHelpers example - demonstrating Chingus GFX
7
+ #
8
+ class Game < Chingu::Window
9
+ def initialize
10
+ super(640,400)
11
+ self.input = {:space => :next_effect, :esc => :exit}
12
+ self.caption = "Example of Chingus GFX Helpers"
13
+
14
+ push_game_state(Fill)
15
+ push_game_state(FillRect)
16
+ push_game_state(FillGradient)
17
+ push_game_state(FillGradientRect)
18
+ push_game_state(Particles)
19
+ end
20
+
21
+ def next_effect
22
+ pop_game_state
23
+ end
24
+ end
25
+
26
+
27
+ class Fill < Chingu::GameState
28
+ def setup
29
+ @white = Color.new(255,255,255,255)
30
+ end
31
+ def draw
32
+ $window.caption = "fill (space to continue)"
33
+ fill(@white)
34
+ end
35
+ end
36
+
37
+ class FillRect < Chingu::GameState
38
+ def setup
39
+ @white = Color.new(255,255,255,255)
40
+ end
41
+ def draw
42
+ $window.caption = "fill_rect (space to continue)"
43
+ fill_rect([10,10,100,100], @white)
44
+ end
45
+ end
46
+
47
+ class FillGradient < Chingu::GameState
48
+ def setup
49
+ @pinkish = Color.new(0xFFCE17B6)
50
+ @blueish = Color.new(0xFF6DA9FF)
51
+ end
52
+
53
+ def draw
54
+ $window.caption = "fill_gradient (space to continue)"
55
+ fill_gradient(:from => @pinkish, :to => @blueish, :orientation => :vertical)
56
+ end
57
+ end
58
+
59
+ class FillGradientRect < Chingu::GameState
60
+ def setup
61
+ @color1 = Color.new(0xFFFFEA02)
62
+ @color2 = Color.new(0xFF078B20)
63
+ end
64
+
65
+ def draw
66
+ $window.caption = "fill_gradient with :rect-option (space to continue)"
67
+ fill_gradient(:from => @color1, :to => @color2, :rect => [100,100,200,200], :orientation => :horizontal)
68
+ end
69
+ end
70
+
71
+ class Particles < Chingu::GameState
72
+ def setup
73
+ @color1 = Color.new(0xFFFFEA02)
74
+ @color2 = Color.new(0xFF078B20)
75
+ @blue_laserish = Color.new(0xFF86EFFF)
76
+ @red = Color.new(0xFFFF0000)
77
+ @white = Color.new(0xFFFFFFFF)
78
+ @yellow = Color.new(0xFFF9F120)
79
+
80
+ # Thanks jsb in #gosu of Encave-fame for fireball.png :)
81
+ @fireball_animation = Animation.new(:file => media_path("fireball.png"), :width => 32, :height => 32)
82
+ @ground_y = $window.height * 0.95
83
+ end
84
+
85
+ def update(time)
86
+ #
87
+ # Fire 1. Dies quickly (big :fade). Small in size (small :zoom)
88
+ #
89
+ Chingu::Particle.new( :x => 100,
90
+ :y => @ground_y,
91
+ :animation => @fireball_animation,
92
+ :zoom => +0.05,
93
+ :fade => -10,
94
+ :rotation => +1,
95
+ :mode => :default
96
+ )
97
+
98
+ #
99
+ # Fire 2. Higher flame, :fade only -4. Wide Flame with bigger :zoom.
100
+ #
101
+ Chingu::Particle.new( :x => 300,
102
+ :y => @ground_y,
103
+ :animation => @fireball_animation,
104
+ :zoom => +0.2,
105
+ :fade => -4,
106
+ :rotation => +3,
107
+ :mode => :default
108
+ )
109
+ #
110
+ # Fire 3. Blue plasma with smooth particle.png and color-overlay.
111
+ #
112
+ Chingu::Particle.new( :x => 500,
113
+ :y => @ground_y,
114
+ :image => "particle.png",
115
+ :color => @blue_laserish,
116
+ :mode => :additive
117
+ )
118
+
119
+ game_objects_of_class(Particle).each { |particle| particle.y -= 5; particle.x += 2 - rand(4) }
120
+ self.game_objects.reject! { |object| object.outside_window? || object.color.alpha == 0 }
121
+ super
122
+ end
123
+
124
+ def draw
125
+ $window.caption = "particle example (space to continue) [particles#: #{game_objects.size} - framerate: #{$window.fps}]"
126
+ fill_gradient(:from => Color.new(255,0,0,0), :to => Color.new(255,60,60,80), :rect => [0,0,$window.width,@ground_y])
127
+ fill_gradient(:from => Color.new(255,100,100,100), :to => Color.new(255,50,50,50), :rect => [0,@ground_y,$window.width,$window.height-@ground_y])
128
+ super
129
+ end
130
+ end
131
+
132
+ Game.new.show
Binary file
Binary file
data/lib/chingu.rb CHANGED
@@ -7,17 +7,19 @@ require 'gosu'
7
7
  require 'set'
8
8
 
9
9
  %w{ helpers
10
+ gfx_helpers
11
+ game_object
12
+ effects
10
13
  game_state_manager
11
14
  game_state
12
15
  window
13
16
  fpscounter
14
17
  named_resource
15
18
  assets
16
- game_object
17
19
  text
18
- data_structures
19
20
  rect
20
21
  animation
22
+ particle
21
23
  input
22
24
  parallax
23
25
  }.each do |lib|
@@ -33,5 +35,5 @@ require 'set'
33
35
  end
34
36
 
35
37
  module Chingu
36
- VERSION = "0.4.3"
38
+ VERSION = "0.4.5"
37
39
  end
@@ -26,7 +26,7 @@ module Chingu
26
26
  @width = options[:width] || 32
27
27
  @index = options[:index] || 0
28
28
  @delay = options[:delay] || 100
29
- @ticks = 0
29
+ @dt = 0
30
30
 
31
31
  @frame_actions = []
32
32
  @frames = Gosu::Image.load_tiles($window, @file, @width, @height, true)
@@ -72,8 +72,8 @@ module Chingu
72
72
  # #next! will look at bounce and loop flags to always return a correct frame (a Gosu#Image)
73
73
  #
74
74
  def next!
75
- if (@ticks += $window.tick) > @delay
76
- @ticks = 0
75
+ if (@dt += $window.milliseconds_since_last_tick) > @delay
76
+ @dt = 0
77
77
  @index += @step
78
78
 
79
79
  # Has the animation hit end or beginning... time for bounce or loop?
data/lib/chingu/assets.rb CHANGED
@@ -54,4 +54,11 @@ module Gosu
54
54
  (path = find_file(name)) ? Gosu::Image.load_tiles($window, path, 32, 32, true) : nil
55
55
  end
56
56
  end
57
+
58
+ class CutTiles
59
+ def self.[](name, width, height)
60
+ @@tiles = Hash.new unless defined?(@@tiles)
61
+ @@tiles[name] ||= Gosu::Image.load_tiles($window, name, width, height, true)
62
+ end
63
+ end
57
64
  end
@@ -0,0 +1,11 @@
1
+ #
2
+ # Core extensions
3
+ #
4
+ # Extensions to the classes GOSU offers
5
+ #
6
+ module Gosu
7
+ class Color
8
+ def average(other, weight)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ #
2
+ # Effect-class
3
+ #
4
+ module Chingu
5
+ class Effect
6
+ def initialize(options)
7
+ super({:mode => :additive}.merge(options))
8
+ @trail = options[:trail] || 10
9
+ end
10
+
11
+ def update(time)
12
+ end
13
+ end
14
+ end
@@ -79,7 +79,10 @@ module Chingu
79
79
  @center_y = options[:center_y] || options[:center] || @@center_y
80
80
  @factor_x = options[:factor_x] || options[:factor] || @@factor_x
81
81
  @factor_y = options[:factor_y] || options[:factor] || @@factor_y
82
- @color = options[:color] || 0xFFFFFFFF
82
+ @color = Gosu::Color.new(options[:color]) if options[:color].is_a? Bignum
83
+ @color = options[:color] if options[:color].respond_to?(:alpha)
84
+ @color = Gosu::Color.new(0xFFFFFFFF) if @color.nil?
85
+
83
86
  @mode = options[:mode] || :default # :additive is also available.
84
87
 
85
88
  # Shortcuts for draw_rot arguments
@@ -117,7 +120,7 @@ module Chingu
117
120
  #
118
121
  # Zoom - increase @factor_x and @factor_y at the same time.
119
122
  #
120
- def zoom(amount)
123
+ def zoom(amount = 0.1)
121
124
  @factor_x += amount
122
125
  @factor_y += amount
123
126
  end
@@ -125,7 +128,7 @@ module Chingu
125
128
  #
126
129
  # Zoom Out - decrease @factor_x and @factor_y at the same time.
127
130
  #
128
- def zoom_out(amount)
131
+ def zoom_out(amount = 0.1)
129
132
  @factor_x -= amount
130
133
  @factor_y -= amount
131
134
  end
@@ -133,25 +136,53 @@ module Chingu
133
136
  #
134
137
  # Rotate object 'amount' degrees
135
138
  #
136
- def rotate(amount)
139
+ def rotate(amount = 1)
137
140
  @angle += amount
138
141
  end
139
-
142
+
143
+ #
144
+ # Fade object by decreasing/increasing color.alpha
145
+ #
146
+ def fade(amount = 1)
147
+ return if amount == 0
148
+
149
+ new_alpha = @color.alpha + amount
150
+ if amount < 0
151
+ @color.alpha = [0, new_alpha].max
152
+ else
153
+ @color.alpha = [0, new_alpha].min
154
+ end
155
+ end
156
+
140
157
  #
141
- # Returns true if game object is inside the game window, false if outside
158
+ # Fade out objects color by decreasing color.alpha
159
+ #
160
+ def fade_out(amount = 1)
161
+ fade(-amount)
162
+ end
163
+
164
+ #
165
+ # Fade in objects color by increasing color.alpha
166
+ #
167
+ def fade_in(amount = 1)
168
+ fade(amount)
169
+ end
170
+
171
+ #
172
+ # Returns true if object is inside the game window, false if outside
142
173
  #
143
174
  def inside_window?(x = @x, y = @y)
144
175
  x >= 0 && x <= $window.width && y >= 0 && y <= $window.height
145
176
  end
146
177
 
147
178
  #
148
- #
179
+ # Returns true object is outside the game window
149
180
  #
150
181
  def outside_window?(x = @x, y = @y)
151
182
  not inside_window?(x,y)
152
183
  end
153
184
 
154
- def update(time = 1)
185
+ def update(time = 0)
155
186
  # Objects gamelogic here, 'time' is the time passed between 2 iterations of the main game loop
156
187
  end
157
188
 
@@ -28,7 +28,7 @@ module Chingu
28
28
 
29
29
  class GameState
30
30
  include Chingu::GameStateHelpers # Easy access to the global game state-queue
31
- include Chingu::DrawHelpers # Adds fill(), fade() etc to each game state
31
+ include Chingu::GFXHelpers # Adds fill(), fade() etc to each game state
32
32
  include Chingu::GameObjectHelpers # adds game_objects_of_class etc ...
33
33
  include Chingu::InputDispatcher # dispatch-helpers
34
34
  include Chingu::InputClient
@@ -0,0 +1,55 @@
1
+ #
2
+ # Premade game state for chingu - Fade between two game states
3
+ # Fade from the current game state to a new one whenever with:
4
+ #
5
+ # push_game_state(Chingu::GameStates::FadeTo.new(new_game_state, :speed => 3))
6
+ #
7
+ # .. Or make your whole game look better with 1 line:
8
+ #
9
+ # transitional_game_state(Chingu::GameStates::FadeTo, :speed => 10)
10
+ #
11
+ module Chingu
12
+ module GameStates
13
+ class FadeTo < Chingu::GameState
14
+ def initialize(new_game_state, options = {})
15
+ @options = {:speed => 3}.merge(options)
16
+ @new_game_state = new_game_state
17
+ end
18
+
19
+ def setup
20
+ @color = Gosu::Color.new(0,0,0,0)
21
+ @alpha = 0.0
22
+ @fading_in = false
23
+ @new_game_state.update(0) # Make sure states game logic is run Once (for a correct draw())
24
+ end
25
+
26
+ def update(dt)
27
+ @alpha += (@fading_in ? -@options[:speed] : @options[:speed])
28
+ if @alpha >= 255
29
+ @fading_in = true
30
+ else
31
+ @color.alpha = @alpha.to_i
32
+ end
33
+ @drawn = false
34
+ end
35
+
36
+ def draw
37
+ # Stop endless loops
38
+ if @drawn == false
39
+ @drawn = true
40
+ @game_state_manager.previous_game_state.draw if @fading_in == false
41
+ @new_game_state.draw if @fading_in == true
42
+
43
+ $window.draw_quad( 0,0,@color,
44
+ $window.width,0,@color,
45
+ $window.width,$window.height,@color,
46
+ 0,$window.height,@color,999)
47
+
48
+ if @fading_in == true && @alpha == 0
49
+ @game_state_manager.switch_game_state(@new_game_state, :transitional => false)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # Premade game state for chingu - A simple pause state.
3
+ # Pause whenever with:
4
+ # push_game_state(Chingu::GameStates::Pause)
5
+ #
6
+ # requires global $window
7
+ #
8
+ module Chingu
9
+ module GameStates
10
+ class Pause < Chingu::GameState
11
+ def initialize(options)
12
+ super
13
+ @white = Color.new(255,255,255,255)
14
+ @color = Gosu::Color.new(200,0,0,0)
15
+ @font = Gosu::Font.new($window, default_font_name, 35)
16
+ @text = "PAUSED - press key to continue"
17
+ end
18
+
19
+ def button_down(id)
20
+ game_state_manager.pop_game_state(:setup => false) # Return the previous game state, dont call setup()
21
+ end
22
+
23
+ def draw
24
+ game_state_manager.previous_game_state.draw # Draw prev game state onto screen (in this case our level)
25
+ $window.draw_quad( 0,0,@color,
26
+ $window.width,0,@color,
27
+ $window.width,$window.height,@color,
28
+ 0,$window.height,@color,10)
29
+
30
+ @font.draw(@text, ($window.width/2 - @font.text_width(@text)/2), $window.height/2 - @font.height, 999)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,67 @@
1
+ module Chingu
2
+ #
3
+ # Various helper-methods to manipulate the screen.
4
+ # All drawings depend on the global variable $window which should be an instance of Gosu::Window or Chingu::Window
5
+ #
6
+ module GFXHelpers
7
+
8
+ #
9
+ # Fills whole window with color 'color'.
10
+ #
11
+ def fill(color)
12
+ $window.draw_quad(0, 0, color,
13
+ $window.width, 0, color,
14
+ $window.width, $window.height, color,
15
+ 0, $window.height, color,
16
+ 0, :default)
17
+ end
18
+
19
+ #
20
+ # Fills a given Rect 'rect' with Color 'color'
21
+ #
22
+ def fill_rect(rect, color)
23
+ rect = Rect.new(rect) # Make sure it's a rect
24
+ $window.draw_quad( rect.x, rect.y, color,
25
+ rect.right, rect.y, color,
26
+ rect.right, rect.bottom, color,
27
+ rect.x, rect.bottom, color,
28
+ 0, :default)
29
+ end
30
+
31
+ #
32
+ # Fills window or a given rect with a gradient between two colors.
33
+ #
34
+ # :from - Start with this color
35
+ # :to - End with this color
36
+ # :rect - Only fill rectangle :rect with the gradient, either a Rect-instance or [x,y,width,height] Array.
37
+ # :orientation - Either :vertical (top to bottom) or :horizontal (left to right)
38
+ #
39
+ def fill_gradient(options)
40
+ default_options = { :from => Gosu::Color.new(255,0,0,0),
41
+ :to => Gosu::Color.new(255,255,255,255),
42
+ :thickness => 10,
43
+ :orientation => :vertical,
44
+ :rect => Rect.new([0, 0, $window.width, $window.height]),
45
+ :zorder => 0,
46
+ :mode => :default
47
+ }
48
+ options = default_options.merge(options)
49
+ rect = Rect.new(options[:rect])
50
+ if options[:orientation] == :vertical
51
+ $window.draw_quad( rect.x, rect.y, options[:from],
52
+ rect.right, rect.y, options[:from],
53
+ rect.right, rect.bottom, options[:to],
54
+ rect.x, rect.bottom, options[:to],
55
+ options[:zorder], options[:mode]
56
+ )
57
+ else
58
+ $window.draw_quad( rect.x, rect.y, options[:from],
59
+ rect.x, rect.bottom, options[:from],
60
+ rect.right, rect.bottom, options[:to],
61
+ rect.right, rect.y, options[:to],
62
+ options[:zorder], options[:mode]
63
+ )
64
+ end
65
+ end
66
+ end
67
+ end
@@ -116,28 +116,6 @@ module Chingu
116
116
  $window.game_state_manager.clear_game_states
117
117
  end
118
118
  end
119
-
120
- #
121
- # Various helper-methods to manipulate the screen
122
- #
123
- module DrawHelpers
124
- #
125
- # Fills whole window with color 'c'
126
- #
127
- def fill(c)
128
- $window.draw_quad(0,0,c,$window.width,0,c,$window.width,$window.width,c,0,$window.height,c,0,:default)
129
- end
130
-
131
- #
132
- # Fills a given Rect 'r' with color 'c'
133
- #
134
- def fill_rect(r, c)
135
- $window.draw_quad(r.x,r.y,c, r.right,r.y,c, r.right,r.bottom,c, r.x,r.bottom,c,0,:default)
136
- end
137
-
138
- def fade(options = {})
139
- end
140
- end
141
119
 
142
120
  module GameObjectHelpers
143
121
  #
@@ -0,0 +1,23 @@
1
+ #
2
+ # Our basic particle class
3
+ #
4
+ include Chingu
5
+ module Chingu
6
+ class Particle < Chingu::GameObject
7
+ def initialize(options)
8
+ super({:mode => :additive}.merge(options))
9
+ @rotation = options[:rotation] || 0
10
+ @zoom = options[:zoom] || 0
11
+ @fade = options[:fade] || 0
12
+ @animation = options[:animation] || nil
13
+ end
14
+
15
+ def update(time)
16
+ self.image = @animation.next! if @animation
17
+ self.rotate(@rotation)
18
+ self.zoom(@zoom)
19
+ self.fade(@fade)
20
+ end
21
+
22
+ end
23
+ end
data/lib/chingu/window.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  module Chingu
2
+ CHINGU_ROOT = File.dirname(File.expand_path($0))
2
3
  class Window < Gosu::Window
3
4
  # adds push_game_state, pop_game_state, current_game_state and previous_game_state
4
5
  include Chingu::GameStateHelpers
5
6
 
6
7
  # adds fill() etc...
7
- include Chingu::DrawHelpers
8
+ include Chingu::GFXHelpers
8
9
 
9
10
  # adds game_objects_of_class etc ...
10
11
  include Chingu::GameObjectHelpers
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.4.4
4
+ version: 0.4.5
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-08-21 00:00:00 -07:00
12
+ date: 2009-08-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -44,12 +44,15 @@ files:
44
44
  - examples/example4.rb
45
45
  - examples/example5.rb
46
46
  - examples/example6.rb
47
+ - examples/example7.rb
47
48
  - examples/media/Parallax-scroll-example-layer-0.png
48
49
  - examples/media/Parallax-scroll-example-layer-1.png
49
50
  - examples/media/Parallax-scroll-example-layer-2.png
50
51
  - examples/media/Parallax-scroll-example-layer-3.png
51
52
  - examples/media/background1.png
52
53
  - examples/media/fire_bullet.png
54
+ - examples/media/fireball.png
55
+ - examples/media/particle.png
53
56
  - examples/media/ruby.png
54
57
  - examples/media/spaceship.png
55
58
  - examples/media/stickfigure.bmp
@@ -58,16 +61,20 @@ files:
58
61
  - lib/chingu.rb
59
62
  - lib/chingu/animation.rb
60
63
  - lib/chingu/assets.rb
61
- - lib/chingu/chipmunk_object.rb
62
- - lib/chingu/data_structures.rb
64
+ - lib/chingu/core_extensions.rb
65
+ - lib/chingu/effects.rb
63
66
  - lib/chingu/fpscounter.rb
64
67
  - lib/chingu/game_object.rb
65
68
  - lib/chingu/game_state.rb
66
69
  - lib/chingu/game_state_manager.rb
70
+ - lib/chingu/game_states/fade_to.rb
71
+ - lib/chingu/game_states/pause.rb
72
+ - lib/chingu/gfx_helpers.rb
67
73
  - lib/chingu/helpers.rb
68
74
  - lib/chingu/input.rb
69
75
  - lib/chingu/named_resource.rb
70
76
  - lib/chingu/parallax.rb
77
+ - lib/chingu/particle.rb
71
78
  - lib/chingu/rect.rb
72
79
  - lib/chingu/text.rb
73
80
  - lib/chingu/window.rb
@@ -1,117 +0,0 @@
1
- module Chingu
2
- #
3
- # A basic class, all your gameobjects / actors should be built on this. Encapsulates
4
- # Gosus draw_rot and it's parameters.
5
- #
6
- # All objects that inherits from this class will automaticly be updated and drawn.
7
- #
8
- class Actor
9
- attr_accessor :image, :x, :y, :angle, :center_x, :center_y, :factor_x, :factor_y, :mode
10
- attr_accessor :update, :draw, :keymap
11
- attr_reader :options
12
-
13
- #
14
- # Class-level default values.
15
- # This allows you to set default-values that affect all created actors after that.
16
- # You might want to draw screenobjects from the top-left @ x/y instead of putting it's center there:
17
- #
18
- # in Gosu::Window#initialize: Actor.center_x = Actor.center_y = 0
19
- #
20
- @@zorder = 100
21
- @@center_x = 0.5
22
- @@center_y = 0.5
23
- @@factor_x = 1.0
24
- @@factor_y = 1.0
25
-
26
- def self.zorder; @@zorder; end
27
- def self.zorder=(value); @@zorder = value; end
28
-
29
- def self.center_x; @@center_x; end
30
- def self.center_x=(value); @@center_x = value; end
31
-
32
- def self.center_y; @@center_y; end
33
- def self.center_y=(value); @@center_y = value; end
34
-
35
- def self.factor_x; @@factor_x; end
36
- def self.factor_x=(value); @@factor_x = value; end
37
-
38
- def self.factor_y; @@factor_y; end
39
- def self.factor_y=(value); @@factor_y = value; end
40
-
41
- #
42
- # Create a new Actor. Arguments are given in hash-format:
43
- #
44
- # :x screen x-coordinate (default 0, to the left)
45
- # :y screen y-coordinate (default 0, top of screen)
46
- # :angle angle of object, used in draw_rot, (default 0, no rotation)
47
- # :zorder a gameclass "foo" with higher zorder then gameclass "bar" is drawn on top of "foo".
48
- # :center_x relative horizontal position of the rotation center on the image.
49
- # 0 is the left border, 1 is the right border, 0.5 is the center (default 0.5)
50
- # :center_y see center_x. (default 0.5)
51
- # :factor_x horizontal zoom-factor, use >1.0 to zoom in. (default 1.0, no zoom).
52
- # :factor_y vertical zoom-factor, use >1.0 to zoom in. (default 1.0, no zoom).
53
- #
54
- # :update [true|false] Automaticly call #update on object each gameloop. Default +true+.
55
- # :draw [true|false] Automaticly call #update on object each gameloop. Default +true+.
56
- #
57
- def initialize(options = {})
58
- @options = options
59
-
60
- # draw_rot arguments
61
- @image = options[:image] if options[:image].is_a? Gosu::Image
62
- @image = Image[options[:image]] if options[:image].is_a? String
63
-
64
- @x = options[:x] || 0
65
- @y = options[:y] || 0
66
- @angle = options[:angle] || 0
67
- @zorder = options[:zorder] || @@zorder
68
- @center_x = options[:center_x] || options[:center] || @@center_x
69
- @center_y = options[:center_y] || options[:center] || @@center_y
70
- @factor_x = options[:factor_x] || options[:factor] || @@factor_x
71
- @factor_y = options[:factor_y] || options[:factor] || @@factor_y
72
- @mode = options[:mode] || :additive
73
-
74
- # gameloop logic
75
- @update = options[:update] || true
76
- @draw = options[:draw] || true
77
-
78
- automatic_update! if @update
79
- automatic_draw! if @draw
80
- end
81
-
82
- #
83
- # Add self to the list of objects that Chingu calls #update on each update-loop.
84
- # This is done by default except if you create a gameobject with {:update => false}
85
- #
86
- def automatic_update!
87
- $window.automatic_update_for(self)
88
- end
89
- #
90
- # Add self to the list of objects that Chingu calls #draw on each update-loop.
91
- # This is done by default except if you create a gameobject with {:draw => false}
92
- #
93
- def automatic_draw!
94
- $window.automatic_draw_for(self)
95
- end
96
-
97
- def keymap=(keymap)
98
- @keymap = keymap
99
- $window.key_recievers << self unless $window.key_recievers.include? self
100
- end
101
-
102
- #
103
- # Override this with your own actor/game-logic
104
- #
105
- def update
106
-
107
- end
108
-
109
- #
110
- # The core of the gameclass, the draw_rot encapsulation. Draws the sprite on screen.
111
- # Calling #to_i on @x and @y enables thoose to be Float's, for subpixel slow movement in #update
112
- #
113
- def draw
114
- @image.draw_rot(@x.to_i, @y.to_i, @zorder, @angle, @center_x, @center_y, @factor_x, @factor_y, @mode)
115
- end
116
- end
117
- end
@@ -1,6 +0,0 @@
1
- module Chingu
2
- Velocity = Struct.new(:x, :y, :z)
3
- Position = Struct.new(:x, :y, :z)
4
- Point = Struct.new(:x, :y)
5
- #Rect = Struct.new(:x, :y, :width, :height)
6
- end