Retro Game Library Documentation


retrogamelib.geometry

This module provides some classes useful for physics and collision detection.
geometry.Vector(object) Vectors are a mathmatical unit describing direction and magnitude. In game programming, they often represent the speed and direction an object is moving, or the direction something is aiming. In cartesian form, they are described by an x and a y value, representing the location of the "front" of the vector, if the "back" of the vector is located at (0, 0).
__init__(x, y)
Creates a new vector. x, y Is the coordinate pair that defines the vector.
copy() -> new Vector
Returns a copy of the vector.
dot(other Vector) -> new Vector
Returns a new vector that is the result of the dot product of this vector and the other vector.
Vector + Vector -> new Vector
(Vector a) + (Vector b) adds the two vectors and returns the result as a new vector.
Vector - Vector -> new Vector
(Vector a) - (Vector b) subtracts b from a and returns the result as a new vector.
-Vector -> new Vector
-(Vector a) returns the opposite of vector a.
Vector * number -> new Vector
(Vector a) * (number c) returns a copy of vector a scaled by scalar c.
Vector / number -> new Vector
(Vector a) / (number c) returns a copy of vector a divided by scalar c.
angle() -> degrees
Returns the polar angle of the vector.
rotate(degrees) -> new Vector
Returns a new vector that is the result of rotating this vector by degrees.
magnitude() -> number
Returns the length of the vector.
normalize() -> new Vector
Returns a new vector whose length is 1, but whose direction is equal to the direction of this vector.
perpendicular() -> new Vector
Returns a new vector that is vertically flipped.

geometry.Polygon(object) Polygons - many sided figure. Polygons are used for collision detection.
__init__(pos, points)
Creates a new polygon. pos Is the location the polygon will be located.
points - a list of pairs (x, y) which define the boundaries of the polygon. There should be as many points as there are pairs.
polygon[index] -> (x, y)
Returns the point at the provided index.
get_points() -> list of pairs
Returns a copy of the polygons points.
project_to_axis(axis) -> Projection
axis is a vector defining some direction (the magnitude is irrelevant). This method will return a projection of the polygon onto this axis.
geometry.Projection
__init__(min, max)
min and max define a line segment in the axis that contains the projection.
Projection has corresponding attributes min and max.
intersection(other) -> number
Returns how much one projection intersects with another.
intersects(other) -> intersection Vector
Returns a vector representing the shortest distance one polygon must be moved to no longer be intersecting with this polygon.
collide(other)
Adjust our position so that we are not touching other.
find_mtd(list of vectors) -> Vector
Returns the shortest vector from a list.
geometry.Rect(geometry.Polygon) An easy way to define a rectangular polygon.
__init__(x, y, width, height)
Define a rectangle.


Copyright © 2009, pymike and saluk