All Projects → SirFroweey → Pydark

SirFroweey / Pydark

PyDark is a 2D and Online Multiplayer video game framework written on-top of Python and PyGame.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pydark

Openage
Free (as in freedom) open source clone of the Age of Empires II engine 🚀
Stars: ✭ 10,712 (+5229.35%)
Mutual labels:  game, game-development, game-engine, engine, multiplayer
Awesome Haxe Gamedev
Resources for game development on haxe
Stars: ✭ 213 (+5.97%)
Mutual labels:  framework, game, game-development, game-engine, engine
Ggez
Rust library to create a Good Game Easily
Stars: ✭ 3,120 (+1452.24%)
Mutual labels:  game, game-development, game-engine, engine
Kengine
Entity-Component-System (ECS) with a focus on ease-of-use, runtime extensibility and compile-time type safety and clarity.
Stars: ✭ 417 (+107.46%)
Mutual labels:  game, game-development, game-engine, engine
Gamedev Resources
🎮 🎲 A wonderful list of Game Development resources.
Stars: ✭ 2,054 (+921.89%)
Mutual labels:  game, game-development, game-engine, engine
Flopnite Ue4
A remake of the popular battle royale game, Fortnite, made in Unreal Engine 4 and integrated with Amazon GameLift
Stars: ✭ 250 (+24.38%)
Mutual labels:  game, game-development, multiplayer, networking
Kaetram Open
An open-source 2D HTML5 adventure based off BrowserQuest (BQ).
Stars: ✭ 138 (-31.34%)
Mutual labels:  game, game-development, game-engine, multiplayer
Dodgem
A Simple Multiplayer Game, built with Mage Game Engine.
Stars: ✭ 12 (-94.03%)
Mutual labels:  game, game-development, game-engine, multiplayer
Fxgl
Stars: ✭ 2,378 (+1083.08%)
Mutual labels:  framework, game, game-development, game-engine
Coffee
An opinionated 2D game engine for Rust
Stars: ✭ 771 (+283.58%)
Mutual labels:  game, game-development, game-engine, engine
Iogrid
Multiplayer game engine/framework built using SocketCluster and Phaser
Stars: ✭ 455 (+126.37%)
Mutual labels:  framework, game-development, game-engine, multiplayer
Evennia
Python MUD/MUX/MUSH/MU* development system
Stars: ✭ 1,309 (+551.24%)
Mutual labels:  game-development, game-engine, engine, multiplayer
Gameproject3
游戏服务器框架,网络层分别用SocketAPI、Boost Asio、Libuv三种方式实现, 框架内使用共享内存,无锁队列,对象池,内存池来提高服务器性能。还包含一个不断完善的Unity 3D客户端,客户端含大量完整资源,坐骑,宠物,伙伴,装备, 这些均己实现上阵和穿戴, 并可进入副本战斗,多人玩法也己实现, 持续开发中。
Stars: ✭ 655 (+225.87%)
Mutual labels:  game, game-development, game-engine, multiplayer
Novelrt
A cross-platform 2D game engine accompanied by a strong toolset for visual novels.
Stars: ✭ 81 (-59.7%)
Mutual labels:  game, game-development, game-engine, engine
Entitas Sync Framework
Networking framework for Entitas ECS. Targeted at turnbased games or other slow-paced genres.
Stars: ✭ 98 (-51.24%)
Mutual labels:  game, game-development, multiplayer, networking
Lambda Lantern
🧙 ‎‎ A 3D game about functional programming patterns. Uses PureScript Native, C++, and Panda3D.
Stars: ✭ 122 (-39.3%)
Mutual labels:  game, game-development, game-engine
Gamedev4noobs
Olá, sejam bem-vindos ao repositório _gamedev4noobs_ do Estúdio Vaca Roxa. O propósito desse repositório, além de contribuir para o projeto 4noobs, é ensinar o básico do desenvolvimento de jogos para iniciantes. Apresentando boas práticas e insumos para criar games incríveis.
Stars: ✭ 122 (-39.3%)
Mutual labels:  game, game-development, game-engine
Simplexrpgengine
Modular game engine built with MonoGame, with GMS2-like workflow and advanced level editor
Stars: ✭ 122 (-39.3%)
Mutual labels:  game, game-engine, engine
O2
2D Game Engine with visual WYSIWYG editor
Stars: ✭ 121 (-39.8%)
Mutual labels:  framework, game-development, game-engine
Openjk
Community effort to maintain and improve Jedi Academy (SP & MP) + Jedi Outcast (SP only) released by Raven Software
Stars: ✭ 1,641 (+716.42%)
Mutual labels:  game, game-development, game-engine

