ippa-chingu 0.5.2.1 → 0.5.3

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
@@ -47,6 +47,7 @@ lib/chingu/game_states/fade_to.rb
47
47
  lib/chingu/game_states/pause.rb
48
48
  lib/chingu/gfx_helpers.rb
49
49
  lib/chingu/helpers.rb
50
+ lib/chingu/inflector.rb
50
51
  lib/chingu/input.rb
51
52
  lib/chingu/named_resource.rb
52
53
  lib/chingu/parallax.rb
@@ -58,5 +59,6 @@ lib/chingu/traits/deprecated_module_visual.rb
58
59
  lib/chingu/traits/deprecated_visual.rb
59
60
  lib/chingu/traits/effect.rb
60
61
  lib/chingu/traits/input.rb
62
+ lib/chingu/traits/rotation_center.rb
61
63
  lib/chingu/traits/velocity.rb
62
64
  lib/chingu/window.rb
data/README.rdoc CHANGED
@@ -5,8 +5,7 @@ DOCUMENTATION: http://rdoc.info/projects/ippa/chingu
5
5
 
6
6
  Ruby 1.9.1 is recommended. Also works with 1.8.7+.
7
7
 
8
- This is an early preview, a lot of functionality is still missing!
9
- It's also in a state of flux while I decide on core-naming etc.
8
+ This is still a rather young project, core classes and naming can still change.
10
9
 
11
10
  == INSTALL
12
11
  gem sources -a http://gems.github.com
