Class: RubyArena::Bullet
- Inherits:
-
Object
- Object
- RubyArena::Bullet
- Includes:
- Movable
- Defined in:
- lib/ruby_arena/bullet.rb
Constant Summary collapse
- DEFAULT_SPEED =
10- DEFAULT_ENERGY =
10- SIZE =
4
Instance Attribute Summary collapse
-
#arena ⇒ Object
readonly
Returns the value of attribute arena.
-
#heading ⇒ Object
readonly
Returns the value of attribute heading.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
-
#speed ⇒ Object
readonly
Returns the value of attribute speed.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #dead? ⇒ Boolean
- #energy ⇒ Object
-
#initialize(args) ⇒ Bullet
constructor
A new instance of Bullet.
- #intersect?(object) ⇒ Boolean
- #size ⇒ Object
- #update ⇒ Object
Methods included from Movable
Constructor Details
#initialize(args) ⇒ Bullet
Returns a new instance of Bullet.
11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby_arena/bullet.rb', line 11 def initialize(args) @x = args.fetch(:x) @y = args.fetch(:y) @heading = args.fetch(:heading) @speed = args.fetch(:speed, DEFAULT_SPEED) @arena = args.fetch(:arena) @origin = args.fetch(:origin) @dead = false end |
Instance Attribute Details
#arena ⇒ Object (readonly)
Returns the value of attribute arena.
9 10 11 |
# File 'lib/ruby_arena/bullet.rb', line 9 def arena @arena end |
#heading ⇒ Object (readonly)
Returns the value of attribute heading.
9 10 11 |
# File 'lib/ruby_arena/bullet.rb', line 9 def heading @heading end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
9 10 11 |
# File 'lib/ruby_arena/bullet.rb', line 9 def origin @origin end |
#speed ⇒ Object (readonly)
Returns the value of attribute speed.
9 10 11 |
# File 'lib/ruby_arena/bullet.rb', line 9 def speed @speed end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
9 10 11 |
# File 'lib/ruby_arena/bullet.rb', line 9 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
9 10 11 |
# File 'lib/ruby_arena/bullet.rb', line 9 def y @y end |
Instance Method Details
#dead? ⇒ Boolean
38 39 40 |
# File 'lib/ruby_arena/bullet.rb', line 38 def dead? @dead end |
#energy ⇒ Object
34 35 36 |
# File 'lib/ruby_arena/bullet.rb', line 34 def energy DEFAULT_ENERGY end |
#intersect?(object) ⇒ Boolean
26 27 28 |
# File 'lib/ruby_arena/bullet.rb', line 26 def intersect?(object) Gosu.distance(x, y, object.x, object.y) < size/2 + object.size/2 end |
#size ⇒ Object
30 31 32 |
# File 'lib/ruby_arena/bullet.rb', line 30 def size SIZE end |
#update ⇒ Object
21 22 23 24 |
# File 'lib/ruby_arena/bullet.rb', line 21 def update move check_if_hit_some_robot end |