Skip to main content

An object oriented terminal game engine

Project description

Charz

An object oriented terminal game engine

Installation

Install using either pip or rye:

pip install charz[all]
rye add charz --features all

If you don't need the keyboard package, simply use:

pip install charz
rye add charz

Getting started

Add to project with keyboard feature:

pip install charz[keyboard]

or

rye add charz --features keyboard

Copy this code into the entry point (main.py or __init__.py)

import colex              # Color constants and styling
import keyboard           # For taking key inputs
from charz import *       # Module can be imported as namespace: "import charz"


class Player(Sprite):
    SPEED: int = 4     # Defining constant
    color = colex.RED  # In reality just a string, like "\x1b[31m" for red
    centered = True    # Apply sprite centereing - Handled by `charz`
    texture = [        # A texture may be defined as a class variable, of type `list[str]`
        "  O",
        "/ | \\",
        " / \\",
    ]

    def update(self) -> None:  # This method is called every frame
        if keyboard.is_pressed("a"):
            self.position.x -= self.SPEED * Time.delta
        if keyboard.is_pressed("d"):
            self.position.x += self.SPEED * Time.delta
        if keyboard.is_pressed("s"):
            self.position.y += self.SPEED * Time.delta
        if keyboard.is_pressed("w"):
            self.position.y -= self.SPEED * Time.delta


class Game(Engine):
    clock = Clock(fps=12)
    screen = Screen(
        auto_resize=True,
        initial_clear=True,
    )

    def __init__(self) -> None:
        Camera.current.mode = Camera.MODE_CENTERED
        self.player = Player(position=Vec2(10, 5))
    
    def update(self) -> None:
        if keyboard.is_pressed("q"):
            self.is_running = False
        if keyboard.is_pressed("e"):
            self.player.queue_free()  # `Engine` will drop reference to player
            # NOTE: Player reference is still kept alive by `Game`, but it won't be updated


if __name__ == "__main__":
    game = Game()
    game.run()

Note: If using rye, replace:

if __name__ == "__main__":

with

def main() -> None:

Rational

This project is heavily inspired by the Godot Game Engine.

Includes

  • Annotations
    • ColorValue (from package colex)
    • Self (from standard typing or from package typing-extensions)
  • Math (from package linflex)
    • lerp
    • sign
    • clamp
    • move_toward
    • Vec2
    • Vec2i
    • Vec3
  • Submodules
    • text
      • fill
      • flip_h
      • flip_v
      • fill_lines
      • flip_lines_h
      • flip_lines_v
      • rotate
  • Framework
    • Engine
    • Clock
    • Screen
    • Scene
  • Datastructures
    • AnimationSet
    • Hitbox
  • Functions
    • load_texture
  • Decorators
    • group
  • Enums
    • Group
  • Singletons
    • Time
    • AssetLoader
  • Components
    • TransformComponent
    • TextureComponent
    • ColorComponent
    • AnimatedComponent
    • ColliderComponent
  • Nodes
    • Node
    • Node2D
    • Camera
    • Sprite
    • Label
    • AnimatedSprite
  • Feature dependent*
    • SimpleMovementComponent

*: Feature dependent imports requires explicit import statements as they are lazy loaded:

# Example when using star import, with feature dependent import
from charz import *
from charz import SimpleMovementComponent

Regarding testing

Tests for charz are currently manual and only somewhat implemented. The plan is to use pytest, however, it's hard to make work since charz is meant for long-running tasks, including IO.

Versioning

charz uses SemVer, according to The Cargo Book.

License

MIT

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

charz-0.1.2.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

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

charz-0.1.2-py3-none-any.whl (37.7 kB view details)

Uploaded Python 3

File details

Details for the file charz-0.1.2.tar.gz.

File metadata

  • Download URL: charz-0.1.2.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.15

File hashes

Hashes for charz-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d6066eb224d49e0970e0aa47a1d30e1ee12e07f8ad5af913d441be41f2a06ff2
MD5 ccacae2df998ed0c808ec43d5e2f3c52
BLAKE2b-256 a97897ad730eda278201d2033d105323cb575e8bbe1bc4d9ac995047d0e3af9e

See more details on using hashes here.

File details

Details for the file charz-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: charz-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 37.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.15

File hashes

Hashes for charz-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d509ba854fbda5a342ba5d79d2a53053d574695b303ddb0f87cdc382396b2833
MD5 4f50fa426ab63144d76a20fe49ec574c
BLAKE2b-256 c60c04f3c8f312b7c564015ebbdd5b7ff7e410733a8cdae9106270d7b075adc7

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