@@ -29,11 +28,13 @@ There was always a huge big chunk of checking keyboard-events in the main loop.
29
28
  Borrowing ideas from Rubygame this has now become @player.keyboard(:left => :move_left, :space => :fire ... etc.
30
29
 
31
30
 
32
- == OVERVIEW
33
- Chingu consists of the following core classes:
31
+ == CORE OVERVIEW
32
+ Chingu consists of the following core classes / concepts:
34
33
 
35
34
  === Chingu::Window
36
- The main window, use it at you use Gosu::Window.
35
+ The main window, use it at you use Gosu::Window now. Calcs the framerate, takes care of states,
36
+ handles chingu-formated input, updates and draws BasicGameObject / GameObjects automaticly.
37
+ Available thoughout your source as $window (Yes, that's the only global Chingu has).
37
38
 
38
39
  === Chingu::GameObject
39
40
  Use this for all your in game objects. The player, the enemies, the bullets, the powerups, the loot laying around.
@@ -44,11 +45,8 @@ Has either Chingu::Window or a Chingu::GameState as "owner".
44
45
  === Chingu::BasicGameObject
45
46
  For those who think GameObject is a too little fat, there's BasicGameObject (GameObject inherits from BasicGameObject).
46
47
  BasicGameObject is just an empty frame (no x,y,image accessors or draw-logic) for you to build on.
47
- It _can_ be extended with Chingus trait-system though. and it belong to either $window or a game state as BasicObject.
48
-
49
- === Chingu::Text
50
- Makes use of Gosu::Font more rubyish and powerful.
51
- In it's core, another Chingu::GameObject + Gosu::Font.
48
+ It _can_ be extended with Chingus trait-system though.
49
+ BasicGameObject#parent points to either $window or a game state and is automaticly set on creation time.
52
50
 
53
51
  === Chingu::GameStateManager
54
52
  Keeps track of the game states. Implements a stack-based system with push_game_state and pop_game_state.
@@ -62,14 +60,40 @@ If using game states, the flow of draw/update/button_up/button_down is:
62
60
  Chingu::Window --> Chingu::GameStateManager --> Chingu::GameState.
63
61
  For example, inside game state Menu you call push_game_state(Level). When Level exists, it will go back to Menu.
64
62
 
63
+ === Traits
64
+ Traits are extensions (or plugins if you so will) to BasicGameObjects.
65
+ The aim is so encapsulate common behaivor into stand alone classes and modules for easy inclusion in your game classes.
66
+ In it's most basic form it's just a class which answers to setup() (called on your game objects creation), update() and draw().
67
+ Traits are a fairly new addition to Chingu and will probably morph some more before stabilizing.
68
+
69
+
70
+ == OTHER CLASSES / HELPERS
71
+
72
+ === Chingu::Text
73
+ Makes use of Gosu::Font more rubyish and powerful.
74
+ In it's core, another Chingu::GameObject + Gosu::Font.
75
+
65
76
  === Chingu::Animation
66
77
  Load and interact with tile-based animations. loop, bounce and access invidual frame(s) easily.
67
78
  An "@image = @animation.next!" in your Player#update is usually enough to get you started!
68
79
 
69
- == Chingu::Parallax
80
+ === Chingu::Parallax
70
81
  A class for easy paralaxxscrolling. See example3.rb for more.
71
82
 
72
- == THE BASICS
83
+ === Various Helpers
84
+ Both $window and game states gets some new graphical helpers, currently only 3, but quite useful:
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.
89
+
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
94
+
95
+
96
+ == BASICS / EXAMPLES
73
97
 
74
98
  === Chingu::Window
75
99
  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.
@@ -444,7 +468,7 @@ See http://www.libgosu.org/rdoc/classes/Gosu/Window.html for a full set of metho
444
468
 
445
469
  == TODO:
446
470
  * add :padding and :align => :topleft etc to class Text
447
- * rename Chingu::Window so 'include Chingu' and 'include Gosu' wont make Window collide
471
+ * (skip) rename Chingu::Window so 'include Chingu' and 'include Gosu' wont make Window collide
448
472
  * (done) BasicObject vs GameObject vs ScreenObject => Became BasicGameObject and GameObject
449
473
  * (50%) some kind of componentsystem for GameObject (which should be cleaned up)
450
474
  * (done) scale <--> growth parameter. See trait "effect"
@@ -460,19 +484,19 @@ See http://www.libgosu.org/rdoc/classes/Gosu/Window.html for a full set of metho
460
484
  * (20% done) make a playable simple game in examples\ that really depends on game states
461
485
  * (done) Make a gem- first gem made on github
462
486
  * (done) Automate gemgenning rake-task even more
463
- * More examples when effects are more complete
487
+ * (done) More examples when effects are more complete
464
488
  * class ChipmunkObject
465
- * class Actor/MovingActor with maybe a bit more logic then the basic GameObject. Would ppl find is useful?
489
+ * (has_trait :velocity :p..) class Actor/MovingActor with maybe a bit more logic then the basic GameObject. Would ppl find is useful?
466
490
  * (60% done) Spell check all docs, sloppy spelling turns ppl off. tnx jduff ;).
467
491
  * Tests
468
492
  * (done) Streamline fps / tick code
469
493
  * (done) Encapsulate Font.new / draw_rot with a "class Text < GameObject"
470
494
  * (10% done) Make it possible for ppl to use the parts of Chingu they like
471
495
  * (done) At least make GameStateManager really easy to use with pure Gosu / Document it!
472
- * A more robust game state <-> game_object system to connect them together.
473
496
  * (50% done) Get better at styling rdocs
474
497
  * (done) all �gamestate� ? �game state� ? it's "game state"
475
498
  * (skipping) intergrate MovieMaker - solve this with traits instead.
499
+ * A more robust game state <-> game_object system to connect them together.
476
500
  * FIX example4: :p => Pause.new would Change the "inside_game_state" to Pause and make @player belong to Pause.
477
501
 
478
502
  == WHY?
data/chingu.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{chingu}
5
- s.version = "0.5.2.1"
5
+ s.version = "0.5.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["ippa"]
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
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/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/velocity.rb", "lib/chingu/window.rb"]
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"]
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"]
data/examples/example1.rb CHANGED
@@ -26,9 +26,7 @@ class Game < Chingu::Window
26
26
  end
27
27
  end
28
28
 
29
- class Player < Chingu::GameObject
30
- has_trait :input
31
-
29
+ class Player < Chingu::GameObject
32
30
  def move_left; @x -= 1; end
33
31
  def move_right; @x += 1; end
34
32
  def move_up; @y -= 1; end
data/examples/example2.rb CHANGED
@@ -24,8 +24,6 @@ end
24
24
  # Our Player
25
25
  #
26
26
  class Player < Chingu::GameObject
27
- has_trait :input
28
-
29
27
  def initialize(options = {})
30
28
  super
31
29
  @image = Image["spaceship.png"]
data/examples/example4.rb CHANGED
@@ -40,8 +40,6 @@ end
40
40
 
41
41
  # Our Player
42
42
  class Player < Chingu::GameObject
43
- has_trait :input
44
-
45
43
  def initialize(options = {})
46
44
  super
47
45
  @image = Image["spaceship.png"]
data/lib/chingu.rb CHANGED
@@ -11,12 +11,14 @@ require 'set'
11
11
  effect
12
12
  velocity
13
13
  input
14
+ rotation_center
14
15
  }.each do |lib|
