Class: RubyArena::Bullet

Inherits:
Object
  • Object
show all
Includes:
Movable
Defined in:
lib/ruby_arena/bullet.rb

Constant Summary collapse

DEFAULT_SPEED =
10
DEFAULT_ENERGY =
10
SIZE =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Movable

#move

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

#arenaObject (readonly)

Returns the value of attribute arena.



9
10
11
# File 'lib/ruby_arena/bullet.rb', line 9

def arena
  @arena
end

#headingObject (readonly)

Returns the value of attribute heading.



9
10
11
# File 'lib/ruby_arena/bullet.rb', line 9

def heading
  @heading
end

#originObject (readonly)

Returns the value of attribute origin.



9
10
11
# File 'lib/ruby_arena/bullet.rb', line 9

def origin
  @origin
end

#speedObject (readonly)

Returns the value of attribute speed.



9
10
11
# File 'lib/ruby_arena/bullet.rb', line 9

def speed
  @speed
end

#xObject (readonly)

Returns the value of attribute x.



9
10
11
# File 'lib/ruby_arena/bullet.rb', line 9

def x
  @x
end

#yObject (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

Returns:



38
39
40
# File 'lib/ruby_arena/bullet.rb', line 38

def dead?
  @dead
end

#energyObject



34
35
36
# File 'lib/ruby_arena/bullet.rb', line 34

def energy
  DEFAULT_ENERGY
end

#intersect?(object) ⇒ Boolean

Returns:



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

#sizeObject



30
31
32
# File 'lib/ruby_arena/bullet.rb', line 30

def size
  SIZE
end

#updateObject



21
22
23
24
# File 'lib/ruby_arena/bullet.rb', line 21

def update
  move
  check_if_hit_some_robot
end