gosu_extensions 0.1.25 → 0.1.26

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 CHANGED
@@ -1 +1 @@
1
- 0.1.25
1
+ 0.1.26
@@ -44,6 +44,7 @@ require 'attachable'
44
44
  require 'damaging'
45
45
  require 'generator'
46
46
  require 'lives'
47
+ require 'hitpoints'
47
48
  require 'targeting'
48
49
  require 'targeting/closest'
49
50
  require 'shooter'
@@ -29,6 +29,7 @@ module Damaging extend Trait
29
29
  class DamageMissingError < RuntimeError
30
30
  def initialize
31
31
  super <<-MESSAGE
32
+
32
33
  In a Damaging thing, you need to define method
33
34
  damage damage = nil, &block
34
35
  with params
@@ -36,6 +37,7 @@ module Damaging extend Trait
36
37
  or
37
38
  damage { 13 + rand(7) } # some block
38
39
  to define how much damage the thing does.
40
+
39
41
  MESSAGE
40
42
  end
41
43
  end
@@ -45,7 +47,7 @@ module Damaging extend Trait
45
47
  end
46
48
 
47
49
  def initialize window
48
- raise DamageMissingError.new unless self.respond_to? :damage
50
+ raise DamageMissingError.new unless respond_to?(:damage)
49
51
  super window
50
52
  end
51
53
 
@@ -0,0 +1,71 @@
1
+ # When hitpoints are at zero or lower, it calls kill! if available, destroy! else.
2
+ #
3
+ module Hitpoints extend Trait
4
+
5
+ # TODO def revive!
6
+ #
7
+
8
+ # Prints an amount of information on these capabilities.
9
+ #
10
+ manual <<-MANUAL
11
+ Defines:
12
+ hitpoints <some trait>
13
+
14
+ Example:
15
+ hitpoints 10_000
16
+
17
+ Call hit(damage = 1) to remove hitpoints. This will call
18
+ * hit! if hitpoints are still higher than 0.
19
+ * kill!, and if not available, destroy! if hitpoints are lower than 0.
20
+ MANUAL
21
+
22
+ def self.included target_class
23
+ target_class.extend ClassMethods
24
+ end
25
+
26
+ module ClassMethods
27
+
28
+ # Define the amount of hitpoints of the thing.
29
+ #
30
+ def hitpoints amount
31
+ include InstanceMethods
32
+ class_inheritable_accessor :prototype_hitpoints
33
+ self.prototype_hitpoints = amount
34
+
35
+ hook = lambda { self.hitpoints = self.class.prototype_hitpoints }
36
+ InitializerHooks.register self, &hook
37
+ end
38
+
39
+ end
40
+
41
+ module InstanceMethods
42
+
43
+ attr_accessor :hitpoints
44
+
45
+ # Override to handle hit!
46
+ #
47
+ def hit!
48
+
49
+ end
50
+ # Hit the thing with that much damage.
51
+ #
52
+ # hit!-s if hitpoints higher than 0
53
+ # kill!-s if lower, or destroy!-s if kill!
54
+ # is not available.
55
+ #
56
+ def hit damage = 1
57
+ self.hitpoints -= damage
58
+ if self.hitpoints > 0
59
+ hit!
60
+ else
61
+ if respond_to?(:kill!)
62
+ kill!
63
+ else
64
+ destroy!
65
+ end
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -3,12 +3,14 @@ module Imageable extend Trait
3
3
  class ImageMissingError < RuntimeError
4
4
  def initialize
5
5
  super <<-MESSAGE
6
+
6
7
  In an Imageable, you either need to define method
7
8
  image path, *args
8
9
  for an unchanging image
9
10
  or
10
11
  sequenced_image path, width, height, frequency = 10, &block
11
12
  for a sprite sequence.
13
+
12
14
  MESSAGE
13
15
  end
14
16
  end
@@ -6,7 +6,7 @@ describe Traits do
6
6
  it "should return a list of all traits that can be included using it_is_a, it_is, or it_has" do
7
7
  ActiveSupport::Deprecation.stub! :warn => :shut_up
8
8
 
9
- Traits.list.should == [Attachable, Controllable, Damaging, Generator, Imageable, Lives, Moveable, Pod, Shooter, ShortLived, Shot, Targetable, Targeting::Closest, Turnable]
9
+ Traits.list.should == [Attachable, Controllable, Damaging, Generator, Hitpoints, Imageable, Lives, Moveable, Pod, Shooter, ShortLived, Shot, Targetable, Targeting::Closest, Turnable]
10
10
  end
11
11
  end
12
12
 
@@ -35,6 +35,7 @@ describe Damaging do
35
35
  end
36
36
  it "should raise with the right message" do
37
37
  lambda { @damaging_class.new(@window) }.should raise_error(Damaging::DamageMissingError, <<-MESSAGE
38
+
38
39
  In a Damaging thing, you need to define method
39
40
  damage damage = nil, &block
40
41
  with params
@@ -42,6 +43,7 @@ describe Damaging do
42
43
  or
43
44
  damage { 13 + rand(7) } # some block
44
45
  to define how much damage the thing does.
46
+
45
47
  MESSAGE
46
48
  )
47
49
  end
@@ -45,12 +45,14 @@ describe Imageable do
45
45
  end
46
46
  it "should raise with the right message" do
47
47
  lambda { @imageable_class.new(@window) }.should raise_error(Imageable::ImageMissingError, <<-MESSAGE
48
+
48
49
  In an Imageable, you either need to define method
49
50
  image path, *args
50
51
  for an unchanging image
51
52
  or
52
53
  sequenced_image path, width, height, frequency = 10, &block
53
54
  for a sprite sequence.
55
+
54
56
  MESSAGE
55
57
  )
56
58
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 25
9
- version: 0.1.25
8
+ - 26
9
+ version: 0.1.26
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -75,6 +75,7 @@ files:
75
75
  - lib/traits/controllable.rb
76
76
  - lib/traits/damaging.rb
77
77
  - lib/traits/generator.rb
78
+ - lib/traits/hitpoints.rb
78
79
  - lib/traits/imageable.rb
79
80
  - lib/traits/lives.rb
80
81
  - lib/traits/moveable.rb