chingu 0.5.5.3 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data.tar.gz.sig CHANGED
Binary file
@@ -38,12 +38,10 @@ examples/media/stickfigure.bmp
38
38
  examples/media/stickfigure.png
39
39
  examples/media/video_games.png
40
40
  lib/chingu.rb
41
- lib/chingu/actor.rb
42
41
  lib/chingu/animation.rb
43
42
  lib/chingu/assets.rb
44
43
  lib/chingu/basic_game_object.rb
45
44
  lib/chingu/core_extensions.rb
46
- lib/chingu/effects.rb
47
45
  lib/chingu/fpscounter.rb
48
46
  lib/chingu/game_object.rb
49
47
  lib/chingu/game_object_list.rb
@@ -52,8 +50,12 @@ lib/chingu/game_state_manager.rb
52
50
  lib/chingu/game_states/debug.rb
53
51
  lib/chingu/game_states/fade_to.rb
54
52
  lib/chingu/game_states/pause.rb
55
- lib/chingu/gfx_helpers.rb
56
- lib/chingu/helpers.rb
53
+ lib/chingu/helpers/game_object.rb
54
+ lib/chingu/helpers/game_state.rb
55
+ lib/chingu/helpers/gfx.rb
56
+ lib/chingu/helpers/input_client.rb
57
+ lib/chingu/helpers/input_dispatcher.rb
58
+ lib/chingu/helpers/rotation_center.rb
57
59
  lib/chingu/inflector.rb
58
60
  lib/chingu/input.rb
59
61
  lib/chingu/named_resource.rb
@@ -64,9 +66,7 @@ lib/chingu/require_all.rb
64
66
  lib/chingu/text.rb
65
67
  lib/chingu/traits/collision_detection.rb
66
68
  lib/chingu/traits/effect.rb
67
- lib/chingu/traits/input.rb
68
69
  lib/chingu/traits/retrofy.rb
69
- lib/chingu/traits/rotation_center.rb
70
70
  lib/chingu/traits/timer.rb
71
71
  lib/chingu/traits/velocity.rb
72
72
  lib/chingu/window.rb
@@ -3,13 +3,12 @@ http://github.com/ippa/chingu/tree/master
3
3
 
4
4
  DOCUMENTATION: http://rdoc.info/projects/ippa/chingu
5
5
 
6
- Ruby 1.9.1 is recommended. Also works with 1.8.7+.
6
+ Ruby 1.9.1 is recommended. Should also work with 1.8.7+.
7
7
 
8
- This is still a rather young project, core classes and naming can still change.
8
+ Chingu has started to settle down, thouch core classes and naming can still change for good reasons.
9
9
 
10
10
  == INSTALL
11
- gem sources -a http://gems.github.com
12
- sudo gem install ippa-chingu
11
+ gem install chingu
13
12
 
14
13
 
15
14
  == DESCRIPTION
@@ -426,6 +425,34 @@ Chingus trait-implementation is just ordinary ruby modules with 3 special method
426
425
  - draw_trait
427
426
  Each of those 3 methods must call "super" to continue the trait-chain.
428
427
 
428
+ Example:
429
+
430
+ class Ogre < Chingu::GameObject
431
+ has_trait :velocity, :timer
432
+
433
+ def initialize(options)
434
+ super
435
+ @red = Gosu::Color.new(0xFFFF0000)
436
+ @white = Gosu::Color.new(0xFFFFFFFF)
437
+
438
+ #
439
+ # some basic physics provided by the velocity-trait
440
+ # These 2 parameters will affect @x and @y every game-iteration
441
+ # So if your ogre is standing on the ground, make sure you cancel out the effect of @acceleration_y
442
+ #
443
+ @velocity_x = 1 # move constantly to the right
444
+ @acceleration_y = 0.4 # gravity is basicly a downwards acceleration
445
+ end
446
+
447
+ def hit_by(object)
448
+ #
449
+ # during() and then() is provided by the timer-trait
450
+ # flash red for 300 millisec when hit, then go back to normal
451
+ #
452
+ during(100) { @color = @red; @mode = :additive }.then { @color = @white; @mode = :default }
453
+ end
454
+ end
455
+
429
456
  The flow for a game object then becomes:
430
457
 
431
458
  -- creating the object
@@ -441,8 +468,8 @@ There's a couple of traits included as default in Chingu:
441
468
 
442
469
  ==== Trait "timer"
443
470
  Adds timer functionallity to your game object
444
- during(300) { @color = Color.new(0xFFFFFFFF) } # forces @color to white ever update for 300 ms
445
- after(400) { self.destroy } # destroy object after 400 ms
471
+ during(300) { @color = Color.new(0xFFFFFFFF) } # forces @color to white every update for 300 ms
472
+ after(400) { self.destroy } # destroy object after 400 ms
446
473
  between(1000,2000) { self.rotate(10) } # starting after 1 second, call rotate(10) every update during 1 second
