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 packagecolex)Self(from standardtypingor from packagetyping-extensions)
- Math (from package
linflex)lerpsignclampmove_towardVec2Vec2iVec3
- Submodules
textfillflip_hflip_vfill_linesflip_lines_hflip_lines_vrotate
- Framework
EngineClockScreenScene
- Datastructures
AnimationSetHitbox
- Functions
load_texture
- Decorators
group
- Enums
Group
- Singletons
TimeAssetLoader
- Components
TransformComponentTextureComponentColorComponentAnimatedComponentColliderComponent
- Nodes
NodeNode2DCameraSpriteLabelAnimatedSprite
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file charz-0.1.3.tar.gz.
File metadata
- Download URL: charz-0.1.3.tar.gz
- Upload date:
- Size: 28.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7d4c2938775c338b3c724e494ee6fdf4cfd678d4aa737cbbbad2bfd8c9ab4b1
|
|
| MD5 |
680dd53d28cc43246e5090df04f40136
|
|
| BLAKE2b-256 |
3375125b7f9547f2cda74b3a38ddea4deb0b6e2d40e03f045e1868d320f4a1f2
|
File details
Details for the file charz-0.1.3-py3-none-any.whl.
File metadata
- Download URL: charz-0.1.3-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8aa3e53d9e99a2942c9150b8aafe4569b85d43fea12c167c359fa94846de5f0
|
|
| MD5 |
23362b0ee5c9cd2a233505249c7c6a36
|
|
| BLAKE2b-256 |
e8bcfd97b89f75bce8e015435567fbe4f00f05b420f2bc83a602a3b99b8dc78a
|