Add wave variations

This commit is contained in:
Stephen Seo 2023-09-30 17:33:27 +09:00
parent 9c7b3617c5
commit 35a59cf753

View file

@ -8,6 +8,10 @@ var projectile = preload("res://circleProjectiles.tscn")
const WAVE_TIME = 5.0
const PROJECTILE_DISTANCE = 1500
const PROJECTILE_VELOCITY = 500
const HORIZONTAL_WAVE_COLOR = Color(1, 0, 1)
const HORIZONTAL_WAVE_COLOR_ALT = Color(1, 1, 0)
const VERTICAL_WAVE_COLOR = Color(0, 1, 1)
const VERTICAL_WAVE_COLOR_ALT = Color(0, 1, 0)
var wave_timer = 3.0
@ -15,6 +19,45 @@ var wave_timer = 3.0
func _ready():
pass # Replace with function body.
func wave_random():
for i in range(10):
var projectile_instance = projectile.instantiate()
var random_angle = randf_range(0.0, PI * 2.0)
var projectile_sprite = projectile_instance.find_child("Sprite2D")
projectile_instance.position = Vector2(cos(random_angle) * PROJECTILE_DISTANCE + player.position.x, sin(random_angle) * PROJECTILE_DISTANCE + player.position.y)
projectile_instance.linear_velocity = Vector2(-cos(random_angle) * PROJECTILE_VELOCITY, -sin(random_angle) * PROJECTILE_VELOCITY)
projectile_sprite.self_modulate = Color(randf_range(0.5, 1.0), randf_range(0.5, 1.0), randf_range(0.5, 1.0))
add_child(projectile_instance)
func wave_horizontal():
var left = true if randi_range(0, 1) == 0 else false
for i in range(8):
var projectile_instance = projectile.instantiate()
var random_angle = 0
if left:
random_angle = randf_range(-PI / 2.0, PI / 2.0)
else:
random_angle = randf_range(PI / 2.0, PI * 3.0 / 2.0)
var projectile_sprite = projectile_instance.find_child("Sprite2D")
projectile_instance.position = Vector2(cos(random_angle) * PROJECTILE_DISTANCE + player.position.x, sin(random_angle) * PROJECTILE_DISTANCE + player.position.y)
projectile_instance.linear_velocity = Vector2(-cos(random_angle) * PROJECTILE_VELOCITY, -sin(random_angle) * PROJECTILE_VELOCITY)
projectile_sprite.self_modulate = HORIZONTAL_WAVE_COLOR if left else HORIZONTAL_WAVE_COLOR_ALT
add_child(projectile_instance)
func wave_vertical():
var up = true if randi_range(0, 1) == 0 else false
for i in range(8):
var projectile_instance = projectile.instantiate()
var random_angle = 0
if up:
random_angle = randf_range(0, PI)
else:
random_angle = randf_range(PI, PI * 2.0)
var projectile_sprite = projectile_instance.find_child("Sprite2D")
projectile_instance.position = Vector2(cos(random_angle) * PROJECTILE_DISTANCE + player.position.x, sin(random_angle) * PROJECTILE_DISTANCE + player.position.y)
projectile_instance.linear_velocity = Vector2(-cos(random_angle) * PROJECTILE_VELOCITY, -sin(random_angle) * PROJECTILE_VELOCITY)
projectile_sprite.self_modulate = VERTICAL_WAVE_COLOR if up else VERTICAL_WAVE_COLOR_ALT
add_child(projectile_instance)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
@ -25,14 +68,15 @@ func _process(delta):
wave_timer += delta
if wave_timer >= WAVE_TIME:
wave_timer = 0
for i in range(10):
var projectile_instance = projectile.instantiate()
var random_angle = randf_range(0.0, PI * 2.0)
var projectile_sprite = projectile_instance.find_child("Sprite2D")
projectile_instance.position = Vector2(cos(random_angle) * PROJECTILE_DISTANCE + player.position.x, sin(random_angle) * PROJECTILE_DISTANCE + player.position.y)
projectile_instance.linear_velocity = Vector2(-cos(random_angle) * PROJECTILE_VELOCITY, -sin(random_angle) * PROJECTILE_VELOCITY)
projectile_sprite.self_modulate = Color(randf_range(0.5, 1.0), randf_range(0.5, 1.0), randf_range(0.5, 1.0))
add_child(projectile_instance)
match randi_range(0, 2):
0:
wave_random()
1:
wave_horizontal()
2:
wave_vertical()
_:
wave_random()
func do_restart():
get_tree().reload_current_scene()