15
16
  root ||= File.dirname(File.expand_path(__FILE__))
16
17
  require File.join(root,"chingu","traits",lib)
17
18
  end
18
19
 
19
20
  %w{ helpers
21
+ inflector
20
22
  gfx_helpers
21
23
  core_extensions
22
24
  basic_game_object
@@ -49,5 +51,5 @@ require 'set'
49
51
  end
50
52
 
51
53
  module Chingu
52
- VERSION = "0.5.2.1"
54
+ VERSION = "0.5.3"
53
55
  end
@@ -6,7 +6,7 @@ module Chingu
6
6
  # An easy to use program to create tileanimations is http://tilestudio.sourceforge.net/
7
7
  #
8
8
  class Animation
9
- attr_accessor :frames
9
+ attr_accessor :frames, :delay
10
10
 
11
11
  #
12
12
  # Create a new Animation.
@@ -36,7 +36,7 @@ module Chingu
36
36
  Array(traits).each do |trait|
37
37
 
38
38
  if trait.is_a?(::Symbol) || trait.is_a?(::String)
39
- string = "Chingu::Traits::#{trait.to_s.downcase.capitalize}"
39
+ string = "Chingu::Traits::#{Chingu::Inflector.camelize(trait)}"
40
40
  klass_or_module = eval(string)
41
41
 
42
42
  if klass_or_module.is_a?(Class)
@@ -48,8 +48,7 @@ module Chingu
48
48
  end
49
49
  end
50
50
  end
51
-
52
-
51
+
53
52
  #
54
53
  # BasicGameUnit initialize
55
54
  #
@@ -7,51 +7,8 @@ module Chingu
7
7
 
8
8
  class GameObject < Chingu::BasicGameObject
9
9
  attr_accessor :image, :x, :y, :angle, :center_x, :center_y, :factor_x, :factor_y, :color, :mode, :zorder
10
-
11
- #
12
- # returns [center_x, center_y]
13
- #
14
- @@rotation_centers = {
15
- :top_left => [0,0],
16
- :left_top => [0,0],
17
-
18
- :center_left => [0,0.5],
19
- :left_center => [0,0.5],
20
-
21
- :bottom_left => [0,1],
22
- :left_bottom => [0,1],
23
-
24
- :top_center => [0.5,0],
25
- :center_top => [0.5,0],
26
-
27
- :center_center => [0.5,0.5],
28
- :center => [0.5,0.5],
29
-
30
- :bottom_center => [0.5,1],
31
- :center_bottom => [0.5,1],
32
-
33
- :top_right => [1,0],
34
- :right_top => [1,0],
35
-
36
- :center_right => [1,0.5],
37
- :right_center => [1,0.5],
38
-
39
- :bottom_right => [1,1],
40
- :right_bottom => [1,1]
41
- }
42
-
43
- #
44
- # Sets @center_x and @center_y according to given alignment. Available alignments are:
45
- #
46
- # :top_left, :center_left, :bottom_left, :top_center,
47
- # :center_center, :bottom_center, :top_right, :center_right and :bottom_right
48
- #
49
- # They're also available in the opposite order with the same meaning.
50
- #
51
- def rotation_center(alignment)
52
- @center_x, @center_y = @@rotation_centers[alignment.to_sym]
53
- end
54
-
10
+ has_trait :input, :rotation_center
11
+
55
12
  def initialize(options = {})
56
13
  super
57
14
 
@@ -115,6 +72,7 @@ module Chingu
115
72
  not inside_window?(x,y)
116
73
  end
117
74
 
75
+ # Calculates the distance from self to a given objevt
118
76
  def distance_to(object)
119
77
  distance(self.x, self.y, object.x, object.y)
120
78
  end
@@ -0,0 +1,12 @@
1
+ module Chingu
2
+ module Inflector
3
+ def Inflector.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
4
+ if first_letter_in_uppercase
5
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
6
+ else
7
+ lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
8
+ end
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,62 @@
1
+ module Chingu
2
+ module Traits
3
+ module RotationCenter
4
+ #
5
+ # returns [center_x, center_y] (see Gosu::Image#draw_rot)
6
+ #
7
+ @@rotation_centers = {
8
+ :top_left => [0,0],
9
+ :left_top => [0,0],
10
+
11
+ :center_left => [0,0.5],
12
+ :middle_left => [0,0.5],
13
+ :left_center => [0,0.5],
14
+ :left_middle => [0,0.5],
15
+
16
+ :bottom_left => [0,1],
17
+ :left_bottom => [0,1],
18
+
19
+ :top_center => [0.5,0],
20
+ :top_middle => [0.5,0],
21
+ :center_top => [0.5,0],
22
+ :middle_top => [0.5,0],
23
+
24
+ :center_center => [0.5,0.5],
25
+ :middle_middle => [0.5,0.5],
26
+ :center => [0.5,0.5],
27
+ :middle => [0.5,0.5],
28
+
29
+ :bottom_center => [0.5,1],
30
+ :bottom_middle => [0.5,1],
31
+ :center_bottom => [0.5,1],
32
+ :middle_bottom => [0.5,1],
33
+
34
+ :top_right => [1,0],
35
+ :right_top => [1,0],
36
+
37
+ :center_right => [1,0.5],
38
+ :middle_right => [1,0.5],
39
+ :right_center => [1,0.5],
40
+ :right_middle => [1,0.5],
41
+
42
+ :bottom_right => [1,1],
43
+ :right_bottom => [1,1]
44
+ }
45
+
46
+ #
47
+ # Sets @center_x and @center_y according to given alignment. Available alignments are:
48
+ #
49
+ # :top_left, :center_left, :bottom_left, :top_center,
50
+ # :center_center, :bottom_center, :top_right, :center_right and :bottom_right
51
+ #
52
+ # They're also available in the opposite order with the same meaning.
53
+ # They're also available (hey, hashlookups are speedy) with "middle" instead of "center" since
54
+ # those 2 words basicly have the same meaning and are both understandable.
55
+ #
56
+ def rotation_center(alignment)
57
+ @center_x, @center_y = @@rotation_centers[alignment.to_sym]
58
+ end
59
+
60
+ end
61
+ end
62
+ end
data/lib/chingu/window.rb CHANGED
@@ -107,12 +107,12 @@ module Chingu
107
107
 
108
108
 
109
109
  #
110
- # Call update(milliseconds_since_last_tick) on all game objects belonging to the main window.
110
+ # Call update() on all game objects belonging to the main window.
111
111
  #
112
112
  update_game_objects
113
113
 
114
114
  #
115
- # Call update(milliseconds_since_last_tick) on all game objects belonging to the current game state.
115
+ # Call update() on all game objects belonging to the current game state.
116
116
  #
117
117
  update_game_state_manager
118
118
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ippa-chingu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ippa
@@ -83,6 +83,7 @@ files:
83
83
  - lib/chingu/game_states/pause.rb
84
84
  - lib/chingu/gfx_helpers.rb
85
85
  - lib/chingu/helpers.rb
86
+ - lib/chingu/inflector.rb
86
87
  - lib/chingu/input.rb
87
88
  - lib/chingu/named_resource.rb
88
89
  - lib/chingu/parallax.rb
@@ -94,10 +95,12 @@ files:
94
95
  - lib/chingu/traits/deprecated_visual.rb
95
96
  - lib/chingu/traits/effect.rb
96
97
  - lib/chingu/traits/input.rb
98
+ - lib/chingu/traits/rotation_center.rb
97
99
  - lib/chingu/traits/velocity.rb
98
100
  - lib/chingu/window.rb
99
101
  has_rdoc: false
100
102
  homepage: http://github.com/ippa/chingu/tree/master
103
+ licenses:
101
104
  post_install_message:
102
105
  rdoc_options:
103
106
  - --main
@@ -119,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
122
  requirements: []
120
123
 
121
124
  rubyforge_project: chingu
122
- rubygems_version: 1.2.0
125
+ rubygems_version: 1.3.5
123
126
  signing_key:
124
127
  specification_version: 3
125
128
  summary: Game framework built on top of the OpenGL accelerated game lib Gosu