Class: GameObject

Inherits:
Object
  • Object
show all
Defined in:
lib/entities/game_object.rb

Direct Known Subclasses

Box, Bullet, Damage, Explosion, Powerup, Tank, Tree

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object_pool, x, y) ⇒ GameObject

Returns a new instance of GameObject.



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

def initialize(object_pool, x, y)
  @x, @y = x, y
  @location = [x, y]
  @components = []
  @object_pool = object_pool
  @object_pool.add(self)
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



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

def components
  @components
end

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#xObject (readonly)

Returns the value of attribute x.



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

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#boxObject



43
44
# File 'lib/entities/game_object.rb', line 43

def box
end

#collideObject



46
47
# File 'lib/entities/game_object.rb', line 46

def collide
end

#draw(viewport) ⇒ Object



24
25
26
# File 'lib/entities/game_object.rb', line 24

def draw(viewport)
  @components.each { |c| c.draw(viewport) }
end

#effect?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/entities/game_object.rb', line 39

def effect?
  false
end

#mark_for_removalObject



32
33
34
# File 'lib/entities/game_object.rb', line 32

def mark_for_removal
  @removable = true
end

#move(new_x, new_y) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/entities/game_object.rb', line 11

def move(new_x, new_y)
  return if new_x == @x && new_y == @y
  @object_pool.tree_remove(self)
  @x = new_x
  @y = new_y
  @location = [new_x, new_y]
  @object_pool.tree_insert(self)
end

#on_collision(object) ⇒ Object



36
37
# File 'lib/entities/game_object.rb', line 36

def on_collision(object)
end

#removable?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/entities/game_object.rb', line 28

def removable?
  @removable
end

#updateObject



20
21
22
# File 'lib/entities/game_object.rb', line 20

def update
  @components.map(&:update)
end