GamesEngine.Physics (games_engine v0.3.1)

Physics context

Summary

Functions

Returns a %Velocity{} with updated speed components after a horizontal or vertical bounce

Calculate's a %Coordinate{} or %Point{}'s new position based on a %Velocity{}

Types

Link to this type

bounce_type()

@type bounce_type() :: :horizontal | :vertical

Functions

Link to this function

bounce(velocity, atom)

Returns a %Velocity{} with updated speed components after a horizontal or vertical bounce

A :horizontal bounce reflects the x component, and a :vertical bounce reflects the y component

Examples

iex> velocity = %GamesEngine.Physics.Velocity{x: 5, y: 0}
iex> GamesEngine.Physics.bounce(velocity, :horizontal)
%GamesEngine.Physics.Velocity{x: -5, y: 0}

iex> velocity = %GamesEngine.Physics.Velocity{x: 0, y: -1.2}
iex> GamesEngine.Physics.bounce(velocity, :vertical)
%GamesEngine.Physics.Velocity{x: 0, y: 1.2}
Link to this function

translate(coordinate, velocity)

Calculate's a %Coordinate{} or %Point{}'s new position based on a %Velocity{}

New row and column attributes will be rounded to conform with %Grid{} constraints when passed a %Coordinate{}

Examples

iex> coordinate = %GamesEngine.Grid.Coordinate{row: 10, col: 10}
iex> velocity = %GamesEngine.Physics.Velocity{x: 1, y: -2.5}
iex> GamesEngine.Physics.translate(coordinate, velocity)
%GamesEngine.Grid.Coordinate{row: 7, col: 11}

iex> point = %GamesEngine.Grid.Point{x: 10, y: 10}
iex> velocity = %GamesEngine.Physics.Velocity{x: 1, y: -2.5}
iex> GamesEngine.Physics.translate(point, velocity)
%GamesEngine.Grid.Point{x: 11, y: 7.5}