Chapter 1: A basic game

You need three pieces: a subclass of Actor, a subclass of World, and Activerse.start from Main.java.

Create the player

Game objects extend Actor. In the constructor, set an image. Put the file next to your sources or on the classpath; ActiverseImage resolves it through ResourcePaths (a real file first, then a classpath / jar resource). Supported types include png, jpg, gif, and bmp.

Override act(). That method runs every simulation tick. Keep heavy work behind conditionals; swapping images or looping sound every tick will stall the frame.

Movement

Actor.keyIsDown(char) still works; it wraps KeyboardInfo.isKeyDown. The char is case-sensitive ('w' is not 'W'). For WASD, use KeyboardInfo.isLetterDown('w'), which treats upper and lower case as the same key.

Other input helpers live on KeyboardInfo: justPressed / justReleased for edges, isKeyDown("shift"), and appendAlphaNumeric for typed text. See Chapter X.

Demo player

import ActiverseEngine.*;

public class Player extends Actor {
    public Player() {
        setImage(new ActiverseImage("player.png"));
    }

    @Override
    public void act() {
        movementViaKey();
    }

    public void movementViaKey() {
        if (KeyboardInfo.isLetterDown('w')) {
            if (KeyboardInfo.isLetterDown('m')) {
                move(8);
            } else {
                move(5);
            }
        }
        if (KeyboardInfo.isLetterDown('s')) {
            move(-5);
        }
        if (KeyboardInfo.isLetterDown('a')) {
            turn(-0.5);
        }
        if (KeyboardInfo.isLetterDown('d')) {
            turn(0.5);
        }
    }
}

Create the world

Subclass World and call super(width, height, cellSize). Width and height are in cells; the window size in pixels is width * cellSize by height * cellSize. Start with super(400, 400, 1) for a 400×400 window.

Optional: setBackgroundImage("world.png"), then addObject(actor, x, y) to place actors in pixel coordinates.

import ActiverseEngine.*;

public class MyWorld extends World {
    public MyWorld() {
        super(400, 400, 1);
        setBackgroundImage("world.png");
        addObject(new Player(), 100, 100);
    }
}

Start from Main

The template Main.java ships with start commented out. Uncomment it (or replace the sandbox world) so the instance actually opens:

import ActiverseEngine.*;

public class Main {
    public static void main(String[] args) {
        Activerse.start(new MyWorld());
    }
}

Run Main, not a random class. The frame title should read Activerse Instance v1.4.2. An End button is always on the world; a Debug button appears when show_debug is true (the default). Next for a first game: Chapter 4 (images and sound), then Chapter 5 (collision). Skip to Chapter 2 if you already need the debug overlay.