Class: Enemy

Inherits:
Chingu::GameObject
  • Object
show all
Defined in:
lib/prkwars/enemy.rb

Overview

A generic Enemy class inheriting from Chingu::Gameobject. Any enemy unit inherits from this class. The class contains a method which returns all the descendants - useful for checking all possible collisions.

Direct Known Subclasses

Stalker, Turret

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#hpObject

Each enemy has hitpoints, how many has to be specified by the enemy class!



12
13
14
# File 'lib/prkwars/enemy.rb', line 12

def hp
  @hp
end

Class Method Details

.descendantsObject

Method returning all the descendants of the Enemy class. Used for collision checks in the main game loop.



20
21
22
# File 'lib/prkwars/enemy.rb', line 20

def self.descendants
  ObjectSpace.each_object(::Class).select { |klass| klass < self }
end