FangEngine.game_object.premade.hud.variable_hud
This module contains the VariableHUD class (WIP)
Class VariableHUD
This class represents the VariableHUD class (WIP)
It will keep its values up to date based on return values of other methods
This class is a work in progress and is not ready for use yet
__init__(self, screen_parent, x: float, y: float, w: float, h: float)
add_image(self, name: str, ref_name: str = None)
This method adds any image from the image store to the HUD
The image will be scaled down to be as tall as the HUD
Parameter name:
Parameter ref_name: a name to uniquely reference this HUD element if you need to access/replace the text later
If not specified you will not be able to access the text
add_metric(self, name: str, function: callable) -> VariableHUD
add_surface(self, surf: Surface, ref_name: str = None)
This method adds any Pygame surface to the HUD
The surface will be scaled down to be as tall as the HUD
Parameter surf:
Parameter ref_name: a name to uniquely reference this HUD element if you need to access/replace the text later
If not specified you will not be able to access the text
add_text(self, text: str, color = (0, 0, 0), ref_name: str = None)
This method adds text to the HUD
Parameter text:
Parameter color:
Parameter ref_name: a name to uniquely reference this HUD element if you need to access/replace the text later
If not specified you will not be able to access the text
broadcast_message(self, message: typing.Union[list, tuple, str])
Broadcasts a message to all other objects on this screen
Parameter message: the message to send
check_collision(self)
Causes this object to check for collisions with other objects
If a collision is detected, the on_collide event of both objects will be triggered
class_name(self) -> str
Returns the name of the class
convert_coords(self, x: float, y: float) -> typing.Tuple[float, float]
Scales coordinates with respect to the the scaling of the screen
This is especially useful for interacting with the mouse directly
handle_input(self, keys: list, mouse: tuple, delta_t: float)
This event allows the handling of user input
This event is triggered every frame
Parameter keys: A list of keys and their states. The index of a key is its ASCII value (use pygame constants)
Parameter mouse: the state of the mouse buttons
Parameter delta_t: the amount of time (in seconds) that has passed since the last frame
on_click(self, pos: tuple, button: int)
Run this method to simulate a click on the HUD
Override this method to change the click event
If a HUD item is clicked, the on_hud_item_click event will be triggered
on_collide(self, other: GameObject)
on_create(self, args, kwargs)
This event is triggered when this object is created
It is run once and only once
on_hud_item_click(self, ref_name: str)
This event is triggered when a HUD item is clicked
Note that even non-named items will trigger this event. Their name will be a float.
Parameter ref_name: the name of the HUD item (set when added)
on_joystick_axis_motion(self, joystick, axis, value)
on_joystick_ball_motion(self, joystick, ball, rel)
on_joystick_button_down(self, joystick, button)
on_joystick_button_up(self, joystick, button)
on_joystick_hat_motion(self, joystick, hat, value)
on_key_down(self, unicode, key, mod)
on_key_up(self, key, mod)
on_message_receive(self, message: typing.Union[list, tuple, str], sender)
This event is run when another object on the same screen broadcasts a message
Parameter message:
Parameter sender: the sender of the message
on_mouse_button_down(self, pos, button)
on_mouse_button_up(self, pos, button)
on_mouse_motion(self, pos, rel, buttons)
on_move(self, dx: float, dy: float)
on_screen_enter(self, previous_screen: str)
on_screen_leave(self, next_screen: str)
remove_item(self, ref_name: str) -> Surface
Removes the specified item from the HUD
Parameter ref_name: the name of the HUD item (set when added)
render(self, buffer: Surface)
Draws the HUD and all contained elements to the specified buffer
show_dialog_box(self, box: dialog_box.DialogBox.__class__, args, kwargs)
This method causes the screen to show a dialog box
Parameter box: the class reference to the dialog box
Parameter args:
Parameter kwargs:
update(self, delta_t: float)
This event is triggered every frame. This is where the main update code should go
Parameter delta_t: the amount of time (in seconds) that has passed since the last frame