Skip to main content

'Game engine for CLI games.'

Project description

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

spaceshooter

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 examples directory.

# 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

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

clighter-0.3.5.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

clighter-0.3.5-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file clighter-0.3.5.tar.gz.

File metadata

  • Download URL: clighter-0.3.5.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for clighter-0.3.5.tar.gz
Algorithm Hash digest
SHA256 0c9cbab29b1045e4663e7dadb1795356b430ffb31eaf94f693a679443cf8efb3
MD5 49351141b38be21d4019b162d0cc3adb
BLAKE2b-256 a535974e0f6b7cf70cb04cfec18fbe71810f73b89e62f84d5c49eb6d05cd75d4

See more details on using hashes here.

File details

Details for the file clighter-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: clighter-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for clighter-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ff291c41cf29e715899a98bc640fec1586971993a395ae80d834b3e501de1287
MD5 e3bfc8df4912365d4659f1a14b79e1c2
BLAKE2b-256 787e1135f983ee254260778b2f0b28f78ac407938207206a876de230c2920c09

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page