class Bullet

Class representing a bullet shot by the player. Destroys itself if is present out of bounds.

Public Class Methods

new(gamespace, options = {}) click to toggle source

Initializes the gamespace where the bullet is present in. Velocity is passed as a paremeter in the options hash

Calls superclass method
# File lib/prkwars/bullet.rb, line 18
def initialize(gamespace, options = {})
  super(options)
  @image = Image['media/bullet.png']
  @gamespace = gamespace

  cache_bounding_box
end

Public Instance Methods

update() click to toggle source

Updating position is not necessary thanks to the velocity trait. In case the bullet is out of bounds, it gets destroyed and explosion particles are spawned.

# File lib/prkwars/bullet.rb, line 31
def update
  return if in_bounds(self, @gamespace)

  2.times do
    ExplosionParticle.create(@gamespace,
                             x: @x, y: @y,
                             zorder: ZOrder::GAMEOBJECT)
    destroy!
  end
end