This is the fifth and most comprehensive project in my Godot learning journey. This project serves as a deep dive into Object-Oriented Programming (OOP) and Advanced Design Patterns within Godot 4.
Through this project, I transitioned from basic scripting to advanced game architecture:
- Object Factory Pattern (ObjectMaker): Implemented a centralized instantiation system to handle projectiles, FX, and pick-ups, ensuring cleaner scene hierarchies and decoupled code.
- Modular Class Inheritance: Created a robust
BaseEnemyclass to handle shared behaviors (gravity, patrol, damage), allowing specific enemies to inherit and override unique AI logic. - State-Driven Transitions: Managed player animations and logic through a state management approach to handle complex interactions between jumping, falling, and attacking.
- Global Event Management: Used a
SignalHub(Singleton) to bridge the gap between gameplay events and the HUD without direct node references.
- Engine: Godot 4.5
- Language: GDScript
- Key Concepts: Factory Pattern, Class Inheritance, Singleton Pattern (Globals), and Signal-driven UI.
The ObjectMaker system is the backbone of this project's scalability. Instead of instantiating scenes locally within each script, this centralized factory manages all dynamic object creation, decoupling the "spawner" from the "object":
# Centralized Object Factory Implementation
extends Node
enum SceneType { EXPLOSION, PICKUP, BULLET }
# Preloading scenes to optimize runtime performance
const SCENES = {
SceneType.EXPLOSION: preload("res://Scenes/Explosion/Explosion.tscn"),
SceneType.PICKUP: preload("res://Scenes/Items/Pickup.tscn"),
SceneType.BULLET: preload("res://Scenes/Projectiles/Bullet.tscn")
}
func create_object(scene_type: SceneType, pos: Vector2) -> void:
if not SCENES.has(scene_type):
return
var new_obj = SCENES[scene_type].instantiate()
new_obj.global_position = pos
# Adding to the current scene tree for proper lifecycle management
get_tree().current_scene.add_child(new_obj)- Course: Developed as part of the "Jumpstart to 2D Game Development" course by Richard Allbert and Martyna Olivares.
- Assets: Game assets provided by the course instructor.