gosu_extensions 0.1.21 → 0.1.22
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/game_window.rb +3 -26
- data/lib/gosu_extensions.rb +0 -2
- data/lib/traits/controllable.rb +15 -23
- data/spec/lib/traits/controllable_spec.rb +34 -0
- metadata +6 -6
- data/bin/gogogosu +0 -33
- data/lib/menu.rb +0 -30
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.22
|
data/lib/core/game_window.rb
CHANGED
|
@@ -45,8 +45,6 @@ class GameWindow < Gosu::Window
|
|
|
45
45
|
|
|
46
46
|
setup_background
|
|
47
47
|
|
|
48
|
-
setup_menu
|
|
49
|
-
|
|
50
48
|
setup_steps
|
|
51
49
|
setup_waves
|
|
52
50
|
setup_scheduling
|
|
@@ -62,11 +60,12 @@ class GameWindow < Gosu::Window
|
|
|
62
60
|
install_main_loop
|
|
63
61
|
end
|
|
64
62
|
|
|
63
|
+
# This is the main game loop.
|
|
64
|
+
#
|
|
65
65
|
def main_loop
|
|
66
66
|
@main_loop ||= lambda do
|
|
67
|
+
# Smoother, but slower: GC.start if rand > 0.98
|
|
67
68
|
next_step
|
|
68
|
-
# Step the physics environment SUBSTEPS times each update.
|
|
69
|
-
#
|
|
70
69
|
SUBSTEPS.times do
|
|
71
70
|
remove_shapes
|
|
72
71
|
move
|
|
@@ -76,28 +75,10 @@ class GameWindow < Gosu::Window
|
|
|
76
75
|
end
|
|
77
76
|
end
|
|
78
77
|
end
|
|
79
|
-
|
|
80
78
|
def install_main_loop
|
|
81
79
|
@current_loop = main_loop
|
|
82
80
|
end
|
|
83
81
|
|
|
84
|
-
def show_menu
|
|
85
|
-
suspend
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def suspend
|
|
89
|
-
return if @suspended
|
|
90
|
-
@current_loop = @menu.loop
|
|
91
|
-
@suspended = Time.now
|
|
92
|
-
p "suspended"
|
|
93
|
-
end
|
|
94
|
-
def continue
|
|
95
|
-
return unless @suspended
|
|
96
|
-
@current_loop = main_loop
|
|
97
|
-
@suspended = false
|
|
98
|
-
p "continued"
|
|
99
|
-
end
|
|
100
|
-
|
|
101
82
|
def media_path
|
|
102
83
|
@media_path || 'media'
|
|
103
84
|
end
|
|
@@ -177,10 +158,6 @@ class GameWindow < Gosu::Window
|
|
|
177
158
|
end
|
|
178
159
|
end
|
|
179
160
|
|
|
180
|
-
def setup_menu
|
|
181
|
-
@menu = Menu.new self
|
|
182
|
-
end
|
|
183
|
-
|
|
184
161
|
def setup_window
|
|
185
162
|
self.caption = self.class.caption || ""
|
|
186
163
|
end
|
data/lib/gosu_extensions.rb
CHANGED
|
@@ -57,8 +57,6 @@ require 'short_lived'
|
|
|
57
57
|
$:.unshift File.join(File.dirname(__FILE__), '/units')
|
|
58
58
|
require 'thing'
|
|
59
59
|
|
|
60
|
-
require 'menu'
|
|
61
|
-
|
|
62
60
|
DEFAULT_SCREEN_WIDTH = 1200 unless defined?(DEFAULT_SCREEN_WIDTH)
|
|
63
61
|
DEFAULT_SCREEN_HEIGHT = 700 unless defined?(DEFAULT_SCREEN_HEIGHT)
|
|
64
62
|
SUBSTEPS = 10 unless defined?(SUBSTEPS)
|
data/lib/traits/controllable.rb
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
# This is a convenience trait.
|
|
1
2
|
#
|
|
3
|
+
# Instead of calling
|
|
4
|
+
# @controls << Control.new(self, @player1, :some_key_code => :action)
|
|
5
|
+
# you can define the controls in the object itself.
|
|
2
6
|
#
|
|
3
7
|
module Controllable extend Trait
|
|
4
8
|
|
|
@@ -8,34 +12,22 @@ module Controllable extend Trait
|
|
|
8
12
|
|
|
9
13
|
module ClassMethods
|
|
10
14
|
|
|
11
|
-
#
|
|
15
|
+
# Enables to define the controls in the object itself, as in the Example:
|
|
16
|
+
#
|
|
17
|
+
# class Spaceship < Thing
|
|
18
|
+
# it_is Controllable
|
|
19
|
+
# controls Gosu::Button::KbA => Turnable::Left,
|
|
20
|
+
# Gosu::Button::KbD => Turnable::Right,
|
|
21
|
+
# Gosu::Button::KbW => Moveable::Accelerate,
|
|
22
|
+
# Gosu::Button::KbS => Moveable::Backwards,
|
|
23
|
+
# Gosu::Button::KbSpace => Shooter::Shoot
|
|
12
24
|
#
|
|
13
|
-
|
|
14
25
|
def controls mapping
|
|
15
26
|
attr_accessor :controls_mapping
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# primary controls taken, use alternate controls
|
|
19
|
-
self.controls_mapping = self.alternate_controls_mapping if self.respond_to? :alternate_controls_mapping
|
|
20
|
-
else
|
|
21
|
-
self.controls_mapping = mapping
|
|
22
|
-
end
|
|
27
|
+
InitializerHooks.register self do
|
|
28
|
+
self.controls_mapping = mapping
|
|
23
29
|
self.window.add_controls_for self
|
|
24
30
|
end
|
|
25
|
-
InitializerHooks.register self, &hook
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def alternate_controls mapping
|
|
29
|
-
attr_accessor :alternate_controls_mapping
|
|
30
|
-
hook = lambda do
|
|
31
|
-
if self.controls_mapping
|
|
32
|
-
# primary controls taken, use alternate controls
|
|
33
|
-
self.controls_mapping = self.alternate_controls_mapping if self.respond_to? :alternate_controls_mapping
|
|
34
|
-
else
|
|
35
|
-
self.controls_mapping = mapping
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
InitializerHooks.register self, &hook
|
|
39
31
|
end
|
|
40
32
|
|
|
41
33
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe Controllable do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@window = stub :window
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe "add_controls_for" do
|
|
10
|
+
before(:each) do
|
|
11
|
+
@controllable_class = test_class_with Controllable do
|
|
12
|
+
controls :a => :b, :c => :d
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
it "should return the mapping" do
|
|
16
|
+
@window.should_receive(:add_controls_for).once
|
|
17
|
+
|
|
18
|
+
@controllable_class.new @window
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe "controls_mapping" do
|
|
23
|
+
before(:each) do
|
|
24
|
+
@window.stub! :add_controls_for => nil
|
|
25
|
+
@controllable = test_class_with Controllable do
|
|
26
|
+
controls :a => :b, :c => :d
|
|
27
|
+
end.new @window
|
|
28
|
+
end
|
|
29
|
+
it "should return the mapping" do
|
|
30
|
+
@controllable.controls_mapping.should == { :a => :b, :c => :d }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
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
|
+
- 22
|
|
9
|
+
version: 0.1.22
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Florian Hanke
|
|
@@ -15,7 +15,7 @@ bindir: bin
|
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
17
|
date: 2010-04-07 00:00:00 +02:00
|
|
18
|
-
default_executable:
|
|
18
|
+
default_executable:
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
21
21
|
name: gosu
|
|
@@ -43,8 +43,8 @@ dependencies:
|
|
|
43
43
|
version_requirements: *id002
|
|
44
44
|
description: ""
|
|
45
45
|
email: florian.hanke@gmail.com
|
|
46
|
-
executables:
|
|
47
|
-
|
|
46
|
+
executables: []
|
|
47
|
+
|
|
48
48
|
extensions: []
|
|
49
49
|
|
|
50
50
|
extra_rdoc_files: []
|
|
@@ -70,7 +70,6 @@ files:
|
|
|
70
70
|
- lib/extensions/module.rb
|
|
71
71
|
- lib/extensions/numeric.rb
|
|
72
72
|
- lib/gosu_extensions.rb
|
|
73
|
-
- lib/menu.rb
|
|
74
73
|
- lib/traits/attachable.rb
|
|
75
74
|
- lib/traits/controllable.rb
|
|
76
75
|
- lib/traits/damaging.rb
|
|
@@ -128,6 +127,7 @@ test_files:
|
|
|
128
127
|
- spec/lib/extensions/module_spec.rb
|
|
129
128
|
- spec/lib/extensions/numeric_spec.rb
|
|
130
129
|
- spec/lib/traits/attachable_spec.rb
|
|
130
|
+
- spec/lib/traits/controllable_spec.rb
|
|
131
131
|
- spec/lib/traits/damaging_spec.rb
|
|
132
132
|
- spec/lib/traits/imageable_spec.rb
|
|
133
133
|
- spec/lib/traits/shooter_spec.rb
|
data/bin/gogogosu
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#!/usr/local/bin/ruby
|
|
2
|
-
# TODO remove
|
|
3
|
-
|
|
4
|
-
Signal.trap("INT") { puts; exit } # CTRL-C
|
|
5
|
-
|
|
6
|
-
File.open(File.join(File.dirname(__FILE__), '../VERSION')) do |f|
|
|
7
|
-
puts "Gosu Extensions #{f.read}"
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
application = ARGV.first
|
|
11
|
-
|
|
12
|
-
puts "Usage: gogogosu <application_name>" and exit(1) unless application
|
|
13
|
-
|
|
14
|
-
require File.dirname(__FILE__) + '/../generator/gogogosu'
|
|
15
|
-
|
|
16
|
-
generator = Generator::Gogogosu.new
|
|
17
|
-
|
|
18
|
-
generator.dir application do
|
|
19
|
-
generator.dir 'lib' do
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
generator.dir 'media' do
|
|
23
|
-
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
puts <<-START
|
|
28
|
-
Great!
|
|
29
|
-
|
|
30
|
-
Now proceed as follows:
|
|
31
|
-
1. cd #{application}
|
|
32
|
-
2.
|
|
33
|
-
START
|
data/lib/menu.rb
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
class Menu < Thing
|
|
2
|
-
|
|
3
|
-
include Controllable
|
|
4
|
-
|
|
5
|
-
# TODO Move away
|
|
6
|
-
#
|
|
7
|
-
controls Gosu::Button::KbP => :continue
|
|
8
|
-
|
|
9
|
-
def initialize window
|
|
10
|
-
@controls = []
|
|
11
|
-
super window
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# TODO duplicate
|
|
15
|
-
#
|
|
16
|
-
def handle_input
|
|
17
|
-
@controls.each &:handle
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def continue
|
|
21
|
-
window.continue
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def loop
|
|
25
|
-
@loop ||= lambda do
|
|
26
|
-
# self.handle_input
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
end
|