This documentation outlines the available API calls and custom classes within the EECS498.007 game engine. There may be inaccuracies present, so if you spot any, please add an issue at the github page with proof of the inaccuracy (spec screenshot). If you're intereseted in contributing, whether that be adding more documentation or improving the style, reach out on discord to @gnufoo!
This section provides documentation on C++ classes that have been made accessible in Lua through LuaBridge, detailing available methods and their usage.
The Actor
class represents an entity in the game world, with functions to manipulate its components and properties.
Returns the name of the actor.
local actorName = actor:GetName()
Returns the ID of the actor.
local actorID = actor:GetID()
Returns a reference to the first component of type type_name
. Returns nil
if a component of type type_name
doesn't exist.
local transform = actor:GetComponent("Transform")
Returns a reference to all components of type type_name
in the form of an indexed table. Returns nil
if a component of type type_name
doesn't exist.
local sprite_renderers = actor:GetComponent("SpriteRenderer")
sprite_renderers[1].sprite = "sprite_1"
Returns a reference to the component with the key key
. Returns nil
if a component with the key key
doesn't exist.
local first_component = actor:GetComponentByKey("1")
Add component of type type_name
to actor and return reference to it. The new component should begin executing lifecycle functions on the next frame. The new comopnent's key will be rn
, where r
denotes a component created at runtime and n
is the number of times that AddComponent(type_name)
has been called in the entire program.
local sprite_renderer = actor:AddComponent("SpriteRenderer")
sprite_renderer.sprite = "new_sprite"
Removes component component_ref
from the actor.
local sprite_renderer = actor:GetComponent("SpriteRenderer")
actor:RemoveComponent(sprite_renderer)
The Vector2
class represents an 2D mathematical vector. Supports adding and subtracting of vetors as well as scalar multiplication.
x
- The x component of the vector.
y
- The y component of the vector.
Converts this vector into a unit vector. Returns the length.
local vector = Vector2(2, 5)
vector.Normalize()
Returns the length of the vector.
local vector = Vector2(2, 5)
Debug.Log(vector.Length())
A static Vector2 function. Returns Length(a - b)
.
local a = Vector2(2, 5)
local b = Vector2(-1, -3)
Debug.Log(Vector2.Distance(a, b))
A static Vector2 function. Returns the dot product of the two vectors.
local a = Vector2(2, 5)
local b = Vector2(-1, -3)
local dot_product = Vector2.Dot(a, b)
Exits the application immediately with error code 0.
Application.Quit()
Puts the application to sleep for the specified number of milliseconds.
milliseconds
- Integer. The number of milliseconds the app will sleep for.
Application.Sleep(1000)
Returns the current frame number.
Application.GetFrame()
Opens the specified web page in the user’s default browser.
url
- String. The URL of the web page to open.
Application.OpenURL("http://www.example.com")
Returns true if the specified keycode is held down on the current frame.
keycode
- The keycode to check.
Input.GetKey("space")
Returns true if the keycode became pressed on the current frame.
keycode
- The keycode to check for a press event.
Input.GetKeyDown("a")
Returns true if the keycode became lifted on the current frame.
keycode
- The keycode to check for a release event.
Input.GetKeyUp("up")
Returns the current mouse position as a table with x and y coordinates.
local position = Input.GetMousePosition()
print("X: " .. position.x .. ", Y: " .. position.y)
Returns true if the specified mouse button is currently pressed.
button_num
- The mouse button number (1 for left, 2 for middle, 3 for right).
Input.GetMouseButton(1)
Returns true if the specified mouse button was pressed down on this frame.
button_num
- The mouse button number to check.
Input.GetMouseButtonDown(3)
Returns true if the specified mouse button was lifted on this frame.
button_num
- The mouse button number to check for a release event.
Input.GetMouseButtonUp(2)
Returns the mouse scroll wheel delta as a float. Returns 0 if there was no scroll event on this frame.
local delta = Input.GetMouseScrollDelta()
print("Mouse scroll delta: " .. delta)
Creates a new actor based on the specified actor template and returns a reference to it. The actor's components will not execute until the next frame, but the actor is discoverable via Actor.Find()
or Actor.FindAll()
immediately.
actor_template_name
- The name of the actor template to instantiate.
local newActor = Actor.Instantiate("Enemy")
Destroys an actor, removing it and all of its components from the scene. No lifecycle functions of the actor's components will run after this call. The actual destruction of the actor occurs at the end of the current frame, after all OnLateUpdate
calls.
actor
- The actor to destroy.
Actor.Destroy(someActor)
Begins playing the specified audio clip on the specified channel, with an option to loop the audio.
channel
- The audio channel on which to play the clip.
clip_name
- The name of the audio clip to play.
does_loop
- Boolean value indicating whether the audio clip should loop (true) or play once (false).
Audio.Play(1, "background_music", true)
Halts audio playback on the specified channel.
channel
- The audio channel whose playback will be halted.
Audio.Halt(1)
Alters the volume of an audio channel.
channel
- The channel whose volume will be adjusted.
volume
- The new volume level as an integer, ranging from 0 (silent) to 128 (maximum volume).
Audio.SetVolume(1, 64)
Draws text on the screen at the specified position and with the given appearance settings.
str_content
- The string content to draw.
x
, y
- The x and y screen coordinates where the text will begin.
font_name
- The name of the font to use.
font_size
- The size of the font.
r
, g
, b
, a
- The red, green, blue, and alpha values for the text color. Each component ranges from 0 to 255.
Text.Draw("Hello, World!", 100, 50, "Arial", 24, 255, 255, 255, 255)
Draws an image to the UI layer using screen coordinates, unaffected by the camera. Images must be redrawn every frame to remain visible. Defaults to white color and full opacity. UI elements render behind text elements by default, with a default sorting order of 0.
image_name
- The name of the image to draw.
x
, y
- Screen coordinates for where to draw the image.
Image.DrawUI("logo", 100, 200)
Extended version of DrawUI, allowing for tint and alpha modifications as well as a specified sorting order. Numeric parameters are treated as floats but are downcasted to integers in C++.
image_name
- The name of the image to draw.
x
, y
- Screen coordinates for where to draw the image.
r
, g
, b
, a
- The red, green, blue, and alpha values for the image color. Each component ranges from 0 to 255.
sorting_order
- The relative order in which to draw images on the UI.
Image.DrawUIEx("hero_icon", 400, 300, 255, 0, 0, 128, 1)
Draws an image in scene coordinates, affected by camera position and zoom. Assumes the pivot point is at the center of the image. This call must be made every frame to maintain visibility, rendering behind UI elements.
image_name
- The name of the image to draw.
x
, y
- Screen coordinates for where to draw the image.
Image.Draw("background", 0, 0)
Draws an image with extended options for rotation, scaling, tint, alpha, and sorting order. Parameters for rotation, colors, and sorting order are treated as floats but downcasted to integers in C++.
image_name
- The name of the image to draw.
x
, y
- Screen coordinates for where to draw the image.
rotation_degrees
- An angle in degrees that indicates the rotation that will be applied to the image, rotating it in a clockwise direction.
scale_x
, scale_y
- Alters the size of an image on the x and y axis, where 1 is the normal size.
r
, g
, b
, a
- The red, green, blue, and alpha values for the image color. Each component ranges from 0 to 255.
sorting_order
- The relative order in which to draw images on the UI.
Image name, position, rotation, scale, pivot point, color, alpha, and sorting order details.
Image.DrawEx("enemy_sprite", 500, 500, 45, 1.0, 1.0, 0.5, 0.5, 255, 255, 255, 255, 2)
Draws a single pixel at specified screen coordinates with the given color and alpha.
x
, y
- Screen coordinates for where to draw the pixel.
r
, g
, b
, a
- The red, green, blue, and alpha values for the pixel color. Each component ranges from 0 to 255.
Image.DrawPixel(500, 500, 255, 255, 255, 255)
Sets the camera's position in the scene using floating-point coordinates.
x
, y
- The x and y coordinates to set the camera's position to.
Camera.SetPosition(100.0, 200.0)
Returns the x-coordinate of the camera's position as a float.
local x = Camera.GetPositionX()
Returns the y-coordinate of the camera's position as a float.
local y = Camera.GetPositionY()
Sets the camera's zoom level in the scene. The zoom factor is a float, adjusting the render scale for Image.Draw()
and Image.DrawEx()
calls accordingly.
zoom_factor
- The zoom factor to set, represented as a float.
Camera.SetZoom(1.5)
Returns the current zoom factor of the camera as a float.
local zoom = Camera.GetZoom()
Loads a new scene at the beginning of the next frame. If called multiple times within a single frame, only the most recent scene_name
will be loaded.
scene_name
- The name of the scene to load.
Scene.Load("basic")
Returns the name of the current scene, excluding the “.scene” file extension.
local currentScene = Scene.GetCurrent()
Marks an actor to persist and not be unloaded or destroyed when a new scene is loaded. This is particularly useful for maintaining global “manager” actors across different scenes.
actor
- A reference to the actor that should not be destroyed.
Scene.DontDestroy(self.actor)