class RubyArena::Bullet

Constants

DEFAULT_ENERGY
DEFAULT_SPEED
SIZE

Attributes

arena[R]
heading[R]
origin[R]
speed[R]
x[R]
y[R]

Public Class Methods

new(args) click to toggle source
# 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

Public Instance Methods

dead?() click to toggle source
# File lib/ruby_arena/bullet.rb, line 38
def dead?
  @dead
end
energy() click to toggle source
# File lib/ruby_arena/bullet.rb, line 34
def energy
  DEFAULT_ENERGY
end
intersect?(object) click to toggle source
# 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() click to toggle source
# File lib/ruby_arena/bullet.rb, line 30
def size
  SIZE
end
update() click to toggle source
# File lib/ruby_arena/bullet.rb, line 21
def update
  move
  check_if_hit_some_robot
end

Private Instance Methods

check_if_hit_some_robot() click to toggle source
# File lib/ruby_arena/bullet.rb, line 44
def check_if_hit_some_robot
  arena.robots.each do |robot|
    if robot != origin && intersect?(robot)
      robot.hit(self)
      @dead = true
    end
  end
end