447
474
 
448
475
  ==== Trait "velocity"
@@ -476,6 +503,8 @@ Provides screen_x and screen_y which takes the zoom into account
476
503
  Also provides new code for draw() which uses screen_x / screen_y instead of x / y
477
504
 
478
505
 
506
+
507
+
479
508
  === Assets / Paths
480
509
 
481
510
  You might wonder why this is necessary in the straight Gosu example:
@@ -529,8 +558,8 @@ See http://www.libgosu.org/rdoc/classes/Gosu/Window.html for a full set of metho
529
558
 
530
559
  === How did you decide on naming of methods / classes?
531
560
  There's 1 zillion ways of naming stuff. As a general guideline I've tried to follow Gosus naming.
532
- If Gosu didn't have a good name for a certain thing/method I've checked Ruby itself and then Rails since alot
533
- of Ruby-devs are familiar with Rails.
561
+ 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.
562
+ GameObject.all is naming straight from rails for example. Most stuff in GameObject follow the naming from Gosus Image#draw_rot.
534
563
 
535
564
  == TODO:
536
565
  * add :padding and :align => :topleft etc to class Text
@@ -580,9 +609,13 @@ If Gosu didn't have a good name for a certain thing/method I've checked Ruby its
580
609
  * Jacius of Rubygame (For doing cool stuff that's well documented as re-usable). So far rect.rb and named_resource.rb is taken from Rubygame.
581
610
  * Jduff for input / commits.
582
611
  * Jlnr,Philymore,Shawn24,JamesKilton for constructive feedback/discussions.
612
+ * Apillet for codesuggestions and cleanups
583
613
  * Thanks to http://github.com/tarcieri for require_all code, good stuff
584
614
 
585
615
  == REQUIREMENTS:
586
616
  * Gosu latest version
587
- * Ruby 1.8.7+ (Works with 1.9+ as well!)
617
+ * Ruby 1.9.1+ or 1.8.7+
618
+ * gem 'opengl' if you want to use Image#retrofy, not needed otherwise
619
+ * gem 'texplay' for some bonus Image-pixel operations, not needed otherwise
620
+
588
621
 
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{chingu}
5
- s.version = "0.5.5.3"
5
+ s.version = "0.5.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["ippa"]
9
- s.date = %q{2009-10-06}
9
+ s.date = %q{2009-10-10}
10
10
  s.description = %q{Game framework built on top of the OpenGL accelerated game lib Gosu.
11
11
  It adds simple yet powerful game states, prettier input handling, deployment safe asset-handling, a basic re-usable game object and automation of common task.}
12
12
  s.email = ["ippa@rubylicio.us"]
13
13
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "benchmarks/README.txt"]
14
- s.files = ["History.txt", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "benchmarks/README.txt", "benchmarks/benchmark.rb", "benchmarks/benchmark3.rb", "benchmarks/benchmark4.rb", "benchmarks/benchmark5.rb", "benchmarks/benchmark6.rb", "benchmarks/meta_benchmark.rb", "benchmarks/meta_benchmark2.rb", "chingu.gemspec", "examples/example1.rb", "examples/example10.rb", "examples/example11.rb", "examples/example12.rb", "examples/example2.rb", "examples/example3.rb", "examples/example4.rb", "examples/example5.rb", "examples/example6.rb", "examples/example7.rb", "examples/example8.rb", "examples/example9.rb", "examples/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/actor.rb", "lib/chingu/animation.rb", "lib/chingu/assets.rb", "lib/chingu/basic_game_object.rb", "lib/chingu/core_extensions.rb", "lib/chingu/effects.rb", "lib/chingu/fpscounter.rb", "lib/chingu/game_object.rb", "lib/chingu/game_object_list.rb", "lib/chingu/game_state.rb", "lib/chingu/game_state_manager.rb", "lib/chingu/game_states/debug.rb", "lib/chingu/game_states/fade_to.rb", "lib/chingu/game_states/pause.rb", "lib/chingu/gfx_helpers.rb", "lib/chingu/helpers.rb", "lib/chingu/inflector.rb", "lib/chingu/input.rb", "lib/chingu/named_resource.rb", "lib/chingu/parallax.rb", "lib/chingu/particle.rb", "lib/chingu/rect.rb", "lib/chingu/require_all.rb", "lib/chingu/text.rb", "lib/chingu/traits/collision_detection.rb", "lib/chingu/traits/effect.rb", "lib/chingu/traits/input.rb", "lib/chingu/traits/retrofy.rb", "lib/chingu/traits/rotation_center.rb", "lib/chingu/traits/timer.rb", "lib/chingu/traits/velocity.rb", "lib/chingu/window.rb"]
14
+ s.files = ["History.txt", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "benchmarks/README.txt", "benchmarks/benchmark.rb", "benchmarks/benchmark3.rb", "benchmarks/benchmark4.rb", "benchmarks/benchmark5.rb", "benchmarks/benchmark6.rb", "benchmarks/meta_benchmark.rb", "benchmarks/meta_benchmark2.rb", "chingu.gemspec", "examples/example1.rb", "examples/example10.rb", "examples/example11.rb", "examples/example12.rb", "examples/example2.rb", "examples/example3.rb", "examples/example4.rb", "examples/example5.rb", "examples/example6.rb", "examples/example7.rb", "examples/example8.rb", "examples/example9.rb", "examples/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/basic_game_object.rb", "lib/chingu/core_extensions.rb", "lib/chingu/fpscounter.rb", "lib/chingu/game_object.rb", "lib/chingu/game_object_list.rb", "lib/chingu/game_state.rb", "lib/chingu/game_state_manager.rb", "lib/chingu/game_states/debug.rb", "lib/chingu/game_states/fade_to.rb", "lib/chingu/game_states/pause.rb", "lib/chingu/helpers/game_object.rb", "lib/chingu/helpers/game_state.rb", "lib/chingu/helpers/gfx.rb", "lib/chingu/helpers/input_client.rb", "lib/chingu/helpers/input_dispatcher.rb", "lib/chingu/helpers/rotation_center.rb", "lib/chingu/inflector.rb", "lib/chingu/input.rb", "lib/chingu/named_resource.rb", "lib/chingu/parallax.rb", "lib/chingu/particle.rb", "lib/chingu/rect.rb", "lib/chingu/require_all.rb", "lib/chingu/text.rb", "lib/chingu/traits/collision_detection.rb", "lib/chingu/traits/effect.rb", "lib/chingu/traits/retrofy.rb", "lib/chingu/traits/timer.rb", "lib/chingu/traits/velocity.rb", "lib/chingu/window.rb"]
15
15
  s.homepage = %q{http://github.com/ippa/chingu/tree/master}
16
16
  s.rdoc_options = ["--main", "README.rdoc"]
17
17
  s.require_paths = ["lib"]
@@ -13,11 +13,12 @@ include Gosu
13
13
  #
14
14
  class Game < Chingu::Window
15
15
  def initialize
16
- super(640,480,false) # leave it blank and it will be 800,600,non fullscreen
16
+ super(640,480,false) # leave it blank and it will be 800,600,non fullscreen
17
+ self.input = { :escape => :exit } # exits example on Escape
18
+
17
19
  @player = Player.create(:x => 200, :y => 200, :image => Image["spaceship.png"])
18
20
  @player.input = { :holding_left => :move_left, :holding_right => :move_right,
19
- :holding_up => :move_up, :holding_down => :move_down, :escape => :exit}
20
- p RUBY_VERSION
21
+ :holding_up => :move_up, :holding_down => :move_down }
21
22
  end
