Skip to content

Game Engine

Javier Alonso edited this page Jul 29, 2024 · 18 revisions

Source Game Engine

The integrated "Game Engine" in the Source API.

Getting Started

First of all, you need to include the API.GameEngine namespace in your project.
To initialize the Game Engine, you need to create a Game class instance, add all the "start" elements of your game and the execute Game.Run()
To add objects, you need to instantiate GameObjects and add Source classes to them.
There's a template called Source Game Engine Class with two methods in it:
Start() which is called at the start of the game.
Update() which is called once per frame.

Here you can add all the logic than you want.

SourceConfig.json file

There's a new value in this file, a new one called buttons, which contains all the keys that are linked to a single action.
For example, the action "Jump" has the keys "Spacebar" and "UpArrow" by default.

Source Game Engine Class Template

In the releases tab, there's a class template for Visual Studio, with which you'll be able to create classes for GameObjects from the Game Engine directly.

Game Engine Classes and Methods

Game

Main class for the creating of a game using the Source Game Engine.

Run() Inits the game engine and call the Start() method of all the MainBrain classes instantiated before this method executes.

GameObject

The main class to instantiate objects into the game using the Source Game Engine.

name Specifies the name of the object.
position Specifies the position of the object.
parent Specifies the parent object of this one.
activeInHierarchy Specifies if the current object is active in the hierarchy of objects.
activeSelf The local active state of this GameObject.
tag The tag that identifies this GameObject.
AddComponent<T>() or AddComponent(componentType) Adds a new component into the GameObject.
GetComponent<T>() or GetComponent(componentType) Gets a component from the GameObject.
GetComponents<T>() or GetComponents(componentType) Gets all the components as the same type from the GameObject.
TryGetComponent<T>(out component) or TryGetComponent(componentType, out component) Tries to get a component from the GameObject.
GetChild(index) Returns a child by index.
SetActive(state) Activates/Deactivates the GameObject, depending on the given true or false value.
Find(name) or Find(name, includeInactive) Tries to find a GameObject with the specified name.
FindWithTag(tag) Tries to find a GameObject with the specified tag.
FindGameObjectsWithTag(tag) Tries to find all the GameObjects with the specified tag.
CompareTag(tag) Is this GameObject tagget with tag?

Input

Main class for the managment of the Input system.

anyKey Specifies if any key is pressed on the current frame.
GetKey(consoleKey) Returns true while the specified key is pressed.
GetKeyDown(consoleKey) Returns true during the frame the user is pressing the specified key.
GetKeyUp(consoleKey) Returns true during the frame the user is releasing the specified key.
GetButton(buttonName) Returns true while the specified button identified as buttonName is pressed.
GetButtonDown(buttonName) Returns true during the frame the user is pressing the specified button identified as buttonName.
GetButtonUp(buttonName) Returns true during the frame the user is releasing the specified button identified as buttonName.

MainBrain

Main class for the managment of the Source Game Engine classes.

print(message) Logs an object if the logger it's active.
Invoke(method, delay) Invokes a method in time seconds.
AddComponent<T>() or AddComponent(componentType) Adds a new component into the GameObject.
GetComponent<T>() or GetComponent(componentType) Gets a component from the GameObject.
GetComponents<T>() or GetComponents(componentType) Gets all the components as the same type from the GameObject.
TryGetComponent<T>(out component) or TryGetComponent(componentType, out component) Tries to get a component from the GameObject.
FindObjectOfType<T>() or FindObjectOfType(type) Tries to find an object of the specified type.
FindObjectsOfType<T>() or FindObjectsOfType(type) Tries to find all the objects of the specified type.

Time

Class for the managment of the Time on the Source Game Engine.

time The elapsed time since the runtime start.
deltaTime The interval in seconds from the last frame to the current one.

Vector2

Represents a two dimensions vector.

x X component of the vector.
y Y component of the vector.

Components

See more about this here.

GameObject Components

There are some components that can be attached to a GameObject, you can add as many as you want.

Component (The main class)

The main class for adding components to a GameObject.

gameObject The GameObject where the class is attached.
position The position of the GameObject where the class is attached.
enabled Specifies if the specified component is enabled or not.

Text

The component for GameObjects to render text on the screen.

text The text to render.
bgColor The background color of the text.
color The color of the text.

MainBrain classes

All the Source Game Engine Classes inherit from MainBrain and can be added as Components to a GameObject.

Attributes

There are some attributes that can be used into the Source Game Engine Classes:
[ExecuteOnGameObjectDisabled] Specifies if the class methods should be executed even if the GameObject isn't active.
[RequireComponent(component)] Specifies which component is required and adds it.