rand bullets
This commit is contained in:
parent
55c2aeac80
commit
4ff19610d3
12 changed files with 126 additions and 56 deletions
|
|
@ -3,4 +3,15 @@ class_name BulletSpawnPattern
|
|||
extends Resource
|
||||
|
||||
|
||||
@abstract func spawn_bullets(bullet_set: BulletSet, preset: BulletPreset) -> void
|
||||
## The amount of times to spawning this pattern for one "round".
|
||||
## This is mostly useful if the pattern or behavior introduces some
|
||||
## form of randomness.
|
||||
@export_range(1, 1, 1, "or_greater") var iterations: int = 1
|
||||
|
||||
|
||||
func spawn_bullets(bullet_set: BulletSet, preset: BulletPreset) -> void:
|
||||
for _n in iterations:
|
||||
_spawn_bullets(bullet_set, preset)
|
||||
|
||||
|
||||
@abstract func _spawn_bullets(bullet_set: BulletSet, preset: BulletPreset) -> void
|
||||
|
|
|
|||
|
|
@ -7,14 +7,9 @@ extends BulletSpawnPattern
|
|||
@export_custom(0, "direction") var line_normal: Vector2 = Vector2.RIGHT
|
||||
|
||||
|
||||
func spawn_bullets(bullet_set: BulletSet, preset: BulletPreset) -> void:
|
||||
func _spawn_bullets(bullet_set: BulletSet, preset: BulletPreset) -> void:
|
||||
for i in bullet_count:
|
||||
var bullet = Bullet.create(
|
||||
preset.textures.pick_random(),
|
||||
preset.hitbox_size,
|
||||
line_normal,
|
||||
preset.face_direction
|
||||
)
|
||||
var bullet = Bullet.create(preset, line_normal)
|
||||
|
||||
var line = line_normal.orthogonal().rotated(bullet_set.spawn_rotation)
|
||||
var weight = float(i) / float(bullet_count - 1)
|
||||
|
|
|
|||
|
|
@ -8,14 +8,9 @@ extends BulletSpawnPattern
|
|||
@export_custom(0, "radians_as_degrees") var direction_rotation: float
|
||||
|
||||
|
||||
func spawn_bullets(bullet_set: BulletSet, preset: BulletPreset) -> void:
|
||||
func _spawn_bullets(bullet_set: BulletSet, preset: BulletPreset) -> void:
|
||||
for i in bullet_count:
|
||||
var angle = (float(i) / float(bullet_count)) * TAU + angle_offset + bullet_set.spawn_rotation
|
||||
var bullet = Bullet.create(
|
||||
preset.textures.pick_random(),
|
||||
preset.hitbox_size,
|
||||
Vector2.from_angle(angle + direction_rotation),
|
||||
preset.face_direction
|
||||
)
|
||||
var bullet = Bullet.create(preset, Vector2.from_angle(angle + direction_rotation))
|
||||
bullet.position = bullet_set.spawn_offset + Vector2.from_angle(angle) * distance_offset
|
||||
bullet_set.add_bullet(bullet)
|
||||
|
|
|
|||
26
systems/bullets/spawn_patterns/spawn_pattern_randomizer.gd
Normal file
26
systems/bullets/spawn_patterns/spawn_pattern_randomizer.gd
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
@tool
|
||||
class_name SpawnPatternRandomizer
|
||||
extends BulletSpawnPattern
|
||||
## Randomizes properties of a child [BulletSpawnPattern] each [member iteration].
|
||||
##
|
||||
## WARNING: Experimental. Only float properties are currently
|
||||
## supported and this class is subject to change in the future.
|
||||
|
||||
|
||||
## The pattern to randomize and defer to.
|
||||
@export var pattern: BulletSpawnPattern
|
||||
|
||||
## Minimum value for each randomized property.
|
||||
@export var property_min_values: Dictionary[StringName, float] = {}
|
||||
## Maximum value for each randomized property.
|
||||
@export var property_max_values: Dictionary[StringName, float] = {}
|
||||
|
||||
|
||||
func _spawn_bullets(bullet_set: BulletSet, preset: BulletPreset) -> void:
|
||||
for property in property_min_values:
|
||||
if property_max_values.has(property):
|
||||
pattern.set(property, randf_range(
|
||||
property_min_values[property],
|
||||
property_max_values[property]
|
||||
))
|
||||
pattern.spawn_bullets(bullet_set, preset)
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://ckedfcjjnv7dq
|
||||
Loading…
Add table
Add a link
Reference in a new issue