22
23
 
23
24
  def update
@@ -65,19 +65,12 @@ class Play < Chingu::GameState
65
65
  :holding_up => :move_up,
66
66
  :holding_down => :move_down,
67
67
  :space => :fire,
68
- :escape => :exit,
69
68
  }
70
- self.input = { :f1 => :debug }
69
+ self.input = { :f1 => :debug, :escape => :exit }
71
70
  end
72
71
 
73
- def debug
74
- #puts "--------"
75
- #GameObject.all.each do |game_object|
76
- # puts game_object.class
77
- #end
78
- #return
79
-
80
- push_game_state(Chingu::GameStates::Debug)
72
+ def debug
73
+ push_game_state(Chingu::GameStates::Debug.new)
81
74
  end
82
75
 
83
76
  #
@@ -97,17 +90,9 @@ class Play < Chingu::GameState
97
90
  # A #super call here would call #update on all Chingu::Actors and check their inputs, and call the specified method.
98
91
  #
99
92
  def update
100
- Bullet.destroy_if { |bullet| bullet.outside_window? }
101
- #Bullet.destroy_if(&:outside_window?)
102
-
103
- #
104
- # Bullet.each_collision(Enemy) do |bullet, enemy|
105
- # enemy.collision_with(bullet)
106
- # bullet.destroy!
107
- # end
108
- #
109
-
110
93
  super
94
+
95
+ Bullet.destroy_if { |bullet| bullet.outside_window? }
111
96
  $window.caption = "FPS: #{$window.fps} - milliseconds_since_last_tick: #{$window.milliseconds_since_last_tick} - game objects# #{current_game_state.game_objects.size} Bullets# #{Bullet.size}"
112
97
  end
113
98
  end
@@ -23,10 +23,9 @@ CHINGU_ROOT = File.dirname(File.expand_path(__FILE__))
23
23
 
