save work and menu

This commit is contained in:
2025-09-07 23:13:51 +02:00
parent 2dfa874181
commit 1290cd19fb
31 changed files with 647 additions and 4717 deletions

View File

@@ -15,7 +15,7 @@ var delay_dup := 0.0
func _ready() -> void:
add_to_group("asteroid")
SPEED = randf() / 50 +50
rotation = randf_range(0.0, 360.0)
func _process(delta: float) -> void:
@@ -47,8 +47,8 @@ func split():
second.direction = direction
first.global_position = position + (2**type * nor)
first.type = type-1
first.set_collision_layer(3)
second.set_collision_layer(3)
first.SPEED = SPEED
second.SPEED = SPEED
second.global_position = position - (2**type * nor)
second.type = type-1
var parent = get_parent()
@@ -65,4 +65,7 @@ func _on_body_entered(body: Node) -> void:
elif body.is_in_group("shoot"):
body.destroy = true
body.queue_free()
GameController.emit_signal("point_gain", type)
split()
elif body is Ship and !body.is_inv():
GameController.emit_signal("player_hit")

9
script/score.gd Normal file
View File

@@ -0,0 +1,9 @@
class_name Score
extends Resource
@export var score_singleplayer : Dictionary[String, int]
@export var score_multiplayer: Dictionary[String, int]
func save():
ResourceSaver.save(self, "user://Score.res")

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

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

23
script/score_saver.gd Normal file
View File

@@ -0,0 +1,23 @@
extends Node2D
var player_name := ""
@export var keyboard := ItemList
@export var label_name := Label
func _on_item_list_item_selected(index: int) -> void:
pass
func _on_item_list_item_activated(index: int) -> void:
var temp = $Control/ItemList.get_item_text(index)
print(temp)
var nbr = player_name.length()
if temp == "Back":
player_name[-1] = ""
elif temp == "Enter":
GameController.emit_signal("go_to_menu", player_name)
elif nbr < 10:
player_name += temp
nbr = player_name.length()
label_name.text = "Player Name " + str(nbr) +"/10:\n" + player_name

View File

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

View File

@@ -4,6 +4,8 @@ class_name Ship
@export var MAX_SPEED: float = 200
@export var SHOOT_NODE: PackedScene
@export var TIME_INVUL := 1.0
@export var animation : AnimationPlayer
const SPEED = 25.0
const JUMP_VELOCITY = -400.0
@@ -14,19 +16,22 @@ var vertical : float
var rota_temp: float
var delay := 0.0
var is_in = true
var delay_inv := 0.0
func _input(event):
pass
if event is InputEventMouseMotion:
mouse_position = event.position
func _ready() -> void:
delay_inv = TIME_INVUL +1
GameController.connect("player_hit", start_inv)
func _physics_process(delta: float) -> void:
delay += delta
if Input.is_action_pressed("ui_accept") and delay >= 0.5:
shoot()
delay = 0
if is_inv():
delay_inv += delta
animation.play("blink")
else:
animation.play("RESET")
horizontal = Input.get_axis("ui_up", "ui_down")
vertical = Input.get_axis("ui_left", "ui_right")
@@ -41,8 +46,12 @@ func _physics_process(delta: float) -> void:
velocity.y = move_toward(velocity.y, 0, SPEED)
if horizontal != 0 or vertical != 0:
direction = velocity
direction = Vector2(vertical, horizontal)
rotation = atan2(horizontal, vertical)
if Input.is_action_pressed("ui_accept") and delay >= 0.5:
shoot()
delay = 0
move_and_slide()
@@ -52,3 +61,10 @@ func shoot()->void:
new.direction = direction
new.position = position + (32 * direction.normalized())
get_parent().add_child(new)
func is_inv() -> bool:
return delay_inv <= TIME_INVUL
func start_inv()->void:
delay_inv = 0.0

View File

@@ -18,3 +18,8 @@ func _process(delta: float) -> void:
time += delta
if time >= 2:
self.queue_free()
func _on_body_entered(body: Node) -> void:
if body is Shoot:
self.queue_free()

View File

@@ -11,7 +11,7 @@ class_name Spawner
@export var load_screen:= false
var current_time := 0.0
var global_time := 0.0
signal add_collision
var list_of_collision_1 : Array[Node]
@@ -34,7 +34,8 @@ func _process(delta: float) -> void:
list_of_collision_1 = []
list_of_collision_2 = []
current_time += delta
if current_time >= delay_spawn and ((load_screen and get_children().size() < 10) or not load_screen):
global_time += delta
if current_time >= clampf(delay_spawn * (1- (global_time / 200)), 0.5, 100) and ((load_screen and get_children().size() < 10) or not load_screen):
current_time = 0
spawn()
@@ -43,6 +44,7 @@ func spawn_duplicate(asteroid: Node2D):
dup.type = asteroid.type
dup.is_in = false
var new_pos = (asteroid.position ).rotated(PI)
dup.SPEED = asteroid.SPEED
dup.position = new_pos
dup.rotation = asteroid.rotation
dup.direction = asteroid.direction
@@ -66,6 +68,7 @@ func spawn():
var new_global_position = Vector2(distance,0).rotated(randf_range(0.0, 360))
new.global_position = new_global_position
new.direction = (player.global_position - new_global_position).normalized()
new.SPEED = randf() * 50 + 50 * ( 1 + (global_time / 200))
add_child(new)

25
script/ui.gd Normal file
View File

@@ -0,0 +1,25 @@
extends CanvasLayer
@export var box_player1: HBoxContainer
@export var label_score: Label
var player_life:= 3
var score := 0
var time := 0.0
func _ready() -> void:
GameController.connect("player_hit", update_player)
GameController.connect("point_gain", update_score)
func _process(delta: float) -> void:
time += delta
func update_score(add : int)->void:
score += 2 ** (5-add) * (1 + (time / 100))
label_score.text = str(score)
func update_player() -> void:
player_life -= 1
if player_life < 0:
GameController.emit_signal("go_to_score_saver", score)
box_player1.get_children(false)[player_life].visible = false

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

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

View File

@@ -38,6 +38,7 @@ func _is_in_false(body: Node2D) -> void:
new_shoot.rotation = body.rotation
new_shoot.time = body.time
get_parent().call_deferred("add_child",new_shoot)
body.queue_free()
func _on_wall_destroy_body_entered(body: Node2D) -> void: