model.entity module¶
Module holding the abstract entity class, the position class and some utility methods for collision checking.
-
class
model.entity.Entity(position=None, rotation=0)¶ Bases:
objectClass that represents an entity that can be placed in a world.
The position of the entity is its top-left corner.
-
add_position(positionDelta)¶
-
add_rotation(rotationDelta)¶
-
at(position)¶ Test if this entity is at a certain position (i.e., the position is inside the entity’s rectangle).
Parameters: position – The position to check. Returns: True if the position is inside the entity’s rectangle.
-
collidable()¶ Return whether entities can collide with this object.
Returns: True if entities can collide with this object, false otherwise. Return type: bool
-
collide(other)¶ Get whether this entity and the other entity or rect are intersecting. If other is a rect, it should be in the form of: [x, y, width, height]
Parameters: other – The entity or rect to check for collision with this entity. Returns: A boolean indicating whether this entitity is colliding with the other entitity or rectangle.
-
get_color()¶ Get the color of the entity.
Returns: The color of the entity. Return type: (int, int, int, int)
-
get_height()¶
-
get_move_delta(steps=1)¶ Get the change in position if the agent were to move.
Parameters: steps – The number of steps the agent would move. Returns: The change in position
-
get_position()¶
-
get_rect()¶
-
get_rotation()¶
-
get_spanning_positions()¶ As an entity can be larger than 1x1, it might span multiple cells. This method returns a list of all cells the entity spans over.
Returns: A list of all positions (cells) the entity spans over.
-
get_width()¶
-
height= 1¶
-
move(steps)¶ Move the entity a certain number of steps.
Parameters: steps – The number of steps to move the agent.
-
rect= None¶
-
set_color(color)¶ Set the color of the entity.
Parameters: color ((int, int, int, int)) – The color to set the entity to.
-
set_height(height)¶
-
set_position(position)¶
-
set_rotation(rotation)¶
-
set_width(width)¶
-
step()¶ Move the entity one step.
-
step_size= 1¶
-
width= 1¶
-
-
class
model.entity.Position(position=None)¶ -
PRECISION= 5¶
-
add(delta)¶
-
angle_to(other)¶ Get the angle between this position and a given position.
-
get()¶
-
get_x()¶
-
get_y()¶
-
manhattan_distance_to(other)¶ Get the manhattan distance between this position and a given position.
Parameters: other – The given position. Returns: The manhattan distance between this position and the given position.
-
static
round(n)¶
-
set(position)¶
-
x= 0¶
-
y= 0¶
-
-
model.entity.collide(r1, r2)¶ Test if two rectangles collide.
Parameters: - r1 – The first rectangle.
- r2 – The second rectangle.
Returns: A boolean indicating whether the rectangles are colliding.
-
model.entity.inside(r, p)¶ Test if a point is inside a rectangle.
Parameters: - r – The rectangle.
- p – The point.
Returns: A boolean indicating whether the point is insiide the rectangle.