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:

1 final class MyGame : GameHelperBase {
2 	/// Called when it is time to redraw the frame
3 	/// it will try for a particular FPS
4 	override void drawFrame() {
5 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT);
6 
7 		glLoadIdentity();
8 
9 		glColor3f(1.0, 1.0, 1.0);
10 		glTranslatef(x, y, 0);
11 		glBegin(GL_QUADS);
12 
13 		glVertex2i(0, 0);
14 		glVertex2i(16, 0);
15 		glVertex2i(16, 16);
16 		glVertex2i(0, 16);
17 
18 		glEnd();
19 	}
20 
21 	int x, y;
22 	override bool update(Duration deltaTime) {
23 		x += 1;
24 		y += 1;
25 		return true;
26 	}
27 
28 	override SimpleWindow getWindow() {
29 		auto window = create2dWindow("My game");
30 		// load textures and such here
31 		return window;
32 	}
33 
34 	final void fillAudioBuffer(short[] buffer) {
35 
36 	}
37 }
38 
39 void main() {
40 	auto game = new MyGame();
41 
42 	runGame(game, maxRedrawRate, maxUpdateRate);
43 }

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

More...

Public Imports

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

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 = 512, int height = 512)

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

runGame
void runGame(GameHelperBase game, int maxUpdateRate = 20, int maxRedrawRate = 0)

Deprecated, use the other overload instead.

runGame
void runGame(int maxUpdateRate = 20, int maxRedrawRate = 0)

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

Suggestion Box / Bug Report