ippa-chingu 0.5.3 → 0.5.4

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/Manifest.txt CHANGED
@@ -1,4 +1,5 @@
1
1
  History.txt
2
+ LICENSE
2
3
  Manifest.txt
3
4
  README.rdoc
4
5
  Rakefile
@@ -6,10 +7,12 @@ benchmarks/README.txt
6
7
  benchmarks/benchmark.rb
7
8
  benchmarks/benchmark3.rb
8
9
  benchmarks/benchmark4.rb
10
+ benchmarks/benchmark5.rb
9
11
  benchmarks/meta_benchmark.rb
10
12
  benchmarks/meta_benchmark2.rb
11
13
  chingu.gemspec
12
14
  examples/example1.rb
15
+ examples/example10.rb
13
16
  examples/example2.rb
14
17
  examples/example3.rb
15
18
  examples/example4.rb
@@ -53,12 +56,13 @@ lib/chingu/named_resource.rb
53
56
  lib/chingu/parallax.rb
54
57
  lib/chingu/particle.rb
55
58
  lib/chingu/rect.rb
59
+ lib/chingu/require_all.rb
56
60
  lib/chingu/text.rb
57
61
  lib/chingu/traits/collision_detection.rb
58
- lib/chingu/traits/deprecated_module_visual.rb
59
- lib/chingu/traits/deprecated_visual.rb
60
62
  lib/chingu/traits/effect.rb
63
+ lib/chingu/traits/effect_module.rb
61
64
  lib/chingu/traits/input.rb
62
65
  lib/chingu/traits/rotation_center.rb
63
66
  lib/chingu/traits/velocity.rb
67
+ lib/chingu/traits/velocity_module.rb
64
68
  lib/chingu/window.rb
data/README.rdoc CHANGED
@@ -83,14 +83,14 @@ A class for easy paralaxxscrolling. See example3.rb for more.
83
83
  === Various Helpers
84
84
  Both $window and game states gets some new graphical helpers, currently only 3, but quite useful:
85
85
 
86
- fill() # Fills whole window with color 'color'.
87
- fill_rect() # Fills a given Rect 'rect' with Color 'color'
88
- fill_gradient() # Fills window or a given rect with a gradient between two colors.
86
+ fill() # Fills whole window with color 'color'.
87
+ fill_rect() # Fills a given Rect 'rect' with Color 'color'
88
+ fill_gradient() # Fills window or a given rect with a gradient between two colors.
89
89
 
90
90
  If you base your models on GameObject (or BasicGameObject) you get:
91
- Enemy.all # Returns all object based on this class
92
- Enemy.each # Iterates through all objects of class Enemt.
93
- Enemy.destroy_if(&block) # destroy all objects for which &block returns true
91
+ Enemy.all # Returns all object based on this class
92
+ Enemy.each # Iterates through all objects of class Enemt.
93
+ Enemy.destroy_if(&block) # destroy all objects for which &block returns true
94
94
 
95
95
 
96
96
  == BASICS / EXAMPLES
@@ -514,6 +514,7 @@ See http://www.libgosu.org/rdoc/classes/Gosu/Window.html for a full set of metho
514
514
  * 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.
515
515
  * Jduff for input / commits.
516
516
  * Jlnr,Philymore,Shawn24,JamesKilton for constructive feedback/discussions.
517
+ * Thanks to http://github.com/tarcieri for require_all code, good stuff
517
518
 
518
519
  == REQUIREMENTS:
519
520
  * Gosu latest version
