Module: Entity::ClassMethods

Includes:
EntityConstants
Included in:
Entity, Entity
Defined in:
lib/game_2d/entity.rb

Constant Summary

Constants included from EntityConstants

EntityConstants::CELL_WIDTH_IN_PIXELS, EntityConstants::MAX_VELOCITY, EntityConstants::PIXEL_WIDTH, EntityConstants::WIDTH

Instance Method Summary collapse

Instance Method Details

#bottom_cell_y_at(y) ⇒ Object

Bottom-most cell Y position occupied



30
# File 'lib/game_2d/entity.rb', line 30

def bottom_cell_y_at(y); (y + HEIGHT - 1) / HEIGHT; end

#constrain_velocity(vel) ⇒ Object

Velocity is constrained to the range -MAX_VELOCITY .. MAX_VELOCITY



33
34
35
# File 'lib/game_2d/entity.rb', line 33

def constrain_velocity(vel)
  [[vel, MAX_VELOCITY].min, -MAX_VELOCITY].max
end

#left_cell_x_at(x) ⇒ Object

Left-most cell X position occupied



19
# File 'lib/game_2d/entity.rb', line 19

def left_cell_x_at(x); x / WIDTH; end

#right_cell_x_at(x) ⇒ Object

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



24
# File 'lib/game_2d/entity.rb', line 24

def right_cell_x_at(x); (x + WIDTH - 1) / WIDTH; end

#top_cell_y_at(y) ⇒ Object

Top-most cell Y position occupied



27
# File 'lib/game_2d/entity.rb', line 27

def top_cell_y_at(y); y / HEIGHT; end