Luigi module reference¶
Luigi 2D game engine
-
class
luigi.
AnimatedFrame
(self: luigi.AnimatedFrame, texture_name: str, regions: List[lg::Box], fps: float, i: int = 0) → None¶ Bases:
luigi.IndexedFrame
(frame) An animated texture region.
-
copy
(self: luigi.AnimatedFrame) → luigi.Frame¶ Clones itself.
-
get_transform
(self: luigi.AnimatedFrame) → lg::Mat3¶ Returns the texture coordinates transform for the current region.
-
i
¶
-
rect
¶
-
texture
¶
-
-
class
luigi.
Box
(self: luigi.Box, x: float = 0, y: float = 0, width: float = 0, height: float = 0) → None¶ Bases:
pybind11_builtins.pybind11_object
(maths) A 2D region describing an axis aligned bounding box.
-
collides
(self: luigi.Box, other: luigi.Box) → bool¶ Whether the box collides with another box.
-
contains
(self: luigi.Box, x: float, y: float) → bool¶ Whether the box contains the point.
-
height
¶
-
static
tape
(x: float, y: float, width: float, height: float, n: int, horizontal: bool = True) → List[luigi.Box]¶ Creates a list of boxes from
n
regions placed at the same x / y level.The first region is Box(x, y, width, height).
Parameters: - n – Number of regions.
- horizontal – True if the regions share the same y level, False if they share the same x level.
-
width
¶
-
x
¶
-
y
¶
-
-
class
luigi.
Camera
¶ Bases:
pybind11_builtins.pybind11_object
(camera) A 2D camera describing a view.Note
The width of the camera is calculated by its height and the screen aspect ratio.
-
height
¶
-
main
= None¶
-
name
¶
-
rot
¶
-
set
(self: luigi.Camera, x: float = 0, y: float = 0, height: float = -1, rot: float = -1) → None¶ Sets the properties of the camera.
Note
If height or rot == -1, then height / rot is not changed.
-
width
¶
-
x
¶
-
y
¶
-
-
class
luigi.
CompoundFrame
(self: luigi.CompoundFrame, frames: Dict[str, luigi.Frame], first: str) → None¶ Bases:
luigi.Frame
(frame) Gathers multiple frames, they can be changed with the
current
property.Note
Useful to make animations with instances of
AnimatedFrame
.Parameters: - frames – A dict of frames.
- first – The name of the first frame.
-
copy
(self: luigi.CompoundFrame) → luigi.Frame¶ Clones itself.
-
current
¶ Changes the current frame by its name.
-
get
(self: luigi.CompoundFrame) → luigi.Frame¶ Returns the current frame.
-
get_transform
(self: luigi.CompoundFrame) → lg::Mat3¶ Returns the texture coordinates transform for the current region.
-
rect
¶
-
texture
¶
-
class
luigi.
Entity
(self: luigi.Entity) → None¶ Bases:
pybind11_builtins.pybind11_object
(entity) An entity is the most basic type for game objects.
Lifetime :
When all entities are created, the
start()
function is called.Then,
update()
and just afterdraw()
are called untildead
is set to true or the scene stops.After the last draw call,
stop()
is called.-
dead
¶
-
draw
(self: luigi.Entity) → None¶ Called each frame after update.
-
start
(self: luigi.Entity) → None¶ When all entities are created.
-
stop
(self: luigi.Entity) → None¶ When the entity is dead or the scene changes.
-
update
(self: luigi.Entity, dt: float) → None¶ Called each frame.
Parameters: dt – The time elapsed since the last frame, in seconds.
-
-
exception
luigi.
Error
¶ Bases:
Exception
(error) A Luigi exception, use it only from C++.
-
class
luigi.
Frame
¶ Bases:
pybind11_builtins.pybind11_object
(frame) Base class for texture regions.
-
copy
(self: luigi.Frame) → luigi.Frame¶ Clones itself.
-
get_transform
(self: luigi.Frame) → lg::Mat3¶ Returns the texture coordinates transform for the current region.
-
rect
¶
-
texture
¶
-
-
class
luigi.
Game
(self: luigi.Game) → None¶ Bases:
pybind11_builtins.pybind11_object
(game) Handles the window and the game environment.
-
add
(self: luigi.Game, entity: luigi.Entity) → None¶ Adds an entity.
-
add_cam
(self: luigi.Game, name: str, height: float = 100) → luigi.Camera¶ Adds a camera.
-
add_layer
(self: luigi.Game, name: str, z: int = 0) → None¶ Adds a layer.
Parameters: z – The z index of the layer, if a layer has a greater z than another layer, then all drawable entities within this layer will be drawn above the entities within the other layer.
-
add_music
(self: luigi.Game, name: str, file: str) → luigi.Music¶ Adds a music.
-
add_scene
(self: luigi.Game, name: str, factory: Callable[[], None] = None, default_cam: str = 'main') → None¶ Adds a scene factory.
Parameters: factory – This function is called when the scene is loaded, used to add entities to the scene. Warning
Don’t add cameras to the scene in the factory function, add cameras in the
construct
function whenrun()
is called and set cameras’ properties in thefactory
function.
-
add_shader
(self: luigi.Game, name: str, vertex_file: str, fragment_file: str, uniforms: List[str]) → lg::Shader¶ Creates a new shader.
Parameters: uniforms – The list of all uniforms names.
-
add_sound
(self: luigi.Game, name: str, file: str) → luigi.Sound¶ Adds a sound.
-
add_texture
(self: luigi.Game, name: str, file: str) → None¶ Creates a new texture.
-
exit
(self: luigi.Game) → None¶ Terminates the game and closes the window.
-
instance
= None¶
-
mouse_pressed
(self: luigi.Game, button: str) → bool¶ Whether a mouse button is down.
-
mouse_typed
(self: luigi.Game, button: str) → bool¶ Whether a mouse button is clicked.
-
play
(self: luigi.Game, name: str) → None¶ Plays a sound or a music.
-
pressed
(self: luigi.Game, key: str) → bool¶ Whether a key is down.
-
run
(self: luigi.Game, construct: Callable[[], None], screen: luigi.ScreenConfig) → None¶ Launches a window and runs the game.
Parameters: construct – This function is called when the game is initialized, used to create scenes, cameras and set properties.
-
set_cam
(self: luigi.Game, name: str) → luigi.Camera¶ Sets the current camera.
Returns: The current camera, which is Camera.main.
-
set_clear_color
(self: luigi.Game, r: float, g: float, b: float, a: float = 1) → None¶ Sets the background color.
-
set_default_volume
(self: luigi.Game, sounds: float = -1, musics: float = -1) → None¶ Sets the default volume for sounds and musics.
Note
A value of -1 describes an unchanged default volume.
-
set_fade_duration
(self: luigi.Game, seconds: float) → None¶ Sets the music transition duration.
-
set_layer
(self: luigi.Game, name: str) → None¶ Selects the layer to add entities.
-
set_scene
(self: luigi.Game, name: str) → None¶ Sets a scene.
Note
If this function is called in construct, it sets the default scene (the first scene to create).
-
set_texture_filter
(self: luigi.Game, filter: str) → None¶ Sets the filter mode for textures created after this call.
Parameters: filter – The filter applied to the texture. Filter types :
- pixel : No blur when scaling the texture (nearest).
- blur : Blur when scaling the texture (linear).
-
typed
(self: luigi.Game, key: str) → bool¶ Whether a key is typed (is down and was up the last frame).
-
-
class
luigi.
IndexedFrame
(self: luigi.IndexedFrame, texture_name: str, regions: List[lg::Box], i: int = 0) → None¶ Bases:
luigi.Frame
(frame) Like
Region
but the region can be changed with the indexi
.-
copy
(self: luigi.IndexedFrame) → luigi.Frame¶ Clones itself.
-
get_transform
(self: luigi.IndexedFrame) → lg::Mat3¶ Returns the texture coordinates transform for the current region.
-
i
¶
-
rect
¶
-
texture
¶
-
-
class
luigi.
Mat3
¶ Bases:
pybind11_builtins.pybind11_object
(maths) A 3x3 matrix.
-
static
create_id
() → luigi.Mat3¶ Identity matrix.
-
static
create_rst
(x: float, y: float, width: float = 1, height: float = 1, rot: float = 0) → luigi.Mat3¶ Rotate -> Scale -> Translate transformation matrix.
-
static
create_srt
(x: float, y: float, width: float = 1, height: float = 1, rot: float = 0) → luigi.Mat3¶ Scale -> Rotate -> Translate transformation matrix.
-
static
create_trs
(x: float, y: float, width: float = 1, height: float = 1, rot: float = 0) → luigi.Mat3¶ Translate -> Rotate -> Scale transformation matrix.
-
static
create_tsr
(x: float, y: float, width: float = 1, height: float = 1, rot: float = 0) → luigi.Mat3¶ Translate -> Scale -> Rotate transformation matrix.
-
static
-
class
luigi.
Mouse
¶ Bases:
pybind11_builtins.pybind11_object
(inputs) Handles the mouse, this class is static.
Property pos: Describes the mouse position in a int 2-tuple. -
pos
¶
-
-
class
luigi.
Music
¶ Bases:
pybind11_builtins.pybind11_object
(audio) A looping music, when the music is changed, a transition is played.
Warning
MP3 is NOT supported due to licensing issues. Only WAV, OGG/Vorbis and FLAC are supported.
-
get_volume
(self: luigi.Music) → float¶ Returns the current sound volume (between 0 and 100).
-
play
(self: luigi.Music) → None¶ Plays the music, a transition is also played.
-
set_loop
(self: luigi.Music, loop: bool = False) → None¶ Sets whether the music is a loop.
-
set_pos
(self: luigi.Music, x: float) → None¶ Changes the 1D position of the music.
-
set_volume
(self: luigi.Music, vol: float) → None¶ Changes the sound volume.
Parameters: vol – The volume between 0 and 100.
-
stop
(self: luigi.Music, fade_out: bool = True) → None¶ Stops the music, a transition is also played if
fade_out
.
-
-
class
luigi.
Region
(*args, **kwargs)¶ Bases:
luigi.Frame
(frame) Describes an (axis aligned) rectangle in a texture.
The constructor can take only the texture name to create a region over the entire texture.
Overloaded function.
- __init__(self: luigi.Region, texture_name: str) -> None
- __init__(self: luigi.Region, texture_name: str, rect: lg::Box) -> None
-
copy
(self: luigi.Region) → luigi.Frame¶ Clones itself.
-
get_transform
(self: luigi.Region) → lg::Mat3¶ Returns the texture coordinates transform for the current region.
-
rect
¶
-
texture
¶
-
class
luigi.
Scene
¶ Bases:
pybind11_builtins.pybind11_object
Gathers multiple layers of entities, created with a scene factory.
-
add
(self: luigi.Scene, entity: luigi.Entity) → None¶ Adds an entity to the current layer.
-
add_layer
(self: luigi.Scene, name: str, z: int = 0) → None¶ Adds a layer with index z.
-
current
= None¶
-
set_layer
(self: luigi.Scene, name: str) → None¶ Sets a layer.
-
-
class
luigi.
ScreenConfig
(self: luigi.ScreenConfig, title: str, width: int, height: int, fps: float, resizable: bool = True) → None¶ Bases:
pybind11_builtins.pybind11_object
(game) Describes the window / the screen, used to run the game.
-
class
luigi.
Shader
¶ Bases:
pybind11_builtins.pybind11_object
(shader) A GPU program.
To set uniforms, call
set_<type>
with the name of the uniform. This method is less efficient than setting a uniform by its id retrieved withget_uniform()
, after that, callset_uniform_<type>
.-
static
get
(name: str) → luigi.Shader¶ Returns the shader associated to this name.
-
get_uniform
(self: luigi.Shader, name: str) → int¶ Retrieves the id of the uniform.
-
set_1f
(self: luigi.Shader, name: str, x: float) → luigi.Shader¶
-
set_2f
(self: luigi.Shader, name: str, x: float, y: float) → luigi.Shader¶
-
set_3f
(self: luigi.Shader, name: str, x: float, y: float, z: float) → luigi.Shader¶
-
set_4f
(self: luigi.Shader, name: str, r: float, g: float, b: float, a: float) → luigi.Shader¶
-
set_mat3
(self: luigi.Shader, name: str, mat: luigi.Mat3) → luigi.Shader¶
-
set_uniform_1f
(self: luigi.Shader, id: int, x: float) → luigi.Shader¶
-
set_uniform_2f
(self: luigi.Shader, id: int, x: float, y: float) → luigi.Shader¶
-
set_uniform_3f
(self: luigi.Shader, id: int, x: float, y: float, z: float) → luigi.Shader¶
-
set_uniform_4f
(self: luigi.Shader, id: int, r: float, g: float, b: float, a: float) → luigi.Shader¶
-
set_uniform_mat3
(self: luigi.Shader, id: int, mat: luigi.Mat3) → luigi.Shader¶
-
static
-
class
luigi.
Sound
¶ Bases:
pybind11_builtins.pybind11_object
(audio) A SFX, can be played multiple times and at different positions.
Warning
MP3 is NOT supported due to licensing issues. Only WAV, OGG/Vorbis and FLAC are supported.
-
get_volume
(self: luigi.Sound) → float¶ Returns the current sound volume (between 0 and 100).
-
play
(self: luigi.Sound) → None¶ Plays the sound.
-
set_pos
(self: luigi.Sound, x: float) → None¶ Changes the 1D position of the sound.
-
set_volume
(self: luigi.Sound, vol: float) → None¶ Changes the sound volume.
Parameters: vol – The volume between 0 and 100.
-
-
class
luigi.
Sprite
(self: luigi.Sprite, frame: luigi.Frame, shader: str = 'main') → None¶ Bases:
luigi.Entity
(sprite) A drawable entity, drawn with a shader, a texture region and a camera (the main camera).
The sprite’s position describes the center of the texture region.
-
static
create
(texture: str, shader: str = 'main') → luigi.Sprite¶ Creates a new sprite with the whole texture.
-
draw
(self: luigi.Sprite) → None¶
-
frame
¶
-
height
¶
-
rect
(self: luigi.Sprite) → luigi.Box¶ - Returns the AABB of the sprite.
Warning
Doesn’t take in account the rotation.
-
rot
¶
-
scale
(self: luigi.Sprite, factor: float) → None¶ Multiplies width and height by a factor.
-
start
(self: luigi.Sprite) → None¶
-
stop
(self: luigi.Sprite) → None¶
-
update
(self: luigi.Sprite, dt: float) → None¶
-
width
¶
-
x
¶
-
y
¶
-
static