@@ -0,0 +1,29 @@
1
+ require 'benchmark'
2
+ require 'rubygems'
3
+ require 'randomr'
4
+
5
+ class Foo
6
+ def initialize
7
+ end
8
+
9
+ def bar
10
+ end
11
+ end
12
+
13
+ foo = Foo.new
14
+
15
+ a = Array.new
16
+ n = 1000000
17
+ Benchmark.bm(22) do |x|
18
+ x.report('respond_to?') do
19
+ n.times do
20
+ foo.respond_to?(:bar)
21
+ end
22
+ end
23
+
24
+ x.report('foo.bar method call') do
25
+ n.times do
26
+ foo.bar
27
+ end
28
+ end
29
+ end
data/chingu.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{chingu}
5
- s.version = "0.5.3"
5
+ s.version = "0.5.4"
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-09-09}
9
+ s.date = %q{2009-09-17}
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", "Manifest.txt", "README.rdoc", "Rakefile", "benchmarks/README.txt", "benchmarks/benchmark.rb", "benchmarks/benchmark3.rb", "benchmarks/benchmark4.rb", "benchmarks/meta_benchmark.rb", "benchmarks/meta_benchmark2.rb", "chingu.gemspec", "examples/example1.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_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/text.rb", "lib/chingu/traits/collision_detection.rb", "lib/chingu/traits/deprecated_module_visual.rb", "lib/chingu/traits/deprecated_visual.rb", "lib/chingu/traits/effect.rb", "lib/chingu/traits/input.rb", "lib/chingu/traits/rotation_center.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/meta_benchmark.rb", "benchmarks/meta_benchmark2.rb", "chingu.gemspec", "examples/example1.rb", "examples/example10.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_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/effect_module.rb", "lib/chingu/traits/input.rb", "lib/chingu/traits/rotation_center.rb", "lib/chingu/traits/velocity.rb", "lib/chingu/traits/velocity_module.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"]
@@ -0,0 +1,71 @@
1
+ require 'rubygems'
2
+ require 'opengl'
3
+ require File.join(File.dirname($0), "..", "lib", "chingu")
4
+ include Gosu
5
+ include Chingu
6
+ $stderr.sync = $stdout.sync = true
7
+
8
+ #
9
+ # Testing out a new module-only-super-chain trait system
10
+ #
11
+ class Game < Chingu::Window
12
+ def initialize
13
+ super(400,400)
14
+ self.caption = "Testing out new module-based traits (SPACE for more spaceships)"
15
+ self.input = { :space => :new_thing, :esc => :exit }
16
+ new_thing(200,200)
17
+ end
18
+
19
+ def update
20
+ puts "--- UPDATE ---"
21
+ super
22
+ end
23
+
24
+ def draw
25
+ puts "--- DRAW ---"
26
+ super
27
+ end
28
+
29
+ def new_thing(x=nil, y=nil)
30
+ Thing.new(:x => x||rand($window.width), :y => y||rand($window.height), :debug => true)
31
+ end
32
+ end
33
+
34
+ class Thing < Chingu::GameObject
35
+ has_trait :effect
36
+ has_trait :velocity
37
+
38
+ def initialize(options)
39
+ super
40
+ @image = Image["spaceship.png"]
41
+ self.rotation_center(:center)
42
+
43
+ # Julians ninjahack to get that sweet pixely feeling when zooming :)
44
+ glBindTexture(GL_TEXTURE_2D, @image.gl_tex_info.tex_name)
45
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
46
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
47
+
48
+ self.factor = 8
49
+ self.rotating = 2
50
+ self.velocity_x = 2
51
+ end
52
+
53
+ def update
54
+ puts "Thing#update"
55
+ if outside_window?
56
+ @velocity_x = -@velocity_x
57
+ @rotating = -@rotating
58
+ end
59
+
60
+ super
61
+ end
62
+
63
+ def draw
64
+ puts "Thing#draw"
65
+ super
66
+ end
67
+
68
+ end
69
+
70
+
71
+ Game.new.show
data/examples/example9.rb CHANGED
@@ -19,6 +19,14 @@ end
19
19
 
20
20
  class FireCube < Chingu::GameObject
21
21
  has_traits :velocity, :effect
