Skip to content

Instantly share code, notes, and snippets.

View viniciusemferreira's full-sized avatar

Vinicius Eduardo viniciusemferreira

  • Lumenalta
  • Campo Grande, Mato Grosso do Sul, Brazil
View GitHub Profile
@viniciusemferreira
viniciusemferreira / aim_component.gd
Created March 25, 2025 21:43
This was supposed to be an aim mechanic, but it ended up looking like the mechanic seen in Dome Keeper, where you drag the boxes, so we should find a better name for it later.
@tool
class_name AimComponent
extends Node2D
## Component that handles aim mechanics with physics-based mouse following
##
## This component creates a physical cursor that follows the mouse position with
## configurable acceleration, drag, and mass properties to simulate different
## weapon handling characteristics.
# Signals
@viniciusemferreira
viniciusemferreira / health_bar_component.gd
Created March 14, 2025 14:04
The HealthBarComponent script for Godot 4 is a UI component that visually represents an entity’s health using a ProgressBar. It connects to a HealthComponent, automatically updating when health changes. The bar dynamically reflects the entity’s remaining health as a percentage. This script is ideal for characters, enemies, or any game object tha…
class_name HealthBarComponent
extends Control
## The HealthComponent this health bar represents.
@export var health_component: HealthComponent
## Reference to the ProgressBar node inside the health bar.
@onready var progress_bar: ProgressBar = $ProgressBar
@viniciusemferreira
viniciusemferreira / health_component.gd
Created March 14, 2025 14:01
The HealthComponent script for Godot 4 is a simple and reusable health system for game entities. It tracks an entity’s health, allowing it to take damage and emit signals when health changes, decreases, or is depleted. The script also provides a function to get the current health as a percentage. When health reaches zero, a death event is trigge…
extends Node
class_name HealthComponent
## Signal emitted when health changes. Sends the amount of change.
signal health_changed(amount: float)
## Signal emitted specifically when health decreases. Sends the amount of damage taken.
signal health_decreased(amount: float)
## Signal emitted when health reaches zero.
@viniciusemferreira
viniciusemferreira / tooltip.gd
Created March 14, 2025 13:36
This Tooltip script for Godot 4 is a reusable component that displays a tooltip when hovering over an assigned node. It supports automatic positioning, optional screen clamping, and customizable offsets. The tooltip fades in and out smoothly and can be toggled using the ALT key if enabled. It works with both Control and Node2D nodes and ensures …
extends Control
class_name Tooltip
@export_category("Tooltip Settings")
## The node that owns this tooltip and triggers its visibility.
@export var owner_node: Node
## If true, allows the tooltip to be toggled on and off with a key press.
## This is kind of specific to some projects, so you might want to remove it.
@viniciusemferreira
viniciusemferreira / velocity_component.gd
Last active May 2, 2025 18:50
A Godot (GDScript) velocity component for handling movement, acceleration, knockback effects, and deceleration, designed for use with a `CharacterBody2D`.
extends Node2D
class_name VelocityComponent
## The maximum speed this object can move at.
@export var max_speed: float = 100
## The rate of acceleration used when applying knockback.
@export var knockback_acceleration: float = 15
## The rate of acceleration when moving normally.
@viniciusemferreira
viniciusemferreira / experience_manager.gd
Last active March 14, 2025 13:26
A simple experience and leveling system that tracks experience, emits signals on updates, and levels up when the target is reached.
extends Node
## Connect to this to keep track of current experience
signal experience_updated(current_experience: float, target_experience: float)
signal level_up(new_level: int) ## Connect to this to keep track of level ups
## The ratio of experience needed to level up, this value will be added
## to the target experience each time the player levels up
const TARGET_EXPERIENCE_RATIO = 5