Always wanted to create games in LUA? Using this package, you can make games in lua, using the PYGAME package!
Project description
LuaGame
A pygame-powered engine that lets you make games in Lua!
Write your game in a .lua file, run it with one Python line.
Compatibility:
This package uses pygame to run properly. The python version this was made on is python 3.12, it might run in higher versions
Installation
pip install LuaGame
How to Use
1. Create your game file: mygame.lua
-- runs once at the start
function load()
player_x = 400
player_y = 300
end
-- runs every frame (dt = time since last frame in seconds)
function update(dt)
if is_key_down("left") then player_x = player_x - 200 * dt end
if is_key_down("right") then player_x = player_x + 200 * dt end
end
-- draw everything here
function draw()
clear(30, 30, 40)
draw_rect(player_x, player_y, 40, 40, 80, 140, 255)
draw_text("Use arrow keys!", 10, 10, 24, 255, 255, 255)
end
2. Run it with Python:
from LuaGame import run_game
run_game("mygame.lua", width=800, height=600, title="My Game")
That's it!
Lua Functions Reference
Drawing
| Function | What it does |
|---|---|
clear(r, g, b) |
Fill the screen with a color |
draw_rect(x, y, w, h, r, g, b) |
Draw a filled rectangle |
draw_circle(x, y, radius, r, g, b) |
Draw a filled circle |
draw_line(x1, y1, x2, y2, r, g, b, width) |
Draw a line |
draw_text(text, x, y, size, r, g, b) |
Draw text on screen |
draw_image(path, x, y) |
Draw an image file |
Input
| Function | What it does |
|---|---|
is_key_down("key") |
True if a key is held down (e.g. "left", "space", "a") |
get_mouse_pos() |
Returns x, y of the mouse |
is_mouse_down(button) |
True if mouse button is held (1=left, 2=middle, 3=right) |
Events (optional functions in your .lua file)
| Function | When it's called |
|---|---|
function load() |
Once at the start |
function update(dt) |
Every frame — dt is seconds since last frame |
function draw() |
Every frame after update |
function keypressed(key) |
When a key is first pressed |
function keyreleased(key) |
When a key is released |
function mousepressed(x, y, button) |
When a mouse button is clicked |
Window & Utility
| Function | What it does |
|---|---|
screen_width() |
Returns the window width |
screen_height() |
Returns the window height |
get_time() |
Returns seconds since the game started |
run_game() Options
run_game(
"mygame.lua", # path to your lua file
width=800, # window width (default 800)
height=600, # window height (default 600)
title="My Game",# window title (default "LuaGame")
fps=60 # frames per second (default 60)
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file luagame-0.1.1.tar.gz.
File metadata
- Download URL: luagame-0.1.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.14.3 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d06c0e8e1476ed95cd91f5d4eb9bf2c1cdeb9ad6ed53d45e9956038d2de8fe0
|
|
| MD5 |
420e072145ea944c8f8dea2f59364fe1
|
|
| BLAKE2b-256 |
98c852e0914eea9e02de0419bf96e0c0745c6e3e0d2102afdb48a0574e20191b
|
File details
Details for the file luagame-0.1.1-py3-none-any.whl.
File metadata
- Download URL: luagame-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.14.3 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbe82e570a4d274be6c028e09f7ddba19fa91eaee3fcd1f56a84feeb08cb2c53
|
|
| MD5 |
9b72b52a396dceb77e6a8548d7f3b613
|
|
| BLAKE2b-256 |
48207b5508f2e15dfb7f4bb89bd563a11b0961989328bd5845ce966789830a17
|