22
+ has_trait :collision_detection
23
+ #
24
+ # TODO:
25
+ # has_trait :collision_detection, :type => :bounding_box
26
+ # has_trait :collision_detection, :type => :radius
27
+ #
28
+
29
+ attr_accessor :color
22
30
 
23
31
  def initialize(options)
24
32
  super
@@ -27,17 +35,18 @@ class FireCube < Chingu::GameObject
27
35
  # initialize with a rightwards velocity with some damping to look more realistic
28
36
  @velocity_x = options[:velocity_x] || 3 - rand(6)
29
37
  @velocity_y = options[:velocity_y] || 3 - rand(6)
30
- @rect = Rect.new([@x, @y, 20, 20])
38
+ @bounding_box = Rect.new([@x, @y, 20, 20])
39
+ @color = Color.new(255,100,255,255)
31
40
  end
32
41
 
33
- def update
34
- super
35
- @rect.x = @x
36
- @rect.y = @y
42
+ def draw
43
+ $window.fill_rect(@bounding_box, @color)
37
44
  end
38
45
 
39
- def draw
40
- $window.fill_rect(@rect, Color.new(@color.alpha,100,255,255))
46
+ def die!
47
+ @color = Color.new(255,255,255,255)
48
+ self.fading = -20
49
+ self.detect_collisions = false
41
50
  end
42
51
 
43
52
  end
@@ -45,7 +54,7 @@ end
45
54
  class Particles < Chingu::GameState
46
55
  def setup
47
56
  self.input = { :space => :new_fire_cube }
48
- 100.times { new_fire_cube }
57
+ 20.times { new_fire_cube }
49
58
  end
50
59
 
51
60
  def new_fire_cube
@@ -62,12 +71,14 @@ class Particles < Chingu::GameState
62
71
  particle.velocity_y = -particle.velocity_y
63
72
  end
64
73
  end
65
- #FireCube.all.each do |particle|
66
- # FireCube.all.each do |particle2|
67
- # if particle.rect.collides_with
68
- #
69
- # end
70
- #end
74
+
75
+ #
76
+ # GameObject.each_collsion wont collide an object with itself
77
+ #
78
+ FireCube.each_collision(FireCube) do |cube1, cube2|
79
+ cube1.die!
80
+ cube2.die!
81
+ end
71
82
 
72
83
  self.game_objects.reject! { |object| object.color.alpha == 0 }
73
84
 
data/lib/chingu.rb CHANGED
@@ -1,55 +1,32 @@
1
+ #--
1
2
  #
3
+ # Chingu -- Game framework built on top of the opengl accelerated gamelib Gosu
4
+ # Copyright (C) 2009 ippa / ippa@rubylicio.us
2
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.
3
10
  #
4
- unless RUBY_VERSION =~ /1\.9/
5
- require 'rubygems'
6
- end
7
- require 'gosu'
8
- require 'set'
9
-
10
- %w{ collision_detection
11
- effect
12
- velocity
13
- input
14
- rotation_center
15
- }.each do |lib|
16
- root ||= File.dirname(File.expand_path(__FILE__))
17
- require File.join(root,"chingu","traits",lib)
18
- end
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
+ #++
19
21
 
20
- %w{ helpers
21
- inflector
22
- gfx_helpers
23
- core_extensions
24
- basic_game_object
25
- game_object
26
- actor
27
- effects
28
- game_state_manager
29
- game_state
30
- window
31
- fpscounter
32
- named_resource
33
- assets
34
- text
35
- rect
36
- animation
37
- particle
38
- input
39
- parallax
40
- }.each do |lib|
41
- root ||= File.dirname(File.expand_path(__FILE__))
42
- require File.join(root,"chingu",lib)
43
- end
22
+ CHINGU_ROOT = File.dirname(File.expand_path(__FILE__))
44
23
 
