Skip to content

Project Setup

Charles Doucet edited this page Sep 9, 2024 · 2 revisions
In this section

Engine

The project is built upon the Godot engine, version 4.3, available here. We cannot use the .NET version to export the game into web support (required for the project's submission on itch.io.

GDSript

Since we C# is not supported on the standard version of Godot, scripts will be written using the engine's own language, GDscript. The language is heavily inspired by C#, but is tailored for the engine's features and game development.

However, its syntax looks a bit more like what we find in Python programming. That said, here's a quick style guide for how variables, functions and properties are named and declared.

Snakecases is the convention for coding when using Godot (in GDScript, but in C# as well).

# DECLARATIONS ------------------------------------------------------
class_name StateMachine
extends Node

signal state_changed(previous, new)

# @export makes the variable visible in the inspector
@export var initial_state: Node

# For variables declaration, var is used instead of types
var my_float = 0.0
var my_int = 0
var my_bool = false

# However, we can force a type for a variable like this
var my_float: float = 0.0
# We can even make it less wordy
var my_float := 0.0


# @onready is similar to the .GetComponent<>() function in Unity
@onready var my_camera: Camera3D = $MainCamera 

# FUNCTIONS ---------------------------------------------------------
# This triggers before the _ready function
func _enter_tree():
	print("hello")

# This triggers when the scene is launched
func _ready():
	state_changed.connect(_on_state_changed)
	_state.enter()

# Called every frame
func _process(delta):
	_state.unhandled_input(event)

# Like _process, but for physics manipulation 
func _physics_process(delta):
	_state.physics_process(delta)

# Custom function
func set_state(value):
	_state = value
	_state_name = _state.name

For the complete styling guide for GDScript, please refer to the online documentation available here.

Display

Clone this wiki locally