Metadata-Version: 2.3
Name: charz
Version: 0.0.41
Summary: An object oriented terminal game engine
Author-email: Havsalt <77575424+Havsalt@users.noreply.github.com>
License: MIT License
        
        Copyright (c) 2025 Havsalt
        
        Permission is hereby granted, free of charge, to any person obtaining
        a copy of this software and associated documentation files (the
        "Software"), to deal in the Software without restriction, including
        without limitation the rights to use, copy, modify, merge, publish,
        distribute, sublicense, and/or sell copies of the Software, and to
        permit persons to whom the Software is furnished to do so, subject to
        the following conditions:
        
        The above copyright notice and this permission notice shall be
        included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
        EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
        MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
        IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
        CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
        TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
        SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Requires-Python: >=3.10
Requires-Dist: colex~=0.3.0
Requires-Dist: linflex~=0.2.0
Requires-Dist: typing-extensions>=4.4.0
Provides-Extra: all
Requires-Dist: keyboard>=0.13.5; extra == 'all'
Requires-Dist: pygame~=2.1; extra == 'all'
Provides-Extra: controller
Requires-Dist: pygame~=2.1; extra == 'controller'
Provides-Extra: keyboard
Requires-Dist: keyboard>=0.13.5; extra == 'keyboard'
Description-Content-Type: text/markdown

# Charz

An object oriented terminal game engine

## Installation

Install using either `pip` or `rye`:

```bash
pip install charz[all]
```

```bash
rye add charz --features all
```

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

```bash
pip install charz
```

```bash
rye add charz
```

## Getting started

```python
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, delta: float) -> None:  # This method is called every frame
        if keyboard.is_pressed("a"):
            self.position.y -= self.SPEED * delta
        if keyboard.is_pressed("d"):
            self.position.y += self.SPEED * delta
        if keyboard.is_pressed("s"):
            self.position.y += self.SPEED * delta
        if keyboard.is_pressed("w"):
            self.position.y -= self.SPEED * delta


class Game(Engine):
    fps = 12
    screen = Screen(auto_resize = True)
    clear_console = True

    def __init__(self) -> None:
        Camera.current.mode = Camera.MODE_CENTERED
        self.player = Player(position=Vec2(10, 5))
    
    def update(self, _delta: float) -> 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 `App`, but it won't be updated


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

## 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`
  - `Vec2`
  - `Vec2i`
  - `Vec3`
- Modules
  - `text`
    - `fill`
    - `flip_h`
    - `flip_v`
    - `fill_lines`
    - `flip_lines_h`
    - `flip_lines_v`
    - `rotate`
  - `colex`    (Dependency)
  - `keyboard` (Optional dependency)
- Framework
  - `Engine`
  - `Clock`
  - `DeltaClock`
  - `Screen`
  - `Scene`
- Datastructures
  - `AnimationSet`
  - `Hitbox`
- Functions
  - `load_texture`
- Decorators
  - `group`
- Singletons
  - `AssetLoader`
- Components
  - `Transform`
  - `Texture`
  - `Color`
  - `Animated`
  - `Collider`
  - `SimpleMovement`
- Nodes
  - `Camera`
  - `Node`
  - `Node2D`
  - `Sprite`
  - `Label`
  - `AnimatedSprite`

## Regarding testing

Tests for `charz` are currently manual and only somewhat implemented. Until I find a testing tool I like, things will be manual, just so I know if the critical parts work.

**NOTE**: Tests cannot be run from `current working directory` at the moment! I'll just monkeypatch it to run on my machine *-famose last words*.

## Versioning

This project will use `semantic versioning` after reaching release `0.1.0`. Consider any patch bump before that to be a breaking change. It is adviced to pin `charz` using `==` in your `pyproject.toml`, until release `0.1.0`.

## License

MIT
