Class: GamesAndRpgParadise::ParticleSimulator::Entity
- Inherits:
-
Object
- Object
- GamesAndRpgParadise::ParticleSimulator::Entity
- Defined in:
- lib/games_and_rpg_paradise/gui/gosu/particle_simulator/entity.rb
Constant Summary collapse
- CAP =
#
CAP
#
0.99
- DAMPEN =
#
DAMPEN
#
0.9
Instance Attribute Summary collapse
-
#vx ⇒ Object
Returns the value of attribute vx.
-
#vy ⇒ Object
Returns the value of attribute vy.
-
#x ⇒ Object
readonly
set to 1.0 if the walls are trampolines.
Instance Method Summary collapse
-
#accelerate(dir) ⇒ Object
# === accelerate ========================================================================= #.
-
#draw ⇒ Object
# === draw ========================================================================= #.
-
#find_closest(targets) ⇒ Object
# === find_closest ========================================================================= #.
-
#initialize(game) ⇒ Entity
constructor
# === initialize ========================================================================= #.
-
#move ⇒ Object
# === move ========================================================================= #.
-
#y? ⇒ Boolean
(also: #y)
# === y? ========================================================================= #.
Constructor Details
#initialize(game) ⇒ Entity
#
initialize
#
31 32 33 34 35 |
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/entity.rb', line 31 def initialize(game) @game = game @x, @y = rand(WIDTH), rand(HEIGHT) @vx = @vy = 0.0 end |
Instance Attribute Details
#vx ⇒ Object
Returns the value of attribute vx.
26 27 28 |
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/entity.rb', line 26 def vx @vx end |
#vy ⇒ Object
Returns the value of attribute vy.
26 27 28 |
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/entity.rb', line 26 def vy @vy end |
#x ⇒ Object (readonly)
set to 1.0 if the walls are trampolines
25 26 27 |
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/entity.rb', line 25 def x @x end |
Instance Method Details
#accelerate(dir) ⇒ Object
#
accelerate
#
97 98 99 100 |
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/entity.rb', line 97 def accelerate(dir) @vx += Gosu.offset_x(dir, @accel) @vy += Gosu.offset_y(dir, @accel) end |
#draw ⇒ Object
#
draw
#
75 76 |
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/entity.rb', line 75 def draw end |
#find_closest(targets) ⇒ Object
#
find_closest
#
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/entity.rb', line 81 def find_closest(targets) closest = targets.first dist = Gosu.distance(closest.x, closest.y, @x, @y) targets.each { |tar| new_dist = Gosu.distance(tar.x, tar.y, @x, @y) if new_dist < dist closest = tar dist = new_dist end } return closest end |
#move ⇒ Object
#
move
#
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/entity.rb', line 40 def move # ======================================================================= # # Degrade the velocity so that it will be capped. # ======================================================================= # @vx = @vx * CAP @vy = @vy * CAP # ======================================================================= # # bounce off the walls # ======================================================================= # @vx = (@x < 0 or @x > WIDTH) ? -(@vx) * DAMPEN : @vx @vy = (@y < 0 or @y > HEIGHT) ? -(@vy) * DAMPEN : @vy @x = WIDTH.to_f if @x > WIDTH @x = 0.0 if @x < 0 @y = HEIGHT.to_f if @y > HEIGHT @y = 0.0 if @y < 0 # ======================================================================= # # put it together # ======================================================================= # @x += @vx @y += @vy end |
#y? ⇒ Boolean Also known as: y
#
y?
#
68 69 70 |
# File 'lib/games_and_rpg_paradise/gui/gosu/particle_simulator/entity.rb', line 68 def y? @y end |