documentation pass before moving on
This commit is contained in:
parent
c6923a3133
commit
ddf3590c96
17 changed files with 84 additions and 44 deletions
51
systems/bullets/bullet_behaviors/linear_motion_behavior.gd
Normal file
51
systems/bullets/bullet_behaviors/linear_motion_behavior.gd
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
class_name LinearMotionBehavior
|
||||
extends BulletBehavior
|
||||
## Makes bullets move in [member Bullet.direction], potentially accelerating.
|
||||
|
||||
|
||||
## Initial speed of the bullet when it is spawned.
|
||||
@export_custom(0, "suffix:px/s") var initial_speed: float = 0.0
|
||||
|
||||
## Rate at which the bullet will speed up.
|
||||
@export_custom(0, "suffix:px/s²") var acceleration: float = 0.0
|
||||
|
||||
## Speed will be clamped between [member min_speed] and [member max_speed].
|
||||
@export_custom(0, "suffix:px/s") var min_speed: float = -INF
|
||||
## Speed will be clamped between [member min_speed] and [member max_speed].
|
||||
@export_custom(0, "suffix:px/s") var max_speed: float = INF
|
||||
|
||||
@export_group("Actions", "action_")
|
||||
## Performed when the bullet reaches either [member min_speed] or
|
||||
## [member max_speed] for the first time.
|
||||
@export var action_speed_clamped: BulletAction
|
||||
|
||||
|
||||
var _bullet_data: Dictionary[Bullet, Data] = {}
|
||||
|
||||
|
||||
func _init_bullet(bullet: Bullet) -> void:
|
||||
var data = Data.new()
|
||||
data.speed = initial_speed
|
||||
_bullet_data[bullet] = data
|
||||
|
||||
|
||||
func _deinit_bullet(bullet: Bullet) -> void:
|
||||
_bullet_data.erase(bullet)
|
||||
|
||||
|
||||
func _process_bullet(bullet: Bullet, delta: float) -> void:
|
||||
if not _bullet_data.has(bullet):
|
||||
return
|
||||
var data = _bullet_data[bullet]
|
||||
data.speed += acceleration * delta
|
||||
if not data.already_clamped and (data.speed <= min_speed or data.speed >= max_speed):
|
||||
data.already_clamped = true
|
||||
if action_speed_clamped:
|
||||
action_speed_clamped.perform(bullet)
|
||||
data.speed = clampf(data.speed, min_speed, max_speed)
|
||||
bullet.position += bullet.direction * data.speed * delta
|
||||
|
||||
|
||||
class Data:
|
||||
var speed: float
|
||||
var already_clamped: bool = false
|
||||
Loading…
Add table
Add a link
Reference in a new issue