Code Monkey home page Code Monkey logo

playbrew's Introduction

PlayBrew

A library-less, ECS-based, pure Java game engine.

PlayBrew is a passion project, designed to explore game engine architecture.

Features

  • Entity Component System ?magic?!
  • Zero dependencies (outside of the standard library).
  • Basic engine features
    • Tilemaps
    • Input
    • Movement
    • Physics
    • Collision
    • Animation
    • And more!

Examples

I think it's easier to learn PlayBrew by jumping into some examples, so here we go!

import com.waffle.core.*;
import com.waffle.ecs.*;
import com.waffle.struct.Vec2f;

class Player extends GameObject {
    private TransformComponent transform;
    private SpriteRenderComponent sprites;
    private final static float SPEED = 50;

    @Override
    public void start() {
        BufferedImage img = null;
        try {
            // Relative to the "resources" folder of your project.
            img = Utils.loadImageFromPath("path/to/image");
        } catch (Exception e) {
            System.out.println("Something went wrong! " + e.getMessage());
        }
        if (img != null) {
            transform = new TransformComponent(200, 300);
            sprites = new SpriteRenderComponent();
            sprites.sprites.add(new SpriteRenderer(new Vec2f(), img, 50, 50));
        }
    }

    // Called each frame, "dt" is the difference in time between the last frame and the current frame
    @Override
    public void update(float dt) {
        transform.position.x += SPEED * dt;
    }
}

class TestGame extends Game {
    private Player player;

    @Override
    public void start() {
        // "world" is a protected member of Game, it is used to manage the ECS
        world.createLayers(2);
        window = createWindow(960, 540, "My test game", new Camera(960, 540));
        player = new Player();

        // Defaults to bottom "layer", 0
        world.createGameObject(player);
        
        window.setVisible(true);
    }

    // Called each frame, just like <Player>.update(float)
    @Override
    public void update(float dt) {
    }

    // Called when the game exits or crashes, used for resource cleanup.
    @Override
    public void free() {
    }
}

public class Main {
    public static void main(String[] args) {
        new GameTest();
    }
}
And just like that, you've made your first game!

There are many components and systems to discover, and you can make your own by simply doing class MyComponent implements IComponent, and class MySystem extends ECSSystem.


Contributing

If you wish to contribute, fantastic! I appreciate the effort put in by every contributor.

Fork this repository, then open a pull request when you're ready!

playbrew's People

Contributors

jwaffled avatar gammraye avatar

Watchers

 avatar

Forkers

gammraye

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.