Class: RubyMan::MovingObject

Inherits:
GridObject show all
Defined in:
lib/ruby_man/GameObjects/moving_object.rb

Overview

GridObject with the ability to move smoothly in 4 directions

Direct Known Subclasses

Ghost, GhostCorpse, MenuGhost, MenuRubyMan, Player

Instance Attribute Summary collapse

Attributes inherited from GridObject

#depth, #grid_x, #grid_y, #image_angle, #image_index, #image_speed, #solid, #sprite

Attributes inherited from GameObject

#game

Instance Method Summary collapse

Methods inherited from GridObject

#bbox, #distance_to, #draw, #set_pos

Methods inherited from GameObject

#button_down, #created, #destroy, #destroyed, #draw, persistent

Constructor Details

#initializeMovingObject

Returns a new instance of MovingObject.



9
10
11
12
13
14
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 9

def initialize
  super
  @direction = Direction.none
  @phase = 0
  @speed = 0
end

Instance Attribute Details

#directionObject

Returns the value of attribute direction.



7
8
9
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 7

def direction
  @direction
end

#phaseObject

Returns the value of attribute phase.



7
8
9
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 7

def phase
  @phase
end

#speedObject

Returns the value of attribute speed.



7
8
9
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 7

def speed
  @speed
end

Instance Method Details

#change_direction(direction) ⇒ Object



33
34
35
36
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 33

def change_direction(direction)
  @direction = direction
  @image_angle = direction.to_angle
end

#collision(_other) ⇒ Object



30
31
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 30

def collision(_other)
end

#direction_free(direction) ⇒ Object



38
39
40
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 38

def direction_free(direction)
  @game.place_free(@grid_x + direction.rel_x, @grid_y + direction.rel_y)
end

#grid_stepObject



27
28
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 27

def grid_step
end

#pixel_xObject



42
43
44
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 42

def pixel_x
  (@grid_x + @direction.rel_x * @phase) * 32
end

#pixel_yObject



46
47
48
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 46

def pixel_y
  (@grid_y + @direction.rel_y * @phase) * 32
end

#update(delta) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 16

def update(delta)
  super
  @phase += @speed * delta
  while @phase > 1
    @phase -= 1
    @grid_x += @direction.rel_x
    @grid_y += @direction.rel_y
    grid_step
  end
end