24
24
  require 'rubygems' unless RUBY_VERSION =~ /1\.9/
25
25
  require 'gosu'
26
- require 'set'
27
26
  require File.join(CHINGU_ROOT,"chingu","require_all") # Thanks to http://github.com/tarcieri/require_all !
28
27
  require_all "#{CHINGU_ROOT}/chingu"
29
28
 
30
29
  module Chingu
31
- VERSION = "0.5.5.3"
30
+ VERSION = "0.5.6"
32
31
  end
@@ -125,6 +125,7 @@ module Chingu
125
125
  #
126
126
  def retrofy
127
127
  frames.each { |frame| frame.retrofy }
128
+ self
128
129
  end
129
130
 
130
131
  #
@@ -48,6 +48,7 @@ module Gosu
48
48
  glBindTexture(GL_TEXTURE_2D, self.gl_tex_info.tex_name)
49
49
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
50
50
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
51
+ self
51
52
  end
52
53
  end
53
54
  end
@@ -29,7 +29,9 @@ module Chingu
29
29
  class GameObject < Chingu::BasicGameObject
30
30
  attr_accessor :image, :x, :y, :angle, :center_x, :center_y, :factor_x, :factor_y, :color, :mode, :zorder
31
31
  attr_reader :paused, :visible, :factor, :center
32
- has_trait :input, :rotation_center
32
+
33
+ include Chingu::Helpers::InputClient # Adds input and input=
34
+ include Chingu::Helpers::RotationCenter # Adds easy and verbose modification of @center_x and @center_y
33
35
 
34
36
  def initialize(options = {})
35
37
  super
@@ -49,20 +49,19 @@ module Chingu
49
49
  #
50
50
 
51
51
  class GameState
52
- include Chingu::GameStateHelpers # Easy access to the global game state-queue
53
- include Chingu::GFXHelpers # Adds fill(), fade() etc to each game state
54
- include Chingu::GameObjectHelpers # adds game_objects_of_class etc ...
55
- include Chingu::InputDispatcher # dispatch-helpers
56
- include Chingu::InputClient
52
+ include Chingu::Helpers::GFX # Adds fill(), fade() etc to each game state
53
+ include Chingu::Helpers::GameState # Easy access to the global game state-queue
54
+ include Chingu::Helpers::GameObject # Adds game_objects_of_class etc ...
55
+ include Chingu::Helpers::InputDispatcher # Input dispatch-helpers
56
+ include Chingu::Helpers::InputClient # GameState can have it's own inputmap
57
57
 
58
- attr_reader :options # so jlnr can access his :level-number
58
+ attr_reader :options
59
59
  attr_accessor :game_state_manager, :game_objects
60
60
 
61
61
  def initialize(options = {})
62
62
  @options = options
63
- ## @game_state_manager = options[:game_state_manager] || $window.game_state_manager
64
63
  @game_objects = GameObjectList.new
65
- @input_clients = Set.new # Set is like a unique Array with Hash lookupspeed
64
+ @input_clients = Array.new
66
65
 
67
66
  # Game state mamanger can be run alone
68
67
  if defined?($window) && $window.respond_to?(:game_state_manager)
@@ -39,7 +39,7 @@ module Chingu
39
39
  # Return to the previous game state, don't call setup() on it when it becomes active.
40
40
  # pop_game_state(:setup => false)
41
41
  #
42
- # If you want to use Chingus GameStateManager _without_ Chingu::Windoe, see example5.rb
42
+ # If you want to use Chingus GameStateManager _without_ Chingu::Window, see example5.rb
43
43
  #
44
44
  class GameStateManager
45
45
  attr_accessor :inside_state
@@ -1,36 +1,53 @@
1
- #--
2
- #
3
- # Chingu -- Game framework built on top of the opengl accelerated gamelib Gosu
4
- # Copyright (C) 2009 ippa / ippa@rubylicio.us
5
- #
6
- # This library is free software; you can redistribute it and/or
7
- # modify it under the terms of the GNU Lesser General Public
8
- # License as published by the Free Software Foundation; either
9
- # version 2.1 of the License, or (at your option) any later version.
10
- #
11
- # This library is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- # Lesser General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU Lesser General Public
17
- # License along with this library; if not, write to the Free Software
18
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
- #
20
- #++
21
-
22
-
23
- #
24
- # Effect-class
25
- #
26
- module Chingu
27
- class Effect
28
- def initialize(options)
29
- super({:mode => :additive}.merge(options))
30
- @trail = options[:trail] || 10
31
- end
32
-
33
- def update
34
- end
35
- end
1
+ #--
2
+ #
3
+ # Chingu -- Game framework built on top of the opengl accelerated gamelib Gosu
4
+ # Copyright (C) 2009 ippa / ippa@rubylicio.us
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ #++
21
+
22
+
23
+ module Chingu
24
+ module Helpers
25
+
26
+ #
27
+ # Convenience-methods for classes that hold game objects
28
+ # Mixed into Chingu::Window and Chingu::GameState
29
+ #
30
+ module GameObject
31
+
32
+ def add_game_object(object)
33
+ @game_objects.add_game_object(object)
34
+ end
35
+
36
+ def remove_game_object(object)
37
+ @game_objects.remove_game_object(object)
38
+ end
39
+
40
+ def game_objects
41
+ @game_objects
42
+ end
43
+
44
+ #
45
+ # Fetch game objects of a certain type/class
46
+ #
47
+ def game_objects_of_class(klass)
48
+ @game_objects.select { |game_object| game_object.is_a? klass }
49
+ end
50
+ end
51
+
52
+ end
36
53
  end
