gosu_extensions 0.1.19 → 0.1.20
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/VERSION +1 -1
- data/lib/core/control.rb +28 -0
- data/lib/core/controls.rb +16 -21
- data/lib/core/game_window.rb +24 -13
- data/lib/gosu_extensions.rb +1 -0
- metadata +4 -4
- data/spec/lib/core/game_window_spec.rb +0 -51
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.20
|
data/lib/core/control.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
#
|
3
|
+
class Control
|
4
|
+
|
5
|
+
#
|
6
|
+
#
|
7
|
+
def initialize window, controllable, mapping = nil
|
8
|
+
@window = window
|
9
|
+
@controllable = controllable
|
10
|
+
@mapping = mapping || controllable.respond_to?(:controls_mapping) && controllable.controls_mapping
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
#
|
15
|
+
def mapping?
|
16
|
+
@mapping && !@mapping.empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
#
|
21
|
+
def handle
|
22
|
+
return if @controllable.destroyed?
|
23
|
+
@mapping.each do |key, command|
|
24
|
+
@controllable.send(command) if @window.button_down? key
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/core/controls.rb
CHANGED
@@ -1,35 +1,30 @@
|
|
1
|
-
# Controls for a controllable.
|
2
|
-
# Example:
|
3
|
-
# # Note: left, right, full_speed_ahead, reverse, revive are
|
4
|
-
# # methods on the @player.
|
5
|
-
# #
|
6
|
-
# @controls << Controls.new(self, @player,
|
7
|
-
# Gosu::Button::KbA => :left,
|
8
|
-
# Gosu::Button::KbD => :right,
|
9
|
-
# Gosu::Button::KbW => :full_speed_ahead,
|
10
|
-
# Gosu::Button::KbS => :reverse,
|
11
|
-
# Gosu::Button::Kb1 => :revive
|
12
|
-
# )
|
13
|
-
#
|
14
1
|
#
|
15
2
|
#
|
16
3
|
class Controls
|
17
4
|
|
18
5
|
#
|
19
6
|
#
|
20
|
-
def initialize
|
21
|
-
@
|
22
|
-
|
23
|
-
|
7
|
+
def initialize
|
8
|
+
@controls = []
|
9
|
+
end
|
10
|
+
|
11
|
+
# Add the given control to the controls, except if it is nil or has no mapping.
|
12
|
+
#
|
13
|
+
def << control
|
14
|
+
return unless control && control.mapping?
|
15
|
+
@controls << control
|
16
|
+
end
|
17
|
+
|
18
|
+
# Remove the control(s) with the given controllable.
|
19
|
+
#
|
20
|
+
def remove_all_of controllable
|
21
|
+
@controls.reject { |control| control.controllable == controllable }
|
24
22
|
end
|
25
23
|
|
26
24
|
#
|
27
25
|
#
|
28
26
|
def handle
|
29
|
-
|
30
|
-
@mapping.each do |key, command|
|
31
|
-
@controllable.send(command) if @window.button_down? key
|
32
|
-
end
|
27
|
+
@controls.each &:handle
|
33
28
|
end
|
34
29
|
|
35
30
|
end
|
data/lib/core/game_window.rb
CHANGED
@@ -37,6 +37,7 @@ class GameWindow < Gosu::Window
|
|
37
37
|
setup_moveables
|
38
38
|
setup_remove_shapes
|
39
39
|
setup_controls
|
40
|
+
setup_window_control # e.g. ESC => exits
|
40
41
|
|
41
42
|
after_initialize
|
42
43
|
|
@@ -195,7 +196,10 @@ class GameWindow < Gosu::Window
|
|
195
196
|
@remove_shapes = RemoveShapes.new
|
196
197
|
end
|
197
198
|
def setup_controls
|
198
|
-
@controls =
|
199
|
+
@controls = Controls.new
|
200
|
+
end
|
201
|
+
def setup_window_control
|
202
|
+
add_controls_for self
|
199
203
|
end
|
200
204
|
def setup_containers
|
201
205
|
@players = []
|
@@ -247,7 +251,7 @@ class GameWindow < Gosu::Window
|
|
247
251
|
# Gosu::Button::Kb1 => :revive
|
248
252
|
#
|
249
253
|
def add_controls_for object
|
250
|
-
@controls <<
|
254
|
+
@controls << Control.new(self, object)
|
251
255
|
end
|
252
256
|
|
253
257
|
def next_step
|
@@ -270,7 +274,7 @@ class GameWindow < Gosu::Window
|
|
270
274
|
# Each step, this is called to handle any input.
|
271
275
|
#
|
272
276
|
def handle_input
|
273
|
-
@controls.
|
277
|
+
@controls.handle
|
274
278
|
end
|
275
279
|
# Does a single step.
|
276
280
|
#
|
@@ -364,6 +368,8 @@ class GameWindow < Gosu::Window
|
|
364
368
|
moveable.add_to @environment
|
365
369
|
end
|
366
370
|
|
371
|
+
# Remove the shapes that are marked for removal.
|
372
|
+
#
|
367
373
|
def remove_shapes
|
368
374
|
@remove_shapes.remove_from @environment, @moveables
|
369
375
|
end
|
@@ -383,35 +389,40 @@ class GameWindow < Gosu::Window
|
|
383
389
|
# Drawing methods
|
384
390
|
#
|
385
391
|
|
392
|
+
# Method called by Gosu.
|
393
|
+
#
|
386
394
|
def draw
|
387
395
|
draw_background
|
388
396
|
draw_ambient
|
389
397
|
draw_moveables
|
390
398
|
draw_ui
|
391
399
|
end
|
400
|
+
# Draws a background image.
|
401
|
+
#
|
392
402
|
def draw_background
|
393
403
|
@background_image.draw 0, 0, Layer::Background, 1.0, 1.0 if @background_image
|
394
404
|
end
|
405
|
+
# Draw ambient objects, like asteroids or the like that do not influence the player.
|
406
|
+
#
|
395
407
|
def draw_ambient
|
396
408
|
|
397
409
|
end
|
410
|
+
# Draw the moveables.
|
411
|
+
#
|
398
412
|
def draw_moveables
|
399
413
|
@moveables.draw
|
400
414
|
end
|
401
|
-
|
402
|
-
|
403
|
-
end
|
404
|
-
|
405
|
-
# Escape exits by default.
|
415
|
+
# Override for example with
|
416
|
+
# @font.draw "P1 Score: ", 10, 10, ZOrder::UI, 1.0, 1.0, 0xffff0000
|
406
417
|
#
|
407
|
-
def
|
408
|
-
|
418
|
+
def draw_ui
|
419
|
+
|
409
420
|
end
|
410
421
|
|
411
|
-
#
|
422
|
+
#
|
412
423
|
#
|
413
|
-
def
|
414
|
-
|
424
|
+
def button_down *
|
425
|
+
handle_input
|
415
426
|
end
|
416
427
|
|
417
428
|
end
|
data/lib/gosu_extensions.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 20
|
9
|
+
version: 0.1.20
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Florian Hanke
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-07 00:00:00 +02:00
|
18
18
|
default_executable: gogogosu
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- Rakefile
|
54
54
|
- VERSION
|
55
55
|
- generator/gogogosu.rb
|
56
|
+
- lib/core/control.rb
|
56
57
|
- lib/core/controls.rb
|
57
58
|
- lib/core/game_window.rb
|
58
59
|
- lib/core/initializer_hooks.rb
|
@@ -118,7 +119,6 @@ signing_key:
|
|
118
119
|
specification_version: 3
|
119
120
|
summary: Default extensions built onto the popular Gosu Framework. Uses Chipmunk for game physics. That's it for now. I'm working on them. Anyway, GAME ON!
|
120
121
|
test_files:
|
121
|
-
- spec/lib/core/game_window_spec.rb
|
122
122
|
- spec/lib/core/initializer_hooks_spec.rb
|
123
123
|
- spec/lib/core/it_is_a_spec.rb
|
124
124
|
- spec/lib/core/trait_spec.rb
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '/../../spec_helper')
|
2
|
-
|
3
|
-
describe GameWindow do
|
4
|
-
|
5
|
-
class Gosu::Window
|
6
|
-
def initialize(*)
|
7
|
-
# Note: Let's not initialize a real window.
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class GameWindowTest < GameWindow
|
12
|
-
def setup_font
|
13
|
-
# Note: Causes errors, test separately.
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
before(:each) do
|
18
|
-
@window = GameWindowTest.new
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "gravity and gravity_vector" do
|
22
|
-
context 'default' do
|
23
|
-
it "should have a calculated value" do
|
24
|
-
@window.gravity_vector.x.should == 0.0
|
25
|
-
@window.gravity_vector.y.should == 0.098
|
26
|
-
end
|
27
|
-
end
|
28
|
-
context 'user defined' do
|
29
|
-
before(:each) do
|
30
|
-
GameWindowTest.gravity 100
|
31
|
-
@window = GameWindowTest.new
|
32
|
-
end
|
33
|
-
it "should have a user defined value" do
|
34
|
-
@window.gravity_vector.x.should == 0.0
|
35
|
-
@window.gravity_vector.y.should == (100/SUBSTEPS)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "draw" do
|
41
|
-
it "should call other draw methods in sequence" do
|
42
|
-
@window.should_receive(:draw_background).once.with
|
43
|
-
@window.should_receive(:draw_ambient).once.with
|
44
|
-
@window.should_receive(:draw_moveables).once.with
|
45
|
-
@window.should_receive(:draw_ui).once.with
|
46
|
-
|
47
|
-
@window.draw
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|