rearengement

This commit is contained in:
2025-09-04 17:55:05 +02:00
parent 1913038265
commit fd67adacc9
23 changed files with 475 additions and 0 deletions

71
script/spawner.gd Normal file
View File

@@ -0,0 +1,71 @@
extends Node2D
@export var asteroidx1 : PackedScene
@export var asteroidx2 : PackedScene
@export var asteroidx3 : PackedScene
@export var asteroidx4 : PackedScene
@export var player : CharacterBody2D
@export var distance:= 600.0
var current_time := 0.0
var list_of_collision_1 : Array[Node]
var list_of_collision_2 : Array[Node]
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
var tmp : Vector2
for i in range(list_of_collision_1.size()):
if list_of_collision_1[i] and list_of_collision_2[i]:
var normal_vec = (list_of_collision_1[i].position - list_of_collision_2[i].position).normalized()
tmp = list_of_collision_1[i].direction
list_of_collision_1[i].direction = (list_of_collision_2[i].direction + normal_vec).normalized()
list_of_collision_2[i].direction = (tmp - normal_vec).normalized()
list_of_collision_1 = []
list_of_collision_2 = []
current_time += delta
if current_time >= 2.0:
current_time = 0
spawn()
func spawn_duplicate(asteroid: Node2D):
var dup = asteroid.duplicate()
dup.position = (asteroid.position - Vector2(320, 320)).rotated(PI/2) + Vector2(320, 320)
dup.direction = (asteroid.direction - Vector2(320, 320)).rotated(PI/2) + Vector2(320, 320)
add_child(dup)
func spawn():
var choice = randi_range(1, 4)
var new
if choice == 1:
new = asteroidx1.instantiate()
new.type = 1
elif choice == 2:
new = asteroidx2.instantiate()
new.type = 2
elif choice == 3:
new = asteroidx3.instantiate()
new.type = 3
elif choice == 4:
new = asteroidx4.instantiate()
new.type = 4
var new_global_position = Vector2(distance,0).rotated(randf_range(0.0, 360)) + Vector2(320, 320)
new.global_position = new_global_position
new.direction = (player.global_position - new_global_position).normalized()
add_child(new)
func add_collision(body1 : Node, body2: Node) -> void:
for i in range(list_of_collision_1.size()):
if list_of_collision_1[i] == body1 and list_of_collision_2[i]== body2:
return
if list_of_collision_1[i] == body2 and list_of_collision_2[i] == body1:
return
list_of_collision_1.append(body1)
list_of_collision_2.append(body2)