@@ -0,0 +1,62 @@
1
+ #--
2
+ #
3
+ # Chingu -- Game framework built on top of the opengl accelerated gamelib Gosu
4
+ # Copyright (C) 2009 ippa / ippa@rubylicio.us
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ #++
21
+
22
+
23
+ module Chingu
24
+ module Helpers
25
+
26
+ #
27
+ # push_game_state accepts either a class inherited from GameState or an object-instance from such a class.
28
+ #
29
+ # It will make call new() on a class, and just push an object.
30
+ #
31
+ module GameState
32
+ def push_game_state(state, options = {})
33
+ $window.game_state_manager.push_game_state(state, options)
34
+ end
35
+
36
+ def pop_game_state(options = {})
37
+ $window.game_state_manager.pop_game_state(options)
38
+ end
39
+
40
+ def switch_game_state(state, options = {})
41
+ $window.game_state_manager.switch_game_state(state, options)
42
+ end
43
+
44
+ def transitional_game_state(state, options = {})
45
+ $window.game_state_manager.transitional_game_state(state, options)
46
+ end
47
+
48
+ def current_game_state
49
+ $window.game_state_manager.current_game_state
50
+ end
51
+
52
+ def previous_game_state
53
+ $window.game_state_manager.previous_game_state
54
+ end
55
+
56
+ def clear_game_states
57
+ $window.game_state_manager.clear_game_states
58
+ end
59
+ end
60
+
61
+ end
62
+ end
@@ -21,11 +21,13 @@
21
21
 
22
22
 
23
23
  module Chingu
24
+ module Helpers
25
+
24
26
  #
25
27
  # Various helper-methods to manipulate the screen.
26
28
  # All drawings depend on the global variable $window which should be an instance of Gosu::Window or Chingu::Window
27
29
  #
28
- module GFXHelpers
30
+ module GFX
29
31
 
30
32
  #
31
33
  # Fills whole window with color 'color'.
@@ -86,4 +88,6 @@ module Chingu
86
88
  end
87
89
  end
88
90
  end
91
+
92
+ end
89
93
  end
@@ -21,18 +21,33 @@
21
21
 
22
22
 
23
23
  module Chingu
24
- module Traits
25
- module Input
26
-
24
+ module Helpers
25
+
26
+ #
27
+ # Input-handler mixin that adds #input= and #input
28
+ #
29
+ # #input= does 2 things:
30
+ # 1) Initialized an inputmap
31
+ # 2) notifies the parent (could be main Window or a GameState) that the object wants input
32
+ #
33
+ # In Chingu this is mixed into Window, GameState and GameObject
34
+ #
35
+ module InputClient
27
36
  def input=(input_map)
28
37
  @input = input_map
29
- @parent.add_input_client(self) if @parent
38
+
39
+ if @parent
40
+ if (@input == nil || @input == {})
41
+ @parent.remove_input_client(self)
42
+ else
43
+ @parent.add_input_client(self)
44
+ end
45
+ end
30
46
  end
31
47
 
32
48
  def input
33
49
  @input
34
50
  end
35
-
36
51
  end
37
52
  end
38
53
  end
