A game engine using Pyglet and Pymunk.
Project description
Jank Engine
Python game engine using Pyglet and Pymunk.
Installation
Install with pip:
python -m pip install -U jank
Install development version:
python -m pip install -U git+https://github.com/LennyPhoenix/Jank-Engine.git
Trello Roadmap
Basic Example
import jank # Import the engine
class Application(jank.Application):
PHYSICS_STEPS = 5 # Turn this up to increase simulation accuracy.
PLAYER_SPEED = 200
PLAYER_JUMP = 500
def __init__(self):
# Initialise the application
super().__init__(debug_mode=True, show_fps=True)
# Set the space's gravity
self.physics_space.gravity = (0, -1000)
# Create controls dictionary
self.controls = {
"left": False,
"right": False
}
# Create the floor
self.floor = jank.Entity(
position=(0, -325),
body_type=jank.Entity.STATIC,
collider=jank.colliders.Rect(
width=950,
height=50
)
)
self.floor.space = self.physics_space
# Create the player object. Note that the Entity class can be subclassed.
self.player = jank.Entity(
position=(0, 0),
collider=jank.colliders.Rect(
width=100,
height=100
)
)
self.player.space = self.physics_space
# Called every 1/120 of a second. (Note this can occasionally be inaccurate.)
def on_fixed_update(self, dt: float):
# Step the physics simulation forwards.
for _ in range(self.PHYSICS_STEPS):
self.physics_space.step(dt/self.PHYSICS_STEPS)
# Set the player's X velocity.
vx = 0
if self.controls["left"]:
vx -= self.PLAYER_SPEED
if self.controls["right"]:
vx += self.PLAYER_SPEED
self.player.velocity = (vx, self.player.velocity.y)
# Jump when the W key is pressed and the player is grounded.
def on_key_press(self, button, modifiers):
if button == jank.key.W and self.player.grounded:
self.player.body.apply_impulse_at_local_point(
(0, self.PLAYER_JUMP)
)
# Called as frequently as possible.
def on_update(self, dt: float):
# Update controls dict
self.controls = {
"left": self.key_handler[jank.key.A],
"right": self.key_handler[jank.key.D]
}
# Instantiate and run the application.
if __name__ == "__main__":
application = Application()
application.run()
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
jank-0.1.1.tar.gz
(17.1 kB
view details)
Built Distribution
jank-0.1.1-py3-none-any.whl
(24.8 kB
view details)
File details
Details for the file jank-0.1.1.tar.gz
.
File metadata
- Download URL: jank-0.1.1.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e3d3665d171fa299bdae7c1edd65ec2edafbc0b0bca571c0e67f6a7c59f83d4 |
|
MD5 | 8c9c04f7d18e4bc8b9f0616d08bbdd2e |
|
BLAKE2b-256 | 9a601cacf7c9d64a0ffec60d59fa95993630041de6aa872a19aecf1baa455f55 |
File details
Details for the file jank-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: jank-0.1.1-py3-none-any.whl
- Upload date:
- Size: 24.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88b1431c46e5f4c794b89f6777d9fbdae6708b524ed3c7cb60ac4292a08dff5c |
|
MD5 | 9061e9c8accf5b19c0e2e2bc0b1b4e73 |
|
BLAKE2b-256 | 5d1813f11c79263b082e334fb43d6adc8b44676b7bbfac1b5ced13aea11c935c |