chingu 0.8.0.4 → 0.8.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{chingu}
8
- s.version = "0.8.0.4"
8
+ s.version = "0.8.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ippa"]
12
- s.date = %q{2011-01-02}
12
+ s.date = %q{2011-01-03}
13
13
  s.description = %q{OpenGL accelerated 2D game framework for Ruby. Builds on Gosu (Ruby/C++) which provides all the core functionality. Chingu adds simple yet powerful game states, prettier input handling, deployment safe asset-handling, a basic re-usable game object and stackable game logic.}
14
14
  s.email = %q{ippa@rubylicio.us}
15
15
  s.extra_rdoc_files = [
@@ -54,6 +54,7 @@ Gem::Specification.new do |s|
54
54
  "examples/example25.yml",
55
55
  "examples/example25_fibers_state_machine.rb",
56
56
  "examples/example26_splash_screen.rb",
57
+ "examples/example27_console.rb",
57
58
  "examples/example2_gamestate_basics.rb",
58
59
  "examples/example3_parallax.rb",
59
60
  "examples/example4_gamestates.rb",
@@ -114,6 +115,7 @@ Gem::Specification.new do |s|
114
115
  "lib/chingu/assets.rb",
115
116
  "lib/chingu/basic_game_object.rb",
116
117
  "lib/chingu/classic_game_object.rb",
118
+ "lib/chingu/console.rb",
117
119
  "lib/chingu/core_ext/array.rb",
118
120
  "lib/chingu/fpscounter.rb",
119
121
  "lib/chingu/game_object.rb",
@@ -162,6 +164,7 @@ Gem::Specification.new do |s|
162
164
  "spec/chingu/animation_spec.rb",
163
165
  "spec/chingu/assets_spec.rb",
164
166
  "spec/chingu/basic_game_object_spec.rb",
167
+ "spec/chingu/console_spec.rb",
165
168
  "spec/chingu/fpscounter_spec.rb",
166
169
  "spec/chingu/game_object_list_spec.rb",
167
170
  "spec/chingu/game_object_spec.rb",
@@ -203,6 +206,7 @@ Gem::Specification.new do |s|
203
206
  "examples/example24_enter_name.rb",
204
207
  "examples/example25_fibers_state_machine.rb",
205
208
  "examples/example26_splash_screen.rb",
209
+ "examples/example27_console.rb",
206
210
  "examples/example2_gamestate_basics.rb",
207
211
  "examples/example3_parallax.rb",
208
212
  "examples/example4_gamestates.rb",
@@ -217,6 +221,7 @@ Gem::Specification.new do |s|
217
221
  "spec/chingu/animation_spec.rb",
218
222
  "spec/chingu/assets_spec.rb",
219
223
  "spec/chingu/basic_game_object_spec.rb",
224
+ "spec/chingu/console_spec.rb",
220
225
  "spec/chingu/fpscounter_spec.rb",
221
226
  "spec/chingu/game_object_list_spec.rb",
222
227
  "spec/chingu/game_object_spec.rb",
@@ -9,10 +9,12 @@ class Game < Chingu::Window
9
9
  super(800,400,false) # leave it blank and it will be 800,600,non fullscreen
10
10
  self.input = { :escape => :exit } # exits example on Escape
11
11
  self.caption = "Demonstration of GameStates::EnterName"
12
- push_game_state(GameStates::EnterName.new(:callback => :got_name))
12
+ push_game_state(GameStates::EnterName.new(:callback => method(:got_name)))
13
13
  end
14
14
 
15
- def got_name
15
+ def got_name(name)
16
+ puts "Got name: #{name}"
17
+ exit
16
18
  end
17
19
  end
18
20
 
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require File.join(File.dirname($0), "..", "lib", "chingu")
4
+ include Gosu
5
+ include Chingu
6
+
7
+ #
8
+ # Chingu::Console tries to emulate how Chingu::Window works but without GFX and keyboardinput
9
+ #
10
+ class Game < Chingu::Console
11
+
12
+ def update
13
+ super
14
+ sleep(0.02) # fake some cpu intensive game logic :P
15
+ puts "Gameloop running at #{fps} FPS. milliseconds since last tick #{dt}."
16
+ end
17
+
18
+ end
19
+
20
+ Game.new.show
@@ -37,7 +37,7 @@ require_all "#{CHINGU_ROOT}/chingu/traits"
37
37
  require_all "#{CHINGU_ROOT}/chingu"
38
38
 
39
39
  module Chingu
40
- VERSION = "0.8.0.4"
40
+ VERSION = "0.8.0.5"
41
41
 
42
42
  DEBUG_COLOR = Gosu::Color.new(0xFFFF0000)
43
43
  DEBUG_ZORDER = 9999
@@ -0,0 +1,134 @@
1
+ #--
2
+ #
3
+ # Chingu -- OpenGL accelerated 2D game framework for Ruby
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
+ module Chingu
23
+ #
24
+ # Console is the non-gfx variant of
25
+ #
26
+ #
27
+ class Console
28
+ include Chingu::Helpers::GameState # Easy access to the global game state-queue
29
+ include Chingu::Helpers::GameObject # Adds game_objects_of_class etc ...
30
+
31
+ attr_reader :root, :game_state_manager, :game_objects, :milliseconds_since_last_tick, :factor
32
+
33
+ def initialize(update_interval = 16.666666)
34
+ $window = self
35
+ @update_interval = update_interval
36
+ @root = File.dirname(File.expand_path($0))
37
+ @game_objects = GameObjectList.new
38
+ @fps_counter = FPSCounter.new
39
+ @game_state_manager = GameStateManager.new
40
+ @milliseconds_since_last_tick = 0
41
+ @factor = 1
42
+ setup
43
+ end
44
+
45
+ #
46
+ # This is our "game-loop". Will loop forever, with framerate specified and call update()
47
+ # The idea is to be very simular to how a Chingu::Window works.
48
+ #
49
+ def start
50
+ loop do
51
+ t1 = Time.now
52
+ update
53
+ t2 = Time.now
54
+ update_duration = t2 - t1
55
+
56
+ milliseconds = (@update_interval/1000 - update_duration)
57
+ sleep(milliseconds) if milliseconds > 0
58
+ end
59
+ end
60
+ alias :show :start
61
+
62
+ # Placeholder to be overwritten
63
+ def setup; end;
64
+
65
+ #
66
+ # Returns self inside GameState.initialize (a game state is not 'active' inside initialize())
67
+ # Or returns current active game state (as in a switched to or pushed game state)
68
+ # ... Falls back to returning $window
69
+ #
70
+ # current_scope is used to make GameObject.all and friends work everywhere.
71
+ #
72
+ def current_scope
73
+ game_state_manager.inside_state || game_state_manager.current_game_state || self
74
+ end
75
+
76
+ #
77
+ # Frames per second, access with $window.fps or $window.framerate
78
+ #
79
+ def fps
80
+ @fps_counter.fps
81
+ end
82
+ alias :framerate :fps
83
+
84
+ #
85
+ # Total amount of game iterations (ticks)
86
+ #
87
+ def ticks
88
+ @fps_counter.ticks
89
+ end
90
+
91
+ #
92
+ # Mathematical short name for "milliseconds since last tick"
93
+ #
94
+ def dt
95
+ @milliseconds_since_last_tick
96
+ end
97
+
98
+ #
99
+ # Chingus core-logic / loop. Gosu will call this each game-iteration.
100
+ #
101
+ def update
102
+ #
103
+ # Register a tick with our rather standard tick/framerate counter.
104
+ # Returns the amount of milliseconds since last tick. This number is used in all update()-calls.
105
+ # Without this self.fps would return an incorrect value.
106
+ # If you override this in your Chingu::Window class, make sure to call super.
107
+ #
108
+ @milliseconds_since_last_tick = @fps_counter.register_tick
109
+
110
+ intermediate_update
111
+ end
112
+
113
+ #
114
+ # "game logic" update that is safe to call even between Gosus update-calls
115
+ #
116
+ def intermediate_update
117
+ #
118
+ # Call update() on all game objects belonging to the main window.
119
+ #
120
+ @game_objects.update
121
+
122
+ #
123
+ # Call update() on all game objects belonging to the current game state.
124
+ #
125
+
126
+ #
127
+ # Call update() on our game_state_manger
128
+ # -> call update on active states
129
+ # -> call update on all game objects in that state
130
+ #
131
+ @game_state_manager.update
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ module Chingu
4
+
5
+ describe "Console" do
6
+ before :each do
7
+ @console = Chingu::Console.new
8
+ end
9
+
10
+ it { @console.should respond_to :start }
11
+ it { @console.should respond_to :fps }
12
+ it { @console.should respond_to :update }
13
+ it { @console.should respond_to :root }
14
+ it { @console.should respond_to :game_state_manager }
15
+ it { @console.should respond_to :root }
16
+ it { @console.should respond_to :milliseconds_since_last_tick }
17
+
18
+ context "a new Chingu::Console" do
19
+
20
+ it "should return itself as current scope" do
21
+ @console.current_scope.should == @console
22
+ end
23
+
24
+ it "should have 0 game objects" do
25
+ @console.game_objects.size.should == 0
26
+ end
27
+ end
28
+
29
+ context "each game iteration" do
30
+
31
+ it "@console.update() should call update() on all unpaused game objects" do
32
+ GameObject.create.should_receive(:update)
33
+ GameObject.create(:paused => true).should_not_receive(:update)
34
+ @console.update
35
+ end
36
+
37
+ it "should increment $window.ticks" do
38
+ @console.ticks.should == 0
39
+ @console.update
40
+ @console.ticks.should == 1
41
+ @console.update
42
+ @console.ticks.should == 2
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -50,6 +50,12 @@ module Chingu
50
50
  @game.game_objects.first.visible?.should == false
51
51
  @game.draw
52
52
  end
53
+
54
+ it "should increment $window.ticks" do
55
+ @game.ticks.should == 0
56
+ @game.update
57
+ @game.ticks.should == 1
58
+ end
53
59
  end
54
60
  end
55
61
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 8
8
8
  - 0
9
- - 4
10
- version: 0.8.0.4
9
+ - 5
10
+ version: 0.8.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - ippa
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-02 00:00:00 +01:00
18
+ date: 2011-01-03 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -147,6 +147,7 @@ files:
147
147
  - examples/example25.yml
148
148
  - examples/example25_fibers_state_machine.rb
149
149
  - examples/example26_splash_screen.rb
150
+ - examples/example27_console.rb
150
151
  - examples/example2_gamestate_basics.rb
151
152
  - examples/example3_parallax.rb
152
153
  - examples/example4_gamestates.rb
@@ -207,6 +208,7 @@ files:
207
208
  - lib/chingu/assets.rb
208
209
  - lib/chingu/basic_game_object.rb
209
210
  - lib/chingu/classic_game_object.rb
211
+ - lib/chingu/console.rb
210
212
  - lib/chingu/core_ext/array.rb
211
213
  - lib/chingu/fpscounter.rb
212
214
  - lib/chingu/game_object.rb
@@ -255,6 +257,7 @@ files:
255
257
  - spec/chingu/animation_spec.rb
256
258
  - spec/chingu/assets_spec.rb
257
259
  - spec/chingu/basic_game_object_spec.rb
260
+ - spec/chingu/console_spec.rb
258
261
  - spec/chingu/fpscounter_spec.rb
259
262
  - spec/chingu/game_object_list_spec.rb
260
263
  - spec/chingu/game_object_spec.rb
@@ -322,6 +325,7 @@ test_files:
322
325
  - examples/example24_enter_name.rb
323
326
  - examples/example25_fibers_state_machine.rb
324
327
  - examples/example26_splash_screen.rb
328
+ - examples/example27_console.rb
325
329
  - examples/example2_gamestate_basics.rb
326
330
  - examples/example3_parallax.rb
327
331
  - examples/example4_gamestates.rb
@@ -336,6 +340,7 @@ test_files:
336
340
  - spec/chingu/animation_spec.rb
337
341
  - spec/chingu/assets_spec.rb
338
342
  - spec/chingu/basic_game_object_spec.rb
343
+ - spec/chingu/console_spec.rb
339
344
  - spec/chingu/fpscounter_spec.rb
340
345
  - spec/chingu/game_object_list_spec.rb
341
346
  - spec/chingu/game_object_spec.rb