boss update
This commit is contained in:
parent
c885095bc1
commit
0c0cc1d5f1
16 changed files with 201 additions and 295 deletions
104
Spawner.gd
104
Spawner.gd
|
@ -1,76 +1,52 @@
|
|||
extends Marker2D
|
||||
extends Node2D
|
||||
|
||||
@export var item: PackedScene
|
||||
@export var waves: Array[Wave]
|
||||
var portal = preload("res://portal.tscn")
|
||||
@export var portal_texture: SpriteFrames
|
||||
@export var random_off_screen = false
|
||||
@export var radius = 100
|
||||
var enemies_previous = false
|
||||
|
||||
func project_ray_to_screen_edge(player_position: Vector2) -> Vector2:
|
||||
var screen_size = get_viewport().size
|
||||
func _ready():
|
||||
spawn_loop()
|
||||
|
||||
# Generate a random point on the screen
|
||||
var random_point = Vector2(randf_range(0, screen_size.x), randf_range(0, screen_size.y))
|
||||
|
||||
# Calculate the direction vector from the player to the random point
|
||||
var direction = (random_point - player_position).normalized()
|
||||
|
||||
# Calculate the intersection points with the screen edges
|
||||
var intersection_points = []
|
||||
|
||||
# Check intersection with the left edge
|
||||
var left_intersection = Vector2(0, player_position.y + direction.y * (0 - player_position.x) / direction.x)
|
||||
if left_intersection.y >= 0 and left_intersection.y <= screen_size.y:
|
||||
intersection_points.append(left_intersection)
|
||||
|
||||
# Check intersection with the right edge
|
||||
var right_intersection = Vector2(screen_size.x, player_position.y + direction.y * (screen_size.x - player_position.x) / direction.x)
|
||||
if right_intersection.y >= 0 and right_intersection.y <= screen_size.y:
|
||||
intersection_points.append(right_intersection)
|
||||
|
||||
# Check intersection with the top edge
|
||||
var top_intersection = Vector2(player_position.x + direction.x * (0 - player_position.y) / direction.y, 0)
|
||||
if top_intersection.x >= 0 and top_intersection.x <= screen_size.x:
|
||||
intersection_points.append(top_intersection)
|
||||
|
||||
# Check intersection with the bottom edge
|
||||
var bottom_intersection = Vector2(player_position.x + direction.x * (screen_size.y - player_position.y) / direction.y, screen_size.y)
|
||||
if bottom_intersection.x >= 0 and bottom_intersection.x <= screen_size.x:
|
||||
intersection_points.append(bottom_intersection)
|
||||
|
||||
# Find the closest intersection point to the player
|
||||
var closest_intersection = intersection_points[0]
|
||||
var min_distance = player_position.distance_to(closest_intersection)
|
||||
for point in intersection_points:
|
||||
var distance = player_position.distance_to(point)
|
||||
if distance < min_distance:
|
||||
closest_intersection = point
|
||||
min_distance = distance
|
||||
|
||||
return closest_intersection
|
||||
signal all_enemies_perished
|
||||
|
||||
func check_enemies_loop():
|
||||
var has_enemies = len(get_tree().get_nodes_in_group("enemy")) > 0
|
||||
if enemies_previous and not has_enemies:
|
||||
all_enemies_perished.emit()
|
||||
enemies_previous = has_enemies
|
||||
|
||||
func spawn_loop():
|
||||
for wave in waves:
|
||||
print("Starting Next Wave")
|
||||
for i in range(len(wave.enemies)):
|
||||
spawn_enemies(wave.quantities[i], wave.spawning_duration, wave.enemies[i])
|
||||
if wave.wait_for_killed:
|
||||
await all_enemies_perished
|
||||
await get_tree().create_timer(wave.spawning_duration + wave.wait).timeout
|
||||
|
||||
func spawn_enemies(count: int, duration: float, enemy: WaveEnemy):
|
||||
var delay = duration / count
|
||||
for i in range(count):
|
||||
await get_tree().create_timer(delay).timeout
|
||||
spawn(enemy)
|
||||
|
||||
func spawn(item: WaveEnemy):
|
||||
|
||||
func spawn():
|
||||
if get_tree().paused:
|
||||
return
|
||||
var spawn_loc = Vector2.ZERO
|
||||
if random_off_screen:
|
||||
spawn_loc = project_ray_to_screen_edge($"../Player".global_position)
|
||||
#print(spawn_loc)
|
||||
|
||||
for i in range(10):
|
||||
var test_pos = Vector2(randf(), randf()) * Vector2(1920, 1080)
|
||||
if not $"../CollisionCheck".is_clear(test_pos, radius):
|
||||
if not $"../CollisionCheck".is_clear(test_pos, item.check_distance):
|
||||
continue
|
||||
spawn_loc = test_pos
|
||||
break
|
||||
|
||||
|
||||
if spawn_loc != Vector2.ZERO:
|
||||
var portal_effect = portal.instantiate()
|
||||
portal_effect.global_position = spawn_loc
|
||||
portal_effect.sprite_frames = portal_texture
|
||||
$/root/Node2D.add_child(portal_effect)
|
||||
await get_tree().create_timer(0.6).timeout
|
||||
var node = item.instantiate()
|
||||
node.global_position = spawn_loc
|
||||
node.rotation_degrees = 360 * randf()
|
||||
$/root/Node2D.add_child(node)
|
||||
var portal_effect = portal.instantiate()
|
||||
portal_effect.global_position = spawn_loc
|
||||
portal_effect.sprite_frames = item.portal_texture
|
||||
$/root/Node2D.add_child(portal_effect)
|
||||
await get_tree().create_timer(0.6).timeout
|
||||
var node = item.enemy.instantiate()
|
||||
node.global_position = spawn_loc
|
||||
node.rotation_degrees = 360 * randf()
|
||||
$/root/Node2D.add_child(node)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue