topdownengine.mobile_object Reference¶
MobileObject
¶
Bases: GameObject
Subclass of GameObject that serves as a wrapper around Controllers with some extra movement functionality.
Attributes:
| Name | Type | Description |
|---|---|---|
animation_paths |
dict[str, str] | None
|
The paths animations were loaded from. |
frame_size |
tuple[int] | None
|
The frame size used to load/generate animations. |
directional_anims |
bool
|
Whether or not to load and use directional animations. |
current_dir |
str
|
Current direction (only set if directional_anims is True). |
controller |
BaseController
|
The controller the MobileObject should use. |
jump_vel |
float
|
The z-velocity that should be used while jumping. |
Source code in topdownengine\mobile_object\__init__.py
current_frame
property
¶
Current animation frame the GameObject is on.
draw_index
property
¶
The draw index of the GameObject.
image
property
¶
Image for drawing.
rect
property
¶
Rect object for drawing.
world_colliders
property
¶
Return a list of collider Rects in world-space, as opposed to GameObject.colliders, which uses relative positioning to the GameObject itself.
__init__(controller, animation_paths=None, frame_size=None, directional_anims=False)
¶
Initialize the MobileObject.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
controller
|
BaseController
|
The controller the MobileObject should use. |
required |
animation_paths
|
dict[str, str]
|
The animation paths to load animations from. Defaults to None. |
None
|
frame_size
|
tuple[int] | None
|
The frame size to use to load/generate animations. Defaults to None. |
None
|
directional_anims
|
bool
|
Whether or not to load and use directional animations. Defaults to False. |
False
|
Source code in topdownengine\mobile_object\__init__.py
generate_colliders()
¶
Default list of Rect objects for collisions.
Source code in topdownengine\game_object.py
jump()
¶
This method sets the MobileObject's z velocity to the jump velocity if the MobileObject is grounded (MobileObject.elevation == MobileObject.z).
Source code in topdownengine\mobile_object\__init__.py
load_animations()
¶
Load unscaled animations.
Source code in topdownengine\game_object.py
scale_animations()
¶
Scale animations.
set_scale(new_scale, game)
classmethod
¶
This method sets the target scale of all GameObjects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_scale
|
int
|
The new target scale being set to. |
required |
game
|
Game | None
|
The Game object being used. While you may pass in None, you MUST pass in a Game instance if you have already defined GameObjects. |
required |
Source code in topdownengine\game_object.py
update(dt, game)
¶
This method updates the MobileObject instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
float
|
The deltatime. |
required |
game
|
Game
|
The Game object. |
required |
Source code in topdownengine\mobile_object\__init__.py
topdownengine.mobile_object.controller¶
BaseController
¶
A base class for all MobileObject controllers.
Source code in topdownengine\mobile_object\controller.py
move(mobile_object, dt, dir)
¶
Change a MobileObject's velocity using a given dir Vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mobile_object
|
MobileObject
|
The MobileObject to move. |
required |
dt
|
float
|
The deltatime. |
required |
dir
|
Vector2
|
Vector to move by. |
required |
Source code in topdownengine\mobile_object\controller.py
update(mobile_object, dt)
¶
Update function for MobileObject controllers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mobile_object
|
MobileObject
|
The MobileObject to update. |
required |
dt
|
float
|
The deltatime. |
required |
KeyboardInputController
¶
Bases: BaseController
A MobileObject controller that uses keyboard inputs.
Attributes:
| Name | Type | Description |
|---|---|---|
input_mgr |
KeyboardInputManager
|
The input manager. |
speed |
float
|
The speed. |
snapping_speed |
float
|
The snapping speed. |
Source code in topdownengine\mobile_object\controller.py
__init__()
¶
move(mobile_object, dt, dir)
¶
Change a MobileObject's velocity using a given dir Vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mobile_object
|
MobileObject
|
The MobileObject to move. |
required |
dt
|
float
|
The deltatime. |
required |
dir
|
Vector2
|
Vector to move by. |
required |
Source code in topdownengine\mobile_object\controller.py
update(mobile_object, dt)
¶
Moves the MobileObject based on keyboard input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mobile_object
|
MobileObject
|
The MobileObject to update. |
required |
dt
|
float
|
The deltatime. |
required |
Source code in topdownengine\mobile_object\controller.py
MovementAIController
¶
Bases: BaseController
A MobileObject controller that follows another MobileObject.
Attributes:
| Name | Type | Description |
|---|---|---|
target_mobile_object |
MobileObject
|
The MobileObject to move toward. |
speed |
float
|
The speed. |
snapping_speed |
float
|
The snapping speed. |
Source code in topdownengine\mobile_object\controller.py
__init__(target_mobile_object)
¶
Initialize the MovementAIController.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_mobile_object
|
MobileObject
|
The MobileObject to move toward. |
required |
Source code in topdownengine\mobile_object\controller.py
move(mobile_object, dt, dir)
¶
Change a MobileObject's velocity using a given dir Vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mobile_object
|
MobileObject
|
The MobileObject to move. |
required |
dt
|
float
|
The deltatime. |
required |
dir
|
Vector2
|
Vector to move by. |
required |
Source code in topdownengine\mobile_object\controller.py
update(mobile_object, dt)
¶
Move the MobileObject towards the target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mobile_object
|
MobileObject
|
The MobileObject to update. |
required |
dt
|
float
|
The deltatime. |
required |
Source code in topdownengine\mobile_object\controller.py
StaticController
¶
Bases: BaseController
A MobileObject controller that keeps the MobileObject still.
Source code in topdownengine\mobile_object\controller.py
move(mobile_object, dt, dir)
¶
Change a MobileObject's velocity using a given dir Vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mobile_object
|
MobileObject
|
The MobileObject to move. |
required |
dt
|
float
|
The deltatime. |
required |
dir
|
Vector2
|
Vector to move by. |
required |
Source code in topdownengine\mobile_object\controller.py
update(mobile_object, dt)
¶
Sets the MobileObject's velocity to (0, 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mobile_object
|
MobileObject
|
The MobileObject to update. |
required |
dt
|
float
|
The deltatime. |
required |