Back to Index

nova.engine

struct Vec2

Some two dimensional vector.

Fields

float x, y;

struct Input

Input state for keyboard and mouse.

Fields

bool[512] keys;
bool[512] keysPressed;
bool[512] keysReleased;
bool[8] mouseButtons;
bool[8] mousePressed;
bool[8] mouseReleased;
Vec2 mousePos;
Vec2 mouseDelta;
Vec2 scrollDelta;

Methods

void update()
bool isKeyDown(int key)
bool isKeyPressed(int key)
bool isKeyReleased(int key)
bool isMouseDown(int button)
bool isMousePressed(int button)
bool isMouseReleased(int button)

struct Character

Fields

uint textureID;
int[2] size;
int[2] bearing;
uint advance;

struct Font

Fields

Character[dchar] characters;

struct Text

Fields

string content;
Font* font;
Color color = Color(0, 0, 0, 1);
bool typewriter = false;
float typewriterDelay = 0.05f;
float typewriterTimer = 0.0f;
int visibleChars = 0;

struct Color

Some RGBA colour.

Fields

float r, g, b, a;

struct Texture

A texture resource.

Fields

uint id;
int width, height;

struct Sound

A sound effect.

Fields

Mix_Chunk* chunk;

struct Music

Background music.

Fields

Mix_Music* music;

struct SpriteFrame

A sprite frame from a spritesheet.

Fields

float x, y, width, height;

struct Sprite

A sprite component for rendering textures.

Fields

Texture* texture;
SpriteFrame frame = SpriteFrame(0, 0, 1, 1);

struct Animation

An animation sequence.

Fields

SpriteFrame[] frames;
float frameDuration = 0.1f;
bool loop = true;

struct Animator

Component for handling animations.

Fields

Animation* currentAnimation;
float timer = 0;
int currentFrameIndex = 0;
bool playing = false;

Methods

void play(Animation* animation)

struct Transform

A transformation between two 2D vectors.

Fields

Vec2 position;
float rotation = 0;
Vec2 scale = Vec2(1, 1);

struct RigidBody

Some rigid body in the physics world.

Fields

Vec2 velocity = Vec2(0, 0);
float mass = 1;
bool isStatic = false;
float restitution = 0.8f;

struct Collider

Some collider in the physics world.

Fields

Type type;
Vec2 size;

struct GameObject

An object in the physics world.

Fields

Transform transform;
RigidBody* rigidbody;
Collider* collider;
Sprite* sprite;
Text* text;
Color color = Color(1, 1, 1, 1);
bool active = true;
void*[TypeInfo] genericComponents;

Methods

void addComponent(T)

Add a component to the game object.

struct Camera

Camera system for controlling the view.

Fields

Vec2 position = Vec2(0, 0);
float zoom = 1.0f;
GameObject* target;
float lerpSpeed = 5.0f;
float shakeDuration = 0.0f;
float shakeMagnitude = 0.0f;
Vec2 shakeOffset = Vec2(0, 0);

Methods

void follow(GameObject* target)
void shake(float duration, float magnitude)
void update(float dt)

interface ISystem

Interface for systems.

Methods

void update(float dt)

class AnimationSystem

System for updating animations.

Fields

Scene scene;

Methods

this(Scene s)
void update(float dt)

struct ParticleTrail

Component for particle trails.

Fields

ParticleEmitter* emitter;

class ParticleTrailSystem

System for updating particle trails.

Fields

Scene scene;

Methods

this(Scene s)
void update(float _)

class Scene

A scene containing game objects and systems.

Fields

GameObject*[] gameObjects;
ParticleEmitter*[] particleEmitters;
Physics physics;
ISystem[] systems;
Camera camera;

Methods

this()
void update(float dt)

struct Renderer

The main renderer of the game.

This is the heart of any game built with Nova.

Fields

circleVBO, spriteVAO, spriteVBO, textVAO, textVBO;

Methods

void initialize()

Initialize the renderer, this must be called prior to the usage of the renderer

at all.

void drawCircle(Transform t, Color c, Camera cam)

Draw some circle via the renderer.

Params:
t The transform
c The colour of the circle in ARGB format
void drawRect(Transform t, Color c, Camera cam)

Draw some rectangle via the renderer.

