This commit is contained in:
2025-09-08 14:49:21 +02:00
parent 1290cd19fb
commit 9ee0d4708b
10 changed files with 54 additions and 33 deletions

View File

@@ -33,8 +33,12 @@ func start_two_player()->void:
func start_menu(user_name : String)->void: func start_menu(user_name : String)->void:
printt(user_name, actual_score) printt(user_name, actual_score)
if is_multiplayer: if is_multiplayer:
var temp = score.score_multiplayer.get_or_add(user_name, 0.0)
if temp < actual_score:
score.score_multiplayer[user_name] = actual_score score.score_multiplayer[user_name] = actual_score
else: else:
var temp = score.score_singleplayer.get_or_add(user_name, 0.0)
if temp < actual_score:
score.score_singleplayer[user_name] = actual_score score.score_singleplayer[user_name] = actual_score
user_name = "" user_name = ""
actual_score = 0 actual_score = 0

View File

@@ -18,3 +18,4 @@ texture = ExtResource("1_u87q6")
polygon = PackedVector2Array(12, -1, 6, -6, 5, -13, -8, -12, -12, -5, -12, 4, -6, 13, -2, 10, 2, 14, 12, 3) polygon = PackedVector2Array(12, -1, 6, -6, 5, -13, -8, -12, -12, -5, -12, 4, -6, 13, -2, 10, 2, 14, 12, 3)
[connection signal="body_entered" from="." to="." method="_on_body_entered"] [connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_body_exited"]

View File

@@ -18,3 +18,4 @@ texture = ExtResource("2_e2m2r")
polygon = PackedVector2Array(16, -23, 3, -29, -11, -27, -22, -12, -27, 2, -25, 21, -6, 30, 17, 23, 23, 10, 29, 1, 20, -8) polygon = PackedVector2Array(16, -23, 3, -29, -11, -27, -22, -12, -27, 2, -25, 21, -6, 30, 17, 23, 23, 10, 29, 1, 20, -8)
[connection signal="body_entered" from="." to="." method="_on_body_entered"] [connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_body_exited"]

View File

@@ -18,3 +18,4 @@ texture = ExtResource("2_beklf")
polygon = PackedVector2Array(23, 10, 36, -11, 22, -32, 8, -43, -32, -40, -40, -25, -43, 1, -40, 23, -24, 41, 3, 43, 38, 19) polygon = PackedVector2Array(23, 10, 36, -11, 22, -32, 8, -43, -32, -40, -40, -25, -43, 1, -40, 23, -24, 41, 3, 43, 38, 19)
[connection signal="body_entered" from="." to="." method="_on_body_entered"] [connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_body_exited"]

View File

@@ -18,3 +18,4 @@ texture = ExtResource("2_gv6mu")
polygon = PackedVector2Array(55, 3, 35, -20, 34, -40, 1, -49, -35, -52, -55, -29, -58, -1, -48, 30, -22, 53, 13, 58, 40, 30) polygon = PackedVector2Array(55, 3, 35, -20, 34, -40, 1, -49, -35, -52, -55, -29, -58, -1, -48, 30, -22, 53, 13, 58, 40, 30)
[connection signal="body_entered" from="." to="." method="_on_body_entered"] [connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_body_exited"]

View File

@@ -43,8 +43,9 @@ func _ready() -> void:
# Trier par ordre alphabétique # Trier par ordre alphabétique
tableau_paires.sort_custom(func(a, b): return a[\"value\"] > b[\"value\"]) tableau_paires.sort_custom(func(a, b): return a[\"value\"] > b[\"value\"])
text += \"1 Player\"
for i in range(clamp(5, 0, tableau_paires.size())): for i in range(clamp(5, 0, tableau_paires.size())):
text += tableau_paires[i][\"key\"] + \" : \" + str(tableau_paires[i][\"value\"]) + \"\\n\" text += \"\\n\" + tableau_paires[i][\"key\"] + \" : \" + str(tableau_paires[i][\"value\"])
" "
[sub_resource type="GDScript" id="GDScript_u3kfb"] [sub_resource type="GDScript" id="GDScript_u3kfb"]
@@ -57,8 +58,9 @@ func _ready() -> void:
# Trier par ordre alphabétique # Trier par ordre alphabétique
tableau_paires.sort_custom(func(a, b): return a[\"value\"] < b[\"value\"]) tableau_paires.sort_custom(func(a, b): return a[\"value\"] < b[\"value\"])
text += \"2 Players\"
for i in range(clamp(5, 0, tableau_paires.size())): for i in range(clamp(5, 0, tableau_paires.size())):
text += tableau_paires[i][\"key\"] + \" : \" + str(tableau_paires[i][\"value\"]) + \"\\n\" text += \"\\n\" + tableau_paires[i][\"key\"] + \" : \" + str(tableau_paires[i][\"value\"])
" "
[node name="load_screen" type="Node2D"] [node name="load_screen" type="Node2D"]

View File

@@ -1,10 +1,23 @@
[gd_scene load_steps=8 format=3 uid="uid://36q833dx6dmq"] [gd_scene load_steps=7 format=3 uid="uid://36q833dx6dmq"]
[ext_resource type="Script" uid="uid://c3i2bhlectmoo" path="res://script/ship.gd" id="1_4cq66"] [ext_resource type="Script" uid="uid://c3i2bhlectmoo" path="res://script/ship.gd" id="1_4cq66"]
[ext_resource type="Texture2D" uid="uid://b037piy3tkefs" path="res://assets/ship.png" id="1_l3rv8"] [ext_resource type="Texture2D" uid="uid://b037piy3tkefs" path="res://assets/ship.png" id="1_l3rv8"]
[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="Animation" id="Animation_fbih1"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Ship:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 1)]
}
[sub_resource type="Animation" id="Animation_bf7x5"] [sub_resource type="Animation" id="Animation_bf7x5"]
resource_name = "blink" resource_name = "blink"
@@ -22,36 +35,18 @@ tracks/0/keys = {
"values": [Color(1, 1, 1, 1), Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 0), Color(1, 1, 1, 1)] "values": [Color(1, 1, 1, 1), Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 0), Color(1, 1, 1, 1)]
} }
[sub_resource type="Animation" id="Animation_fbih1"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Ship:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 1)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_l7n8u"] [sub_resource type="AnimationLibrary" id="AnimationLibrary_l7n8u"]
_data = { _data = {
&"RESET": SubResource("Animation_fbih1"), &"RESET": SubResource("Animation_fbih1"),
&"blink": SubResource("Animation_bf7x5") &"blink": SubResource("Animation_bf7x5")
} }
[node name="CharacterBody2D" type="CharacterBody2D" node_paths=PackedStringArray("animation")] [node name="CharacterBody2D" type="CharacterBody2D" node_paths=PackedStringArray("animation", "target")]
script = ExtResource("1_4cq66") script = ExtResource("1_4cq66")
SHOOT_NODE = ExtResource("2_v4325") SHOOT_NODE = ExtResource("2_v4325")
TIME_INVUL = 2.0 TIME_INVUL = 2.0
animation = NodePath("AnimationPlayer") animation = NodePath("AnimationPlayer")
target = NodePath("Node2D")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
rotation = 1.5708
shape = SubResource("RectangleShape2D_4cq66")
[node name="Ship" type="Sprite2D" parent="."] [node name="Ship" type="Sprite2D" parent="."]
texture_filter = 1 texture_filter = 1
@@ -62,3 +57,9 @@ texture = ExtResource("1_l3rv8")
libraries = { libraries = {
&"": SubResource("AnimationLibrary_l7n8u") &"": SubResource("AnimationLibrary_l7n8u")
} }
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
polygon = PackedVector2Array(14, 2, 14, -2, -9, -10, -13, -10, -14, -9, -14, 8, -13, 9, -9, 9)
[node name="Node2D" type="Node2D" parent="."]
position = Vector2(15, 0)

View File

@@ -68,4 +68,10 @@ func _on_body_entered(body: Node) -> void:
GameController.emit_signal("point_gain", type) GameController.emit_signal("point_gain", type)
split() split()
elif body is Ship and !body.is_inv(): elif body is Ship and !body.is_inv():
GameController.emit_signal("player_hit") body.is_currently_hit = true
#GameController.emit_signal("player_hit")
func _on_body_exited(body: Node) -> void:
if body is Ship:
body.is_currently_hit = false

View File

@@ -11,11 +11,10 @@ func _on_item_list_item_selected(index: int) -> void:
func _on_item_list_item_activated(index: int) -> void: func _on_item_list_item_activated(index: int) -> void:
var temp = $Control/ItemList.get_item_text(index) var temp = $Control/ItemList.get_item_text(index)
print(temp)
var nbr = player_name.length() var nbr = player_name.length()
if temp == "Back": if temp == "Back":
player_name[-1] = "" player_name[-1] = ""
elif temp == "Enter": elif temp == "Enter" and player_name.length() > 0:
GameController.emit_signal("go_to_menu", player_name) GameController.emit_signal("go_to_menu", player_name)
elif nbr < 10: elif nbr < 10:
player_name += temp player_name += temp

View File

@@ -6,6 +6,7 @@ class_name Ship
@export var SHOOT_NODE: PackedScene @export var SHOOT_NODE: PackedScene
@export var TIME_INVUL := 1.0 @export var TIME_INVUL := 1.0
@export var animation : AnimationPlayer @export var animation : AnimationPlayer
@export var target : Node2D
const SPEED = 25.0 const SPEED = 25.0
const JUMP_VELOCITY = -400.0 const JUMP_VELOCITY = -400.0
@@ -17,6 +18,7 @@ var rota_temp: float
var delay := 0.0 var delay := 0.0
var is_in = true var is_in = true
var delay_inv := 0.0 var delay_inv := 0.0
var is_currently_hit := false
func _input(event): func _input(event):
pass pass
@@ -47,19 +49,22 @@ func _physics_process(delta: float) -> void:
if horizontal != 0 or vertical != 0: if horizontal != 0 or vertical != 0:
direction = Vector2(vertical, horizontal) direction = Vector2(vertical, horizontal)
rotation = atan2(horizontal, vertical) rotation = rotate_toward(rotation ,atan2(horizontal, vertical), 0.5)
if Input.is_action_pressed("ui_accept") and delay >= 0.5: if Input.is_action_pressed("ui_accept") and delay >= 0.5:
shoot() shoot()
delay = 0 delay = 0
if !is_inv() and is_currently_hit:
GameController.emit_signal("player_hit")
move_and_slide() move_and_slide()
func shoot()->void: func shoot()->void:
var new = SHOOT_NODE.instantiate() var new = SHOOT_NODE.instantiate()
new.direction = direction new.direction = (target.global_position - global_position).normalized()
new.position = position + (32 * direction.normalized()) new.position = target.global_position
get_parent().add_child(new) get_parent().add_child(new)