arsd.game

An add-on for simpledisplay.d, joystick.d, and simpleaudio.d that includes helper functions for writing simple games (and perhaps other multimedia programs). Whereas simpledisplay works with an event-driven framework, arsd.game always uses a consistent timer for updates.

Usage example:

final class MyGame : GameHelperBase {
	/// Called when it is time to redraw the frame
	/// it will try for a particular FPS
	override void drawFrame() {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT);

		glLoadIdentity();

		glColor3f(1.0, 1.0, 1.0);
		glTranslatef(x, y, 0);
		glBegin(GL_QUADS);

		glVertex2i(0, 0);
		glVertex2i(16, 0);
		glVertex2i(16, 16);
		glVertex2i(0, 16);

		glEnd();
	}

	int x, y;
	override bool update(Duration deltaTime) {
		x += 1;
		y += 1;
		return true;
	}

	override SimpleWindow getWindow() {
		auto window = create2dWindow("My game");
		// load textures and such here
		return window;
	}

	final void fillAudioBuffer(short[] buffer) {

	}
}

void main() {
	auto game = new MyGame();

	runGame(game, maxRedrawRate, maxUpdateRate);
}

It provides an audio thread, input scaffold, and helper functions.

More...

Public Imports

arsd.gamehelpers
public import arsd.gamehelpers;
Undocumented in source.
arsd.color
public import arsd.color;
Undocumented in source.
arsd.simpledisplay
public import arsd.simpledisplay;
Undocumented in source.
arsd.simpleaudio
public import arsd.simpleaudio;
Undocumented in source.
core.time
public import core.time;
Undocumented in source.
arsd.joystick
public import arsd.joystick;
Undocumented in source.

Members

Classes

GameHelperBase
class GameHelperBase

This is the base class for your game.

OpenGlTexture
class OpenGlTexture

Simple class for putting a TrueColorImage in as an OpenGL texture.

Functions

clearOpenGlScreen
void clearOpenGlScreen(SimpleWindow window)
create2dWindow
SimpleWindow create2dWindow(string title, int width, int height)

Creates a simple 2d opengl simpledisplay window. It sets the matrix for pixel coordinates and enables alpha blending and textures.

runGame
deprecated void runGame(GameHelperBase game, int maxUpdateRate, int maxRedrawRate)

Deprecated, use the other overload instead.

runGame
void runGame(int maxUpdateRate, int maxRedrawRate)

Runs your game. It will construct the given class and destroy it at end of scope. Your class must have a default constructor and must implement GameHelperBase. Your class should also probably be final for performance reasons.

Structs

VirtualController
struct VirtualController

The virtual controller is based on the SNES. If you need more detail, try using the joystick or keyboard and mouse members directly.

Detailed Description

The MyGame handler is actually a template, so you don't have virtual function indirection and not all functions are required. The interfaces are just to help you get the signatures right, they don't force virtual dispatch at runtime.

See Also

Meta