0% found this document useful (0 votes)
8 views4 pages

Flappy Bird Godot Setup Guide

Uploaded by

Pascal chad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Flappy Bird Godot Setup Guide

Uploaded by

Pascal chad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

# Flappy Bird Project Setup Guide for Godot 4.

## Project Structure Overview

### 1. Project Hierarchy


```
FlappyBird/

├── scenes/
│ ├── main.tscn
│ ├── player.tscn
│ ├── pipe.tscn
│ └── background.tscn

├── scripts/
│ ├── main.gd
│ ├── player.gd
│ └── pipe.gd

├── assets/
│ ├── sprites/
│ │ ├── bird/
│ │ ├── pipes/
│ │ └── background/
│ │
│ └── sounds/
│ ├── jump.wav
│ ├── score.wav
│ └── collision.wav
```

## Detailed Scene Setup

### 2. Main Scene (main.tscn)


#### Scene Hierarchy:
```
Main (Node3D)

├── Camera3D
├── DirectionalLight3D

├── Player (CharacterBody3D)

├── PipeContainer (Node3D)

├── Background (Node3D)

└── CanvasLayer
├── ScoreLabel
├── GameOverLabel
└── StartLabel
```

#### Script Implementation (main.gd):


```gdscript
extends Node3D

# Game state management


enum GameState {
MENU,
PLAYING,
GAME_OVER
}

# Configurable game parameters


@export var scroll_speed : float = 200.0
@export var jump_force : float = 10.0
@export var gravity : float = 20.0
@export var pipe_spawn_interval : float = 2.0
@export var pipe_gap : float = 5.0 # Adjusted for 3D space

# Node References
@onready var player : CharacterBody3D = $Player
@onready var pipe_container : Node3D = $PipeContainer
@onready var score_label : Label = $CanvasLayer/ScoreLabel
@onready var game_over_label : Label = $CanvasLayer/GameOverLabel
@onready var start_label : Label = $CanvasLayer/StartLabel

# Game variables
var current_game_state : GameState = GameState.MENU
var score : int = 0
var high_score : int = 0

# Pipe scene reference


var pipe_scene : PackedScene = preload("res://scenes/pipe.tscn")

# Spawn timer for pipes


var pipe_spawn_timer : float = 0.0

func _ready():
# Initialize game
reset_game()

# Hide game over and score labels initially


game_over_label.visible = false
score_label.visible = false
start_label.visible = true

# Load high score


load_high_score()

func _process(delta):
match current_game_state:
GameState.MENU:
handle_menu_input()
GameState.PLAYING:
handle_playing_state(delta)
GameState.GAME_OVER:
handle_game_over_input()

# ... (rest of the script similar to 2D version, adjusted for 3D)


```

### 3. Player Scene (player.tscn)


#### Scene Hierarchy:
```
Player (CharacterBody3D)

├── MeshInstance3D (Bird Model)
├── CollisionShape3D
└── AudioStreamPlayer3D (for sounds)
```

#### Script Implementation (player.gd):


```gdscript
extends CharacterBody3D

@export var jump_force : float = 10.0


@export var gravity : float = 20.0

@onready var game : Node3D = get_parent()


@onready var mesh : MeshInstance3D = $MeshInstance3D
@onready var collision_shape : CollisionShape3D = $CollisionShape3D

func _physics_process(delta):
# Only process physics if game is in playing state
if game.current_game_state != game.GameState.PLAYING:
return

# Apply gravity
velocity.y -= gravity * delta

# Handle jump input


if Input.is_action_just_pressed("jump"):
velocity.y = jump_force
$AudioStreamPlayer3D.play()

# Optional: Add rotation/tilt effect


rotate_x(deg_to_rad(-30))
else:
# Gradually return to neutral rotation
rotation.x = lerp_angle(rotation.x, 0, delta * 5)

# Move and slide


move_and_slide()

# Check for collision


for i in get_slide_collision_count():
var collision = get_slide_collision(i)
if collision.get_collider().is_in_group("pipes") or
collision.get_collider().is_in_group("ground"):
game_over()

func game_over():
# Trigger game over state
game.current_game_state = game.GameState.GAME_OVER
game.game_over_label.text = "Game Over\nScore: %d\nHigh Score: %d" %
[game.score, game.high_score]
game.game_over_label.visible = true
$AudioStreamPlayer3D.stream = preload("res://assets/sounds/collision.wav")
$AudioStreamPlayer3D.play()
```

### 4. Pipe Scene (pipe.tscn)


#### Scene Hierarchy:
```
Pipe (Node3D)

├── UpperPipe (StaticBody3D)
│ ├── MeshInstance3D
│ └── CollisionShape3D

├── LowerPipe (StaticBody3D)
│ ├── MeshInstance3D
│ └── CollisionShape3D

└── ScoreArea (Area3D)
└── CollisionShape3D
```

#### Script Implementation (pipe.gd):


```gdscript
extends Node3D

signal score_point

@export var scroll_speed : float = 10.0

func _process(delta):
# Move pipe towards the player (negative Z axis)
position.z += scroll_speed * delta

# Remove pipe when too far


if position.z > 20: # Adjust based on your scene scale
queue_free()

func _on_score_area_body_entered(body):
if body.is_in_group("player"):
emit_signal("score_point")
```

## Detailed Setup Instructions

### Scene Creation Steps:


1. Create New 3D Scene
- Right-click in Scene dock
- Add Node3D as root
- Rename to "Main"

2. Add Player
- Right-click on Main node
- Add CharacterBody3D
- Rename to "Player"
- Add MeshInstance3D as child (for bird visuals)
- Add CollisionShape3D
- Add AudioStreamPlayer3D for sounds

3.

You might also like