Params:
t The transform
c The colour of the rectangle in ARGB format
void drawText(Transform t, Text txt, Camera cam)
void drawSprite(Transform t, Sprite sprite, Color c, Camera cam)

Draw a sprite with optional spritesheet frame.

Params:
t The transform
sprite The sprite to render
c The color tint
void drawParticles(ParticleEmitter emitter, Camera cam)

Draw particles from an emitter.

Params:
emitter The particle emitter

struct Particle

A single particle.

Fields

Vec2 position;
Vec2 velocity;
Color color;
float size;
float life = 0;
float startLife = 0;
float rotation = 0;
float rotationSpeed = 0;

struct ParticleEmitter

A particle emitter system.

Fields

Vec2 position;
Particle[] particles;
float emissionRate = 0;
Vec2 velocityMin = Vec2(-1, -1);
Vec2 velocityMax = Vec2(1, 1);
Color colorStart = Color(1, 1, 1, 1);
Color colorEnd = Color(1, 1, 1, 0);
float lifetimeMin = 1.0f;
float lifetimeMax = 2.0f;
float sizeStart = 0.1f;
float sizeEnd = 0.0f;
Vec2 gravity = Vec2(0, 0);
bool active = true;
bool loop = true;
float rotationSpeedMin = 0;
float rotationSpeedMax = 0;
float emitTimer = 0;

Methods

void update(float dt)
void burst(int count)

struct Physics

The physics engine.

Fields

GameObject*[] objects;
Vec2 gravity = Vec2(0, -0.5f);

Methods

void delegate(GameObject* obj)
void addObject(GameObject* obj)

Add some object to the physics world.

Params:
obj The object to add
void update(float dt)

Update the physics loop.

Params:
dt Delta time
void checkCollisions()

Check for collisions in the physics world.

bool isColliding(GameObject* a, GameObject* b)

Determine whether two game objects are colliding.

Params:
a Object A
b Object B
Returns: Whether or not they are colliding
void resolveCollision(GameObject* a, GameObject* b)

Resolve a collision between two game objects.

Params:
a Object A
b Object B

struct Nova

The engine instance.

Fields

GLFWwindow* window;
bool running;
Renderer renderer;
FT_Library ft;
Scene activeScene;
Sound*[] sounds;
Music*[] musicTracks;
Texture*[] textures;
Font*[] loadedFonts;
double lastTime;
Input input;
Vec2 lastMousePos;
bool showFps = false;
Text* fpsText;
float currentFps = 0.0f;
float fpsUpdateTimer = 0.0f;

Methods

@property ref Physics physics()
@property ref GameObject*[] gameObjects()
@property ref ParticleEmitter*[] particleEmitters()
void loadScene(Scene scene)

Load a new scene.

void playSound(Sound* sound, int loops = 0, float volume = 0.5f)

Load a music track.

void playMusic(Music* music, bool loop = true, float volume = 0.5f)
void pauseMusic()
void resumeMusic()
void stopMusic()
SpriteFrame createFrame(int x, int y, int width, int height, int texWidth, int texHeight)

Create a spritesheet frame.

Params:
x X position in pixels
y Y position in pixels
width Frame width in pixels
height Frame height in pixels
texWidth Total texture width
texHeight Total texture height
Returns: SpriteFrame with UV coordinates
void initialize(string title, int xDims = 1920, int yDims = 1080, int targetFPS = 60)

Initialize the game engine.

Params:
title The window title
void addRigidBody(GameObject* obj, float mass = 1, bool isStatic = false)

Add a game object to the world as a rigid body.

Params:
obj The object
mass The mass of the object
isStatic Whether or not it is static, defaults to false
void addCollider(GameObject* obj, Collider.Type type, Vec2 size)

Add a collider to the world.

