Skip to content
Newer
Older
100644 891 lines (699 sloc) 38.1 KB
7ac9722 @ippa first commit
ippa authored
1 = CHINGU
2ae593b @ippa Easier gemspec build in Rakefile. Chingu gem 0.2.0 released.
ippa authored
2 http://github.com/ippa/chingu/tree/master
3
dec2095 @ippa readme
ippa authored
4 DOCUMENTATION: http://rdoc.info/projects/ippa/chingu
5
3b938a8 readme updates and fixes
ippa authored
6 Ruby 1.9.2 is recommended. Should also work with 1.8.7+.
d85fa8e readme updates/fixes
ippa authored
7 Chingu development is mostly conducted using Win7 / Ruby 1.9.2.
2ae593b @ippa Easier gemspec build in Rakefile. Chingu gem 0.2.0 released.
ippa authored
8
9 == INSTALL
62df2a7 @ippa README updates, a simple trait-example. Image#retrofy now returns sel…
ippa authored
10 gem install chingu
2ae593b @ippa Easier gemspec build in Rakefile. Chingu gem 0.2.0 released.
ippa authored
11
7ac9722 @ippa first commit
ippa authored
12
13 == DESCRIPTION
9d2d0c2 @ippa New Chingu tagline. Updated and fixes for docs across the whole lib. …
ippa authored
14 OpenGL accelerated 2D game framework for Ruby.
15 Builds on the awesome Gosu (Ruby/C++) which provides all the core functionality.
3d68151 README updates and fixes to reflect on recent changes
ippa authored
16 It adds simple yet powerful game states, pretty input handling, deployment safe asset-handling, a basic re-usable game object and automation of common task.
2ae593b @ippa Easier gemspec build in Rakefile. Chingu gem 0.2.0 released.
ippa authored
17
7ac9722 @ippa first commit
ippa authored
18
83a8311 added 'Projects using chingu' in README. Examples rock when learning …
ippa authored
19 == PROJECTS USING CHINGU
20 Links to some of the projects using/depending on Chingu:
5e317bb fix formatting in 'projects using chingu' list in readme once and for…
ippa authored
21 * https://github.com/Spooner/fidgit (GUI-lib )
22 * https://github.com/Spooner/sidney (Sleep Is Death remake in ruby)
23 * https://github.com/ippa/the_light_at_the_end_of_the_tunnel (LD#16 game compo entry)
24 * https://github.com/ippa/gnorf (LD#18 game compo entry. Decent minigame with online highscores.)
25 * https://github.com/ippa/holiday_droid (Work in progess platformer)
26 * https://github.com/ippa/pixel_pang (Work in progress remake of the classic Pang)
27 * https://github.com/ippa/whygone (An odd little platformer-puzzle-game for _why day)
28 * https://github.com/erisdiscord/gosu-tmx (a TMX map loader)
29 * https://github.com/rkachowski/tmxtilemap (Another TMX-class)
30 * https://github.com/erisdiscord/gosu-ring (Secret of Mana-style ring menu for chingu/gosu)
31 * https://github.com/deps/Berzerk (remake of the classic game. comes with robots.)
32 * https://github.com/rkachowski/tigjamuk10 ("sillyness from tigjamuk - CB2 bistro in Cambridge, January 2010")
33 * https://github.com/zukunftsalick/ruby-raid (Remake of Ataris river raid, unsure of status)
34 * https://github.com/edward/spacewar (a small game, unsure of status)
35 * https://github.com/jstorimer/zig-zag (2D scrolling game, unsure of status)
83a8311 added 'Projects using chingu' in README. Examples rock when learning …
ippa authored
36
37
7ac9722 @ippa first commit
ippa authored
38 == THE STORY
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
39 The last years I've dabbled around a lot with game development.
7ac9722 @ippa first commit
ippa authored
40 I've developed games in both Rubygame and Gosu. I've looked at gamebox.
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
41 Rubygame is a very capable framework with a lot of functionality (collision detection, very good event system etc). Gosu is way more minimalistic but also faster with OpenGL -acceleration. Gosu isn't likely to get much more complex since it does what it should do very well and fast.
7ac9722 @ippa first commit
ippa authored
42
73e1c95 @ippa GameObject.new now contains zero magic. GameObject.create works as ne…
ippa authored
43 After 10+ game prototypes and some finished smaller games I started to see patterns each time I started a new game. Making classes with x/y/image/other-parameters that I called update/draw on in the main loop.
44 This became the basic Chingu::GameObject which encapsulates Gosus "Image.draw_rot" and enables automatic updating/drawing through "game_objects".
7ac9722 @ippa first commit
ippa authored
45
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
46 There was always a huge big chunk of checking keyboard-events in the main loop.
47 Borrowing ideas from Rubygame this has now become @player.keyboard(:left => :move_left, :space => :fire ... etc.
7ac9722 @ippa first commit
ippa authored
48
2ae593b @ippa Easier gemspec build in Rakefile. Chingu gem 0.2.0 released.
ippa authored
49
2c37992 @ippa alot of fixes, rotation_center understands :middle, input back in Gam…
ippa authored
50 == CORE OVERVIEW
51 Chingu consists of the following core classes / concepts:
7ac9722 @ippa first commit
ippa authored
52
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
53 === Chingu::Window
3d68151 README updates and fixes to reflect on recent changes
ippa authored
54 The main window, use it at you use Gosu::Window now. Calculates the framerate, takes care of states,
36f1d24 readme fixes
unknown authored
55 handles chingu-formated input, updates and draws BasicGameObject / GameObjects automatically.
56 Available throughout your source as $window (Yes, that's the only global Chingu has).
3d68151 README updates and fixes to reflect on recent changes
ippa authored
57 You can also set various global settings. For example, self.factor=3, will make all fortcomming GameObjects scale 3 times.
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
58
59 === Chingu::GameObject
cf2b3c2 @ippa components -> traits. everything now works with 1.8.7 and 1.9.1. vari…
ippa authored
60 Use this for all your in game objects. The player, the enemies, the bullets, the powerups, the loot laying around.
3e1d67d @ippa readme updates + release github gem 0.3.0
ippa authored
61 It's very reusable and doesn't contain any game-logic (that's up to you!). Only stuff to put it on screen a certain way.
73e1c95 @ippa GameObject.new now contains zero magic. GameObject.create works as ne…
ippa authored
62 If you do GameObject.create() instead of new() Chingu will keep save the object in the "game_object"-list for automatic updates/draws.
63 GameObjects also have the nicer Chingu input-mapping: @player.input = { :left => :move_left, :right => :move_right, :space => :fire}
64 Has either Chingu::Window or a Chingu::GameState as "parent".
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
65
cf2b3c2 @ippa components -> traits. everything now works with 1.8.7 and 1.9.1. vari…
ippa authored
66 === Chingu::BasicGameObject
67 For those who think GameObject is a too little fat, there's BasicGameObject (GameObject inherits from BasicGameObject).
68 BasicGameObject is just an empty frame (no x,y,image accessors or draw-logic) for you to build on.
36f1d24 readme fixes
unknown authored
69 It _can_ be extended with Chingus trait-system though. The new() vs create() behavior of GameObject comes from BasicGameObject.
70 BasicGameObject#parent points to either $window or a game state and is automatically set on creation time.
3e1d67d @ippa readme updates + release github gem 0.3.0
ippa authored
71
72 === Chingu::GameStateManager
73 Keeps track of the game states. Implements a stack-based system with push_game_state and pop_game_state.
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
74
75 === Chingu::GameState
3e1d67d @ippa readme updates + release github gem 0.3.0
ippa authored
76 A "standalone game loop" that can be activated and deactivated to control game flow.
77 A game state is very much like a main gosu window. You define update() and draw() in a gamestate.
78 It comes with 2 extras that main window doesn't have. #setup (called when activated) and #finalize (called when deactivated)
79
80 If using game states, the flow of draw/update/button_up/button_down is:
81 Chingu::Window --> Chingu::GameStateManager --> Chingu::GameState.
82 For example, inside game state Menu you call push_game_state(Level). When Level exists, it will go back to Menu.
7ac9722 @ippa first commit
ippa authored
83
2c37992 @ippa alot of fixes, rotation_center understands :middle, input back in Gam…
ippa authored
84 === Traits
3d68151 README updates and fixes to reflect on recent changes
ippa authored
85 Traits are extensions (or plugins if you so will) to BasicGameObjects included on the class-level.
36f1d24 readme fixes
unknown authored
86 The aim is so encapsulate common behavior into modules for easy inclusion in your game classes.
76d78c0 @ippa draw/update in traits are now draw_trait/update_trait. Make Chingu au…
ippa authored
87 Making a trait is easy, just an ordinary module with the methods setup_trait(), update_trait() and/or draw_trait().
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
88 It currently has to be namespaced to Chingu::Traits for "traits" to work inside GameObject-classes.
2c37992 @ippa alot of fixes, rotation_center understands :middle, input back in Gam…
ippa authored
89
90 == OTHER CLASSES / HELPERS
91
92 === Chingu::Text
ff48b59 @ippa more readme updates, mention HighScoreList
ippa authored
93 Makes use of Image#from_text more rubyish and powerful.
94 In it's core, another Chingu::GameObject + image genning with Image#from_text.
2c37992 @ippa alot of fixes, rotation_center understands :middle, input back in Gam…
ippa authored
95
cf2b3c2 @ippa components -> traits. everything now works with 1.8.7 and 1.9.1. vari…
ippa authored
96 === Chingu::Animation
97 Load and interact with tile-based animations. loop, bounce and access invidual frame(s) easily.
ff48b59 @ippa more readme updates, mention HighScoreList
ippa authored
98 An "@image = @animation.next" in your Player#update is usually enough to get you started!
cf2b3c2 @ippa components -> traits. everything now works with 1.8.7 and 1.9.1. vari…
ippa authored
99
2c37992 @ippa alot of fixes, rotation_center understands :middle, input back in Gam…
ippa authored
100 === Chingu::Parallax
ff48b59 @ippa more readme updates, mention HighScoreList
ippa authored
101 A class for easy parallaxscrolling. Add layers with different damping, move the camera to generate a new snapshot. See example3.rb for more.
102
103 === Chingu::HighScoreList
104 A class to keep track of high scores, limit the list, automatic sorting on score, save/load to disc. See example13.rb for more.
7ac9722 @ippa first commit
ippa authored
105
d85fa8e readme updates/fixes
ippa authored
106 === Chingu::OnlineHighScoreList
107 A class to keep/sync online highscores to http://gamercv.com/. A lot more fun competing with others for positions then a local list.
108
2c37992 @ippa alot of fixes, rotation_center understands :middle, input back in Gam…
ippa authored
109 === Various Helpers
110 Both $window and game states gets some new graphical helpers, currently only 3, but quite useful:
111
55692d2 @ippa readme formating
ippa authored
112 fill() # Fills whole window with color 'color'.
113 fill_rect() # Fills a given Rect 'rect' with Color 'color'
114 fill_gradient() # Fills window or a given rect with a gradient between two colors.
0a8e0f5 @ippa README additions
ippa authored
115 draw_circle() # Draws a circle
116 draw_rect() # Draws a rect
2c37992 @ippa alot of fixes, rotation_center understands :middle, input back in Gam…
ippa authored
117
118 If you base your models on GameObject (or BasicGameObject) you get:
4055869 @ippa alot of small fixes and cleanups. Paralaxx-class can now repeat textu…
ippa authored
119 Enemy.all # Returns an Array of all Enemy-instances
120 Enemy.size # Returns the amount of Enemy-instances
121 Enemy.destroy_all # Destroys all Enemy-instances
122 Enemy.destroy_if(&block) # Destroy all objects for which &block returns true
2c37992 @ippa alot of fixes, rotation_center understands :middle, input back in Gam…
ippa authored
123
124
125 == BASICS / EXAMPLES
179ae00 @ippa readme updates, examples etc
ippa authored
126
700c950 @ippa big README update
ippa authored
127 === Chingu::Window
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
128 With Gosu the main window inherits from Gosu::Window. In Chingu we use Chingu::Window. It's a basic Gosu::Window with extra cheese on top of it. keyboard handling, automatic update/draw calls to all gameobjects, fps counting etc.
700c950 @ippa big README update
ippa authored
129
179ae00 @ippa readme updates, examples etc
ippa authored
130 You're probably familiar with this very common Gosu pattern:
131
132 ROOT_PATH = File.dirname(File.expand_path(__FILE__))
133 class Game < Gosu::Window
134 def initialize
135 @player = Player.new
136 end
137
138 def update
139 if button_down? Button::KbLeft
0bbf047 @ippa more docs
ippa authored
140 @player.left
141 elsif button_down? Button::KbRight
142 @player.right
143 end
144
179ae00 @ippa readme updates, examples etc
ippa authored
145 @player.update
146 end
147
148 def draw
149 @player.draw
150 end
151 end
152
153 class Player
154 attr_accessor :x,:y,:image
155 def initialize(options)
156 @x = options[:x]
157 @y = options[:y]
158 @image = Image.new(File.join(ROOT_PATH, "media", "player.png"))
159 end
160
161 def move_left
162 @x -= 1
163 end
164
165 def move_right
166 @x += 1
167 end
168
169 def draw
170 @image.draw(@x,@y,100)
171 end
172 end
173
174 Game.new.show # Start the Game update/draw loop!
175
176
d169eb1 various readme updates
ippa authored
177 Chingu doesn't change the fundamental concept/flow of Gosu, but it will make the above code shorter:
179ae00 @ippa readme updates, examples etc
ippa authored
178
179 #
180 # We use Chingu::Window instead of Gosu::Window
181 #
cfa1e45 @jduff little fix to one ofthe examples in the docs, a bunch of spelling
jduff authored
182 class Game < Chingu::Window
179ae00 @ippa readme updates, examples etc
ippa authored
183 def initialize
3d68151 README updates and fixes to reflect on recent changes
ippa authored
184 super # This is always needed if you override Window#initialize
179ae00 @ippa readme updates, examples etc
ippa authored
185 #
36f1d24 readme fixes
unknown authored
186 # Player will automatically be updated and drawn since it's a Chingu::GameObject
f9fd433 @ippa Various README updates, biggest beeing a description of the execution…
ippa authored
187 # You'll need your own Chingu::Window#update and Chingu::Window#draw after a while, but just put #super there and Chingu can do its thing.
179ae00 @ippa readme updates, examples etc
ippa authored
188 #
73e1c95 @ippa GameObject.new now contains zero magic. GameObject.create works as ne…
ippa authored
189 @player = Player.create
2ae593b @ippa Easier gemspec build in Rakefile. Chingu gem 0.2.0 released.
ippa authored
190 @player.input = {:left => :move_left, :right => :move_right}
179ae00 @ippa readme updates, examples etc
ippa authored
191 end
192 end
193
194 #
4ff81f3 @ippa Actor -> GameObject for our minimal abstract gameclass. save Actor-na…
ippa authored
195 # If we create classes from Chingu::GameObject we get stuff for free.
f9fd433 @ippa Various README updates, biggest beeing a description of the execution…
ippa authored
196 # The accessors image,x,y,zorder,angle,factor_x,factor_y,center_x,center_y,mode,alpha.
197 # We also get a default #draw which draws the image to screen with the parameters listed above.
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
198 # You might recognize those from #draw_rot - http://www.libgosu.org/rdoc/classes/Gosu/Image.html#M000023
d169eb1 various readme updates
ippa authored
199 # And in it's core, that's what Chingu::GameObject is, an encapsulation of draw_rot with some extras.
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
200 # For example, we get automatic calls to draw/update with Chingu::GameObject, which usually is what you want.
179ae00 @ippa readme updates, examples etc
ippa authored
201 # You could stop this by doing: @player = Player.new(:draw => false, :update => false)
202 #
4ff81f3 @ippa Actor -> GameObject for our minimal abstract gameclass. save Actor-na…
ippa authored
203 class Player < Chingu::GameObject
179ae00 @ippa readme updates, examples etc
ippa authored
204 def initialize(options)
205 super(options.merge(:image => Image["player.png"])
206 end
207
208 def move_left
209 @x -= 1
210 end
211
212 def move_right
213 @x += 1
214 end
215 end
216
217 Game.new.show # Start the Game update/draw loop!
218
0bbf047 @ippa more docs
ippa authored
219 Roughly 50 lines became 26 more powerful lines. (you can do @player.angle = 100 for example)
179ae00 @ippa readme updates, examples etc
ippa authored
220
dec2095 @ippa readme
ippa authored
221 If you've worked with Gosu for a while you're probably tired of passing around the window-parameter.
700c950 @ippa big README update
ippa authored
222 Chingu solves this (as has many other developers) with a global variable $window. Yes, globals are bad, but in this case it kinda makes sense. It's used under the hood in various places.
223
f9fd433 @ippa Various README updates, biggest beeing a description of the execution…
ippa authored
224 The basic flow of Chingu::Window once show() is called is this (this is called one game iteration or game loop):
225
226 - Chingu::Window#draw() is called
227 -- draw() is called on game objects belonging to Chingu::Window
228 -- draw() is called on all game objects belonging to current game state
229
230 - Chingu::Window#update() is called
231 -- Input for Chingu::Window is processed
232 -- Input for all game objects belonging to Chingu::Window is processed
233 -- update() is called on all game objects belonging to Chingu::Window
234 -- Input for current game state is processed
235 -- Input for game objects belonging to current game state is processed
236 -- update() is called on all game objects belonging to current game state
237
238 ... the above is repeatet until game exists.
239
4ff81f3 @ippa Actor -> GameObject for our minimal abstract gameclass. save Actor-na…
ippa authored
240 === Chingu::GameObject
73e1c95 @ippa GameObject.new now contains zero magic. GameObject.create works as ne…
ippa authored
241 This is our basic "game unit"-class, meaning most in game objects (players, enemies, bullets etc) should be inherited from Chingu::GameObject.
242 The basic ideas behind it are:
700c950 @ippa big README update
ippa authored
243
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
244 * Encapsulate only the very common basics that Most in game objects need
245 * Keep naming close to Gosu, but add smart convenient methods / shortcuts and a more rubyish feeling
2ae593b @ippa Easier gemspec build in Rakefile. Chingu gem 0.2.0 released.
ippa authored
246 * No game logic allowed in GameObject, since that's not likely to be useful for others.
700c950 @ippa big README update
ippa authored
247
9d2d0c2 @ippa New Chingu tagline. Updated and fixes for docs across the whole lib. …
ippa authored
248 It's based around Image#draw_rot. So basically all the arguments that you pass to draw_rot can be passed to GameObject#new when creating a new object.
249 An example using almost all arguments would be:
700c950 @ippa big README update
ippa authored
250
251 #
252 # You probably recognize the arguments from http://www.libgosu.org/rdoc/classes/Gosu/Image.html#M000023
253 #
254 @player = Player.new(:image => Image["player.png"], :x=>100, :y=>100, :zorder=>100, :angle=>45, :factor_x=>10, :factor_y=>10, :center_x=>0, :center_y=>0)
255
256 #
257 # A shortcut for the above line would be
258 #
3d68151 README updates and fixes to reflect on recent changes
ippa authored
259 @player = Player.new(:image => "player.png", :x=>100, :y=>100, :zorder=>100, :angle=>45, :factor=>10, :center=>0)
700c950 @ippa big README update
ippa authored
260
261 #
262 # I've tried doing sensible defaults:
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
263 # x/y = [middle of the screen] for super quick display where it should be easy in sight)
700c950 @ippa big README update
ippa authored
264 # angle = 0 (no angle by default)
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
265 # center_x/center_y = 0.5 (basically the center of the image will be drawn at x/y)
700c950 @ippa big README update
ippa authored
266 # factor_x/factor_y = 1 (no zoom by default)
267 #
268 @player = Player.new
269
270 #
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
271 # By default Chingu::Window calls update & draw on all GameObjects in it's own update/draw.
700c950 @ippa big README update
ippa authored
272 # If this is not what you want, use :draw and :update
273 #
274 @player = Player.new(:draw => false, :update => false)
275
a3f161e @ippa readme update
ippa authored
276 === Input
277 One of the core things I wanted a more natural way of inputhandling.
278 You can define input -> actions on Chingu::Window, Chingu::GameState and Chingu::GameObject.
279 Like this:
280
281 #
282 # When left arrow is pressed, call @player.turn_left ... and so on.
283 #
284 @player.input = { :left => :turn_left, :right => :turn_right, :left => :halt_left, :right => :halt_right }
285
286
287 #
288 # In Gosu the equivalent would be:
289 #
290 def button_down(id)
291 @player.turn_left if id == Button::KbLeft
292 @player.turn_right if id == Button::KbRight
293 end
294
295 def button_up(id)
296 @player.halt_left if id == Button::KbLeft
297 @player.halt_right if id == Button::KbRight
298 end
299
300
301 Another more complex example:
302
303 #
304 # So what happens here?
305 #
306 # Pressing P would create an game state out of class Pause, cache it and activate it.
307 # Pressing ESC would call Play#close
308 # Holding down LEFT would call Play#move_left on every game iteration
309 # Holding down RIGHT would call Play#move_right on every game iteration
cfa1e45 @jduff little fix to one ofthe examples in the docs, a bunch of spelling
jduff authored
310 # Releasing SPACE would call Play#fire
a3f161e @ippa readme update
ippa authored
311 #
312
313 class Play < Chingu::GameState
314 def initialize
b66d53f @ippa README updates and fixes
ippa authored
315 self.input = { :p => Pause,
316 :escape => :close,
317 :holding_left => :move_left,
318 :holding_right => :move_right,
319 :released_space => :fire }
a3f161e @ippa readme update
ippa authored
320 end
321 end
322 class Pause < Chingu::GameState
323 # pause logic here
324 end
325
326 In Gosu the above code would include code in button_up(), button_down() and a check for button_down?() in update().
327
328 Every symbol can be prefixed by either "released_" or "holding_" while no prefix at all defaults to pressed once.
329
cfa1e45 @jduff little fix to one ofthe examples in the docs, a bunch of spelling
jduff authored
330 So, why not :up_space or :release_space instead of :released_space?
b66d53f @ippa README updates and fixes
ippa authored
331 +:up_space+ doesn't sound like english, :release_space sounds more like a command then an event.
a3f161e @ippa readme update
ippa authored
332
b66d53f @ippa README updates and fixes
ippa authored
333
8481eed @ippa github didn't turn + and * into bold and typewriterfont as I wanted
ippa authored
334 Or +:hold_left+ or :down_left instead of :holding_left?
335 :holding_left sounds like something that's happening over a period of time, not a single trigger, which corresponds well to how it works.
a3f161e @ippa readme update
ippa authored
336
cfa1e45 @jduff little fix to one ofthe examples in the docs, a bunch of spelling
jduff authored
337 And with the default :space => :something you would imagine that :something is called once. You press :space once, :something is executed once.
a3f161e @ippa readme update
ippa authored
338
339
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
340 === GameState / GameStateManager
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
341 Chingu incorporates a basic push/pop game state system (as discussed here: http://www.gamedev.net/community/forums/topic.asp?topic_id=477320).
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
342
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
343 Game states is a way of organizing your intros, menus, levels.
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
344
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
345 Game states aren't complicated. In Chingu a GameState is a class that behaves mostly like your default Gosu::Window (or in our case Chingu::Window) game loop.
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
346
347
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
348 # A simple GameState-example
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
349 class Intro < Chingu::GameState
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
350
668deec @ippa Make README clearer regarding how game states work + doc bugfixes in …
ippa authored
351 def initialize(options)
352 # called as usual when class is created, load resources and simular here
353 end
354
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
355 def update
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
356 # game logic here
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
357 end
358
359 def draw
360 # screen manipulation here
361 end
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
362
668deec @ippa Make README clearer regarding how game states work + doc bugfixes in …
ippa authored
363 # Called Each time when we enter the game state, use this to reset the gamestate to a "virgin state"
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
364 def setup
365 @player.angle = 0 # point player upwards
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
366 end
367
b66d53f @ippa README updates and fixes
ippa authored
368 # Called when we leave the game state
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
369 def finalize
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
370 push_game_state(Menu) # switch to game state "Menu"
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
371 end
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
372
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
373 end
374
cfa1e45 @jduff little fix to one ofthe examples in the docs, a bunch of spelling
jduff authored
375 Looks familiar yet?
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
376 You can activate the above game state in 2 ways
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
377
378 class Game < Chingu::Window
379 def initialize
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
380 #
381 # 1) Create a new Intro-object and activate it (pushing to the top).
382 # This version makes more sense if you want to pass parameters to the gamestate, for example:
383 # push_game_state(Level.new(:level_nr => 10))
384 #
385 push_game_state(Intro.new)
386
387 #
388 # 2) This leaves the actual object-creation to the game state manager.
31b2b88 @ippa remove some game state cache magic, internal rename in game state man…
ippa authored
389 # Intro#initialize() is called, then Intro#setup()
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
390 #
391 push_game_state(Intro)
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
392 end
393 end
54ec455 @ippa More about game states in README, new commented example
ippa authored
394
395 Another example:
396
397 class Game < Chingu::Window
398 def initialize
399 #
400 # We start by pushing Menu to the game state stack, making it active as the only state on stack.
cfa1e45 @jduff little fix to one ofthe examples in the docs, a bunch of spelling
jduff authored
401 # :setup => :false which will skip setup() from being called (standard when switching to a new state)
54ec455 @ippa More about game states in README, new commented example
ippa authored
402 #
403 push_game_state(Menu, :setup => false)
404
405 #
cfa1e45 @jduff little fix to one ofthe examples in the docs, a bunch of spelling
jduff authored
406 # We push another game state to the stack, Play. We now have 2 states, which active being first / active.
54ec455 @ippa More about game states in README, new commented example
ippa authored
407 #
cfa1e45 @jduff little fix to one ofthe examples in the docs, a bunch of spelling
jduff authored
408 # :finalize => false will skip setup() from being called on game state
409 # that's being pushed down the stack, in this case Intro.setup().
54ec455 @ippa More about game states in README, new commented example
ippa authored
410 #
411 push_game_state(Play, :finalize => false)
412
413 #
414 # This would remove Play state from the stack, going back to the Menu-state. But also:
415 # .. skipping the standard call to Menu#setup (the new game state)
416 # .. skipping the standard call to Play#finalize (the current game state)
417 #
418 # :setup => false can for example be useful when pop'ing a Pause game state. (see example4.rb)
419 #
420 pop_game_state(:setup => false, :finalize => :false)
421
422 #
423 # Replace the current game state with a new one.
424 # :setup and :finalize options are available here as well.
425 #
426 switch_game_state(Credits)
427 end
428 end
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
429
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
430 A GameState in Chingu is just a class with the following instance methods:
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
431
668deec @ippa Make README clearer regarding how game states work + doc bugfixes in …
ippa authored
432 * initialize() - as you might expect, called when GameState is created.
433 * setup() - called each time the game state becomes active.
434 * button_down(id) - called when a button is down.
435 * button_up(id) - called when a button is released.
54ec455 @ippa More about game states in README, new commented example
ippa authored
436 * update() - just as in your normal game loop, put your game logic here.
437 * draw() - just as in your normal game loop, put your screen manipulation here.
438 * finalize() - called when a game state de-activated (for example by pushing a new one on top with push_game_state)
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
439
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
440 Chingu::Window automatically creates a @game_state_manager and makes it accessible in our game loop.
441 By default the game loop calls update() / draw() on the the current game state.
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
442
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
443 Chingu also has a couple of helpers-methods for handling the game states:
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
444 In a main loop or in a game state:
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
445 * push_game_state(state) - adds a new gamestate on top of the stack, which then becomes the active one
446 * pop_game_state - removes active gamestate and activates the previous one
54ec455 @ippa More about game states in README, new commented example
ippa authored
447 * switch_game_state(state) - replaces current game state with a new one
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
448 * current_game_state - returns the current game state
449 * previous_game_state - returns the previous game state (useful for pausing and dialog boxes, see example4.rb)
450 * pop_until_game_state(state) - pop game states until given state is found
451 * clear_game_states - removes all game states from stack
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
452
2ae593b @ippa Easier gemspec build in Rakefile. Chingu gem 0.2.0 released.
ippa authored
453 To switch to a certain gamestate with a keypress use Chingus input handler:
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
454 class Intro < Chingu::GameState
455 def setup
2ae593b @ippa Easier gemspec build in Rakefile. Chingu gem 0.2.0 released.
ippa authored
456 self.input = { :space => lambda{push_gamestate(Menu.new)} }
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
457 end
458 end
459
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
460 Or Chingus shortcut:
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
461
462 class Intro < Chingu::GameState
463 def setup
54ec455 @ippa More about game states in README, new commented example
ippa authored
464 self.input = { :space => Menu }
7619f4f @ippa Major internal rewrite. New GameState system with 1 example. Docs.
ippa authored
465 end
466 end
54ec455 @ippa More about game states in README, new commented example
ippa authored
467
668deec @ippa Make README clearer regarding how game states work + doc bugfixes in …
ippa authored
468 Chingus inputhandler will detect that Menu is a GameState-class, create a new instance and activate it with push_game_state().
700c950 @ippa big README update
ippa authored
469
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
470 === Premade game states
471 Chingu comes with some pre-made game states.
472 A simple but usefull one is GameStates::Pause. Once pushed it will draw the previous game state but not update it --
473 effectively pausing it.
474
cc31df6 Document new Editor better
ippa authored
475 == GameStates::Edit
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
476 The biggest and most usable is GameStates::Edit which enables fast 'n easy level-building with game objects.
477 Start example19 and press 'E' to get a full example.
478
479 Edit commands / shortcuts:
01205cc README updates
ippa authored
480 F1: Help screen
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
481 1-5: create object 1..5 shown in toolbar at mousecursor
01205cc README updates
ippa authored
482 CTRL+A: select all objects (not in-code-created ones though)
cc31df6 Document new Editor better
ippa authored
483 CTRL+S: Save
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
484 E: Save and Quit
01205cc README updates
ippa authored
485 Q: Quit (without saving)
cc31df6 Document new Editor better
ippa authored
486 ESC: Deselect all objects
01205cc README updates
ippa authored
487 Right Mouse Button Click: Copy object bellow cursor for fast duplication
cc31df6 Document new Editor better
ippa authored
488 Arrow-keys (with selected objects): Move objects 1 pixel at the time
489 Arrow-keys (with no selected objects): Scroll within a viewport
490
01205cc README updates
ippa authored
491
492 Bellow keys operates on all currently selected game objects
493 -----------------------------------------------------------------------------------
494 DEL: delete selected objects
495 BACKSPACE: reset angle and scale to default values
496 Page Up: Increase zorder
497 Page Down: Decrease zorder
cc31df6 Document new Editor better
ippa authored
498
01205cc README updates
ippa authored
499 R: scale up
500 F: scale down
501 T: tilt left
502 G: tilt right
503 Y: inc zorder
504 H: dec zorder
505 U: less transparency
755e5e1 fix
ippa authored
506 J: more transparency
01205cc README updates
ippa authored
507
cc31df6 Document new Editor better
ippa authored
508 Mouse Wheel (with no selected objects): Scroll viewport up/down
509 Mouse Wheel: Scale up/down
510 SHIFT + Mouse Wheel: Tilt left/right
511 CTRL + Mouse Wheel: Zorder up/down
01205cc README updates
ippa authored
512 ALT + Mouse Wheel: Transparency less/more
cc31df6 Document new Editor better
ippa authored
513
514 Move mouse cursor close to the window border to scroll a viewport if your game state has one.
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
515
516 If you're editing game state BigBossLevel the editor will save to big_boss_level.yml by default.
517 All the game objects in that file are then easily loaded with the load_game_objects command.
518
519 Both Edit.new and load_game_objects take parameters as
520 :file => "enemies.yml" # Save edited game objects to file enemies.yml
521 :debug => true # Will print various debugmsgs to console, usefull if something behaves oddly
522 :except => Player # Don't edit or load objects based on class Player
523
3d68151 README updates and fixes to reflect on recent changes
ippa authored
524 === WorkFlow
525 (This text is under development)
526
527 == The setup-method
528 If a setup() is available in a instance of Chingu::GameObject, Chingu::Window and Chingu::GameState it will automatically be called.
0825f85 goodbuy automatic_assets-trait, hello animation-trait (automatic load…
ippa authored
529 This is the perfect spot to include various setup/init-tasks like setting colors or loading animations (if you're not using the animation-trait).
3d68151 README updates and fixes to reflect on recent changes
ippa authored
530 You could also override initialize() for this purpose but it's been proven prone to errors again and again.
531 Compare the 2 snippets below:
532
533 # Easy to mess up, forgetting options or super
534 def initialize(options = {})
535 super
536 @color = Color::WHITE
537 end
538
539 # Less code, easier to get right and works in GameObject, Window and GameState
540 # Feel free to call setup() anytime, there's no magic about ut except it's autocalled once on object creation time.
541 def setup
542 @color = Color::WHITE
543 end
544
4055869 @ippa alot of small fixes and cleanups. Paralaxx-class can now repeat textu…
ippa authored
545 === Traits
3d68151 README updates and fixes to reflect on recent changes
ippa authored
546 Traits (sometimes called behaviors in other frameworks) is a way of adding logic to any class inheriting from BasicGameObject / GameObject.
0a8e0f5 @ippa README additions
ippa authored
547 Chingus trait-implementation is just ordinary ruby modules with 3 special methods:
4055869 @ippa alot of small fixes and cleanups. Paralaxx-class can now repeat textu…
ippa authored
548 - setup_trait
549 - update_trait
550 - draw_trait
551 Each of those 3 methods must call "super" to continue the trait-chain.
552
0a8e0f5 @ippa README additions
ippa authored
553 Inside a certian trait-module you can also have a module called ClassMethods, methods inside that module will be added,
554 yes you guessed it, as class methods. If initialize_trait is defined inside ClassMethods it will be called class-evaluation time
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
555 (basicly on the trait :some_trait line).
0a8e0f5 @ippa README additions
ippa authored
556
557 A simple trait could be:
558
d169eb1 various readme updates
ippa authored
559 module Chingu
560 module Trait
561 module Inspect
3d68151 README updates and fixes to reflect on recent changes
ippa authored
562
d169eb1 various readme updates
ippa authored
563 #
564 # methods namespaced to ClassMethods get's extended as ... class methods!
565 #
566 module ClassMethods
567 def initialize_trait(options)
0a8e0f5 @ippa README additions
ippa authored
568 # possible initialize stuff here
d169eb1 various readme updates
ippa authored
569 end
570
571 def inspect
572 "There's {self.size} active instances of class {self.to_s}"
573 end
0a8e0f5 @ippa README additions
ippa authored
574 end
575
d169eb1 various readme updates
ippa authored
576 #
3b938a8 readme updates and fixes
ippa authored
577 # Since it's namespaced outside ClassMethods it becomes a normal instance-method
d169eb1 various readme updates
ippa authored
578 #
0a8e0f5 @ippa README additions
ippa authored
579 def inspect
d169eb1 various readme updates
ippa authored
580 "Hello I'm an #{self.class.to_s}"
0a8e0f5 @ippa README additions
ippa authored
581 end
3b938a8 readme updates and fixes
ippa authored
582
583 #
584 # setup_trait is called when a object is created from a class that included the trait
585 # you most likely want to put all the traits settings and option parsing here
586 #
587 def setup_trait(options)
588 @long_inspect = true
589 end
3d68151 README updates and fixes to reflect on recent changes
ippa authored
590
591 end
0a8e0f5 @ippa README additions
ippa authored
592 end
593 end
594
d169eb1 various readme updates
ippa authored
595 class Enemy < GameObject
596 trait :inspect # includes Chingu::Trait::Inspect and extends Chingu::Trait::Inspect::ClassMethods
597 end
598 10.times { Enemy.create }
599 Enemy.inspect # => "There's 10 active instances of class Enemy"
600 Enemy.all.first.inspect # => "Hello I'm a Enemy"
0a8e0f5 @ippa README additions
ippa authored
601
602
d6e340b mention GameObject#setup as an GameObject#initialize alternative in r…
ippa authored
603 Example of using traits :velocity and :timer.
604 We also use GameObject#setup which will automtically be called ad the end of GameObject#initialize.
605 It's often a little bit cleaner to use setup() then to override initialize().
62df2a7 @ippa README updates, a simple trait-example. Image#retrofy now returns sel…
ippa authored
606
607 class Ogre < Chingu::GameObject
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
608 traits :velocity, :timer
d6e340b mention GameObject#setup as an GameObject#initialize alternative in r…
ippa authored
609
610 def setup
62df2a7 @ippa README updates, a simple trait-example. Image#retrofy now returns sel…
ippa authored
611 @red = Gosu::Color.new(0xFFFF0000)
612 @white = Gosu::Color.new(0xFFFFFFFF)
613
614 #
615 # some basic physics provided by the velocity-trait
616 # These 2 parameters will affect @x and @y every game-iteration
617 # So if your ogre is standing on the ground, make sure you cancel out the effect of @acceleration_y
618 #
0a8e0f5 @ippa README additions
ippa authored
619 self.velocity_x = 1 # move constantly to the right
620 self.acceleration_y = 0.4 # gravity is basicly a downwards acceleration
62df2a7 @ippa README updates, a simple trait-example. Image#retrofy now returns sel…
ippa authored
621 end
622
623 def hit_by(object)
624 #
625 # during() and then() is provided by the timer-trait
626 # flash red for 300 millisec when hit, then go back to normal
627 #
0a8e0f5 @ippa README additions
ippa authored
628 during(100) { self.color = @red; self.mode = :additive }.then { self.color = @white; self.mode = :default }
62df2a7 @ippa README updates, a simple trait-example. Image#retrofy now returns sel…
ippa authored
629 end
630 end
631
4055869 @ippa alot of small fixes and cleanups. Paralaxx-class can now repeat textu…
ippa authored
632 The flow for a game object then becomes:
633
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
634 -- creating a GameObject class X ( with a "trait :bounding_box, :scale => 0.80" )
8740bde @ippa big trait-overhaul/refactor, may break your code. replace your has_tr…
ippa authored
635 1) trait gets merged into X, instance and class methods are added
0a8e0f5 @ippa README additions
ippa authored
636 2) GameObject.initialize_trait(:scale => 0.80) (initialize_trait is a class-method!)
8740bde @ippa big trait-overhaul/refactor, may break your code. replace your has_tr…
ippa authored
637 -- creating an instance of X
a2e8f20 @ippa README fix
ippa authored
638 1) GameObject#initialize(options)
639 2) GameObject#setup_trait(options)
640 -- each game iteration
641 3) GameObject#draw_trait
642 4) GameObject#draw
643 5) GameObject#update_trait
644 6) GameObject#update
4055869 @ippa alot of small fixes and cleanups. Paralaxx-class can now repeat textu…
ippa authored
645
646 There's a couple of traits included as default in Chingu:
647
3b938a8 readme updates and fixes
ippa authored
648 ==== Trait "sprite"
649 This trait fuels GameObject. A GameObject is a BasicGameObject + the sprite-trait.
650 Adds accessors :x, :y, :angle, :factor_x, :factor_y, :center_x, :center_y, :zorder, :mode, :visible, :color.
651 See documentation for GameObject for how it works.
652
4055869 @ippa alot of small fixes and cleanups. Paralaxx-class can now repeat textu…
ippa authored
653 ==== Trait "timer"
f9fd433 @ippa Various README updates, biggest beeing a description of the execution…
ippa authored
654 Adds timer functionality to your game object
3d68151 README updates and fixes to reflect on recent changes
ippa authored
655 during(300) { self.color = Color.new(0xFFFFFFFF) } # forces @color to white every update for 300 ms
656 after(400) { self.destroy } # destroy object after 400 ms
657 between(1000,2000) { self.angle += 10 } # starting after 1 second, modify angleevery update during 1 second
658 every(2000) { Sound["bleep.wav"].play } # play bleep.wav every 2 seconds
4055869 @ippa alot of small fixes and cleanups. Paralaxx-class can now repeat textu…
ippa authored
659
660 ==== Trait "velocity"
f9fd433 @ippa Various README updates, biggest beeing a description of the execution…
ippa authored
661 Adds accessors velocity_x, velocity_y, acceleration_x, acceleration_y, max_velocity to game object.
4055869 @ippa alot of small fixes and cleanups. Paralaxx-class can now repeat textu…
ippa authored
662 They modify x, y as you would expect. *speed / angle will come*
663
8740bde @ippa big trait-overhaul/refactor, may break your code. replace your has_tr…
ippa authored
664 ==== Trait "bounding_box"
d169eb1 various readme updates
ippa authored
665 Adds accessor 'bounding_box', which returns an instance of class Rect based on current image size,x,y,factor_x,factor_y,center_x,center_y
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
666 You can also scale the calculated rect with trait-options:
8740bde @ippa big trait-overhaul/refactor, may break your code. replace your has_tr…
ippa authored
667
668 # This would return a rect slightly smaller then the image.
669 # Make player think he's better @ dodging bullets then he really is ;)
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
670 trait :bounding_box, :scale => 0.80
ab2e34e @ippa readme fixes and formating
ippa authored
671
672 # Make the bounding box bigger then the image
673 # :debug => true shows the actual box in red on the screen
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
674 trait :bounding_box, :scale => 1.5, :debug => true
d169eb1 various readme updates
ippa authored
675
676 Inside your object you will also get a cache_bounding_box(). After that the bounding_box will be quicker but it will not longer adapt to size-changes.
8740bde @ippa big trait-overhaul/refactor, may break your code. replace your has_tr…
ippa authored
677
0a8e0f5 @ippa README additions
ippa authored
678 ==== Trait "bounding_circle"
8740bde @ippa big trait-overhaul/refactor, may break your code. replace your has_tr…
ippa authored
679 Adds accessor 'radius', which returns a Fixnum based on current image size,factor_x and factor_y
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
680 You can also scale the calculated radius with trait-options:
8740bde @ippa big trait-overhaul/refactor, may break your code. replace your has_tr…
ippa authored
681
682 # This would return a radius slightly bigger then what initialize was calculated
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
683 trait :bounding_circle, :scale => 1.10
ab2e34e @ippa readme fixes and formating
ippa authored
684
685 # :debug => true shows the actual circle in red on the screen
7009e62 document GameStates::Edit in readme + various other fixes
ippa authored
686 trait :bounding_circle, :debug => true
4055869 @ippa alot of small fixes and cleanups. Paralaxx-class can now repeat textu…
ippa authored
687
d169eb1 various readme updates
ippa authored
688 Inside your object you will also get a cache_bounding_circle(). After that radius() will be quicker but it will not longer adapt to size-changes.
689
0825f85 goodbuy automatic_assets-trait, hello animation-trait (automatic load…
ippa authored
690 ==== Trait "animation"
691 Automatically load animations depending on the class-name.
692 Useful when having a lot of simple classes thats mainpurpose is displaying an animation.
3dae48f README documentation for trait automatic_assets + fixed tabspacing in…
ippa authored
693 Assuming the below code is included in a class FireBall.
694
0825f85 goodbuy automatic_assets-trait, hello animation-trait (automatic load…
ippa authored
695 #
696 # If a fire_ball_10x10.png/bmp exists, it will be loaded as a tileanimation.
3dae48f README documentation for trait automatic_assets + fixed tabspacing in…
ippa authored
697 # 10x10 would indicate the width and height of each tile so Chingu knows hows to cut it up into single frames.
0825f85 goodbuy automatic_assets-trait, hello animation-trait (automatic load…
ippa authored
698 # The animation will then be available in animations[:default] as an Animation-instance.
3d68151 README updates and fixes to reflect on recent changes
ippa authored
699 #
0825f85 goodbuy automatic_assets-trait, hello animation-trait (automatic load…
ippa authored
700 # If more then 1 animation exist, they'll will be loaded at the same time, for example:
701 # fire_ball_10x10_fly.png # Will be available in animations[:fly] as an Animation-instance
702 # fire_ball_10x10_explode.png # Will be available in animations[:explode] as an Animation-instance
3d68151 README updates and fixes to reflect on recent changes
ippa authored
703 #
704 # The below example will set the 200ms delay between each frame on all animations loaded.
705 #
d169eb1 various readme updates
ippa authored
706 trait :animation, :delay => 200
3dae48f README documentation for trait automatic_assets + fixed tabspacing in…
ippa authored
707
f9fd433 @ippa Various README updates, biggest beeing a description of the execution…
ippa authored
708 ==== Trait "effect"
709 Adds accessors rotation_rate, fade_rate and scale_rate to game object.
710 They modify angle, alpha and factor_x/factor_y each update. Since this is pretty easy to do yourself this trait might be up for deprecation.
2348fe1 document game state trait viewport
ippa authored
711
d169eb1 various readme updates
ippa authored
712 ==== Trait "viewport"
2348fe1 document game state trait viewport
ippa authored
713 A game state trait. Adds accessor *viewport*. Set viewport.x and viewport.y to.
714 Basically what viewport.x = 10 will do is draw all game objects 10 pixels to the left of their ordinary position.
715 Since the viewport has moved 10 pixels to the right, the game objects will be seen "moving" 10 pixels to the left.
d169eb1 various readme updates
ippa authored
716 This is great for scrolling games. You also have:
717
718 viewport.game_area = [0,0,1000,400] # Set scrolling limits, the effective game world if you so will
719 viewport.center_around(object) # Center viweport around an object which responds to x() and y()
720
721 viewport.lag = 0.95 # Set a lag-factor to use in combination with x_target / y_target
722 viewport.x_target = 100 # This will move viewport towards X-coordinate 100, the speed is determined by the lag-parameter.
2348fe1 document game state trait viewport
ippa authored
723
d169eb1 various readme updates
ippa authored
724 ==== Trait "collision_detection"
4055869 @ippa alot of small fixes and cleanups. Paralaxx-class can now repeat textu…
ippa authored
725 Adds class and instance methods for basic collision detection.
726
727 # Class method example
728 # This will collide all Enemy-instances with all Bullet-instances using the attribute #radius from each object.
727c8f4 @ippa more collision detection work, radius_collision? is now bounding_circ…
ippa authored
729 Enemy.each_bounding_circle_collision(Bullet) do |enemy, bullet|
4055869 @ippa alot of small fixes and cleanups. Paralaxx-class can now repeat textu…
ippa authored
730 end
731
732 # You can also use the instance methods. This will use the Rect bounding_box from @player and each EnemyRocket-object.
733 @player.each_bounding_box_collision(EnemyRocket) do |player, enemyrocket|
734 player.die!
735 end
0a8e0f5 @ippa README additions
ippa authored
736
737 #
738 # each_collision automatically tries to access #radius and #bounding_box to see what a certain game object provides
739 # It knows how to collide radius/radius, bounding_box/bounding_box and radius/bounding_box !
740 # Since You're not explicity telling what collision type to use it might be slighty slower.
741 #
742 [Player, PlayerBullet].each_collision(Enemy, EnemyBullet) do |friend, foe|
d169eb1 various readme updates
ippa authored
743 # do something
744 end
0a8e0f5 @ippa README additions
ippa authored
745
d169eb1 various readme updates
ippa authored
746 #
747 # You can also give each_collision() an array of objects.
748 #
749 Ball.each_collsion(@array_of_ground_items) do |ball, ground|
750 # do something
0a8e0f5 @ippa README additions
ippa authored
751 end
d169eb1 various readme updates
ippa authored
752
a2e8f20 @ippa README fix
ippa authored
753 ==== (IN DEVELOPMENT) Trait "retrofy"
4055869 @ippa alot of small fixes and cleanups. Paralaxx-class can now repeat textu…
ippa authored
754 Providing easier handling of the "retrofy" effect (non-blurry zoom)
755 Aims to help out when using zoom-factor to create a retrofeeling with big pixels.
756 Provides screen_x and screen_y which takes the zoom into account
757 Also provides new code for draw() which uses screen_x / screen_y instead of x / y
758
759
62df2a7 @ippa README updates, a simple trait-example. Image#retrofy now returns sel…
ippa authored
760
700c950 @ippa big README update
ippa authored
761 === Assets / Paths
179ae00 @ippa readme updates, examples etc
ippa authored
762
cfa1e45 @jduff little fix to one ofthe examples in the docs, a bunch of spelling
jduff authored
763 You might wonder why this is necessary in the straight Gosu example:
179ae00 @ippa readme updates, examples etc
ippa authored
764 ROOT_PATH = File.dirname(File.expand_path(__FILE__))
765 @image = Image.new(File.join(ROOT_PATH, "media", "player.png"))
766
dec2095 @ippa readme
ippa authored
767 It enables you to start your game from any directory and it will still find your assets (pictures, samples, fonts etc..) correctly.
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
768 For a local development version this might not be important, you're likely to start the game from the games root-dir.
cfa1e45 @jduff little fix to one ofthe examples in the docs, a bunch of spelling
jduff authored
769 But as soon as you try to deploy (for example to windows with OCRA - http://github.com/larsch/ocra/tree/master) you'll run into trouble of you don't do it like that.
179ae00 @ippa readme updates, examples etc
ippa authored
770
771 Chingu solves this problem behind the scenes for the most common assets. The 2 lines above can be replaced with:
b66d53f @ippa README updates and fixes
ippa authored
772 Image["player.png"]
773
774 You also have:
b34e818 @ippa small README-fix by apillet. Bugfix in gfx draw_circle.
ippa authored
775 Sound["shot.wav"]
b66d53f @ippa README updates and fixes
ippa authored
776 Song["intromusic.ogg"]
0fb6fca document Font[] in readme
ippa authored
777 Font["arial"]
778 Font["verdana", 16] # 16 is the size of the font
779
9b850a6 @ippa better docs about default asset directories
ippa authored
780 The default settings are like this:
ab2e34e @ippa readme fixes and formating
ippa authored
781 Image["image.png"] -- searches directories ".", "images", "gfx" and "media"
782 Sample["sample.wav"] -- searches directories ".", "sounds", "sfx" and "media"
783 Song["song.ogg"] -- searches directories ".", "songs", "sounds", "sfx" and "media"
0fb6fca document Font[] in readme
ippa authored
784 Font["verdana"] -- searches directories ".", "fonts", "media"
9b850a6 @ippa better docs about default asset directories
ippa authored
785
b66d53f @ippa README updates and fixes
ippa authored
786 Add your own searchpaths like this:
9b850a6 @ippa better docs about default asset directories
ippa authored
787 Gosu::Image.autoload_dirs << File.join(ROOT, "gfx")
788 Gosu::Sound.autoload_dirs << File.join(ROOT, "samples")
b66d53f @ippa README updates and fixes
ippa authored
789
8481eed @ippa github didn't turn + and * into bold and typewriterfont as I wanted
ippa authored
790 This will add \path\to\your\game\gfx and \path\to\your\game\samples to Image and Sound.
b66d53f @ippa README updates and fixes
ippa authored
791
792 Thanks to Jacious of rubygame-fame (http://rubygame.org/) for his named resource code powering this.
179ae00 @ippa readme updates, examples etc
ippa authored
793
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
794 === Text
795 Text is a class to give the use of Gosu::Font more rubyish feel and fit it better into Chingu.
796
797 # Pure Gosu
798 @font = Gosu::Font.new($window, "verdana", 30)
799 @font.draw("A Text", 200, 50, 55, 2.0)
800
801 # Chingu
0a8e0f5 @ippa README additions
ippa authored
802 @text = Chingu::Text.create("A Text", :x => 200, :y => 50, :zorder => 55, :factor_x => 2.0)
2ae593b @ippa Easier gemspec build in Rakefile. Chingu gem 0.2.0 released.
ippa authored
803 @text.draw
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
804
36f1d24 readme fixes
unknown authored
805 @text.draw is usually not needed as Text is a GameObject and therefore automatically updated/drawn (it #create is used instead of #new)
73e1c95 @ippa GameObject.new now contains zero magic. GameObject.create works as ne…
ippa authored
806 It's not only that the second example is readable by ppl now even familiar with Gosu, @text comes with a number of changeable properties, x,y,zorder,angle,factor_x,color,mode etc.
807 Set a new x or angle or color and it will instantly update on screen.
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
808
7ac9722 @ippa first commit
ippa authored
809
b66d53f @ippa README updates and fixes
ippa authored
810 == MISC / FAQ
73e1c95 @ippa GameObject.new now contains zero magic. GameObject.create works as ne…
ippa authored
811 === How do I access my main-window easily?
8481eed @ippa github didn't turn + and * into bold and typewriterfont as I wanted
ippa authored
812 Chingu keeps a global variable, $window, which contains the Chingu::Window instance.
b66d53f @ippa README updates and fixes
ippa authored
813 Since Chingu::Window is just Gosu::Window + some cheese you can do your $window.button_down?, $window.draw_line() etc from anywhere.
814 See http://www.libgosu.org/rdoc/classes/Gosu/Window.html for a full set of methods.
815
73e1c95 @ippa GameObject.new now contains zero magic. GameObject.create works as ne…
ippa authored
816 === How did you decide on naming of methods / classes?
817 There's 1 zillion ways of naming stuff. As a general guideline I've tried to follow Gosus naming.
2c70414 @ippa readme fixes
ippa authored
818 If Gosu didn't have a good name for a certain thing/method I've checked Ruby itself and then Rails since alot of Ruby-devs are familiar with Rails.
819 GameObject.all is naming straight from rails for example. Most stuff in GameObject follow the naming from Gosus Image#draw_rot.
73e1c95 @ippa GameObject.new now contains zero magic. GameObject.create works as ne…
ippa authored
820
9d2d0c2 @ippa New Chingu tagline. Updated and fixes for docs across the whole lib. …
ippa authored
821 As far as possible, use correct rubyfied english game_objects, not gameobjects. class HighScore, not Highscore.
822
3d68151 README updates and fixes to reflect on recent changes
ippa authored
823
824 == WHY?
825 * Plain Gosu is very minimalistic, perfect to build some higher level logic on!
826 * Deployment and asset handling should be simple
827 * Managing game states/scenes (intros, menus, levels etc) should be simple
d85fa8e readme updates/fixes
ippa authored
828 * There are a lot patterns in game development
3d68151 README updates and fixes to reflect on recent changes
ippa authored
829
830 == OPINIONS
831 * Less code is usually better
832 * Hash arguments FTW. And it becomes even better in 1.9.
833 * Don't separate too much from Gosus core-naming
834
835 == CREDITS:
3b938a8 readme updates and fixes
ippa authored
836 * Spooner (input-work, tests and various other patches)
837 * Jacob Huzak (sprite-trait, tests etc)
3d68151 README updates and fixes to reflect on recent changes
ippa authored
838 * Jacius of Rubygame (For doing cool stuff that's well documented as re-usable). So far rect.rb and named_resource.rb is straight outta Rubygame.
839 * Banister (of texplay fame) for general feedeback and help with ruby-internals and building the trait-system
840 * Jduff for input / commits
841 * Jlnr,Philymore,Shawn24,JamesKilton for constructive feedback/discussions
842 * Ariel Pillet for codesuggestions and cleanups
843 * Deps for making the first real full game with Chingu (and making it better in the process)
844 * Thanks to http://github.com/tarcieri for require_all code, good stuff
d85fa8e readme updates/fixes
ippa authored
845 .. Did I forget anyone here? Msg me on github.
3d68151 README updates and fixes to reflect on recent changes
ippa authored
846
847 == REQUIREMENTS:
d85fa8e readme updates/fixes
ippa authored
848 * Gosu, preferable the latest version
3d68151 README updates and fixes to reflect on recent changes
ippa authored
849 * Ruby 1.9.1+ or 1.8.7+
850 * gem 'texplay' for some bonus Image-pixel operations, not needed otherwise
851
852 == TODO - this list is Discontinued and no longer updated!
cf2b3c2 @ippa components -> traits. everything now works with 1.8.7 and 1.9.1. vari…
ippa authored
853 * add :padding and :align => :topleft etc to class Text
2c37992 @ippa alot of fixes, rotation_center understands :middle, input back in Gam…
ippa authored
854 * (skip) rename Chingu::Window so 'include Chingu' and 'include Gosu' wont make Window collide
cf2b3c2 @ippa components -> traits. everything now works with 1.8.7 and 1.9.1. vari…
ippa authored
855 * (done) BasicObject vs GameObject vs ScreenObject => Became BasicGameObject and GameObject
856 * (50%) some kind of componentsystem for GameObject (which should be cleaned up)
857 * (done) scale <--> growth parameter. See trait "effect"
858 * (done) Enemy.all ... instead of game_objects_of_type(Enemy) ? could this be cool / understandable?
af5b2aa @ippa readme updates
ippa authored
859 * (done) Don't call .update(time) with timeparameter, make time available thru other means when needed.
860 * (10% done) debug screen / game state.. check out shawn24's elite irb sollution :)
2ae593b @ippa Easier gemspec build in Rakefile. Chingu gem 0.2.0 released.
ippa authored
861 * (done) Complete the input-definitions with all possible inputs (keyboard, gamepad, mouse)!
3e1d67d @ippa readme updates + release github gem 0.3.0
ippa authored
862 * (done) Complete input-stuff with released-states etc
c175256 @ippa cleanups
ippa authored
863 * (done) More gfx effects, for example: fade in/out to a specific color (black makes sense between levels).
bb0bf06 @ippa game state related fixes. more consistent naming, new methods, better…
ippa authored
864 * (posted request on forums) Summon good proven community gosu snippets into Chingu
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
865 * (done) Generate docs @ ippa.github.com- http://rdoc.info/projects/ippa/chingu !
866 * (done) A good scene-manager to manage welcome screens, levels and game flow- GameStateManager / GameState !
54ec455 @ippa More about game states in README, new commented example
ippa authored
867 * (20% done) make a playable simple game in examples\ that really depends on game states
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
868 * (done) Make a gem- first gem made on github
54ec455 @ippa More about game states in README, new commented example
ippa authored
869 * (done) Automate gemgenning rake-task even more
2c37992 @ippa alot of fixes, rotation_center understands :middle, input back in Gam…
ippa authored
870 * (done) More examples when effects are more complete
4ff81f3 @ippa Actor -> GameObject for our minimal abstract gameclass. save Actor-na…
ippa authored
871 * class ChipmunkObject
73e1c95 @ippa GameObject.new now contains zero magic. GameObject.create works as ne…
ippa authored
872 * (done) class Actor/MovingActor with maybe a bit more logic then the basic GameObject.
af5b2aa @ippa readme updates
ippa authored
873 * (60% done) Spell check all docs, sloppy spelling turns ppl off. tnx jduff ;).
dec2095 @ippa readme
ippa authored
874 * Tests
3e1d67d @ippa readme updates + release github gem 0.3.0
ippa authored
875 * (done) Streamline fps / tick code
5c7b343 @ippa README.rdoc update and spellfixes
ippa authored
876 * (done) Encapsulate Font.new / draw_rot with a "class Text < GameObject"
3e1d67d @ippa readme updates + release github gem 0.3.0
ippa authored
877 * (10% done) Make it possible for ppl to use the parts of Chingu they like
c175256 @ippa cleanups
ippa authored
878 * (done) At least make GameStateManager really easy to use with pure Gosu / Document it!
54ec455 @ippa More about game states in README, new commented example
ippa authored
879 * (50% done) Get better at styling rdocs
3e1d67d @ippa readme updates + release github gem 0.3.0
ippa authored
880 * (done) all “gamestate” ? “game state” ? it's "game state"
cf2b3c2 @ippa components -> traits. everything now works with 1.8.7 and 1.9.1. vari…
ippa authored
881 * (skipping) intergrate MovieMaker - solve this with traits instead.
2c37992 @ippa alot of fixes, rotation_center understands :middle, input back in Gam…
ippa authored
882 * A more robust game state <-> game_object system to connect them together.
3e1d67d @ippa readme updates + release github gem 0.3.0
ippa authored
883 * FIX example4: :p => Pause.new would Change the "inside_game_state" to Pause and make @player belong to Pause.
0bbf047 @ippa more docs
ippa authored
884
8740bde @ippa big trait-overhaul/refactor, may break your code. replace your has_tr…
ippa authored
885
886
887 "If you program and want any longevity to your work, make a game.
888 All else recycles, but people rewrite architectures to keep games alive.", _why
889
3d68151 README updates and fixes to reflect on recent changes
ippa authored
890
Something went wrong with that request. Please try again.