tp work and first steep for menu

This commit is contained in:
2025-09-07 16:05:59 +02:00
parent 6e599c8f1c
commit 2dfa874181
11 changed files with 4991 additions and 48 deletions

View File

@@ -11,7 +11,7 @@ config_version=5
[application] [application]
config/name="asteroid" config/name="asteroid"
run/main_scene="uid://btcb75wp78ory" run/main_scene="uid://jx8hrj6k1ju8"
config/features=PackedStringArray("4.4", "Forward Plus") config/features=PackedStringArray("4.4", "Forward Plus")
config/icon="res://icon.svg" config/icon="res://icon.svg"

102
scene/load_screen.tscn Normal file
View File

@@ -0,0 +1,102 @@
[gd_scene load_steps=6 format=3 uid="uid://jx8hrj6k1ju8"]
[ext_resource type="PackedScene" uid="uid://d1ugwu6dqomtg" path="res://scene/wall.tscn" id="1_7iavl"]
[ext_resource type="Theme" uid="uid://b46gto6k33wqr" path="res://theme.tres" id="3_7iavl"]
[ext_resource type="PackedScene" uid="uid://b6hqwxrexoa2n" path="res://scene/spawner.tscn" id="3_ruca2"]
[sub_resource type="GDScript" id="GDScript_pyuau"]
script/source = "extends Button
func _ready() -> void:
grab_focus()
"
[sub_resource type="GDScript" id="GDScript_7iavl"]
script/source = "extends Button
func _on_pressed() -> void:
get_tree().quit()
"
[node name="load_screen" type="Node2D"]
[node name="wall" parent="." node_paths=PackedStringArray("spawner") instance=ExtResource("1_7iavl")]
spawner = NodePath("../spawner")
[node name="Camera2D" type="Camera2D" parent="."]
[node name="spawner" parent="." node_paths=PackedStringArray("player") instance=ExtResource("3_ruca2")]
player = NodePath("../CharacterBody2D")
delay_spawn = 1.0
load_screen = true
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="Control" type="Control" parent="CanvasLayer"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/Control"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -75.5
offset_top = -55.0
offset_right = 75.5
offset_bottom = 55.0
grow_horizontal = 2
grow_vertical = 2
[node name="buttons" type="VBoxContainer" parent="CanvasLayer/Control/HBoxContainer"]
layout_mode = 2
alignment = 1
[node name="1" type="Button" parent="CanvasLayer/Control/HBoxContainer/buttons"]
layout_mode = 2
focus_next = NodePath("../2")
focus_previous = NodePath("../exit")
theme = ExtResource("3_7iavl")
text = "1 Player"
script = SubResource("GDScript_pyuau")
[node name="2" type="Button" parent="CanvasLayer/Control/HBoxContainer/buttons"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 0
focus_next = NodePath("../exit")
focus_previous = NodePath("../1")
theme = ExtResource("3_7iavl")
disabled = true
text = "2 Players"
[node name="exit" type="Button" parent="CanvasLayer/Control/HBoxContainer/buttons"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 0
focus_next = NodePath("../1")
focus_previous = NodePath("../2")
theme = ExtResource("3_7iavl")
text = "Exit"
script = SubResource("GDScript_7iavl")
[node name="scores" type="VBoxContainer" parent="CanvasLayer/Control/HBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="CanvasLayer/Control/HBoxContainer/scores"]
layout_mode = 2
[node name="Label2" type="Label" parent="CanvasLayer/Control/HBoxContainer/scores"]
layout_mode = 2
[connection signal="pressed" from="CanvasLayer/Control/HBoxContainer/buttons/exit" to="CanvasLayer/Control/HBoxContainer/buttons/exit" method="_on_pressed"]

View File

@@ -6,14 +6,13 @@
[node name="main_game" type="Node2D"] [node name="main_game" type="Node2D"]
[node name="wall" parent="." instance=ExtResource("1_u115g")] [node name="wall" parent="." node_paths=PackedStringArray("spawner") instance=ExtResource("1_u115g")]
spawner = NodePath("../spawner")
[node name="Camera2D" type="Camera2D" parent="."] [node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(320, 320) zoom = Vector2(0.375, 0.375)
[node name="CharacterBody2D" parent="." instance=ExtResource("2_02eqj")] [node name="CharacterBody2D" parent="." instance=ExtResource("2_02eqj")]
position = Vector2(156, 206)
[node name="spawner" parent="." node_paths=PackedStringArray("player") instance=ExtResource("3_50rem")] [node name="spawner" parent="." node_paths=PackedStringArray("player") instance=ExtResource("3_50rem")]
player = NodePath("../CharacterBody2D") player = NodePath("../CharacterBody2D")
distance = 500.0

View File

@@ -5,9 +5,10 @@
[ext_resource type="PackedScene" uid="uid://b1jtii12cqye1" path="res://scene/shoot.tscn" id="2_v4325"] [ext_resource type="PackedScene" uid="uid://b1jtii12cqye1" path="res://scene/shoot.tscn" id="2_v4325"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4cq66"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_4cq66"]
size = Vector2(16, 28)
[node name="CharacterBody2D" type="CharacterBody2D"] [node name="CharacterBody2D" type="CharacterBody2D"]
collision_layer = 3
collision_mask = 3
script = ExtResource("1_4cq66") script = ExtResource("1_4cq66")
SHOOT_NODE = ExtResource("2_v4325") SHOOT_NODE = ExtResource("2_v4325")

View File

@@ -1,57 +1,80 @@
[gd_scene load_steps=4 format=3 uid="uid://d1ugwu6dqomtg"] [gd_scene load_steps=5 format=3 uid="uid://d1ugwu6dqomtg"]
[ext_resource type="Script" uid="uid://b6422kdu30lo4" path="res://script/wall.gd" id="1_xxgf6"] [ext_resource type="Script" uid="uid://b6422kdu30lo4" path="res://script/wall.gd" id="1_xxgf6"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_oh6kn"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_oh6kn"]
size = Vector2(20, 640) size = Vector2(40, 680)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_xxgf6"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_xxgf6"]
size = Vector2(640, 20) size = Vector2(680, 40)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_80ewm"]
size = Vector2(630, 630)
[node name="wall" type="Node2D"] [node name="wall" type="Node2D"]
script = ExtResource("1_xxgf6") script = ExtResource("1_xxgf6")
[node name="ColorRect" type="ColorRect" parent="."] [node name="ColorRect" type="ColorRect" parent="."]
offset_right = 640.0 offset_left = -320.0
offset_bottom = 640.0 offset_top = -320.0
offset_right = 320.0
offset_bottom = 320.0
color = Color(0, 0, 0, 1) color = Color(0, 0, 0, 1)
[node name="StaticBody2D" type="StaticBody2D" parent="."] [node name="wall" type="Area2D" parent="."]
position = Vector2(-320, -320)
collision_layer = 2
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] [node name="CollisionShape2D" type="CollisionShape2D" parent="wall"]
position = Vector2(0, 320) position = Vector2(0, 320)
shape = SubResource("RectangleShape2D_oh6kn") shape = SubResource("RectangleShape2D_oh6kn")
[node name="CollisionShape2D2" type="CollisionShape2D" parent="StaticBody2D"] [node name="CollisionShape2D2" type="CollisionShape2D" parent="wall"]
position = Vector2(640, 320) position = Vector2(640, 320)
shape = SubResource("RectangleShape2D_oh6kn") shape = SubResource("RectangleShape2D_oh6kn")
[node name="CollisionShape2D3" type="CollisionShape2D" parent="StaticBody2D"] [node name="CollisionShape2D3" type="CollisionShape2D" parent="wall"]
position = Vector2(320, 0) position = Vector2(320, 0)
shape = SubResource("RectangleShape2D_xxgf6") shape = SubResource("RectangleShape2D_xxgf6")
[node name="CollisionShape2D4" type="CollisionShape2D" parent="StaticBody2D"] [node name="CollisionShape2D4" type="CollisionShape2D" parent="wall"]
position = Vector2(320, 640) position = Vector2(320, 640)
shape = SubResource("RectangleShape2D_xxgf6") shape = SubResource("RectangleShape2D_xxgf6")
[node name="Area2D" type="Area2D" parent="."] [node name="wall_destroy" type="Area2D" parent="."]
position = Vector2(-969, -963)
scale = Vector2(3, 3)
collision_layer = 2
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="wall_destroy"]
position = Vector2(0, 320)
shape = SubResource("RectangleShape2D_oh6kn")
[node name="CollisionShape2D2" type="CollisionShape2D" parent="wall_destroy"]
position = Vector2(640, 320)
shape = SubResource("RectangleShape2D_oh6kn")
[node name="CollisionShape2D3" type="CollisionShape2D" parent="wall_destroy"]
position = Vector2(320, 0)
shape = SubResource("RectangleShape2D_xxgf6")
[node name="CollisionShape2D4" type="CollisionShape2D" parent="wall_destroy"]
position = Vector2(320, 640)
shape = SubResource("RectangleShape2D_xxgf6")
[node name="in" type="Area2D" parent="."]
position = Vector2(-320, -320)
collision_layer = 3 collision_layer = 3
collision_mask = 3 collision_mask = 3
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] [node name="CollisionShape2D" type="CollisionShape2D" parent="in"]
position = Vector2(0, 320) position = Vector2(320, 320)
shape = SubResource("RectangleShape2D_oh6kn") shape = SubResource("RectangleShape2D_80ewm")
[node name="CollisionShape2D2" type="CollisionShape2D" parent="Area2D"] [connection signal="body_entered" from="wall" to="." method="_on_area_2d_body_entered"]
position = Vector2(640, 320) [connection signal="body_exited" from="wall" to="." method="_on_area_2d_body_exited"]
shape = SubResource("RectangleShape2D_oh6kn") [connection signal="body_entered" from="wall_destroy" to="." method="_on_wall_destroy_body_entered"]
[connection signal="body_entered" from="in" to="." method="_is_in_true"]
[node name="CollisionShape2D3" type="CollisionShape2D" parent="Area2D"] [connection signal="body_exited" from="in" to="." method="_is_in_false"]
position = Vector2(320, 0)
shape = SubResource("RectangleShape2D_xxgf6")
[node name="CollisionShape2D4" type="CollisionShape2D" parent="Area2D"]
position = Vector2(320, 640)
shape = SubResource("RectangleShape2D_xxgf6")
[connection signal="body_exited" from="Area2D" to="." method="_on_area_2d_body_exited"]

