Godot GDScript Patterns

Godot GDScript Patterns

Teaches the AI Godot 4 GDScript patterns such as signals, scenes, state machines and optimization for building game systems.

Skill files3 files

references/

SKILL.md79 lines
1
---
2
name: godot-gdscript-patterns
3
description: Master Godot 4 GDScript patterns including signals, scenes, state machines, and optimization. Use when building Godot games, implementing game systems, or learning GDScript best practices.
4
---
5
6
# Godot GDScript Patterns
7
8
Production patterns for Godot 4.x game development with GDScript, covering architecture, signals, scenes, and optimization.
9
10
## When to Use This Skill
11
12
- Building games with Godot 4
13
- Implementing game systems in GDScript
14
- Designing scene architecture
15
- Managing game state
16
- Optimizing GDScript performance
17
- Learning Godot best practices
18
19
## Core Concepts
20
21
### 1. Godot Architecture
22
23
```
24
Node: Base building block
25
├── Scene: Reusable node tree (saved as .tscn)
26
├── Resource: Data container (saved as .tres)
27
├── Signal: Event communication
28
└── Group: Node categorization
29
```
30
31
### 2. GDScript Basics
32
33
```gdscript
34
class_name Player
35
extends CharacterBody2D
36
37
# Signals
38
signal health_changed(new_health: int)
39
signal died
40
41
# Exports (Inspector-editable)
42
@export var speed: float = 200.0
43
@export var max_health: int = 100
44
@export_range(0, 1) var damage_reduction: float = 0.0
45
@export_group("Combat")
46
@export var attack_damage: int = 10
47
@export var attack_cooldown: float = 0.5
48
49
# Onready (initialized when ready)
50
@onready var sprite: Sprite2D = $Sprite2D
51
@onready var animation: AnimationPlayer = $AnimationPlayer
52
@onready var hitbox: Area2D = $Hitbox
53
54
# Private variables (convention: underscore prefix)
55
var _health: int
56
var _can_attack: bool = true
57
58
func _ready() -> void:
59
_health = max_health
60
61
func _physics_process(delta: float) -> void:
62
var direction := Input.get_vector("left", "right", "up", "down")
63
velocity = direction * speed
64
move_and_slide()
65
66
func take_damage(amount: int) -> void:
67
var actual_damage := int(amount * (1.0 - damage_reduction))
68
_health = max(_health - actual_damage, 0)
69
health_changed.emit(_health)
70
71
if _health <= 0:
72
died.emit()
73
```
74
75
## Detailed patterns and worked examples
76
77
Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.
78
79

© Seth Hobson · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…