Class: BulletTurret

Inherits:
Chingu::GameObject
  • Object
show all
Includes:
GamespacePersistence
Defined in:
lib/prkwars/bullet_turret.rb

Overview

A bullet shot by the Turret enemy unit. Destroys itself if out of bounds.

Instance Method Summary collapse

Methods included from GamespacePersistence

#correct_coords, #in_bounds

Constructor Details

#initialize(gamespace, options = {}) ⇒ BulletTurret

Initializes gamespace in which the bullet is present and assigns the turret. Velocity of the bullet is passed as an options parameter, used by the chingu library.



16
17
18
19
20
# File 'lib/prkwars/bullet_turret.rb', line 16

def initialize(gamespace, options = {})
  super(options)
  @image = Image['media/bullet_turret.png']
  @gamespace = gamespace
end

Instance Method Details

#updateObject

As velocity is set by chingu, the only thing update does is that it checks whether there’s any reason for the bullets to exist - if not, they get destroyed.



26
27
28
# File 'lib/prkwars/bullet_turret.rb', line 26

def update
  destroy! unless in_bounds(self, @gamespace)
end