module Entity::ClassMethods

Public Instance Methods

bottom_cell_y_at(y) click to toggle source

Bottom-most cell Y position occupied

# File lib/game_2d/entity.rb, line 30
def bottom_cell_y_at(y); (y + HEIGHT - 1) / HEIGHT; end
constrain_velocity(vel, max=MAX_VELOCITY) click to toggle source

Velocity is constrained to the range -MAX_VELOCITY .. MAX_VELOCITY

# File lib/game_2d/entity.rb, line 33
def constrain_velocity(vel, max=MAX_VELOCITY)
  [[vel, max].min, -max].max
end
left_cell_x_at(x) click to toggle source

Left-most cell X position occupied

# File lib/game_2d/entity.rb, line 19
def left_cell_x_at(x); x / WIDTH; end
right_cell_x_at(x) click to toggle source

Right-most cell X position occupied If we’re exactly within a column (@x is an exact multiple of WIDTH), then this equals left_cell_x. Otherwise, it’s one higher

# File lib/game_2d/entity.rb, line 24
def right_cell_x_at(x); (x + WIDTH - 1) / WIDTH; end
top_cell_y_at(y) click to toggle source

Top-most cell Y position occupied

# File lib/game_2d/entity.rb, line 27
def top_cell_y_at(y); y / HEIGHT; end