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

61
script/asteroid.gd Normal file
View File

@@ -0,0 +1,61 @@
extends RigidBody2D
var SPEED : float
var direction : Vector2
var type:= 1
var is_firt_entree := true
@export var particles := load("res://destroy.tscn")
@export var asteroidx1 : = load("res://asteroidx1.tscn")
@export var asteroidx2 : = load("res://asteroidx2.tscn")
@export var asteroidx3 : = load("res://asteroidx3.tscn")
func _ready() -> void:
add_to_group("asteroid")
SPEED = randf() / 50 +50
rotation = randf_range(0.0, 360.0)
func _process(_delta: float) -> void:
linear_velocity = direction * SPEED
func split():
var packed_use: PackedScene
if type == 1:
var part = particles.instantiate()
part.global_position = global_position
get_parent().call_deferred("add_child", part)
queue_free()
return
elif type == 2:
packed_use = asteroidx1
elif type == 3:
packed_use = asteroidx2
elif type == 4:
packed_use = asteroidx3
var first = packed_use.instantiate()
var second = packed_use.instantiate()
var nor = direction.rotated(PI/2).normalized()
first.direction = direction
second.direction = direction
first.global_position = position + (2**type * nor)
first.type = type-1
second.global_position = position - (2**type * nor)
second.type = type-1
var parent = get_parent()
var part = particles.instantiate()
part.global_position = global_position
parent.call_deferred("add_child", first)
parent.call_deferred("add_child", second)
parent.call_deferred("add_child", part)
queue_free()
func _on_body_entered(body: Node) -> void:
if body.is_in_group("asteroid"):
get_parent().add_collision(body, self)
if body.is_in_group("shoot"):
body.queue_free()
split()

1
script/asteroid.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://b8a23hkmesx0l

14
script/destroy.gd Normal file
View File

@@ -0,0 +1,14 @@
extends CPUParticles2D
var time :=0.0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
emitting = true
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
time+=delta
if time >= 10:
queue_free()

1
script/destroy.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://bgbncoa145y1l

51
script/ship.gd Normal file
View File

@@ -0,0 +1,51 @@
extends CharacterBody2D
@export var MAX_SPEED: float = 200
@export var SHOOT_NODE: PackedScene
const SPEED = 25.0
const JUMP_VELOCITY = -400.0
var mouse_position: Vector2 = Vector2.ZERO
var direction :=Vector2(1,0)
var horizontal : float
var vertical : float
var rota_temp: float
var delay := 0.0
func _input(event):
pass
if event is InputEventMouseMotion:
mouse_position = event.position
func _physics_process(delta: float) -> void:
delay += delta
if Input.is_action_pressed("ui_accept") and delay >= 0.5:
shoot()
delay = 0
horizontal = Input.get_axis("ui_up", "ui_down")
vertical = Input.get_axis("ui_left", "ui_right")
if vertical != 0:
velocity.x = move_toward(velocity.x, MAX_SPEED * vertical, SPEED)
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if horizontal != 0:
velocity.y = move_toward(velocity.y, MAX_SPEED * horizontal, SPEED)
else:
velocity.y = move_toward(velocity.y, 0, SPEED)
if horizontal != 0 or vertical != 0:
direction = velocity
rotation = atan2(horizontal, vertical)
move_and_slide()
func shoot()->void:
var new = SHOOT_NODE.instantiate()
new.direction = direction
new.position = position + (18 * direction.normalized())
get_parent().add_child(new)

1
script/ship.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://c3i2bhlectmoo

17
script/shoot.gd Normal file
View File

@@ -0,0 +1,17 @@
extends RigidBody2D
@export var SPEED : float = 100.0
var direction: Vector2:
set(val):
direction = val.normalized() * SPEED
var time := 0.0
func _ready() -> void:
add_to_group("shoot")
func _process(delta: float) -> void:
linear_velocity = direction
time += delta
#if time >= 2:
# self.queue_free()

1
script/shoot.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://dsd0opfd8kyow

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)

1
script/spawner.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://bclp1tkc2npvv

7
script/wall.gd Normal file
View File

@@ -0,0 +1,7 @@
extends Node2D
@export var spawner: Node2D
func _body_entered_for_multiple(body: Node2D) -> void:
if body.is_in_group("asteroid") and body.get("is_firt_entree") == false:
spawner.spawn()

1
script/wall.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://b6422kdu30lo4