Skip to content

srcimon/screwbox

Repository files navigation

Project Logo

Minimalist 2D Java game engine. Result of covid lockdown.

Maven Central javadoc Build Lines of Code Coverage

About

ScrewBox is a small pure Java 2D game engine. I started developing ScrewBox in february 2021 right during too much time at hand because of covid lockdown. I use it to learn about Java and have some fun. If you want to get something startet in a few minutes ScrewBox might be a fun choice.

youtube trailer
▶ Watch trailer on Youtube

Features

  • Entity Component System Add and remove game objects and behaviour. Save and load the game state.
  • Render Engine Fast rendering of shapes, animated graphics and text. Enhance graphics with dynamic light and shadow effects.
  • Physics System Move objects and resolve collisions. Detect objects via raycasting.
  • Particle Effects Add particle effects to create some nice visuals.
  • Asset Management Load game assets without interrupting the game.
  • Basic UI Create an animated interactive game ui in an instant.
  • Input Support Receive player interactions via keyboard and mouse.
  • Game Scenes Use scenes to structure different game situations.
  • Audio Support Play wav and midi sounds. Control the volume, pan and balance. Get information on whats currently playing. Thats it. Only the basics.
  • Support for Tiled Editior Import your game map and tilesets in Json format from the Tiled Editor

Getting started

  1. Create a new Maven project and add screwbox-core dependency (Java 21 required):

    <dependency>
        <groupId>io.github.srcimon</groupId>
        <artifactId>screwbox-core</artifactId>
        <version>1.13.0</version>
    </dependency>
  2. Create new class and run (JVM option -Dsun.java2d.opengl=true highly recommended)

    import io.github.srcimon.screwbox.core.Engine;
    import io.github.srcimon.screwbox.core.ScrewBox;
    
    import static io.github.srcimon.screwbox.core.assets.FontBundle.BOLDZILLA;
    import static io.github.srcimon.screwbox.core.graphics.TextDrawOptions.font;
    
    public class HelloWorldApp {
    
        public static void main(String[] args) {
            Engine screwBox = ScrewBox.createEngine();
    
            screwBox.environment().addSystem(engine -> {
                var screen = engine.graphics().screen();
                var drawOptions = font(BOLDZILLA).scale(4).alignCenter();
                screen.drawText(screen.center(), "Hello world!", drawOptions);
            });
    
            screwBox.start();
        }
    }

Modules

Here is a quick overview over all modules contained in this library:

screwbox

BOM to manage all library dependencies.

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.github.srcimon</groupId>
            <artifactId>screwbox</artifactId>
            <version>1.13.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

screwbox-core

Adds the core functionality of the ScrewBox engine. Nothing more needed to make game.

<dependency>
    <groupId>io.github.srcimon</groupId>
    <artifactId>screwbox-core</artifactId>
</dependency>
// creating a fancy black window
ScrewBox.createEngine().start();

screwbox-tiled

Adds support for tilesets and maps made with Tiled Editor. For real code have a look at the pathfinding example.

<dependency>
    <groupId>io.github.srcimon</groupId>
    <artifactId>screwbox-tiled</artifactId>
</dependency>
// loading a map made with Tiled Editor
Map map = Map.fromJson("underworld_map.json");

Documentation

ScrewBox packs some examples. You can inspect these examples to learn how to use the engine.

Example Description
hello-world Very simple hello world application. Shows how to get started.
pathfinding Example application showing how to use pathfinding and importing maps from Tiled Editor
particles Demonstration of particle interaction with mouse
game-of-life An interactive game of life implementation.
platformer A much more complex example showing how to make a platformer.

Libraries used

Acknowledgments

The project idea was inspired by Gurkenlabs Litiengine.

super hero and cat standing next to each other