Set up framework for more advance pickup behaviours.
This commit is contained in:
parent
a0df0be862
commit
935b61bd3b
16 changed files with 485 additions and 20 deletions
14
resources/pickups/drift_diagonal.tres
Normal file
14
resources/pickups/drift_diagonal.tres
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[gd_resource type="Resource" script_class="PickupDriftBehavior" format=3 uid="uid://cdiglwsw46g4y"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b4lar4f3526b1" path="res://resources/pickups/pickup_drift_behavior.gd" id="1_drift"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_drift")
|
||||
drift_type = 3
|
||||
wave_amplitude = 100.0
|
||||
wave_frequency = 2.0
|
||||
drift_speed = 30.0
|
||||
diagonal_forward = true
|
||||
drift_along_x = true
|
||||
reverse_direction = false
|
||||
randomize_origin = false
|
||||
14
resources/pickups/drift_leaf_fall.tres
Normal file
14
resources/pickups/drift_leaf_fall.tres
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[gd_resource type="Resource" script_class="PickupDriftBehavior" format=3 uid="uid://pickup_drift_leaf"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://pickup_drift_uid" path="res://resources/pickups/pickup_drift_behavior.gd" id="1_drift"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_drift")
|
||||
drift_type = 2
|
||||
drift_speed = 30.0
|
||||
fall_speed = 15.0
|
||||
wave_amplitude = 40.0
|
||||
wave_frequency = 1.0
|
||||
drift_along_x = true
|
||||
reverse_direction = false
|
||||
randomize_origin = false
|
||||
13
resources/pickups/drift_sine_wave.tres
Normal file
13
resources/pickups/drift_sine_wave.tres
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[gd_resource type="Resource" script_class="PickupDriftBehavior" format=3 uid="uid://cr7lye10sx1q6"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b4lar4f3526b1" path="res://resources/pickups/pickup_drift_behavior.gd" id="1_drift"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_drift")
|
||||
drift_type = 1
|
||||
drift_speed = 30.0
|
||||
wave_amplitude = 40.0
|
||||
wave_frequency = 1.0
|
||||
drift_along_x = true
|
||||
reverse_direction = false
|
||||
randomize_origin = false
|
||||
43
resources/pickups/pickup_behavior.gd
Normal file
43
resources/pickups/pickup_behavior.gd
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
class_name PickupBehavior extends Resource
|
||||
|
||||
## Base resource that defines how a pickup moves and looks on screen.
|
||||
## Assign to [member pickup_behavior] on a PickupBehaviorController.
|
||||
|
||||
@export_group("Animation")
|
||||
## Whether the pickup bobs up and down in place.
|
||||
@export var bob_enabled: bool = true
|
||||
## Bob oscillation frequency in cycles per second.
|
||||
@export var bob_frequency: float = 2.0
|
||||
## Bob vertical amplitude in pixels (peak-to-center).
|
||||
@export var bob_amplitude: float = 4.0
|
||||
|
||||
## Whether the pickup subtly shakes (jitter) in place.
|
||||
@export var shake_enabled: bool = false
|
||||
## Shake frequency in Hz (how fast the jitter oscillates).
|
||||
@export var shake_frequency: float = 8.0
|
||||
## Shake amplitude in pixels (peak-to-center).
|
||||
@export var shake_amplitude: float = 1.5
|
||||
|
||||
## Optional fade-in duration (0 = no fade).
|
||||
@export var fade_in_duration: float = 0.0
|
||||
## Optional fade-out duration when the pickup is about to be collected
|
||||
## (used by controller; 0 = no fade).
|
||||
@export var fade_out_duration: float = 0.0
|
||||
|
||||
var _elapsed: float = 0.0
|
||||
|
||||
|
||||
func start() -> void:
|
||||
_elapsed = 0.0
|
||||
|
||||
|
||||
func process(delta: float) -> float:
|
||||
# Returns the current opacity factor (0..1) based on fade timers.
|
||||
_elapsed += delta
|
||||
|
||||
var target_alpha: float = 1.0
|
||||
|
||||
if fade_in_duration > 0 and _elapsed < fade_in_duration:
|
||||
target_alpha = clampf(_elapsed / fade_in_duration, 0.0, 1.0)
|
||||
|
||||
return target_alpha
|
||||
1
resources/pickups/pickup_behavior.gd.uid
Normal file
1
resources/pickups/pickup_behavior.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d0l8e2ymk0lx1
|
||||
47
resources/pickups/pickup_drift_behavior.gd
Normal file
47
resources/pickups/pickup_drift_behavior.gd
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
class_name PickupDriftBehavior extends Resource
|
||||
|
||||
## Base resource that defines the global travel pattern of a pickup across
|
||||
## the screen. Assign to [member drift_behavior] on a PickupBehaviorController.
|
||||
|
||||
enum DriftType {
|
||||
STATIONARY, ## Does not move (aside from bob/shake).
|
||||
SINE_WAVE, ## Travels in a sine curve.
|
||||
LEAF_FALL, ## Drifts downward with gentle horizontal sway.
|
||||
DIAGONAL, ## Moves diagonally in one direction.
|
||||
}
|
||||
|
||||
@export_group("Drift")
|
||||
## The drift pattern to apply.
|
||||
@export var drift_type: DriftType = DriftType.STATIONARY
|
||||
|
||||
## Horizontal speed in pixels per second (applies to SINE_WAVE, LEAF_FALL).
|
||||
@export var drift_speed: float = 30.0
|
||||
## Vertical fall speed in pixels per second (applies to LEAF_FALL).
|
||||
@export var fall_speed: float = 15.0
|
||||
|
||||
## Horizontal wave amplitude in pixels (applies to SINE_WAVE, LEAF_FALL).
|
||||
@export var wave_amplitude: float = 40.0
|
||||
## Wave frequency in cycles per second (applies to SINE_WAVE, LEAF_FALL).
|
||||
@export var wave_frequency: float = 1.0
|
||||
|
||||
## Diagonal direction: +X forward, -X backward (applies to DIAGONAL).
|
||||
@export var diagonal_forward: bool = true
|
||||
|
||||
## Main drift axis for SINE_WAVE and LEAF_FALL.
|
||||
## true = horizontal travel (x), false = vertical travel (y).
|
||||
@export var drift_along_x: bool = true
|
||||
|
||||
## Reverse the primary direction (left/right or up/down).
|
||||
@export var reverse_direction: bool = false
|
||||
|
||||
## Randomize the perpendicular axis origin (y if horizontal, x if vertical).
|
||||
@export var randomize_origin: bool = false
|
||||
|
||||
## Phase offset in radians — randomize per-instance for variety.
|
||||
@export var phase_offset: float = 0.0
|
||||
|
||||
var _initial_x: float = 0.0
|
||||
|
||||
|
||||
func reset(initial_position: Vector2) -> void:
|
||||
_initial_x = initial_position.x
|
||||
1
resources/pickups/pickup_drift_behavior.gd.uid
Normal file
1
resources/pickups/pickup_drift_behavior.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b4lar4f3526b1
|
||||
13
resources/pickups/rare_powerup.tres
Normal file
13
resources/pickups/rare_powerup.tres
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[gd_resource type="Resource" script_class="PickupBehavior" format=3 uid="uid://pickup_rare_powerup"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://pickup_behavior_uid" path="res://resources/pickups/pickup_behavior.gd" id="1_behavior"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_behavior")
|
||||
bob_enabled = true
|
||||
bob_frequency = 3.5
|
||||
bob_amplitude = 6.0
|
||||
shake_enabled = true
|
||||
shake_frequency = 12.0
|
||||
shake_amplitude = 1.5
|
||||
fade_in_duration = 0.5
|
||||
8
resources/pickups/std_powerup.tres
Normal file
8
resources/pickups/std_powerup.tres
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[gd_resource type="Resource" script_class="PickupBehavior" format=3 uid="uid://dflj31qle75ol"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://d0l8e2ymk0lx1" path="res://resources/pickups/pickup_behavior.gd" id="1_behavior"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_behavior")
|
||||
shake_enabled = true
|
||||
fade_in_duration = 0.3
|
||||
Loading…
Add table
Add a link
Reference in a new issue