View File

@@ -3,6 +3,8 @@ extends RigidBody2D
var SPEED : float var SPEED : float
var direction : Vector2 var direction : Vector2
var type:= 1 var type:= 1
var is_in := false
var delay_dup := 0.0
@export var particles := load("res://scene/destroy.tscn") @export var particles := load("res://scene/destroy.tscn")
@@ -16,7 +18,10 @@ func _ready() -> void:
SPEED = randf() / 50 +50 SPEED = randf() / 50 +50
rotation = randf_range(0.0, 360.0) rotation = randf_range(0.0, 360.0)
func _process(_delta: float) -> void: func _process(delta: float) -> void:
if delay_dup < 1:
delay_dup += delta
linear_velocity = direction * SPEED linear_velocity = direction * SPEED
func split(): func split():
@@ -58,7 +63,6 @@ func _on_body_entered(body: Node) -> void:
if body.is_in_group("asteroid"): if body.is_in_group("asteroid"):
get_parent()._add_collision(body, self) get_parent()._add_collision(body, self)
elif body.is_in_group("shoot"): elif body.is_in_group("shoot"):
body.destroy = true
body.queue_free() body.queue_free()
split() split()
else:
direction = -direction

View File

@@ -1,5 +1,7 @@
extends CharacterBody2D extends CharacterBody2D
class_name Ship
@export var MAX_SPEED: float = 200 @export var MAX_SPEED: float = 200
@export var SHOOT_NODE: PackedScene @export var SHOOT_NODE: PackedScene
@@ -11,6 +13,7 @@ var horizontal : float
var vertical : float var vertical : float
var rota_temp: float var rota_temp: float
var delay := 0.0 var delay := 0.0
var is_in = true
func _input(event): func _input(event):
pass pass
@@ -47,5 +50,5 @@ func _physics_process(delta: float) -> void:
func shoot()->void: func shoot()->void:
var new = SHOOT_NODE.instantiate() var new = SHOOT_NODE.instantiate()
new.direction = direction new.direction = direction
new.position = position + (18 * direction.normalized()) new.position = position + (32 * direction.normalized())
get_parent().add_child(new) get_parent().add_child(new)

