ippa-chingu 0.4.0 → 0.4.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/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.4.0"
5
+ s.version = "0.4.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-08-19}
9
+ s.date = %q{2009-08-20}
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"]
data/examples/example1.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require 'rubygems'
2
- require '../lib/chingu.rb'
2
+ require File.join(File.dirname($0), "..", "lib", "chingu")
3
3
  include Gosu
4
4
 
5
5
  #
6
6
  # A minimalistic Chingu example.
7
7
  # Chingu::Window provides #update and #draw which calls corresponding methods for all objects based on Chingu::Actors
8
8
  #
9
- # Image["picture.png"] is a deploymentsafe shortcut to Gosu's Image.new and supports multiple locations for "picture.png"
9
+ # Image["picture.png"] is a deployment safe shortcut to Gosu's Image.new and supports multiple locations for "picture.png"
10
10
  # By default current dir, media\ and gfx\ is searched. To add own directories:
11
11
  #
12
12
  # Image.autoload_dirs << File.join(self.root, "data", "my_image_dir")
@@ -16,7 +16,7 @@ class Game < Chingu::Window
16
16
  super
17
17
  @player = Player.new(:x => 200, :y => 200, :image => Image["spaceship.png"])
18
18
  @player.input = { :holding_left => :move_left, :holding_right => :move_right,
19
- :holding_up => :move_up, :holding_down => :move_down}
19
+ :holding_up => :move_up, :holding_down => :move_down, :escape => :exit}
20
20
  end
21
21
 
22
22
  def update
data/examples/example2.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require '../lib/chingu.rb'
2
+ require File.join(File.dirname($0), "..", "lib", "chingu")
3
3
  include Gosu
4
4
 
5
5
  #
@@ -19,7 +19,9 @@ class Game < Chingu::Window
19
19
  :holding_right => :move_right,
20
20
  :holding_up => :move_up,
21
21
  :holding_down => :move_down,
22
- :space => :fire}
22
+ :space => :fire,
23
+ :escape => :exit
24
+ }
23
25
  end
24
26
 
25
27
  #
data/examples/example3.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require '../lib/chingu.rb'
2
+ require File.join(File.dirname($0), "..", "lib", "chingu")
3
3
  include Gosu
4
4
 
5
5
  #
@@ -9,7 +9,7 @@ include Gosu
9
9
  class Game < Chingu::Window
10
10
  def initialize
11
11
  super
12
- self.input = {:holding_left => :scroll_left, :holding_right => :scroll_right, :escape => :close}
12
+ self.input = {:holding_left => :scroll_left, :holding_right => :scroll_right, :escape => :exit}
13
13
 
14
14
  @parallax = Chingu::Parallax.new(:x => 0, :y => 0, :center_x => 0, :center_y => 0)
15
15
 
data/examples/example4.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require '../lib/chingu.rb'
2
+ require File.join(File.dirname($0), "..", "lib", "chingu")
3
3
  include Gosu
4
4
 
5
5
  #
@@ -34,7 +34,7 @@ class Game < Chingu::Window
34
34
  push_game_state(Intro)
35
35
 
36
36
  # Yes you can do crazy things like this :)
37
- self.input = { :left_mouse_button => lambda{Chingu::Text.new(:text => "Woff!")}, :esc => :close}
37
+ self.input = { :left_mouse_button => lambda{Chingu::Text.new(:text => "Woff!")}, :esc => :exit}
38
38
  end
39
39
  end
40
40
 
@@ -75,7 +75,7 @@ module Chingu
75
75
  #
76
76
  def button_down(id)
77
77
  dispatch_button_down(id, self)
78
- @input_clients.each { |object| dispatch_button_down(id, object) }
78
+ @input_clients.each { |object| dispatch_button_down(id, object) } if @input_clients
79
79
  end
80
80
 
81
81
  #
@@ -83,7 +83,7 @@ module Chingu
83
83
  #
84
84
  def button_up(id)
85
85
  dispatch_button_up(id, self)
86
- @input_clients.each { |object| dispatch_button_up(id, object) }
86
+ @input_clients.each { |object| dispatch_button_up(id, object) } if @input_clients
87
87
  end
88
88
 
89
89
  #
@@ -2,10 +2,22 @@ module Chingu
2
2
  #
3
3
  # GameStateManger is responsible for keeping track of game states with a simple pop/push stack.
4
4
  #
5
- # Related blogpost: http://gamedevgeek.com/tutorials/managing-game-states-in-c/
5
+ # More about the concept of states in games:
6
+ # http://gamedevgeek.com/tutorials/managing-game-states-in-c/
7
+ # http://www.gamedev.net/community/forums/topic.asp?topic_id=477320
6
8
  #
7
9
  # Chingu::Window automatically creates a @game_state_manager and makes it accessible in our game loop.
8
- # By default the game loop calls update() / draw() on @game_state_manager
10
+ # By default the game loop calls update(dt), draw, button_up(id) and button_down(id) on the active state.
11
+ #
12
+ # ==== Chingu Examples
13
+ #
14
+ # Enter a new game state, Level, don't call finalize() on the game state we're leaving.
15
+ # push_game_state(Level, :finalize => false)
16
+ #
17
+ # Return to the previous game state, don't call setup() on it when it becomes active.
18
+ # pop_game_state(:setup => false)
19
+ #
20
+ # If you want to use Chingus GameStateManager _without_ Chingu::Windoe, see example5.rb
9
21
  #
10
22
  class GameStateManager
11
23
  attr_accessor :inside_state
@@ -14,7 +26,7 @@ module Chingu
14
26
  @inside_state = nil
15
27
  @game_states = []
16
28
  end
17
-
29
+
18
30
  #
19
31
  # Gets the currently active gamestate (top of stack)
20
32
  #
@@ -24,7 +36,7 @@ module Chingu
24
36
  alias :current current_game_state
25
37
 
26
38
  #
27
- # Returns all gamestates with top of stack first
39
+ # Returns all gamestates with currenlty active game state on top.
28
40
  #
29
41
  def game_states
30
42
  @game_states.reverse
@@ -32,6 +44,8 @@ module Chingu
32
44
 
33
45
  #
34
46
  # Switch to a given game state, _replacing_ the current active one.
47
+ # By default setup() is called on the game state we're switching _to_.
48
+ # .. and finalize() is called on the game state we're switching _from_.
35
49
  #
36
50
  def switch_game_state(state, options = {})
37
51
  options = {:setup => true, :finalize => true}.merge(options)
@@ -57,7 +71,9 @@ module Chingu
57
71
  alias :switch :switch_game_state
58
72
 
59
73
  #
60
- # Adds a state to the game state-stack and activates it
74
+ # Adds a state to the game state-stack and activates it.
75
+ # By default setup() is called on the new game state
76
+ # .. and finalize() is called on the game state we're leaving.
61
77
  #
62
78
  def push_game_state(state, options = {})
63
79
  options = {:setup => true, :finalize => true}.merge(options)
@@ -79,6 +95,8 @@ module Chingu
79
95
 
80
96
  #
81
97
  # Pops a state off the game state-stack, activating the previous one.
98
+ # By default setup() is called on the game state that becomes active.
99
+ # .. and finalize() is called on the game state we're leaving.
82
100
  #
83
101
  def pop_game_state(options = {})
84
102
  options = {:setup => true, :finalize => true}.merge(options)
@@ -99,28 +117,7 @@ module Chingu
99
117
  alias :pop :pop_game_state
100
118
 
101
119
  #
