Introduction

DHEngine is a lightweight game engine built on top of pygame. It provides structured systems like windows, sprites, physics, events, and cameras while staying simple and beginner-friendly.

Installation

pip install dhengine

Python 3.11 or newer is required.

Quick Start Example

This example shows a complete minimal game loop using DHEngine.

Imports

from dhengine import *
import pygame

Window & Core Systems

win = Window((800,600), "DhEngine Demo")
clock = Clock()
events = Events()

Create a Player Sprite

img = pygame.Surface((40,40), pygame.SRCALPHA)
img.fill((0,200,255))player = Sprite(img, (100,100))

Physics & Camera

body = Body(player.rect, (3,0), 0.4)
cam = Camera()

Main Game Loop

running = True
while running:
    dt = clock.tick()
    ev = events.poll()
    if events.quit(ev):
        running = False
    body.update()
    cam.follow(player)

    win.fill()
    win.screen.blit(player.image, cam.apply(player.rect))
    win.update()

pygame.quit()

Window

The Window class creates and manages the game window.

win = Window((width, height), title)

Clock

The Clock controls frame rate and delta time.

dt = clock.tick()

Events

The Events system simplifies pygame event handling.

ev = events.poll()
if events.quit(ev):
    running = False

Sprite

Sprite represents an image with position and rect data.

player = Sprite(image, position)

Body (Physics)

The Body class applies velocity and gravity to a rect.

body = Body(rect, velocity, gravity)
body.update()

Camera

The Camera offsets rendering to follow entities.

cam.follow(player)
screen.blit(image, cam.apply(rect))