Class: GamesAndRpgParadise::ParticleSimulator::Hunter

Inherits:
Entity
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/gui/gosu/particle_simulator/hunter.rb

Constant Summary

Constants inherited from Entity

Entity::CAP, Entity::DAMPEN

Instance Attribute Summary collapse

Attributes inherited from Entity

#vx, #vy, #x

Instance Method Summary collapse

Methods inherited from Entity

#accelerate, #find_closest, #move, #y?

Constructor Details

#initialize(game, color) ⇒ Hunter

#

initialize

#


18
19
20
21
22
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/hunter.rb', line 18

def initialize(game, color)
  super(game) # Entity will define @game
  @color = color
  reset
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



13
14
15
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/hunter.rb', line 13

def color
  @color
end

#fragsObject (readonly)

Returns the value of attribute frags.



12
13
14
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/hunter.rb', line 12

def frags
  @frags
end

Instance Method Details

#drawObject

#

draw

#


65
66
67
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/hunter.rb', line 65

def draw
  @game.draw_square(@x, @y, H_RADIUS, @color)
end

#resetObject

#

reset (reset tag)

#


27
28
29
30
31
32
33
34
35
36
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/hunter.rb', line 27

def reset
  # ======================================================================= #
  # === @accel
  # ======================================================================= #
  @accel = H_ACCEL
  # ======================================================================= #
  # === @frags
  # ======================================================================= #
  @frags = 0
end

#update(preys) ⇒ Object

#

update

#


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/hunter.rb', line 41

def update(preys)
  # ======================================================================= #
  # Find the closest prey and accelerate towards it
  # ======================================================================= #
  closest = find_closest(preys)
  # ======================================================================= #
  # if closest is too close, eat it
  # ======================================================================= #
  if Gosu.distance(closest.x, closest.y, @x, @y) < 5
    closest.eaten = true
    @frags += 1
  end
  # ======================================================================= #
  # take the angle from the hunter to the prey and run along that path
  # ======================================================================= #
  accelerate(
    Gosu.angle(@x, @y, closest.x, closest.y)
  )
  move
end