@@ -1,166 +1,104 @@
1
- #--
2
- #
3
- # Chingu -- Game framework built on top of the opengl accelerated gamelib Gosu
4
- # Copyright (C) 2009 ippa / ippa@rubylicio.us
5
- #
6
- # This library is free software; you can redistribute it and/or
7
- # modify it under the terms of the GNU Lesser General Public
8
- # License as published by the Free Software Foundation; either
9
- # version 2.1 of the License, or (at your option) any later version.
10
- #
11
- # This library is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- # Lesser General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU Lesser General Public
17
- # License along with this library; if not, write to the Free Software
18
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
- #
20
- #++
21
-
22
-
23
- module Chingu
24
-
25
- module InputClient
26
- def input=(input_map)
27
- @input = input_map
28
- @parent.add_input_client(self) if @parent
29
- end
30
-
31
- def input
32
- @input
33
- end
34
- end
35
-
36
- module InputDispatcher
37
- attr_reader :input_clients
38
-
39
- def add_input_client(object)
40
- @input_clients << object
41
- end
42
-
43
- def remove_input_client(object)
44
- @input_clients.delete(object)
45
- end
46
-
47
- def dispatch_button_down(id, object)
48
- return if(object.nil? || object.input.nil?)
49
-
50
- object.input.each do |symbol, action|
51
- if Input::SYMBOL_TO_CONSTANT[symbol] == id
52
- dispatch_action(action, object)
53
- end
54
- end
55
- end
56
-
57
- def dispatch_button_up(id, object)
58
- return if object.nil? || object.input.nil?
59
-
60
- object.input.each do |symbol, action|
61
- if symbol.to_s.include? "released_"
62
- symbol = symbol.to_s.sub("released_", "").to_sym
63
- if Input::SYMBOL_TO_CONSTANT[symbol] == id
64
- dispatch_action(action, object)
65
- end
66
- end
67
- end
68
- end
69
-
70
- #
71
- # Dispatches input-mapper for any given object
72
- #
73
- def dispatch_input_for(object, prefix = "holding_")
74
- return if object.nil? || object.input.nil?
75
-
76
- object.input.each do |symbol, action|
77
- if symbol.to_s.include? prefix
78
- symbol = symbol.to_s.sub(prefix, "").to_sym
79
- if $window.button_down?(Input::SYMBOL_TO_CONSTANT[symbol])
80
- dispatch_action(action, object)
81
- end
82
- end
83
- end
84
- end
85
-
86
- #
87
- # For a given object, dispatch "action".
88
- # An action can be:
89
- #
90
- # * Symbol (:p, :space), translates into a method-call
91
- # * Proc/Lambda, call() it
92
- # * GameState-instance, push it on top of stack
93
- # * GameState-inherited class, create a new instance, cache it and push it on top of stack
94
- #
95
- def dispatch_action(action, object)
96
- # puts "Dispatch Action: #{action} - Objects class: #{object.class.to_s}"
97
- if action.is_a? Symbol
98
- object.send(action)
99
- elsif action.is_a? Proc
100
- action.call
101
- elsif action.is_a? Chingu::GameState
102
- push_game_state(action)
103
- elsif action.superclass == Chingu::GameState
104
- push_game_state(action)
105
- end
106
- end
107
- end
108
-
109
- #
110
- # push_game_state accepts either a class inherited from GameState or an object-instance from such a class.
111
- #
112
- # It will make call new() on a class, and just push an object.
113
- #
114
- module GameStateHelpers
115
- def push_game_state(state, options = {})
116
- $window.game_state_manager.push_game_state(state, options)
117
- end
118
-
119
- def pop_game_state(options = {})
120
- $window.game_state_manager.pop_game_state(options)
121
- end
122
-
123
- def switch_game_state(state, options = {})
124
- $window.game_state_manager.switch_game_state(state, options)
125
- end
126
-
127
- def transitional_game_state(state, options = {})
128
- $window.game_state_manager.transitional_game_state(state, options)
129
- end
130
-
131
- def current_game_state
132
- $window.game_state_manager.current_game_state
133
- end
134
-
135
- def previous_game_state
136
- $window.game_state_manager.previous_game_state
137
- end
138
-
139
- def clear_game_states
140
- $window.game_state_manager.clear_game_states
141
- end
142
- end
143
-
144
- module GameObjectHelpers
145
-
146
- def add_game_object(object)
147
- @game_objects.add_game_object(object)
148
- end
149
-
150
- def remove_game_object(object)
151
- @game_objects.remove_game_object(object)
152
- end
153
-
154
- def game_objects
155
- @game_objects
156
- end
157
-
158
- #
159
- # Fetch game objects of a certain type/class
160
- #
161
- def game_objects_of_class(klass)
162
- @game_objects.select { |game_object| game_object.is_a? klass }
163
- end
164
- end
165
-
1
+ #--
2
+ #
3
+ # Chingu -- Game framework built on top of the opengl accelerated gamelib Gosu
4
+ # Copyright (C) 2009 ippa / ippa@rubylicio.us
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ #++
21
+
22
+
23
+ module Chingu
24
+ module Helpers
25
+
26
+ #
27
+ # Methods for parsing and dispatching Chingus input-maps
28
+ # Mixed into Chingu::Window and Chingu::GameState
29
+ #
30
+ module InputDispatcher
31
+ attr_reader :input_clients
32
+
33
+ def add_input_client(object)
34
+ @input_clients << object unless @input_clients.include?(object)
35
+ end
36
+
37
+ def remove_input_client(object)
38
+ @input_clients.delete(object)
39
+ end
40
+
41
+ def dispatch_button_down(id, object)
42
+ return if(object.nil? || object.input.nil?)
43
+
44
+ object.input.each do |symbol, action|
45
+ if Input::SYMBOL_TO_CONSTANT[symbol] == id
46
+ dispatch_action(action, object)
47
+ end
48
+ end
49
+ end
50
+
51
+ def dispatch_button_up(id, object)
52
+ return if object.nil? || object.input.nil?
53
+
54
+ object.input.each do |symbol, action|
55
+ if symbol.to_s.include? "released_"
56
+ symbol = symbol.to_s.sub("released_", "").to_sym
57
+ if Input::SYMBOL_TO_CONSTANT[symbol] == id
58
+ dispatch_action(action, object)
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ #
65
+ # Dispatches input-mapper for any given object
66
+ #
67
+ def dispatch_input_for(object, prefix = "holding_")
68
+ return if object.nil? || object.input.nil?
69
+
70
+ object.input.each do |symbol, action|
71
+ if symbol.to_s.include? prefix
72
+ symbol = symbol.to_s.sub(prefix, "").to_sym
73
+ if $window.button_down?(Input::SYMBOL_TO_CONSTANT[symbol])
74
+ dispatch_action(action, object)
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ #
81
+ # For a given object, dispatch "action".
82
+ # An action can be:
83
+ #
84
+ # * Symbol (:p, :space), translates into a method-call
85
+ # * Proc/Lambda, call() it
86
+ # * GameState-instance, push it on top of stack
87
+ # * GameState-inherited class, create a new instance, cache it and push it on top of stack
88
+ #
89
+ def dispatch_action(action, object)
90
+ # puts "Dispatch Action: #{action} - Objects class: #{object.class.to_s}"
91
+ if action.is_a? Symbol
92
+ object.send(action)
93
+ elsif action.is_a? Proc
94
+ action.call
95
+ elsif action.is_a? Chingu::GameState
96
+ push_game_state(action)
97
+ elsif action.superclass == Chingu::GameState
98
+ push_game_state(action)
99
+ end
100
+ end
101
+ end
102
+
103
+ end
166
104
  end
