class RubyMan::GridObject

GameObject aligned to game’s grid

Attributes

depth[RW]
grid_x[RW]
grid_y[RW]
image_angle[RW]
image_index[RW]
image_speed[RW]
solid[RW]
sprite[R]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/ruby_man/GameObjects/grid_object.rb, line 12
def initialize
  super
  @grid_x = -1
  @grid_y = -1
  @depth = 0
  @image_index = 0
  @image_speed = 1
  @image_angle = 0
  @solid = false
  @scale = 1.0
end

Public Instance Methods

bbox() click to toggle source
# File lib/ruby_man/GameObjects/grid_object.rb, line 52
def bbox
  AABB.new(pixel_x, pixel_y,
           pixel_x + @sprite.width, pixel_y + @sprite.height)
end
distance_to(other) click to toggle source
# File lib/ruby_man/GameObjects/grid_object.rb, line 57
def distance_to(other)
  rel_x = other.pixel_x - pixel_x
  rel_y = other.pixel_y - pixel_y
  Math.sqrt(rel_x.abs2 + rel_y.abs2)
end
draw() click to toggle source
Calls superclass method RubyMan::GameObject#draw
# File lib/ruby_man/GameObjects/grid_object.rb, line 31
def draw
  super
  return unless sprite
  sprite.draw(pixel_x, pixel_y, depth,
              image_angle, image_index.to_i, @scale)
end
pixel_x() click to toggle source
# File lib/ruby_man/GameObjects/grid_object.rb, line 44
def pixel_x
  @grid_x * 32
end
pixel_y() click to toggle source
# File lib/ruby_man/GameObjects/grid_object.rb, line 48
def pixel_y
  @grid_y * 32
end
set_pos(x, y) click to toggle source
# File lib/ruby_man/GameObjects/grid_object.rb, line 63
def set_pos(x, y)
  @grid_x = x
  @grid_y = y
  @phase = 0
end
sprite=(new_sprite) click to toggle source
# File lib/ruby_man/GameObjects/grid_object.rb, line 38
def sprite=(new_sprite)
  return if @sprite == new_sprite
  @image_index = 0
  @sprite = new_sprite
end
update(delta) click to toggle source
Calls superclass method RubyMan::GameObject#update
# File lib/ruby_man/GameObjects/grid_object.rb, line 24
def update(delta)
  super
  return unless sprite
  @image_index += @image_speed * delta * @sprite.frames.size
  @image_index %= @sprite.frames.size
end