arcade 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/arcade/base.rb +31 -10
- data/lib/arcade/version.rb +1 -1
- metadata +8 -8
data/lib/arcade/base.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
module Arcade
|
2
|
+
module Errors
|
3
|
+
class NameError < StandardError;end
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
1
7
|
module Arcade
|
2
8
|
module Keyboard
|
3
9
|
Gosu::Button.constants.each do |cons|
|
@@ -15,7 +21,7 @@ end
|
|
15
21
|
class Arcade::GameWindow < Gosu::Window
|
16
22
|
def initialize width, height
|
17
23
|
@current_time = Gosu::milliseconds
|
18
|
-
@objects =
|
24
|
+
@objects = {}
|
19
25
|
|
20
26
|
@keypress_listeners = Hash.new { |h,k| h[k] = [] }
|
21
27
|
|
@@ -27,7 +33,7 @@ class Arcade::GameWindow < Gosu::Window
|
|
27
33
|
self.add_listener key, game_object
|
28
34
|
end
|
29
35
|
|
30
|
-
@objects
|
36
|
+
@objects.merge! game_object.name => game_object
|
31
37
|
end
|
32
38
|
|
33
39
|
def register game_object
|
@@ -35,6 +41,10 @@ class Arcade::GameWindow < Gosu::Window
|
|
35
41
|
self.add_object(game_object)
|
36
42
|
end
|
37
43
|
|
44
|
+
def get_object object_name
|
45
|
+
@objects[object_name]
|
46
|
+
end
|
47
|
+
|
38
48
|
def add_listener key, object
|
39
49
|
@keypress_listeners[key] << object
|
40
50
|
end
|
@@ -48,7 +58,7 @@ class Arcade::GameWindow < Gosu::Window
|
|
48
58
|
end
|
49
59
|
|
50
60
|
def draw
|
51
|
-
|
61
|
+
each_object do |game_object|
|
52
62
|
game_object.draw
|
53
63
|
end
|
54
64
|
end
|
@@ -63,8 +73,8 @@ class Arcade::GameWindow < Gosu::Window
|
|
63
73
|
end
|
64
74
|
end
|
65
75
|
|
66
|
-
|
67
|
-
(@objects - [object]).each do |other|
|
76
|
+
each_object do |object|
|
77
|
+
(@objects.values - [object]).each do |other|
|
68
78
|
if object.collides_with?(other)
|
69
79
|
object.collided_with(other)
|
70
80
|
end
|
@@ -83,7 +93,7 @@ class Arcade::GameWindow < Gosu::Window
|
|
83
93
|
object.hit_edge(edge) if edge
|
84
94
|
end
|
85
95
|
|
86
|
-
|
96
|
+
each_object do |object|
|
87
97
|
object._update(dt)
|
88
98
|
end
|
89
99
|
end
|
@@ -99,6 +109,13 @@ class Arcade::GameWindow < Gosu::Window
|
|
99
109
|
x+width, y+height, color,
|
100
110
|
x, y+height, color
|
101
111
|
end
|
112
|
+
|
113
|
+
private
|
114
|
+
def each_object
|
115
|
+
@objects.each do |name, object|
|
116
|
+
yield object
|
117
|
+
end
|
118
|
+
end
|
102
119
|
end
|
103
120
|
|
104
121
|
class Arcade::GameObject
|
@@ -122,7 +139,9 @@ class Arcade::GameObject
|
|
122
139
|
if prop = mname.scan(/^set_(.+)/).flatten.first
|
123
140
|
@state.send(:"#{prop}=", *args)
|
124
141
|
else
|
125
|
-
@state.send(method, *args)
|
142
|
+
@state.send(method, *args).tap do |val|
|
143
|
+
warn "WARNING: Called #{self.class}##{method}, but it returned nil. You should set a default value." if val.nil?
|
144
|
+
end
|
126
145
|
end
|
127
146
|
end
|
128
147
|
|
@@ -158,10 +177,13 @@ class Arcade::GameObject
|
|
158
177
|
|
159
178
|
setup_defaults
|
160
179
|
instance_exec &block
|
180
|
+
|
181
|
+
# Every GameObject must have a name
|
182
|
+
raise Arcade::Errors::NameError, "#{self.class}#name is nil" if self.name.nil?
|
161
183
|
end
|
162
184
|
|
163
|
-
def
|
164
|
-
|
185
|
+
def get_object object_name
|
186
|
+
window.get_object object_name
|
165
187
|
end
|
166
188
|
|
167
189
|
def draw
|
@@ -233,7 +255,6 @@ class Arcade::GameObject
|
|
233
255
|
|
234
256
|
def collided_with other
|
235
257
|
klass = other.class
|
236
|
-
|
237
258
|
if self.can_collide_with?(klass)
|
238
259
|
instance_exec other, &@collision_listeners[klass]
|
239
260
|
end
|
data/lib/arcade/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arcade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70303611838520 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70303611838520
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: gosu
|
27
|
-
requirement: &
|
27
|
+
requirement: &70303611837660 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70303611837660
|
36
36
|
description: ! 'Arcade is a simple Ruby-vased DSL for creating old-school arcade games
|
37
37
|
like Pong. The philosophy is similar to GameMaker, except expressed as a Ruby library
|
38
38
|
instead of a crazy GUI.
|
@@ -65,7 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
65
|
version: '0'
|
66
66
|
segments:
|
67
67
|
- 0
|
68
|
-
hash:
|
68
|
+
hash: 4028498995742475186
|
69
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
70
|
none: false
|
71
71
|
requirements:
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
segments:
|
76
76
|
- 0
|
77
|
-
hash:
|
77
|
+
hash: 4028498995742475186
|
78
78
|
requirements: []
|
79
79
|
rubyforge_project:
|
80
80
|
rubygems_version: 1.8.17
|