Skip to content

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

License

Notifications You must be signed in to change notification settings

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 flow.
  • 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. Add animated transitions to smoothly switch between the scenes.
  • Audio Support Play wav and midi sounds. Control the volume and pan manually or automatically based on the position of the sound source. Get information on whats currently playing.
  • Support for Tiled Editor 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>2.2.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>2.2.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 Hello world application with some interactive particle effects.
pathfinding Example application showing how to use pathfinding and importing maps from Tiled Editor
game-of-life An interactive game of life implementation.
platformer A much more complex example showing how to make a platformer.
vacuum-outlaw Example for a top down game.

Libraries used

Acknowledgments

The project idea was inspired by Gurkenlabs Litiengine.

super hero and cat standing next to each other