Params:
obj Source object
type Type of collider
size Size of object as a 2D vector
void addSprite(GameObject* obj, Texture* texture, SpriteFrame frame = SpriteFrame(0, 0, 1, 1)

Add a sprite to a game object.

Params:
obj The game object
texture The texture to use
frame Optional sprite frame (defaults to full texture)
void toggleFpsCounter(FPSCounterPosition pos)

Toggle the FPS counter.

Params:
pos The position of the FPS counter
void drawFps(Camera cam)
void run()

Run the game.

ref Input getInput()

Get the input state for this frame.

Returns: Reference to the input system
Vec2 screenToWorld(Vec2 screenPos)

Convert screen coordinates to world coordinates.

Params:
screenPos Position in screen coordinates (pixels)
Returns: Position in world coordinates
Vec2 worldToScreen(Vec2 worldPos)

Convert world coordinates to screen coordinates.

Params:
worldPos Position in world coordinates
Returns: Position in screen coordinates (pixels)
void cleanup()

Destroy the window and clean up the underlying GLFW resources.

ENUM KeyEvent

Common key events.

Members

Release = 0
Press = 1
Repeat = 2
Unknown = -1

ENUM Key

Common key constants.

Members

Space = 32
Apostrophe = 39
Comma = 44
Minus = 45
Period = 46
Slash = 47
Num0 = 48
Num1 = 49
Num2 = 50
Num3 = 51
Num4 = 52
Num5 = 53
Num6 = 54
Num7 = 55
Num8 = 56
Num9 = 57
Semicolon = 59
Equal = 61
A = 65
B = 66
C = 67
D = 68
E = 69
F = 70
G = 71
H = 72
I = 73
J = 74
K = 75
L = 76
M = 77
N = 78
O = 79
P = 80
Q = 81
R = 82
S = 83
T = 84
U = 85
V = 86
W = 87
X = 88
Y = 89
Z = 90
LeftBracket = 91
Backslash = 92
RightBracket = 93
GraveAccent = 96
Escape = 256
Enter = 257
Tab = 258
Backspace = 259
Insert = 260
Delete = 261
Right = 262
Left = 263
Down = 264
Up = 265
PageUp = 266
PageDown = 267
Home = 268
End = 269
CapsLock = 280
ScrollLock = 281
NumLock = 282
PrintScreen = 283
Pause = 284
F1 = 290
F2 = 291
F3 = 292
F4 = 293
F5 = 294
F6 = 295
F7 = 296
F8 = 297
F9 = 298
F10 = 299
F11 = 300
F12 = 301
LeftShift = 340
LeftControl = 341
LeftAlt = 342
LeftSuper = 343
RightShift = 344
RightControl = 345
RightAlt = 346
RightSuper = 347

ENUM Mouse

Mouse button constants.

Members

Left = 0
Right = 1
Middle = 2
Button4 = 3
Button5 = 4
Button6 = 5
Button7 = 6
Button8 = 7

ENUM FPSCounterPosition

FPS Counter position.

Members

TopLeft
TopRight
BottomLeft
BottomRight
Center

ENUM BufferBit

OpenGL bitmask constant.

Members

Color = 0x00004000
Depth = 0x00000100
Stencil = 0x00000400
void pollEvents()

Poll for events.

bool shouldClose(GameWindow* gw)

Should the game window close?

Params:
gw The game window.
Returns: Whether or not it should close
double getTime()

Get the current game time.

Returns: The current game time as a double.
ulong getKey(GameWindow* gw, int keyCode)

Get some keypress.

Params:
gw The game window.
keyCode The current key.
Returns: GLFW_PRESS or not.
ulong getMouseButton(GameWindow* gw, int mbCode)

Get some mouse button press.

Params:
gw The game window.
mbCode The current mouse button.
Returns: GLFW_PRESS or not.
void getCursorPosition(GameWindow* window, double* x, double* y)

Get the position of the mouse cursor.

Params:
window The game window.
x X position to read the value into
y Y position to read the value into
void clearColor(float r, float b, float g, float a)

Set background to some color.

Params:
r Red
b Blue
g Green
a Alpha
void clear(BufferBit bb)

Clear buffers to preset values.

Params:
bb Bitfield mask
void swapBuffers(GameWindow* gw)

Swap the front and back buffers of the specified window.

Params:
gw The game engine window
extern (C) void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)

Key callback.

Params:
window The game engine window
key The key
scancode The scan code
action The action
mods The modifiers
extern (C) void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods)

Mouse button callback function.

Params:
window The game engine window.
button The button
action The action
mods The modifiers
extern (C) void cursorPosCallback(GLFWwindow* window, double xpos, double ypos)

The cursor position callback function.

Params:
window The game window
xpos X position of the cursor
ypos Y position of the cursor
extern (C) void scrollCallback(GLFWwindow* window, double xoffset, double yoffset)

The scroll callback function.

Params:
window The game window
xoffset X offset for scroll
yoffset Y offset for scroll