Giter VIP home page Giter VIP logo

reforge's Introduction

ReForge - Forge IV

A 2D game engine written in Python using both SDL2 and PyGame.

Getting Started

How to install.

pip install ReForge

Examples

Creating a window.

import os

os.environ["REFORGE_API"] = "sdl2"

import reforge, ctypes

def reforgeEntry(argc: int, argv: reforge.List[str]) -> int:
    context = reforge.Context()
    context.makeContextCurrent()
    window = reforge.Window(title = "ReForge", width = 1200, height = 600)
    context.registerWindow(window)
    renderer = reforge.Renderer(window)
    scene = reforge.Scene()

    while not context.isTerminated():
        context.pollEvents()
        renderer.clear(reforge.Vector4(0.0, 0.0, 0.0, 255.0))
        renderer.renderScene(scene)
        renderer.present()

    context.terminate()
    return reforge.exitSuccess

Rendering a rect.

import os

os.environ["REFORGE_API"] = "sdl2"

import reforge, ctypes

def reforgeEntry(argc: int, argv: reforge.List[str]) -> int:
    context = reforge.Context()
    context.makeContextCurrent()
    window = reforge.Window(title = "ReForge", width = 1200, height = 600)
    context.registerWindow(window)
    renderer = reforge.Renderer(window)
    scene = reforge.Scene()

    entity = scene.createEntity()
    entity.addComponent(reforge.RectComponent(fill = False, color = reforge.Vector4(0.0, 128.0, 128.0, 255.0)))
    entity.getComponent(reforge.TransformComponent).scale = reforge.Vector2(200.0, 200.0)
    entity.getComponent(reforge.TransformComponent).position = \
        window.size / 2.0 - entity.getComponent(reforge.TransformComponent).scale / 2.0

    while not context.isTerminated():
        context.pollEvents()
        renderer.clear(reforge.Vector4(0.0, 0.0, 0.0, 255.0))
        renderer.renderScene(scene)
        renderer.present()

    renderer.terminate()
    context.terminate()
    return reforge.exitSuccess

Using the low-level API.

import os

os.environ["REFORGE_API"] = "sdl2"

import reforge, ctypes

def reforgeEntry(argc: int, argv: reforge.List[str]) -> int:
    context = reforge.api.Context()
    window = reforge.api.Window(title = "ReForge", width = 1200, height = 600)
    renderer = reforge.api.Renderer(window)
    inputHandler = reforge.api.Input(window)
    eventHandler = reforge.api.EventHandler()
    event = reforge.api.Event()
    running = True

    while running:
        while eventHandler.pollEvents(event):
            if event.type == reforge.api.EventType.WindowClosed:
                running = False

            inputHandler.eventHandler(event)

        if inputHandler.keyboard.keys[reforge.api.Key.Escape]:
            running = False

        renderer.clear(reforge.Vector4(0.0, 0.0, 0.0, 255.0))
        renderer.present()

    eventHandler.terminate()
    inputHandler.terminate()
    renderer.terminate()
    window.terminate()
    context.terminate()
    return reforge.exitSuccess

reforge's People

Contributors

aermoss avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.