Clighter
Clighter is a game engine for terminal games. You can use this library to build none flickering, totaly fluid games. You have very easy to use APIs in your hand with clighter.
When you use clighter you don't have to think about how to render objects with multiple characters, you also don't need to think about the collision between objects and many other features that clighter provides you.
Simple spaceshooter game
Quick Start
1. Installation
- Install with pip
$ pip install clighter
- Clone the library use without installation
$ git clone https://github.com/bilginyuksel/clighter
$ cd clighter/examples
$ mkdir <your-folder>
$ cd <your-folder>
After you execute the commands above you can create your own structure for your game.
NOTE: Do not forget to import sys and append to the directory where clighter exist. Follow the example code block to use the clighter package effectively for your project under
examplesdirectory.
# This code is a must if you create your game under examples directory and if you want to use the local clighter package from that directory.
import sys
sys.path.append('../..')
# Then you can import the clighter
import clighter
# or
from clighter import * # to use all classes and functions without clighter prefix
2. Usage
Render a character to the scene and subscribe character to input channel. Whenever user enters w,a,s,d the character will move to the given direction.
Also we need a character, you can copy the character.txt file from clighter/examples/main/assets/character.txt or you can create a brand new character for yourself. Be sure to give correct filepath.
from clighter import CLIGame, GameObject, Position
class Character(GameObject):
def __init__(self, position: Position) -> None:
super().__init__(position, None, filepath='assets/character.txt',
obstacle=False, controllable=True)
def on_key_pressed(self, key: chr):
if key == 's':
self.position.y += 3
elif key == 'w':
self.position.y -= 3
elif key == 'd':
self.position.x += 3
elif key == 'a':
self.position.x -= 3
if __name__ == '__main__':
game = CLIGame()
factory = GameObjectFactory()
character = Character(Position(10, 10))
# channel=True and scene=True means character will be put to scene and subscribe to channel
factory.put(character, channel=True, scene=True)
game.start()
Some of the features
Rendering
Clighter will automatically handle object rendering. You just need to provide a .txt file to the game object. After you give the filepath to the object it will automatically render it without a problem.
Also you can move the character without having any rendering problems at all. Just change the position of the object and it will move.
class SomeObject(GameObject):
...
...
def update(self):
# the object will move at x_axis by 1 unit in every frame.
self.position.x += 1
...
...
Collision
Collision is a very important and good feature when you create games. With clighter you can create layered rendering hierarcy between the objects with the z_index. When you put some objects in the same z_index whenever they collide with each other the engine will automatically trigger their collide functions.
NOTE: If there are a lot objects in the scene then calculating collision for every object will be a lot of work but good news: you can simply optimize it via using a single parameter. For instance if there are a lot of bullets in the map then the system will control the collision effect between bullets and character both at the same time. But you can deactivate the bullet collision search and the game will be much more faster.
class Bullet(GameObject):
def __init__(self):
# When you set `trigger_collision` parameter to False the engine will skip collision effect for bullet. But that does not mean you will miss this collision effect. If this bullet collides with a character you can catch the collision effect with the character's collide function.
GameObject.__init__(self, position, dimension=None, filepath=None,
obstacle=False, controllable=False, trigger_collision=False)
# if `trigger_collision` parameter is False then the function below will not be triggered even if there is a collision but if this bullet object collides with another object and if the collided objects `trigger_colision` parameter is True then the collision effect can be captured with collided object's collide function.
def collide(self, obj: GameObject):
pass
Metadata
Release files for clighter 0.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| clighter-0.3.5.tar.gz | 17.1 kB | Without provenance | Details for clighter-0.3.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| clighter-0.3.5-py3-none-any.whl | Python 3 | none | any | Details for clighter-0.3.5-py3-none-any.whl |
Total release size: 38.3 kB
Release files / clighter-0.3.5.tar.gz
| Download URL | clighter-0.3.5.tar.gz |
|---|---|
| Size | 17.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0c9cbab29b1045e4663e7dadb1795356b430ffb31eaf94f693a679443cf8efb3
|
|
BLAKE2b-256 checksum How to use checksums |
a535974e0f6b7cf70cb04cfec18fbe71810f73b89e62f84d5c49eb6d05cd75d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
|
Release files / clighter-0.3.5-py3-none-any.whl
| Download URL | clighter-0.3.5-py3-none-any.whl |
|---|---|
| Size | 21.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ff291c41cf29e715899a98bc640fec1586971993a395ae80d834b3e501de1287
|
|
BLAKE2b-256 checksum How to use checksums |
787e1135f983ee254260778b2f0b28f78ac407938207206a876de230c2920c09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
|
Security for clighter 0.3.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.