45
- %w{ pause
46
- fade_to
47
- debug
48
- }.each do |lib|
49
- root ||= File.dirname(File.expand_path(__FILE__))
50
- require File.join(root,"chingu","game_states",lib)
51
- end
24
+ require 'rubygems' unless RUBY_VERSION =~ /1\.9/
25
+ require 'gosu'
26
+ require 'set'
27
+ require File.join(CHINGU_ROOT,"chingu","require_all") # Thanks to http://github.com/tarcieri/require_all !
28
+ require_all "#{CHINGU_ROOT}/chingu"
52
29
 
53
30
  module Chingu
54
- VERSION = "0.5.3"
31
+ VERSION = "0.5.4"
55
32
  end
@@ -8,22 +8,10 @@ module Chingu
8
8
  class BasicGameObject
9
9
  attr_reader :options, :parent
10
10
 
11
- #
12
- # Create class variable @traits in every new class derived from GameObject
13
- #
14
- def self.inherited(subclass)
15
- subclass.instance_variable_set("@traits", Set.new)
16
- end
17
-
18
- class << self
19
- attr_accessor :traits
20
- end
21
-
22
11
  #
23
12
  # adds a trait or traits to a certain game class
24
13
  #
25
14
  # Executes a ruby "include" the specified module
26
- # and sets up update and draw hooks.
27
15
  #
28
16
  def self.has_trait(*traits)
29
17
  has_traits(*traits)
@@ -34,17 +22,8 @@ module Chingu
34
22
  #
35
23
  def self.has_traits(*traits)
36
24
  Array(traits).each do |trait|
37
-
38
25
  if trait.is_a?(::Symbol) || trait.is_a?(::String)
39
- string = "Chingu::Traits::#{Chingu::Inflector.camelize(trait)}"
40
- klass_or_module = eval(string)
41
-
42
- if klass_or_module.is_a?(Class)
43
- trait = klass_or_module.new(self, {})
44
- @traits << trait
45
- elsif klass_or_module.is_a?(Module)
46
- include klass_or_module
47
- end
26
+ include Chingu::Traits.const_get(Chingu::Inflector.camelize(trait))
48
27
  end
49
28
  end
50
29
  end
@@ -58,11 +37,6 @@ module Chingu
58
37
  #
59
38
  def initialize(options = {})
60
39
  @options = options
61
- setupable_traits
62
- updateable_traits
63
- drawable_traits
64
-
65
- @setupable_traits.each { |c| c.setup(self, options) }
66
40
 
67
41
  #
68
42
  # A GameObject can either belong to a GameState or our mainwindow ($window)
@@ -73,37 +47,19 @@ module Chingu
73
47
  @parent.add_game_object(self) if @parent
74
48
  end
75
49
 
50
+ # This will call #setup on the latest trait mixed in, which then will pass it on with super.
51
+ setup_trait(options)
76
52
  end
77
53
 
78
- #
79
- # Get all traits
80
- #
81
- def traits; self.class.traits || []; end
82
-
83
- def setupable_traits
84
- @setupable_traits ||= traits.select { |c| c.respond_to?(:setup) }
85
- end
86
- def updateable_traits
87
- @updateable_traits ||= traits.select { |c| c.respond_to?(:update) }
88
- end
89
- def drawable_traits
90
- @drawable_traits ||= traits.select { |c| c.respond_to?(:draw) }
54
+
55
+ def setup_trait(options)
91
56
  end
92
57
 
93
- #
94
- # Call .update on all traits that implements it
95
- #
96
58
  def update
97
- @updateable_traits.each { |c| c.update(self) }
98
59
  end
99
60
 
100
- #
101
- # Call .draw on all traits that implements it
102
- #
103
61
  def draw
104
- @drawable_traits.each { |c| c.draw(self) }
105
- end
106
-
62
+ end
107
63
 
108
64
  #
109
65
  # Fetch all objects of a current class.
@@ -1,3 +1,25 @@
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
+
1
23
  #
2
24
  # Core extensions to GOSU
3
25
  # Some of these require the gem 'texplay'