Learn Godot - 10 Code Examples & CST Typing Practice Test
Godot Engine is a free, open-source, cross-platform game engine that allows developers to build 2D, 3D, and hybrid games using an intuitive scene system, GDScript, C#, or visual scripting.
Learn GODOT with Real Code Examples
Updated Nov 24, 2025
Code Sample Descriptions
Godot Simple 2D Todo Game Prototype
# TodoItem.gd
extends Node2D
var task_name = ""
func _on_TodoItem_pressed():
print("Task completed: %s" % task_name)
# Attach this script to a Button or Node representing a task in a 2D scene.
Demonstrates a simple Godot 2D prototype where tasks are represented as nodes, using GDScript for logic and interaction.
Godot Basic Player Movement
# Player.gd
extends CharacterBody2D
@export var speed = 200
func _physics_process(delta):
var direction = Vector2.ZERO
if Input.is_action_pressed("ui_right"):
direction.x += 1
if Input.is_action_pressed("ui_left"):
direction.x -= 1
if Input.is_action_pressed("ui_down"):
direction.y += 1
if Input.is_action_pressed("ui_up"):
direction.y -= 1
velocity = direction.normalized() * speed
move_and_slide()
Implements simple player movement using input actions in GDScript for a 2D scene.
Godot Object Spawner
# Spawner.gd
extends Node2D
@export var object_scene: PackedScene
func _process(delta):
if Input.is_action_just_pressed("spawn_object"):
var obj = object_scene.instantiate()
add_child(obj)
obj.position = Vector2(randf() * 400, randf() * 400)
Spawns new objects dynamically in the scene using GDScript on key press.
Godot Collectible Coins
# Coin.gd
extends Area2D
signal coin_collected
func _on_body_entered(body):
if body.name == "Player":
emit_signal("coin_collected")
queue_free()
# Connect 'coin_collected' signal to update score in UI.
Implements collectible coins that increase a score counter when the player overlaps them.
Godot Simple Timer
# TimerController.gd
extends Node
var time_left = 10
func _ready():
$Timer.start()
func _on_Timer_timeout():
time_left -= 1
$Label.text = str(time_left)
if time_left <= 0:
$Timer.stop()
Shows a countdown timer that updates a label and stops when time reaches zero.
Godot Simple Door Interaction
# Door.gd
extends Node2D
var is_open = false
func toggle_door():
is_open = !is_open
$AnimationPlayer.play(is_open ? "open" : "close")
print(is_open ? "Door opened" : "Door closed")
Demonstrates a door that opens and closes when interacted with by the player.
Godot Simple Projectile
# Projectile.gd
extends Area2D
@export var speed = 400
func _process(delta):
position.x += speed * delta
func _on_body_entered(body):
queue_free()
Spawns and moves a projectile forward with a fixed velocity, destroying it on collision.
Godot Simple Enemy AI
# Enemy.gd
extends CharacterBody2D
@export var speed = 100
var player
func _ready():
player = get_parent().get_node("Player")
func _physics_process(delta):
if player:
var dir = (player.position - position).normalized()
velocity = dir * speed
move_and_slide()
Demonstrates a simple enemy that follows the player using position tracking.
Godot Simple HUD UI
# HUD.gd
extends CanvasLayer
var score = 0
func update_score(amount):
score += amount
$ScoreLabel.text = "Score: %d" % score
Displays score or health using UI elements with GDScript updates.
Godot Scene Switcher
# SceneSwitcher.gd
extends Node
func switch_scene(scene_path: String):
get_tree().change_scene_to_file(scene_path)
Switches between different scenes in a Godot project using GDScript.
Frequently Asked Questions about Godot
What is Godot?
Godot Engine is a free, open-source, cross-platform game engine that allows developers to build 2D, 3D, and hybrid games using an intuitive scene system, GDScript, C#, or visual scripting.
What are the primary use cases for Godot?
2D platformers and adventure games. 3D indie games and prototypes. Mobile and casual games. Game jams and rapid prototyping. Web games exported to HTML5
What are the strengths of Godot?
Fully open-source with no royalties. Lightweight engine, fast iteration. Exceptional 2D tooling. Extensible with C++ modules. Large and growing community
What are the limitations of Godot?
3D performance not as high as Unreal/Unity (improving rapidly). Smaller asset store compared to Unity. Console export requires 3rd party partners. GDScript ecosystem still maturing. Advanced AAA features limited
How can I practice Godot typing speed?
CodeSpeedTest offers 10+ real Godot code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.