102
- # Returns a GameState-instance from either a class or object
103
- #
104
- def game_state_instance(state)
105
- new_state = nil
106
- #
107
- # If state is a GameState-instance, just queue it
108
- #
109
- if state.is_a? Chingu::GameState
110
- new_state = state
111
- #
112
- # If state is a GameState-class, create it.
113
- #
114
- elsif state.superclass == Chingu::GameState
115
- new_state = state.new({})
116
- end
117
-
118
- return new_state
119
- end
120
-
121
-
122
- #
123
- # Returns the previous game state
120
+ # Returns the previous game state. Shortcut: "previous"
124
121
  #
125
122
  def previous_game_state
126
123
  @game_states[@game_states.index(current_game_state)-1]
@@ -128,7 +125,7 @@ module Chingu
128
125
  alias :previous previous_game_state
129
126
 
130
127
  #
131
- # Remove all game states from stack
128
+ # Remove all game states from stack. Shortcut: "clear"
132
129
  #
133
130
  def clear_game_states
134
131
  @game_states.clear
@@ -143,39 +140,68 @@ module Chingu
143
140
  break if state == new_state
144
141
  end
145
142
  end
146
-
147
- #
148
- # Bellow follows a set of auto-called Gosu::Window methods.
149
- # We define them game_state_manager so Gosu::Window can call them here.
150
- # Then the game_state_manager is responsible to resend them to the active state.
151
- # Or in the future many states.
143
+
152
144
  #
153
-
145
+ # This method should be called from button_down(id) inside your main loop.
146
+ # Enables the game state manager to call button_down(id) on active game state.
154
147
  #
155
- # Called before #update when the user pressed a button while the window had the focus.
148
+ # If you're using Chingu::Window instead of Gosu::Window this will automaticly be called.
156
149
  #
157
150
  def button_down(id)
158
151
  current_game_state.button_down(id) if current_game_state
159
152
  end
160
153
 
161
154
  #
162
- # Called when the user released a button.
155
+ # This method should be called from button_up(id) inside your main loop.
156
+ # Enables the game state manager to call button_up(id) on active game state.
157
+ #
158
+ # If you're using Chingu::Window instead of Gosu::Window this will automaticly be called.
163
159
  #
164
160
  def button_up(id)
165
161
  current_game_state.button_up(id) if current_game_state
166
162
  end
167
163
 
168
164
  #
169
- # Calls #update on the current gamestate, if there is one.
165
+ # This method should be called from update() inside your main loop.
166
+ # Enables the game state manager to call update() on active game state.
167
+ #
168
+ # If you're using Chingu::Window instead of Gosu::Window this will automaticly be called.
170
169
  #
171
170
  def update(time = nil)
172
171
  current_game_state.update(time) if current_game_state
173
172
  end
173
+
174
+ #
175
+ # This method should be called from draw() inside your main loop.
176
+ # Enables the game state manager to call update() on active game state.
174
177
  #
175
- # Calls draw() on the current gamestate, if there is one.
178
+ # If you're using Chingu::Window instead of Gosu::Window this will automaticly be called.
176
179
  #
177
180
  def draw
178
181
  current_game_state.draw if current_game_state
179
182
  end
183
+
184
+ private
185
+
186
+ #
187
+ # Returns a GameState-instance from either a GameState class or GameState-object
188
+ #
189
+ def game_state_instance(state)
190
+ new_state = nil
191
+ #
192
+ # If state is a GameState-instance, just queue it
193
+ #
194
+ if state.is_a? Chingu::GameState
195
+ new_state = state
196
+ #
197
+ # If state is a GameState-class, create it.
198
+ #
199
+ elsif state.superclass == Chingu::GameState
200
+ new_state = state.new({})
201
+ end
202
+
203
+ return new_state
204
+ end
205
+
180
206
  end
181
207
  end
data/lib/chingu.rb CHANGED
@@ -26,5 +26,5 @@ require 'set'
26
26
  end
27
27
 
28
28
  module Chingu
29
- VERSION = "0.4.0"
29
+ VERSION = "0.4.1"
30
30
  end
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.0
4
+ version: 0.4.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-08-19 00:00:00 -07:00
12
+ date: 2009-08-20 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency