gosu_extensions 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -2
- data/VERSION +1 -1
- data/lib/core/collision.rb +10 -12
- data/lib/core/control.rb +1 -1
- data/lib/core/game_window.rb +1 -1
- data/lib/core/scheduling.rb +0 -2
- data/lib/traits/generator.rb +17 -6
- data/lib/traits/hitpoints.rb +3 -9
- data/lib/traits/lives.rb +6 -3
- data/lib/traits/targeting/closest.rb +1 -11
- data/lib/units/sprite.rb +1 -1
- metadata +3 -2
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ begin
|
|
6
6
|
gemspec.email = "florian.hanke@gmail.com"
|
7
7
|
gemspec.homepage = "http://www.github.com/floere/gosu_extensions"
|
8
8
|
gemspec.description = ""
|
9
|
-
gemspec.authors = ["Florian Hanke"]
|
9
|
+
gemspec.authors = ["Florian Hanke", "Severin Schoepke (various improvements)"]
|
10
10
|
gemspec.rdoc_options = ["--inline-source", "--charset=UTF-8"]
|
11
11
|
gemspec.files = FileList["[A-Z]*", "{generator,lib}/**/*"]
|
12
12
|
gemspec.test_files = FileList["spec/**/*_spec.rb"]
|
@@ -26,4 +26,6 @@ require 'spec/rake/spectask'
|
|
26
26
|
desc "Run all specs in spec directory"
|
27
27
|
Spec::Rake::SpecTask.new(:spec) do |t|
|
28
28
|
t.spec_files = FileList['spec/**/*_spec.rb']
|
29
|
-
end
|
29
|
+
end
|
30
|
+
|
31
|
+
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
data/lib/core/collision.rb
CHANGED
@@ -35,11 +35,10 @@ class Collision
|
|
35
35
|
#
|
36
36
|
def simple_package definition
|
37
37
|
lambda do |this_shape, _|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
movable.instance_eval &definition
|
38
|
+
window.moveables.each do |moveable|
|
39
|
+
if moveable.shape == this_shape
|
40
|
+
moveable.instance_eval &definition
|
41
|
+
break
|
43
42
|
end
|
44
43
|
end
|
45
44
|
end
|
@@ -50,15 +49,14 @@ class Collision
|
|
50
49
|
def complex_package definition
|
51
50
|
lambda do |this_shape, that_shape|
|
52
51
|
this_that = Array.new(2)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
if movable.shape == this_shape
|
57
|
-
this_that[0] = movable
|
52
|
+
window.moveables.each do |moveable|
|
53
|
+
if moveable.shape == this_shape
|
54
|
+
this_that[0] = moveable
|
58
55
|
end
|
59
|
-
if
|
60
|
-
this_that[1] =
|
56
|
+
if moveable.shape == that_shape
|
57
|
+
this_that[1] = moveable
|
61
58
|
end
|
59
|
+
break if this_that.all?
|
62
60
|
end
|
63
61
|
definition.call *this_that
|
64
62
|
end
|
data/lib/core/control.rb
CHANGED
data/lib/core/game_window.rb
CHANGED
@@ -247,7 +247,7 @@ class GameWindow < Gosu::Window
|
|
247
247
|
@environment.window = self
|
248
248
|
@environment.damping = -self.damping + 1 # recalculate the damping such that 0.0 has no damping.
|
249
249
|
end
|
250
|
-
# Callbacks
|
250
|
+
# Callbacks.
|
251
251
|
#
|
252
252
|
def setup_players; end
|
253
253
|
def setup_enemies; end
|
data/lib/core/scheduling.rb
CHANGED
data/lib/traits/generator.rb
CHANGED
@@ -39,14 +39,20 @@ end
|
|
39
39
|
|
40
40
|
module InstanceMethods
|
41
41
|
|
42
|
+
#
|
43
|
+
#
|
42
44
|
def destroyed!
|
43
45
|
stop_generating!
|
44
46
|
end
|
45
47
|
|
48
|
+
#
|
49
|
+
#
|
46
50
|
def stop_generating!
|
47
51
|
@stop_generating = true
|
48
52
|
end
|
49
53
|
|
54
|
+
#
|
55
|
+
#
|
50
56
|
def generation klass, every_rate, til
|
51
57
|
return lambda {} if @stop_generating
|
52
58
|
lambda do
|
@@ -56,12 +62,17 @@ end
|
|
56
62
|
end
|
57
63
|
end
|
58
64
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns the generated thing.
|
68
|
+
#
|
69
|
+
# TODO generate klass, times = 1, &after_generation ?
|
70
|
+
#
|
71
|
+
def generate klass
|
72
|
+
generated = klass.new self.window
|
73
|
+
generated.warp self.position
|
74
|
+
self.window.register generated
|
75
|
+
generated
|
65
76
|
end
|
66
77
|
|
67
78
|
end
|
data/lib/traits/hitpoints.rb
CHANGED
@@ -47,6 +47,7 @@ module Hitpoints extend Trait
|
|
47
47
|
def hit!
|
48
48
|
|
49
49
|
end
|
50
|
+
|
50
51
|
# Hit the thing with that much damage.
|
51
52
|
#
|
52
53
|
# hit!-s if hitpoints higher than 0
|
@@ -55,15 +56,8 @@ module Hitpoints extend Trait
|
|
55
56
|
#
|
56
57
|
def hit damage = 1
|
57
58
|
self.hitpoints -= damage
|
58
|
-
if
|
59
|
-
|
60
|
-
else
|
61
|
-
if respond_to?(:kill!)
|
62
|
-
kill!
|
63
|
-
else
|
64
|
-
destroy!
|
65
|
-
end
|
66
|
-
end
|
59
|
+
hit! if hitpoints > 0
|
60
|
+
respond_to?(:kill!) ? kill! : destroy! if hitpoints == 0
|
67
61
|
end
|
68
62
|
|
69
63
|
end
|
data/lib/traits/lives.rb
CHANGED
@@ -43,14 +43,17 @@ module Lives extend Trait
|
|
43
43
|
3
|
44
44
|
end
|
45
45
|
|
46
|
+
# Override to handle killed!
|
47
|
+
#
|
48
|
+
def killed!
|
49
|
+
|
50
|
+
end
|
51
|
+
|
46
52
|
# Does three things:
|
47
53
|
# * Deduct 1 live.
|
48
54
|
# * Check to see if the amount is 0.
|
49
55
|
# * Calls #destroy! if yes.
|
50
56
|
#
|
51
|
-
def killed!
|
52
|
-
|
53
|
-
end
|
54
57
|
def kill!
|
55
58
|
self.lives -= 1
|
56
59
|
killed! if self.lives > 0
|
@@ -9,17 +9,7 @@ module Targeting
|
|
9
9
|
# TODO fire arc
|
10
10
|
#
|
11
11
|
def acquire *targets
|
12
|
-
|
13
|
-
lowest_distance = nil
|
14
|
-
|
15
|
-
targets.each do |target|
|
16
|
-
distance = (target.position - self.position).length
|
17
|
-
next if lowest_distance && distance > lowest_distance
|
18
|
-
lowest_distance = distance
|
19
|
-
closest = target
|
20
|
-
end
|
21
|
-
|
22
|
-
closest
|
12
|
+
targets.sort_by {|target| distance = (target.position - self.position).length }.first
|
23
13
|
end
|
24
14
|
end
|
25
15
|
|
data/lib/units/sprite.rb
CHANGED
metadata
CHANGED