instruction stringlengths 34 212 | input stringlengths 0 7.8k | output stringlengths 70 3.97k | source stringclasses 1
value |
|---|---|---|---|
Erstelle eine GDScript-Funktion namens '_physics_process': | func _physics_process(delta: float) -> void:
if not _is_playing:
return
# To have the best of both the audio-based time and system-based time, we
# apply a smoothing filter (1€ filter) on the delta between the two values,
# then add it to the system-based time. This allows us to have a stable
# value that is al... | null | |
Vervollständige den GDScript-Code: | extends Node3D
@export_enum("Left", "Right") var hand : int = 0
@export var fallback_mesh : Node3D
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var text = ""
if hand == 0:
text += "Left hand\n"
else:
text += "Right hand\n"
var controller_tracker : XRPosi... | text +=" - Using palm pose\n"
else:
pose = controller_tracker.get_pose(&"grip")
if pose:
text +=" - Using grip pose\n"
if pose:
if pose.tracking_confidence == XRPose.XR_TRACKING_CONFIDENCE_NONE:
text += "- No tracking data\n"
elif pose.tracking_confidence == XRPose.XR_TRACKING_CONFIDENCE_LOW... | null |
Vervollständige den GDScript-Code: | extends Camera3D
## If true, we are in control of positioning.
@export var enable_positioning: bool = true:
set(value):
if enable_positioning == value:
return
enable_positioning = value
if is_inside_tree():
$Area3D/CollisionShape3D.disabled = not enable_positioning
if enable_positioning:
# We just... | global_transform = last_transform
## Our camera should be pointed at this node.
@export var lookat_node: Node3D
@onready var last_transform: Transform3D = global_transform
@onready var display: MeshInstance3D = $CameraBody/DisplayContainer/Display
# Called when the node enters the scene tree for the first time.
... | null |
Vervollständige den GDScript-Code: | @tool
extends EditorPlugin
const BeehaveEditorDebugger := preload("debug/debugger.gd")
var editor_debugger: BeehaveEditorDebugger
var frames: RefCounted
var _custom_types: Array[StringName] = []
func _init():
name = "BeehavePlugin"
add_autoload_singleton("BeehaveGlobalMetrics", "metrics/beehave_global_metrics.gd")... | "hint": PROPERTY_HINT_NONE,
"hint_string": "If enabled, the debugger will start in a separate window"
})
ProjectSettings.save()
print("Beehave initialized!")
func _enter_tree() -> void:
editor_debugger = BeehaveEditorDebugger.new()
if Engine.get_version_info().minor >= 2:
frames = preload("debug/new_fr... | null |
Vervollständige den GDScript-Code: | @tool
## A [Cutscene] that is triggered by the presence of the player and the player's input.
##
## An active Interaction may be run by the player walking up to it and 'interacting' with it,
## usually via something as ubiquitous as the spacebar key. Common examples found in most RPGs are
## NPC conversations, opening... | # presence of overlapping areas, since factors such as gamestate and the existence of another
# running events are relevant.
var _overlapping_areas: = []
# A hidden Button control tells us when the player has clicked on the interaction. Note that only
# the topmost button may be clicked.
@onready var _button: Button =... | null |
Vervollständige den GDScript-Code: | extends XRController3D
# Check if we can use our palm pose or should fallback to our grip pose.
| # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var controller_tracker : XRControllerTracker = XRServer.get_tracker(tracker)
if controller_tracker:
var new_pose : String = "palm_pose"
var xr_pose : XRPose = controller_tracker.get_pose(new_pose)
if not xr_pose or... | null |
Vervollständige den GDScript-Code: | # Changes scenes after fading the screen on `any key` or on the A/B/cross
# buttons on a gamepad.
extends Control
const FADE_IN_TIME := 0.5
const FADE_OUT_TIME := 2.5
@onready var screen_fader: TextureRect = $FadeLayer/ScreenFader | @onready var main_screen := $Background/MainScreen
@onready var menu_sounds: MenuSoundPlayer = $MenuSoundPlayer
func _ready() -> void:
screen_fader.fade_in()
func _unhandled_input(event: InputEvent) -> void:
if screen_fader.is_playing:
return
if event is InputEventKey or event.is_action_pressed("thrust_forwards... | null |
Vervollständige den GDScript-Code: | extends Node2D
const VU_COUNT = 16
const FREQ_MAX = 11050.0
const WIDTH = 800
const HEIGHT = 250
const HEIGHT_SCALE = 8.0
const MIN_DB = 60
const ANIMATION_SPEED = 0.1
var spectrum: AudioEffectSpectrumAnalyzerInstance
var min_values: Array[float] = []
var max_values: Array[float] = []
func _draw() -> void:
@warnin... | draw_line(
Vector2(w * i, HEIGHT - height),
Vector2(w * i + w - 2, HEIGHT - height),
Color.from_hsv(float(VU_COUNT * 0.6 + i * 0.5) / VU_COUNT, 0.5, 1.0),
2.0,
true
)
# Draw a reflection of the bars with lower opacity.
draw_rect(
Rect2(w * i, HEIGHT, w - 2, height),
Color.from_hsv(... | null |
Vervollständige den GDScript-Code: | extends Node
# Keep the number of samples per second to mix low, as GDScript is not super fast.
var sample_hz := 22050.0
var pulse_hz := 440.0
var phase := 0.0
# Actual playback stream, assigned in _ready().
var playback: AudioStreamPlayback
func _fill_buffer() -> void:
var increment := pulse_hz / sample_hz
var t... | while to_fill > 0:
playback.push_frame(Vector2.ONE * sin(phase * TAU)) # Audio frames are stereo.
phase = fmod(phase + increment, 1.0)
to_fill -= 1
func _process(_delta: float) -> void:
_fill_buffer()
func _ready() -> void:
# Setting mix rate is only possible before play().
$Player.stream.mix_rate = sample_... | null |
Vervollständige den GDScript-Code: | @tool
class_name Door extends AreaTransition
# A locked door will block movement by placing a dummy gamepiece on the cell occupied by the door.
const GP_SCENE: = preload("res://src/field/gamepieces/gamepiece.tscn")
@export var is_locked: = false:
set(value):
if value != is_locked:
is_locked = value
if no... | open()
if _dummy_gp != null:
_dummy_gp.queue_free()
_dummy_gp = null
# Keep a reference to the object used to block movement through a locked door.
# Note that this gamepiece has no animation, movement, etc. It exists to occupy a board cell.
var _dummy_gp: Gamepiece = null
@onready var _anim: = $Ani... | null |
Vervollständige den GDScript-Code: | extends Node3D
signal session_started
signal focus_lost
signal focus_gained
signal pose_recentered
## Set the highest refresh rate we wish to enable.
## We'll find the closest matching one.
@export var maximum_refresh_rate: int = 90
var xr_interface: OpenXRInterface
var xr_is_focused: bool = false
## Get our OpenX... | xr_interface.session_visible.connect(_on_openxr_visible_state)
xr_interface.session_focussed.connect(_on_openxr_focused_state)
xr_interface.session_stopping.connect(_on_openxr_stopping)
xr_interface.pose_recentered.connect(_on_openxr_pose_recentered)
else:
# We couldn't start OpenXR.
print("OpenXR not inst... | null |
Vervollständige den GDScript-Code: | extends Panel
enum SyncSource {
SYSTEM_CLOCK,
SOUND_CLOCK,
}
const BPM = 116
const BARS = 4
const COMPENSATE_FRAMES = 2
const COMPENSATE_HZ = 60.0
var playing: bool = false
var sync_source := SyncSource.SYSTEM_CLOCK
# Used by system clock.
var time_begin: float | var time_delay: float
func _process(_delta: float) -> void:
if not playing or not $Player.playing:
return
var time := 0.0
if sync_source == SyncSource.SYSTEM_CLOCK:
# Obtain from ticks.
time = (Time.get_ticks_usec() - time_begin) / 1000000.0
# Compensate.
time -= time_delay
elif sync_source == SyncSourc... | null |
Vervollständige den GDScript-Code: | # Math and vector utility functions.
# @Category - Utilities
class_name GSAIUtils
# Returns the `vector` with its length capped to `limit`.
static func clampedv3(vector: Vector3, limit: float) -> Vector3:
var length_squared := vector.length_squared()
var limit_squared := limit * limit
if length_squared > limit_squa... | # Returns an angle in radians between the positive X axis and the `vector`.
#
# This assumes orientation for 3D agents that are upright and rotate
# around the Y axis.
static func vector3_to_angle(vector: Vector3) -> float:
return atan2(vector.x, vector.z)
# Returns an angle in radians between the positive X axis and... | null |
Vervollständige den GDScript-Code: | # Copyright (c) 2023 Patryk Kalinowski (patrykkalinowski.com)
# SPDX-License-Identifier: MIT
## Implementation of the 1€ filter (https://gery.casiez.net/1euro/).[br]
## Modification of https://github.com/patrykkalinowski/godot-xr-kit/blob/master/addons/xr-kit/smooth-input-filter/scripts/one_euro_filter.gd
class_name O... | x_filter = LowPassFilter.new()
dx_filter = LowPassFilter.new()
func alpha(rate: float, cutoff: float) -> float:
var tau: float = 1.0 / (2 * PI * cutoff)
var te: float = 1.0 / rate
return 1.0 / (1.0 + tau/te)
func filter(value: float, delta: float) -> float:
var rate: float = 1.0 / delta
var dx: float = (value... | null |
Vervollständige den GDScript-Code: | extends RayCast2D
@export var cast_speed := 7000.0
@export var max_length := 1400
@export var growth_time := 0.1
@onready var casting_particles := $CastingParticles2D
@onready var collision_particles := $CollisionParticles2D
@onready var beam_particles := $BeamParticles2D
@onready var fill := $FillLine2D
@onready var... |
func set_is_casting(cast: bool) -> void:
is_casting = cast
if is_casting:
target_position = Vector2.ZERO
fill.points[1] = target_position
appear()
else:
collision_particles.emitting = false
disappear()
set_physics_process(is_casting)
beam_particles.emitting = is_casting
casting_particles.emitting = i... | null |
Vervollständige den GDScript-Code: | # A specialized steering agent that updates itself every frame so the user does
# not have to using a RigidBody2D
# @category - Specialized agents
class_name GSAIRigidBody2DAgent
extends GSAISpecializedAgent
# The RigidBody2D to keep track of
var body: RigidBody2D: set = _set_body
var _last_position: Vector2
var _bod... | # @tags - virtual
func _apply_steering(acceleration: GSAITargetAcceleration, _delta: float) -> void:
var _body: RigidBody2D = _body_ref.get_ref()
if not _body:
return
_applied_steering = true
_body.apply_central_impulse(GSAIUtils.to_vector2(acceleration.linear))
_body.apply_torque_impulse(acceleration.angular)
... | null |
Vervollständige den GDScript-Code: | ## An Assertion Tool to verify float values
@abstract class_name GdUnitFloatAssert
extends GdUnitAssert
## Verifies that the current value is null.
@abstract func is_null() -> GdUnitFloatAssert
## Verifies that the current value is not null.
@abstract func is_not_null() -> GdUnitFloatAssert
## Verifies that the c... | ## Overrides the default failure message by given custom message.
@abstract func override_failure_message(message: String) -> GdUnitFloatAssert
## Appends a custom message to the failure message.
@abstract func append_failure_message(message: String) -> GdUnitFloatAssert
## Verifies that the current value is less tha... | null |
Vervollständige den GDScript-Code: | extends XRNode3D
## Detect which tracker we should use to position our hand, we prefer
## hand tracking as this works in unison with our hand skeleton updates.
## Hand for which to get our tracking data.
@export_enum("Left","Right") var hand : int = 0
# Called every frame. 'delta' is the elapsed time since the previ... | else "/user/hand_tracker/right"
var hand_tracker : XRHandTracker = XRServer.get_tracker(new_tracker)
if hand_tracker and hand_tracker.has_tracking_data:
if tracker != new_tracker:
print("Switching to left hand tracker" if hand == 0 \
else "Switching to right hand tracker")
tracker = new_tracker
pose ... | null |
Vervollständige den GDScript-Code: | ## An Assertion Tool to verify array values
@abstract class_name GdUnitArrayAssert
extends GdUnitAssert
## Verifies that the current value is null.
@abstract func is_null() -> GdUnitArrayAssert
## Verifies that the current value is not null.
@abstract func is_not_null() -> GdUnitArrayAssert
## Verifies that the c... | ## Verifies that the current Array is not empty, it has a size of minimum 1.
@abstract func is_not_empty() -> GdUnitArrayAssert
## Verifies that the current Array is the same. [br]
## Compares the current by object reference equals
@abstract func is_same(expected: Variant) -> GdUnitArrayAssert
## Verifies that the cu... | null |
Vervollständige den GDScript-Code: | ## An inventory item, tracking both it's UI representation and underlying data.
## Will be replaced in future iterations of the OpenRPG project.
## Please see UIInventory for additional information.
class_name UIInventoryItem extends TextureRect
var ID: = Inventory.ItemTypes.KEY
var count: = 0: | set = set_count
@onready var _count_label: = $Count as Label
func set_count(value: int) -> void:
count = max(value, 0)
if count == 0:
queue_free()
elif count > 1:
_count_label.show()
_count_label.text = str(count)
else:
_count_label.hide()
| null |
Vervollständige den GDScript-Code: | class_name PickupAbleBody3D
extends RigidBody3D
var highlight_material : Material = preload("res://shaders/highlight_material.tres")
var picked_up_by : Area3D
var closest_areas : Array
var original_parent : Node3D
var tween : Tween
# Called when this object becomes the closest body in an area
func add_is_closest(ar... | # Pick this object up.
func pick_up(pick_up_by) -> void:
# Already picked up? Can't pick up twice.
if picked_up_by:
if picked_up_by == pick_up_by:
return
let_go()
# Remember some state we want to reapply on release.
original_parent = get_parent()
var current_transform = global_transform
# Remove us from... | null |
Vervollständige den GDScript-Code: | # Helper global object that holds helpful mathematics functions that are not
# part of Godot.
class_name MathUtils
extends Node
# Returns the radius of a circumcircle for a triangle.
# The circumscribed circle or circumcircle of a polygon is a circle that passes
# through all the vertices of the polygon.
# Adapted fro... |
var a := vertices[0]
var b := vertices[1]
var c := vertices[2]
var A := b.x - a.x
var B := b.y - a.y
var C := c.x - a.x
var D := c.y - a.y
var E := A * (a.x + b.x) + B * (a.y + b.y)
var F := C * (a.x + c.x) + D * (a.y + c.y)
var G := 2 * (A * (c.y - b.y) - B * (c.x - b.x))
var dx: float
var dy: float
if... | null |
Vervollständige den GDScript-Code: | # Handles the input that brings up the minimap or the quit menu.
extends CanvasLayer
@onready var screen_fader: TextureRect = $ScreenFader
@onready var map: TextureRect = $MapDisplay
@onready var upgrade_menu := $UpgradeUI
@onready var quit_menu := $QuitMenu
func _ready() -> void:
Events.player_died.connect(reset.b... | Events.quit_requested.connect(quit)
Events.upgrade_unlocked.connect(upgrade_menu.open)
screen_fader.fade_in()
func _unhandled_input(event: InputEvent) -> void:
if get_tree().paused:
return
if event.is_action_pressed("ui_cancel"):
quit_menu.open()
if event.is_action_pressed("toggle_map") and not map.is_anima... | null |
Vervollständige den GDScript-Code: | class_name PianoKey
extends Control
var pitch_scale: float
@onready var key: ColorRect = $Key
@onready var start_color: Color = key.color
@onready var color_timer: Timer = $ColorTimer
func setup(pitch_index: int) -> void: | name = "PianoKey" + str(pitch_index)
var exponent := (pitch_index - 69.0) / 12.0
pitch_scale = pow(2, exponent)
func activate() -> void:
key.color = (Color.YELLOW + start_color) / 2
var audio := AudioStreamPlayer.new()
add_child(audio)
audio.stream = preload("res://piano_keys/A440.wav")
audio.pitch_scale = pit... | null |
Erstelle eine Godot-Klasse 'GSAIGroupBehavior' die von GSAISteeringBehavior erbt mit folgenden Funktionen: _init, _report_neighbor | # Base type for group-based steering behaviors.
# @category - Base types
class_name GSAIGroupBehavior
extends GSAISteeringBehavior
# Container to find neighbors of the agent and calculate group behavior.
var proximity: GSAIProximity
var _callback := Callable(self, "_report_neighbor")
func _init(agent: GSAISteeringAg... | null | |
Erstelle eine Godot-Klasse 'Hurtbox' die von Area2D erbt mit folgenden Funktionen: take_damage | #*
#* hurtbox.gd
#* =============================================================================
#* Copyright (c) 2023-present Serhii Snitsaruk and the LimboAI contributors.
#*
#* Use of this source code is governed by an MIT-style
#* license that can be found in the LICENSE file or at
#* https://opensource.org/licens... | null | |
Vervollständige den GDScript-Code: | #*
#* hitbox.gd
#* =============================================================================
#* Copyright (c) 2023-present Serhii Snitsaruk and the LimboAI contributors.
#*
#* Use of this source code is governed by an MIT-style
#* license that can be found in the LICENSE file or at
#* https://opensource.org/license... |
## Damage value to apply.
@export var damage: float = 1.0
## Push back the victim.
@export var knockback_enabled: bool = false
## Desired pushback speed.
@export var knockback_strength: float = 500.0
func _ready() -> void:
area_entered.connect(_area_entered)
func _area_entered(hurtbox: Hurtbox) -> void:
if hurtb... | null |
Erstelle eine GDScript-Funktion namens 'initialize': | func initialize() -> void:
_update_all()
# Get the final value of a stat, with all modifiers applied to it.
func get_stat(stat_name := "") -> float:
assert(stat_name in _stats_list)
return _cache[stat_name]
# Adds a modifier to the stat corresponding to `stat_name` and returns the new modifier's id.
func add_modif... | extracted_function |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.