@@ -21,7 +21,7 @@
21
21
 
22
22
 
23
23
  module Chingu
24
- module Traits
24
+ module Helpers
25
25
  module RotationCenter
26
26
  #
27
27
  # returns [center_x, center_y] (see Gosu::Image#draw_rot)
@@ -11,7 +11,7 @@ module Chingu
11
11
  #
12
12
  # repeat: [true|false] When one background ends within the screen, repeat/loop it
13
13
  #
14
- def initialize(options)
14
+ def initialize(options = {})
15
15
  super(options)
16
16
  @repeat = options[:repeat] || true
17
17
  @backgrounds = Array.new
@@ -1,20 +1,11 @@
1
1
  module Chingu
2
2
 
3
3
  class Window < Gosu::Window
4
- # adds push_game_state, pop_game_state, current_game_state and previous_game_state
5
- include Chingu::GameStateHelpers
6
-
7
- # adds fill() etc...
8
- include Chingu::GFXHelpers
9
-
10
- # adds game_objects_of_class etc ...
11
- include Chingu::GameObjectHelpers
12
-
13
- # Input dispatch helpers
14
- include Chingu::InputDispatcher
15
-
16
- # input= and input
17
- include Chingu::InputClient
4
+ include Chingu::Helpers::GFX # Adds fill(), fade() etc to each game state
5
+ include Chingu::Helpers::GameState # Easy access to the global game state-queue
6
+ include Chingu::Helpers::GameObject # Adds game_objects_of_class etc ...
7
+ include Chingu::Helpers::InputDispatcher # Input dispatch-helpers
8
+ include Chingu::Helpers::InputClient # WIndow has its own inputmap
18
9
 
19
10
  attr_reader :root, :game_state_manager, :game_objects, :milliseconds_since_last_tick
20
11
 
@@ -27,7 +18,6 @@ module Chingu
27
18
  # - Standard #update which updates all Chingu::GameObject's
28
19
  # - Standard #draw which goes through
29
20
  # - Assethandling with Image["picture.png"] and Sample["shot.wav"]
30
- # - Default input mapping escape to close
31
21
  #
32
22
  def initialize(width = 800, height = 600, fullscreen = false, update_interval = 16.666666)
33
23
  fullscreen ||= ARGV.include?("--fullscreen")
@@ -40,7 +30,7 @@ module Chingu
40
30
  Gosu::Song.autoload_dirs = [".", File.join(@root, "sfx"), File.join(@root, "media")]
41
31
 
42
32
  @game_objects = GameObjectList.new
43
- @input_clients = Set.new # Set is like a unique Array with Hash lookupspeed
33
+ @input_clients = Array.new
44
34
 
45
35
  @fps_counter = FPSCounter.new
46
36
  @game_state_manager = GameStateManager.new
