Jeux

Créer un jeu 2D avec Godot 4 — Guide complet débutant

Créer un jeu 2D avec Godot 4 — Guide complet débutant

Godot 4 a révolutionné le développement de jeux indépendants. Open source, léger, et puissant, il est aujourd'hui une alternative sérieuse à Unity et Unreal pour les petits studios et les solo devs.

Pourquoi Godot 4 ?

Critère Godot 4 Unity Unreal
Prix Gratuit Freemium Freemium
Open Source Partiel
Taille ~80 MB ~1 GB ~10 GB
GDScript ✓ Python-like C# C++
2D natif ✓ Excellent Moyen Limité

Le script du joueur (GDScript)

extends CharacterBody2D

const SPEED = 200.0
const JUMP_VELOCITY = -400.0
const GRAVITY = 980.0

func _physics_process(delta: float) -> void:
    if not is_on_floor():
        velocity.y += GRAVITY * delta

    if Input.is_action_just_pressed("ui_accept") and is_on_floor():
        velocity.y = JUMP_VELOCITY

    var direction = Input.get_axis("ui_left", "ui_right")
    if direction:
        velocity.x = direction * SPEED
    else:
        velocity.x = move_toward(velocity.x, 0, SPEED)

    move_and_slide()

Les ennemis avec State Machine

extends CharacterBody2D

enum State { PATROL, CHASE, ATTACK, DEAD }

var state: State = State.PATROL
var player: Node2D = null
const DETECTION_RANGE = 200.0

func _physics_process(delta: float) -> void:
    match state:
        State.PATROL:
            _patrol(delta)
        State.CHASE:
            _chase(delta)

Export et distribution

# Export WebAssembly (navigateur)
godot --export-release "Web" build/web/index.html

# Export Windows
godot --export-release "Windows Desktop" build/game.exe

Ressources pour aller plus loin

  • Documentation officielle : docs.godotengine.org
  • GDQuest : tutoriels vidéo de qualité
  • Kenney.nl : assets gratuits pour prototyper

// Commentaires (0)

Connectez-vous pour laisser un commentaire.

Aucun commentaire pour le moment.