Class: Bullet

Inherits:
GameObject show all
Defined in:
lib/entities/bullet.rb

Instance Attribute Summary collapse

Attributes inherited from GameObject

#components, #location, #x, #y

Instance Method Summary collapse

Methods inherited from GameObject

#collide, #draw, #effect?, #mark_for_removal, #move, #on_collision, #removable?, #update

Constructor Details

#initialize(object_pool, source_x, source_y, target_x, target_y) ⇒ Bullet

Returns a new instance of Bullet.



4
5
6
7
8
9
10
# File 'lib/entities/bullet.rb', line 4

def initialize(object_pool, source_x, source_y, target_x, target_y)
  super(object_pool, source_x, source_y)
  @target_x, @target_y = target_x, target_y
  BulletPhysics.new(self, object_pool)
  BulletGraphics.new(self)
  BulletSounds.play(self, object_pool.camera)
end

Instance Attribute Details

#fired_atObject

Returns the value of attribute fired_at.



2
3
4
# File 'lib/entities/bullet.rb', line 2

def fired_at
  @fired_at
end

#sourceObject

Returns the value of attribute source.



2
3
4
# File 'lib/entities/bullet.rb', line 2

def source
  @source
end

#speedObject

Returns the value of attribute speed.



2
3
4
# File 'lib/entities/bullet.rb', line 2

def speed
  @speed
end

#target_xObject

Returns the value of attribute target_x.



2
3
4
# File 'lib/entities/bullet.rb', line 2

def target_x
  @target_x
end

#target_yObject

Returns the value of attribute target_y.



2
3
4
# File 'lib/entities/bullet.rb', line 2

def target_y
  @target_y
end

Instance Method Details

#boxObject



12
13
14
# File 'lib/entities/bullet.rb', line 12

def box
  [@x, @y]
end

#explodeObject



16
17
18
19
# File 'lib/entities/bullet.rb', line 16

def explode
  Explosion.new(object_pool, @x, @y, @source)
  mark_for_removal
end

#fire(source, speed) ⇒ Object



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

def fire(source, speed)
  @source = source
  @speed = speed
  @fired_at = Gosu.milliseconds
end