Skip to main content

A lightweight 2D game engine built on Pyglet

Project description

MoonFrame

MoonFrame is a Python game development framework built on top of Pyglet. It provides a simple and intuitive API for creating 2D games, handling graphics, input, and more. Its kinda like a mix between Pygame and SDL2, but with a more modern and Python design. This README will give you a quick overview of how to get started with MoonFrame and what features it offers.

Example files

You can find example files in the examples directory of the MoonFrame repository. These examples demonstrate various features of the framework, such as rendering textures, handling input, and implementing game loops. Feel free to explore these examples to get a better understanding of how to use MoonFrame in your own projects.

  • coolcat.py: A more advanced example that demonstrates a simple game with a cat texture that can be moved around the screen.

Installation

You can install MoonFrame using pip:

pip install moonframe

Basic Usage

Here's a simple example of how to create a window and render a texture with controls using MoonFrame:

import moonframe as mfr

class GameApp:
    def __init__(self, renderer, input_handler):
        self.renderer = renderer
        self.input = input_handler
        self.x, self.y = 100, 100
        
        self.cat = mfr.Texture(renderer, r"cat.avif", x=self.x, y=self.y)
        self.cat.resize(128, 128)

    def update(self):
        if self.input.is_key_pressed('right'): self.x += 5
        if self.input.is_key_pressed('down'): self.y -= 5
        if self.input.is_key_pressed('up'): self.y += 5
        if self.input.is_key_pressed('left'): self.x -= 5

        self.cat.set_pos(self.x, self.y)

    def draw(self):
        self.renderer.set_draw_color(20, 20, 30)
        self.renderer.clear()

win = mfr.Window("Suburban Cat", 800, 600)
renderer = mfr.Renderer(win)
event = mfr.Event()
input_handler = mfr.Input(win)
app = GameApp(renderer, input_handler)

running = True
while running:
    while win.poll_event(win, event):
        if event.type == event.QUIT:
            running = False
            break

    if not running:
        break
    
    app.update()
    app.draw()
    renderer.present()

win.handle.close()

Features

  • Window Management: Create and manage game windows with ease.
  • Rendering: Draw textures, shapes, and more with a simple API.
  • Input Handling: Capture keyboard and mouse input for interactive games.
  • Event System: Handle events like window resizing, quitting, and custom events.
  • Collision Detection: Built-in support for detecting collisions between game objects.

Methods and Classes

  • Window: Create and manage game windows.
  • Renderer: Handle all rendering operations.
  • Texture: Load and manipulate textures.
  • Input: Capture and process user input.
  • Drawable: Base class for drawable objects.
  • Event: Handle various events in the game loop.
  • Collision: Utility class for collision detection and response.
  • Text: Class for displaying text on the screen
  • Audio: Handles any music and sfx

Methods

  • Window.poll_event(): Poll for events from the window.
  • Renderer.set_draw_color(): Set the color for drawing operations.
  • Renderer.clear(): Clear the rendering target.
  • Texture.resize(): Resize a texture to specified dimensions.
  • Texture.set_pos(): Set the position of a texture.
  • Input.is_key_pressed(): Check if a specific key is currently pressed.
  • Collision.is_colliding(): Check for collisions between two objects.
  • And many more!

Contributing

Contributions to MoonFrame are welcome! If you have an idea for a new feature or want to fix a bug, please open an issue or submit a pull request on GitHub.

License

MoonFrame is licensed under the MIT License. See the LICENSE file for more details.

Version History

  • 1.1.0 - Highlight: Added new Text and Sound class:

    • Text:

      • Make text object mfr.Text(renderer, text, x, y, font_name, font_size, color)
      • Added set_text() method for changing the text
      • Added change_color() method for changing color of the text
      • Added change_size() method for changing size of the text
      • Added change_font() method for changing font of the text
      • Added set_pos method for changing the coordinates of the text
    • Sound:

      • Make audio object: mfr.Sound(path)
      • Added play() method to play audio
      • Added stop() method to stop audio
      • Added pause() method to pause audio
      • Added set_volume() method to change volume of audio
      • Added is_playing() method to check if audio is playing or not
    • Added various mouse control methods and also callback methods to the Input class

    • Added two examples to the examples folder for noobs to see and learn from

  • 1.0.0 - Initial release with basic window management, rendering, and input handling.

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

moonframe_engine-1.1.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

moonframe_engine-1.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file moonframe_engine-1.1.1.tar.gz.

File metadata

  • Download URL: moonframe_engine-1.1.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for moonframe_engine-1.1.1.tar.gz
Algorithm Hash digest
SHA256 2aa39c694675c577e4601a07acfb9f912357a0adaa16e6981d7a44f8e7c94a8f
MD5 58cdf1a5933e8fb82069393d13d8abbe
BLAKE2b-256 ff5a982ebdcf262d426afb4e57885f943c6d58228824c0ec1794bb3669f67c5b

See more details on using hashes here.

File details

Details for the file moonframe_engine-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for moonframe_engine-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 400bd955c79cd897b86ee363ff792ea448dddb79f705cee0f9834a8a77596997
MD5 d82242a306213e240ed9454295bed2a3
BLAKE2b-256 a44a0c2f2a2d5d34bcb9d0970e6c47c56a702301701e16eb8360d9ab504d795b

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