Python Game Engine
Project description
Whenever I have played a great computer game for the first time, I was wondering how they do it. Then I tried to recreate it.
Pygame (https://www.pygame.org) is a great library for making your own game with python.
When starting a new game from scratch you always need to build the basic structure. The game engine wonder gives you a collection of components you can use with Pygame.
The game engine wonder is only a frame for your programming, so you have to know Pygame for creating new games.
Many ideas in wonder are inspired by Unity 3D (https://unity.com)
If you are looking for more simple to use Pygame frameworks:
pygame zero https://github.com/lordmauve/pgzero
python arcade library https://arcade.academy
The game engine wonder includes Box2D as physics engine.
Goals:
explicit is better then implicit - wonder is only the frame for your game
Component based - more components, less classes
Inspired by Unity 3D - Similar names for object types and methods
Physics engine included
If you like it, use it. If you have some suggestions, tell me (hebi@ninja-python.com).
All game assets that I use in examples are free and from https://www.kenney.nl. Thank you.
acclaimer
You can use this alpha version 0.1.0 of the game engine wonder but there will be some changes in the future.
installing wonder game engine
Install with pip
pip install wonder
If that does not work on your platform you can install the different components separately
Install pygame
pip install pygame
Install physics engine Box2D
pip install box2d
For installing wonder simply copy file wonder.py to your directory.
cp wonder.py
wonder game engine - making a new game
main game
level 1 - scene
A scene contains of gameobject
create
add gameobject
gameobject
create border
component rigidbody static
create blocks
move racket
debug
create ball
move ball
create block
create scoremanager
restrart
0 ball level 1
next level
wonder game engine - behind the curtain
central engine and the systems
pattern singleton
game loop update draw
timing
event system
on_load_scene
observer pattern
get_object
GetObject
gameobject
mixin
transform
components
SpriteRenderer
scene
layered container for gameobject
render system
layered observer
Component SpriteRenderer
consists of surface and rect
change current scene
add or remove gameobject
add or remove component
physic and collision system
bodies
Component Rigidbody is b2Body
synchornize transform
body types
fixtures
component collider is b2Fixture
boxcollider
debug
joints
distance joints
get_gameobject
animator component
particle system
tile system
GRID_WIDTH = 5
GRID_HEIGHT = 7
CELL_WIDTH = 64
CELL_HEIGHT = 64
tilemap = TileMap(GRID_WIDTH,GRID_HEIGHT,CELL_WIDTH,CELL_HEIGHT)
The tilemap.transform.position is always the top left position of the map. With changing position you can move the complete map.
tilemap.palette.add(TilePaletteItem(0, tile_type='ground', image=pygame.image.load('res_tile/ground.png')))
tilemap.palette.add(TilePaletteItem(1, tile_type='wall', image=pygame.image.load('res_tile/wall.png')))
..
To create a tile from the palette at a specific position in the tile map use the function create_tile_from_palette(position_x,position_y,tile_type or id)
tilemap.create_tile_from_palette(0,0,'ground')
You can create a complete tile map with set_all_tiles
tilemap.set_all_tiles([[1,1,1,1,1],
[1,0,0,0,1],
[1,0,0,0,1],
[1,0,0,0,1],
[1,0,0,0,1],
[1,0,0,0,1],
[1,1,1,1,1]])
A class TileMap can have more than one layer of tiles. Negative values are None.
new_layer = tilemap.add_layer()
tilemap.set_all_tiles([[-1,-1,-1,-1,-1],
[-1, 4,-1,-1,-1],
..
[-1,-1,-1, 2,-1],
[-1,-1,-1,-1,-1]],tile_layer=new_layer)
To see something tilemap as gameobject needs rendering component
tilemap.add(TileMapRenderer(tilemap))
With class TileController a tile can react
tilemap.palette.add(TilePaletteItem(4, tile_type='player', image=pygame.image.load('res_tile/player_01.png'),
tile_controller_class=Player))
Class Player is in gameloop update cycle
class Player(TileController):
def __init__(self,tile:Tile):
super().__init__(tile)
..
def update(self, delta_time: float):
..
Class TileController has some convinient methods.
Changelog
Version |
|
---|---|
0.1.0 |
first version |
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
File details
Details for the file wonder-0.1.0.tar.gz
.
File metadata
- Download URL: wonder-0.1.0.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 462e9d925831cea4e127ee7db92957126ad2788bd7db08d7d878ef48a7e4ffe7 |
|
MD5 | 4a58f803d8910e036aa275dab023b732 |
|
BLAKE2b-256 | 599ff7fd201dfe47db2465aecca0cf6319577750b7d096074cfd565a7e783add |
File details
Details for the file wonder-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: wonder-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed6a7355838e3ae8f0d74436a56741ca2c1c9149e1b40fd3429ba71498ad4754 |
|
MD5 | eb948bba92cceae345349b6bf7a9aed8 |
|
BLAKE2b-256 | f197506b32cc574313cb02b0407bb469cb1947f59486adb4f0a53eb87bc71911 |