This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends RefCounted | |
class_name StateMachine | |
class PDA: | |
var stack = [] | |
func push(state): | |
if stack.size() > 0: | |
stack[-1].exit(state) | |
stack.append(state) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Sprite2D | |
const MoveSpeed = 50 | |
var _initial_y | |
func _ready(): | |
_initial_y = global_position.y | |
func _process(delta: float) -> void: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Beginner-friendly GDScript 1 to GDScript 2 Conversion Guide | |
First and foremost, this should not be considered a replacement for the official migration guide, | |
found at https://docs.godotengine.org/en/latest/tutorials/migrating/upgrading_to_godot_4.html! | |
Instead, this document is intended to be a friendly guide to helping you upgrade your projects from | |
GDScript 1 to 2. To do this, I'm going to list the most common conversions I've run into while upgrading | |
a few of my games and tools. This document is written as of the first release candidate version of Godot 4.0. | |
The first thing to do when converting a project (no need if you're starting from new) is to either have your | |
project in source control, or make a duplicate of your entire project's folder and rename it. This will |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Camera2D | |
# Courtesy of KidsCanCode: http://kidscancode.org/godot_recipes/3.x/2d/screen_shake/ (this may change in the near future, so it may require a search) | |
# If you intend to use this, don't forget to turn on camera rotation! And keep in mind that smaller numbers are often the most useful - huge numbers make this thing *really* shake | |
# 3.5.x | |
export var decay = 0.8 # How quickly the shaking stops [0, 1]. | |
export var max_offset = Vector2(100, 75) # Maximum hor/ver shake in pixels. | |
export var max_roll = 0.1 # Maximum rotation in radians (use sparingly). | |
export (NodePath) var target # Assign the node this camera will follow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In your Enemy.gd script | |
... | |
const KILL_EFFECT_SCENE = preload(...) | |
func take_damage(amount: float) -> void: | |
enemy_stats.hitpoints -= amount | |
if enemy_stats.hitpoints <= 0: | |
kill() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node | |
# Make this a global singleton if you want | |
func shake_horizontal(thing, strength: float) -> void: | |
var orig_pos = thing.position | |
var current_amount = 6 | |
var shake_count = int(abs(current_amount)) | |
for i in shake_count: # Tweak these values | |
var tween = create_tween().tween_property(thing, "position", Vector2.RIGHT * pow(-1, i) * strength * current_amount, 0.01) | |
await tween.finished |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# meta-description: Classic movement for RPG or top-down games that do not apply gravity | |
# meta-name: RPG movement | |
# meta-default: true | |
# meta-space-indent: 4 | |
extends _BASE_ | |
const SPEED = 450.0 | |
const FRICTION = 1000.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## For a beginner-friendly version of the following (more advanced users likely will get better use of the below, | |
## if you're just starting out...), see this new gist: | |
## https://gist.github.com/WolfgangSenff/0a9c1d800db42a9a9441b2d0288ed0fd | |
This document represents the beginning of an upgrade or migration document for GDScript 2.0 and Godot 4.0. I'm focusing on 2D | |
at the moment as I'm upgrading a 2D game, but will hopefully have more to add for 3D afterward. | |
## If you want more content like this, please help fund my cat's medical bills at https://ko-fi.com/kyleszklenski - thank you very much! On to the migration guide. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Area2D | |
const FlightMagnitude = 20.0 | |
const FlightFrequency = 5.0 | |
const FlightSpeed = 8.0 | |
var _current_flight_angle := 0.0 | |
var _flying_left := 1 | |
func _physics_process(delta : float) -> void: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node2D | |
func _ready() -> void: | |
var file = File.new() | |
var file_location = "user://cache_temp/icon.png" | |
if not file.file_exists(file_location): | |
var result = file.open(file_location, File.WRITE_READ) | |
var buffer = preload("res://icon.png").get_data().get_data() | |
file.store_buffer(buffer) | |
file.close() |