View File

@@ -1,6 +1,9 @@
extends RigidBody2D extends RigidBody2D
class_name Shoot
@export var SPEED : float = 100.0 @export var SPEED : float = 100.0
var destroy = false
var is_in := true
var direction: Vector2: var direction: Vector2:
set(val): set(val):
direction = val.normalized() * SPEED direction = val.normalized() * SPEED
@@ -13,5 +16,5 @@ func _process(delta: float) -> void:
linear_velocity = direction linear_velocity = direction
time += delta time += delta
#if time >= 2: if time >= 2:
# self.queue_free() self.queue_free()

View File

@@ -1,5 +1,6 @@
extends Node2D extends Node2D
class_name Spawner
@export var asteroidx1 : PackedScene @export var asteroidx1 : PackedScene
@export var asteroidx2 : PackedScene @export var asteroidx2 : PackedScene
@export var asteroidx3 : PackedScene @export var asteroidx3 : PackedScene
@@ -7,8 +8,9 @@ extends Node2D
@export var player : CharacterBody2D @export var player : CharacterBody2D
@export var distance:= 600.0 @export var distance:= 600.0
@export var delay_spawn := 3.0 @export var delay_spawn := 3.0
@export var load_screen:= false
var current_time := 50.0 var current_time := 0.0
signal add_collision signal add_collision
@@ -17,7 +19,7 @@ var list_of_collision_2 : Array[Node]
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
pass # Replace with function body. pass
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
@@ -32,14 +34,17 @@ func _process(delta: float) -> void:
list_of_collision_1 = [] list_of_collision_1 = []
list_of_collision_2 = [] list_of_collision_2 = []
current_time += delta current_time += delta
if current_time >= 2.0: if current_time >= delay_spawn and ((load_screen and get_children().size() < 10) or not load_screen):
current_time = 0 current_time = 0
spawn() spawn()
func spawn_duplicate(asteroid: Node2D): func spawn_duplicate(asteroid: Node2D):
var dup = asteroid.duplicate(DUPLICATE_USE_INSTANTIATION) var dup = asteroid.duplicate(DUPLICATE_USE_INSTANTIATION)
dup.currently_in = true dup.type = asteroid.type
dup.position = (asteroid.position - Vector2(320, 320)).rotated(PI) + Vector2(320, 320) dup.is_in = false
var new_pos = (asteroid.position ).rotated(PI)
dup.position = new_pos
dup.rotation = asteroid.rotation
dup.direction = asteroid.direction dup.direction = asteroid.direction
call_deferred("add_child", dup) call_deferred("add_child", dup)
@@ -58,7 +63,7 @@ func spawn():
elif choice == 4: elif choice == 4:
new = asteroidx4.instantiate() new = asteroidx4.instantiate()
new.type = 4 new.type = 4
var new_global_position = Vector2(distance,0).rotated(randf_range(0.0, 360)) + Vector2(320, 320) var new_global_position = Vector2(distance,0).rotated(randf_range(0.0, 360))
new.global_position = new_global_position new.global_position = new_global_position
new.direction = (player.global_position - new_global_position).normalized() new.direction = (player.global_position - new_global_position).normalized()
add_child(new) add_child(new)