PyDark

PyDark is a 2D and Online Multiplayer video game framework written on-top of Python and PyGame.

Our goal with PyDark was to make it easy to learn and integrate into existing pygame applications. PyDark is designed to be fully customizable and scalable, allowing developers to inherit base classes and make new sub-classes.

Prerequisites: Python 2.7.x, PyGame, Twisted

Overview

PyDark runs on top of PyDark.engine.Scene objects. A scene is a collection of objects that are displayed within' the scene. Think of it like a movie scene, where a series of scenes define a movie.

In a nutshell, you have a collection of modules avaialble to you, them being:

  1. PyDark.engine (core functionality, i.e.: Scenes, Sprites, etc).
  2. PyDark.ui (base UI elements for your game, integrate them into your games or build entirely new UI elements).
  3. PyDark.net (twisted networking TCP and UDP client/server networking classes)
  4. PyDark.io (series of functions and classes for file-access, SpriteSheet loading, encryption, map generation and much more)
  5. PyDark.constants (classes that define PyDark event types)
  6. PyDark.icon (static module containing base64 encoded string of base window icon)
  7. PyDark.vector2d (contains base vector2d class for 2D vector math functionality)

Examples

Main menu

A simple example showcasing PyDarks UI module that displays a main menu scene. Keep in mind you'll be needing to manually provide the following files: (login_overlay_bg.jpg, input.png, input_selected.png, click.wav, button.png, button_hover.png).

import PyDark.engine
import PyDark.ui
import PyDark.vector2d


def login_button_pressed(event, game_instance):
    game_instance.currentScene = "game_scene"
    print event, event.fired_by
    print username.text
    print password.text


game = PyDark.engine.Game(
    title="FrowCraft",
    window_size=(800, 650),
    center_window=True,
    FPS=30,
    online=True,
    server_ip="localhost",
    server_port=8000
)

login_scene = PyDark.engine.Scene(surface=game, name="login_scene")
game_scene = PyDark.engine.Scene(surface=game, name="game_scene")

login_overlay = PyDark.ui.Overlay(
    parent=login_scene,
    size=(login_scene.window_size()[0], 330),
    image="login_overlay_bg.jpg",
    position=(0,0),
)


login_header = PyDark.ui.Label(
    name="login_header",
    text="FrowCraft",
    size=30,
    font="Arial",
    color=PyDark.engine.Color(255, 255, 255, 1),
    position=(100, 10),
    aa=True,
    center=True
)

username_label = PyDark.ui.Label(
    name="username_label",
    text="Username:",
    size=14,
    font="Arial",
    color=PyDark.engine.Color(0, 0, 0, 1),
    position=(0, 60),
    center=True
)

username = PyDark.ui.TextBox(
    name="username",
    position=(100, 80),
    center=True,
    default_image="input.png",
    image_selected="input_selected.png"
)

password_label = PyDark.ui.Label(
    name="password_label",
    text="Password:",
    size=14,
    font="Arial",
    color=PyDark.engine.Color(0, 0, 0, 1),
    position=(0, 150),
    center=True
)

password = PyDark.ui.TextBox(
    name="password",
    position=(0, 170),
    center=True,
    default_image="input.png",
    image_selected="input_selected.png"
)

login_button = PyDark.ui.Button(
    name="login_button",
    position=(100, 260),
    on_press=lambda e, game=game:login_button_pressed(e, game),
    center=True,
    sound="click.wav",
    default_image="button.png",
    image_hover="button_hover.png",
    image_selected="button_hover.png"
)

login_overlay.add_object(login_header)
login_overlay.add_object(username_label)
login_overlay.add_object(username)
login_overlay.add_object(password_label)
login_overlay.add_object(password)
login_overlay.add_object(login_button)

login_scene.add_object(login_overlay)

game.add_scene(login_scene)
game.add_scene(game_scene)

game.currentScene = "login_scene"
game.start()

login_overlay.add_object(OBJECT)

Adds an object to our PyDark.ui.Overlay object. This will draw OBJECT on-top of the overlay object. An overlay defines a section of the screen to draw UI elements on).

login_scene.add_object(OBJECT)

Adds an object to a scene, the scene being the login_scene. Needed to display an object during a scene. Only required to do so once.

game.add_scene(SCENE)

Adds a scene to our game instance. Needed to specify which scenes we are going to make available for our game.

game.currentScene = "login_scene"

Defines the current scene to display on our game.

game.start()

Start main game loop.

Networking

Networking in PyDark is event-based and is built to keep things simple for client/server communication. One way PyDark acheives this is by supplying functions to modify python dictionaries that contain the make-up of your networking logic.

An example of this is via PyDark.net.ServerProtocol.headers and PyDark.net.ClientProtocol.headers. These instance variables are python dictionaries that will contain (key, value) pairs consisting of (header, callback).

header

unique (string) that defines this networking packet (data) type. An example is 'msg' and 'login'. These of course are arbitrary, you can name your headers whatever you want.

callback

class-method (function) callback to trigger when we receive a packet with this header.

In PyDark we call these things handles. So to register a new handle in your protocol, do something like:

import PyDark.net

class MyProtocol(PyDark.net.ClientProtocol):
    def __init__(self, factory, log):
        PyDark.net.ClientProtocol.__init__(self, factory, log)
        self.register_handle("msg", self.chat_message)
    def chat_message(self, payload):
        print "Payload:", payload
        self.message("msg:Thanks for the welcome message!")

(Client protocol example)

Notice the line: self.register_handle("msg", self.chat_message). This line tells PyDark.net that we want to call the chat_message class-method after receiving a 'msg' packet from the server. In the back-end PyDark.net processes all communication between the server and client by calling packet.split(":"). This will split the packet with two values (header, data). Thus your packets should be in the format of "header:data". You can send this packet via your ClientProtocol or ServerProtocol by calling self.message("msg:your message here"). Note: Ensure colons(:) are filtered out to prevent the PyDark.net code from generating an IndexError.

import PyDark.net

class OurProtocol(PyDark.net.ServerProtocol):
    def __init__(self, factory):
        PyDark.net.ServerProtocol.__init__(self, factory)
        self.register_handle("msg", self.chat_message)
        
    def chat_message(self, payload):
        print "Payload:", payload
        
    def clientConnected(self, player_or_peer):
		print "{player_or_peer} has connected!".format(player_or_peer=player_or_peer)
		self.message("msg:hello, world!")

(Server protocol example)

Note: it is possible to use PyDark.net networking code outside an PyDark.engine.Game() instance. Take a look at the client.py and server.py examples on how to acheive that.

Real PyDark implementation

The best and easiest way to create a networked game in PyDark is to create two (or more) files named client.py and server.py. Your client code should store your PyDark game and client networking logic (PyDark.net.ClientProtocol sub-class, Sprites, Tilsheets, Scenes, Mainloop, etc). While the server.py file should only store PyDark.net server networking logic.

With this in mind, the way you specify your game is an online game is via the following example:

game = PyDark.engine.Game(
    title="FrowCraft",
    window_size=(800, 650),
    center_window=True,
    FPS=30,
    online=True,
    server_ip="localhost",
    server_port=8000,
    protocol=OurProtocol
)

Pay close attention to the online=True, server_ip="localhost", server_port=8000, and protocol=MyProtocol keyword arguments. These inform PyDark that our game instance is an online game instance and we specify which IP and PORT to connect to. Finally, we specify our PyDark.net.ClientProtocol instance as the games networking protocol.

In the back-end, PyDark will attempt to connect to the server. If a connection is successful, the instance variable game.connection will return a PyDark.net.TCP_Client instance and the instance variable game.network will return a PyDark.net.*Factory instance. Otherwise, both varaibles will be None.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].