Class: GameObject

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

Overview

class GameObject

Direct Known Subclasses

Brick, Bullet, Bush, Eagle, Explosion, Stone, Tank, Upgrade, Water

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, width, heigth, solid = true) ⇒ GameObject



9
10
11
12
13
14
15
# File 'lib/entities/gameobject.rb', line 9

def initialize(x, y, width, heigth, solid = true)
  @x = x
  @y = y
  @collider = nil
  @collider = Collider.new(x, y, width, heigth) if solid
  @done = false
end

Instance Attribute Details

#colliderObject (readonly)

Returns the value of attribute collider.



6
7
8
# File 'lib/entities/gameobject.rb', line 6

def collider
  @collider
end

#xObject (readonly)

Returns the value of attribute x.



7
8
9
# File 'lib/entities/gameobject.rb', line 7

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



7
8
9
# File 'lib/entities/gameobject.rb', line 7

def y
  @y
end

Instance Method Details

#collide?(other) ⇒ Boolean



34
35
36
37
# File 'lib/entities/gameobject.rb', line 34

def collide?(other)
  return false if @collider.nil? || other.collider.nil? || other == self
  @collider.collides?(other.collider)
end

#collision_detect(_objects) ⇒ Object



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

def collision_detect(_objects)
  nil
end

#done?Boolean



26
27
28
# File 'lib/entities/gameobject.rb', line 26

def done?
  @done
end

#drawObject



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

def draw
  @sprite.draw(@x, @y, 1) if solid?
  @sprite.draw(@x, @y, 3) unless solid?
end

#hitted(_by) ⇒ Object



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

def hitted(_by)
  # puts "#{self} hitted by #{by}"
end

#solid?Boolean



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

def solid?
  !@collider.nil?
end

#updateObject



30
31
32
# File 'lib/entities/gameobject.rb', line 30

def update
  fail NotImplementedError, 'Abstract method, IMPLEMENT update (call @sprite.update!)'
end