@@ -106,12 +96,18 @@ module Chingu
106
96
  #
107
97
  # Call update() on all game objects belonging to the main window.
108
98
  #
109
- update_game_objects
99
+ @game_objects.update
110
100
 
111
101
  #
112
102
  # Call update() on all game objects belonging to the current game state.
113
103
  #
114
- update_game_state_manager
104
+
105
+ #
106
+ # Call update() on our game_state_manger
107
+ # -> call update on active states
108
+ # -> call update on all game objects in that state
109
+ #
110
+ @game_state_manager.update
115
111
  end
116
112
 
117
113
  #
@@ -131,22 +127,6 @@ module Chingu
131
127
  @game_state_manager.draw
132
128
  end
133
129
 
134
- #
135
- # Call update() on all game objects in main game window.
136
- #
137
- def update_game_objects
138
- @game_objects.update
139
- end
140
-
141
- #
142
- # Call update() on our game_state_manger
143
- # -> call update on active state
144
- # -> call update on all game objects in that state
145
- #
146
- def update_game_state_manager
147
- @game_state_manager.update
148
- end
149
-
150
130
  #
151
131
  # By default button_up sends the keyevent to the GameStateManager
152
132
  # .. Which then is responsible to send it to the right GameState(s)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chingu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5.3
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ippa
@@ -30,7 +30,7 @@ cert_chain:
30
30
  hxtMlw==
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2009-10-06 00:00:00 +02:00
33
+ date: 2009-10-10 00:00:00 +02:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
@@ -97,12 +97,10 @@ files:
97
97
  - examples/media/stickfigure.png
98
98
  - examples/media/video_games.png
99
99
  - lib/chingu.rb
100
- - lib/chingu/actor.rb
101
100
  - lib/chingu/animation.rb
102
101
  - lib/chingu/assets.rb
103
102
  - lib/chingu/basic_game_object.rb
104
103
  - lib/chingu/core_extensions.rb
105
- - lib/chingu/effects.rb
106
104
  - lib/chingu/fpscounter.rb
107
105
  - lib/chingu/game_object.rb
108
106
  - lib/chingu/game_object_list.rb
@@ -111,8 +109,12 @@ files:
111
109
  - lib/chingu/game_states/debug.rb
112
110
  - lib/chingu/game_states/fade_to.rb
113
111
  - lib/chingu/game_states/pause.rb
114
- - lib/chingu/gfx_helpers.rb
115
- - lib/chingu/helpers.rb
112
+ - lib/chingu/helpers/game_object.rb
113
+ - lib/chingu/helpers/game_state.rb
114
+ - lib/chingu/helpers/gfx.rb
115
+ - lib/chingu/helpers/input_client.rb
116
+ - lib/chingu/helpers/input_dispatcher.rb
117
+ - lib/chingu/helpers/rotation_center.rb
116
118
  - lib/chingu/inflector.rb
117
119
  - lib/chingu/input.rb
118
120
  - lib/chingu/named_resource.rb
@@ -123,9 +125,7 @@ files:
123
125
  - lib/chingu/text.rb
124
126
  - lib/chingu/traits/collision_detection.rb
125
127
  - lib/chingu/traits/effect.rb
126
- - lib/chingu/traits/input.rb
127
128
  - lib/chingu/traits/retrofy.rb
128
- - lib/chingu/traits/rotation_center.rb
129
129
  - lib/chingu/traits/timer.rb
130
130
  - lib/chingu/traits/velocity.rb
131
131
  - lib/chingu/window.rb
metadata.gz.sig CHANGED
@@ -1 +1,4 @@
1
- k3Gc��b5]K�Ȇ�1�mV\��!=� DМ�(�%�7R�<Z[.[ 0���#\����4�C���W��9�L��@��Q�H ʠ�9��,��T�K ���-H�7�wS� V�P`3T"t<W��6yL�z��Y,������E nVl_yP�e�6TC�Oe�+q'^����l=�%�|@
1
+ Y�ֿi��� J_$���q����/x[~��Q�}h<5���ڛ�w_�����{
2
+ ҼB�s�F��4��Þ9��Rۖ侎�F�
3
+ �}�� 2ɭ�"�mM���� �|�شN7��$����ǫq"�Z���Bf��&| y᪸T�V����.̴P(5�
4
+ �W���p)J��68�zj�`�PQ�IO5�hes�ZY�O�
@@ -1,17 +0,0 @@
1
- module Chingu
2
- #
3
- # A game object class with most components included, nice for quick prototypes
4
- #
5
- # TODO: we probably wanna expand this concept or remove Actor as a whole.
6
- #
7
- class Actor < Chingu::GameObject
8
- has_traits :effect, :velocity, :input
9
-
10
- def update
11
- # needed for traits to work
12
- super
13
-
14
- # your game logic Here
15
- end
16
- end
17
- end