Skip to main content

A pygame-powered engine that runs .lua game files.

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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

luagame-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

luagame-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file luagame-0.1.0.tar.gz.

File metadata

  • Download URL: luagame-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.3 Windows/11

File hashes

Hashes for luagame-0.1.0.tar.gz
Algorithm Hash digest
SHA256 270ca6ff4d05dae50c150e4713a80c55af01da776da9b5e0150b4fe540681c98
MD5 b861d6738543f7c4205c113539eef5d0
BLAKE2b-256 b97ee7a487f59fb6a2d2727d53d48f94e8a05f0261bdf717702af6836f11489f

See more details on using hashes here.

File details

Details for the file luagame-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: luagame-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.3 Windows/11

File hashes

Hashes for luagame-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88ebc3029e8a63aa53dc6b0a81b0cd62628e2a635f20445112835721e4c440f3
MD5 b18cb698b4313e1ac9912d469158a522
BLAKE2b-256 3bfd995deb8d9f747d60068b8d13dc2427dfc0d1812ac0ec4fe3810d19a3cdea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page