View File

@@ -1,8 +1,44 @@
extends Node2D extends Node2D
@export var spawner : Spawner
var ship_scene = load("res://scene/ship.tscn")
var shoot_scene = load("res://scene/shoot.tscn")
func _on_area_2d_body_exited(body: Node2D) -> void: func _on_area_2d_body_exited(body: Node2D) -> void:
if body.is_in_group("asteroid") and not body.is_in and body.delay_dup > 0.5:
spawner.spawn_duplicate(body)
body.queue_free()
func _on_area_2d_body_entered(body: Node2D) -> void:
pass
func _is_in_true(body: Node2D) -> void:
if body.is_in_group("asteroid") or body is Ship:
body.is_in = true
func _is_in_false(body: Node2D) -> void:
if body.is_in_group("asteroid"): if body.is_in_group("asteroid"):
body.set_collision_layer(3) body.is_in = false
body.set_collision_mask(3) elif body is Ship:
body.is_in = false
var new_ship = ship_scene.instantiate()
new_ship.position = body.position.rotated(PI) *.95
new_ship.rotation = body.rotation
get_parent().call_deferred("add_child",new_ship)
spawner.player = new_ship
body.queue_free()
elif body is Shoot and not body.destroy:
body.is_in = false
var new_shoot = shoot_scene.instantiate()
new_shoot.position = body.position.rotated(PI)
new_shoot.direction = body.direction
new_shoot.rotation = body.rotation
new_shoot.time = body.time
get_parent().call_deferred("add_child",new_shoot)
func _on_wall_destroy_body_entered(body: Node2D) -> void:
body.queue_free()

4767
theme.tres Normal file

File diff suppressed because one or more lines are too long