Game over screen
This commit is contained in:
parent
9028ec47cc
commit
7688cdabd2
|
|
@ -4,6 +4,9 @@ extends Area2D
|
||||||
@export var score : int = 0
|
@export var score : int = 0
|
||||||
@export var bullet_scene: PackedScene
|
@export var bullet_scene: PackedScene
|
||||||
|
|
||||||
|
@export var life_max : float = 30
|
||||||
|
@onready var life : float = life_max
|
||||||
|
|
||||||
var screen_size
|
var screen_size
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
|
@ -30,12 +33,20 @@ func _process(delta: float) -> void:
|
||||||
#position = position.clamp(Vector2.ZERO, screen_size)
|
#position = position.clamp(Vector2.ZERO, screen_size)
|
||||||
|
|
||||||
func _on_shoot_timer_timeout():
|
func _on_shoot_timer_timeout():
|
||||||
_shoot(Vector2(0, 80))
|
_shoot(Vector2(0, 40))
|
||||||
_shoot(Vector2(0, -80))
|
_shoot(Vector2(0, -40))
|
||||||
|
|
||||||
func _shoot(socket : Vector2):
|
func _shoot(socket : Vector2):
|
||||||
var bullet = bullet_scene.instantiate()
|
var bullet = bullet_scene.instantiate()
|
||||||
bullet.position = position + socket.rotated(self.rotation)
|
bullet.position = position + socket.rotated(self.rotation)
|
||||||
bullet.rotation = self.rotation + PI/2 * sign(socket.y)
|
bullet.rotation = self.rotation + PI/2 * sign(socket.y)
|
||||||
|
bullet.instigator = self
|
||||||
get_parent().add_child(bullet)
|
get_parent().add_child(bullet)
|
||||||
|
|
||||||
|
func take_damage(damage : float):
|
||||||
|
life -= damage
|
||||||
|
if life <= 0:
|
||||||
|
#get_tree().reload_current_scene()
|
||||||
|
get_tree().paused = true
|
||||||
|
$GameOverScreen.show()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
[gd_scene load_steps=7 format=3 uid="uid://ifus76ia8xws"]
|
[gd_scene load_steps=8 format=3 uid="uid://ifus76ia8xws"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://83sv1yu3pkya" path="res://Characters/Ships/player_ship.png" id="1_5mj4t"]
|
[ext_resource type="Texture2D" uid="uid://83sv1yu3pkya" path="res://Characters/Ships/player_ship.png" id="1_5mj4t"]
|
||||||
[ext_resource type="Script" uid="uid://doegfk88vnwo1" path="res://Characters/player.gd" id="1_eovys"]
|
[ext_resource type="Script" uid="uid://doegfk88vnwo1" path="res://Characters/player.gd" id="1_eovys"]
|
||||||
[ext_resource type="PackedScene" uid="uid://ngrscx1l0dn5" path="res://GPE/CannonBall/cannon_ball.tscn" id="2_65n15"]
|
[ext_resource type="PackedScene" uid="uid://ngrscx1l0dn5" path="res://GPE/CannonBall/cannon_ball.tscn" id="2_65n15"]
|
||||||
[ext_resource type="PackedScene" uid="uid://c2pruida0t5o0" path="res://Player/hud.tscn" id="3_vb825"]
|
[ext_resource type="PackedScene" uid="uid://c2pruida0t5o0" path="res://Player/hud.tscn" id="3_vb825"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://bu4cvy8wdnt54" path="res://Player/game_over_screen.tscn" id="5_l48on"]
|
||||||
|
|
||||||
[sub_resource type="SpriteFrames" id="SpriteFrames_eovys"]
|
[sub_resource type="SpriteFrames" id="SpriteFrames_eovys"]
|
||||||
animations = [{
|
animations = [{
|
||||||
|
|
@ -33,7 +34,7 @@ sprite_frames = SubResource("SpriteFrames_eovys")
|
||||||
rotation = -1.5707964
|
rotation = -1.5707964
|
||||||
shape = SubResource("CapsuleShape2D_vb825")
|
shape = SubResource("CapsuleShape2D_vb825")
|
||||||
|
|
||||||
[node name="CanvasLayer" parent="." instance=ExtResource("3_vb825")]
|
[node name="HUD" parent="." instance=ExtResource("3_vb825")]
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
drag_horizontal_enabled = true
|
drag_horizontal_enabled = true
|
||||||
|
|
@ -41,3 +42,5 @@ drag_vertical_enabled = true
|
||||||
|
|
||||||
[node name="ShootTimer" type="Timer" parent="."]
|
[node name="ShootTimer" type="Timer" parent="."]
|
||||||
autostart = true
|
autostart = true
|
||||||
|
|
||||||
|
[node name="GameOverScreen" parent="." instance=ExtResource("5_l48on")]
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,22 @@ extends Area2D
|
||||||
@export var speed: float = 200.0
|
@export var speed: float = 200.0
|
||||||
@export var damage: int = 10
|
@export var damage: int = 10
|
||||||
|
|
||||||
|
var instigator
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
# Déplace la balle dans la direction de sa rotation
|
# Déplace la balle dans la direction de sa rotation
|
||||||
#var velocity = Vector2(speed, 0).rotated(rotation)
|
#var velocity = Vector2(speed, 0).rotated(rotation)
|
||||||
connect("body_entered", _on_body_entered)
|
connect("body_entered", _on_body_entered)
|
||||||
|
connect("area_entered", _on_body_entered)
|
||||||
|
$LifetimeTimer.timeout.connect(_on_lifetime_expired)
|
||||||
|
|
||||||
func _physics_process(delta: float):
|
func _physics_process(delta: float):
|
||||||
position += Vector2(speed, 0).rotated(rotation) * delta
|
position += Vector2(speed, 0).rotated(rotation) * delta
|
||||||
|
|
||||||
func _on_body_entered(body):
|
func _on_body_entered(body):
|
||||||
if body.has_method("take_damage"):
|
if body.has_method("take_damage") and instigator != body:
|
||||||
body.take_damage(damage)
|
body.take_damage(damage)
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|
||||||
|
func _on_lifetime_expired():
|
||||||
|
queue_free()
|
||||||
|
|
|
||||||
|
|
@ -14,3 +14,7 @@ shape = SubResource("CircleShape2D_u2lho")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
texture = ExtResource("1_f08vj")
|
texture = ExtResource("1_f08vj")
|
||||||
|
|
||||||
|
[node name="LifetimeTimer" type="Timer" parent="."]
|
||||||
|
wait_time = 3.0
|
||||||
|
autostart = true
|
||||||
|
|
|
||||||
13
Player/game_over_screen.gd
Normal file
13
Player/game_over_screen.gd
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
extends CanvasLayer
|
||||||
|
|
||||||
|
@onready var RestartButton = $ColorRect/VBoxContainer/RestartButton
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
RestartButton.pressed.connect(_on_restart_pressed)
|
||||||
|
hide()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_restart_pressed():
|
||||||
|
get_tree().paused = false
|
||||||
|
get_tree().reload_current_scene()
|
||||||
1
Player/game_over_screen.gd.uid
Normal file
1
Player/game_over_screen.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://2336s7ck60n5
|
||||||
61
Player/game_over_screen.tscn
Normal file
61
Player/game_over_screen.tscn
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
[gd_scene load_steps=4 format=3 uid="uid://bu4cvy8wdnt54"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://2336s7ck60n5" path="res://Player/game_over_screen.gd" id="1_bltct"]
|
||||||
|
[ext_resource type="Theme" uid="uid://ctsajyu6uieal" path="res://Player/widgets/game_theme.tres" id="1_pm5wk"]
|
||||||
|
|
||||||
|
[sub_resource type="LabelSettings" id="LabelSettings_bltct"]
|
||||||
|
font_size = 32
|
||||||
|
outline_size = 3
|
||||||
|
outline_color = Color(0.511324, 0.2294738, 0, 1)
|
||||||
|
shadow_size = 6
|
||||||
|
shadow_color = Color(0, 0, 0, 1)
|
||||||
|
|
||||||
|
[node name="GameOverScreen" type="CanvasLayer"]
|
||||||
|
process_mode = 2
|
||||||
|
script = ExtResource("1_bltct")
|
||||||
|
|
||||||
|
[node name="ColorRect" type="ColorRect" parent="."]
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
offset_left = 4.0
|
||||||
|
offset_top = -4.0
|
||||||
|
offset_right = 4.0
|
||||||
|
offset_bottom = -4.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
color = Color(0, 0, 0, 0.3137255)
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="ColorRect"]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 8
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
offset_left = -46.0
|
||||||
|
offset_top = -20.0
|
||||||
|
offset_right = 58.0
|
||||||
|
offset_bottom = 10.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="ColorRect/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "GAME OVER"
|
||||||
|
label_settings = SubResource("LabelSettings_bltct")
|
||||||
|
|
||||||
|
[node name="HSeparator" type="HSeparator" parent="ColorRect/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="RestartButton" type="Button" parent="ColorRect/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme = ExtResource("1_pm5wk")
|
||||||
|
text = "Restart
|
||||||
|
"
|
||||||
|
|
||||||
|
[node name="MainMenuButton" type="Button" parent="ColorRect/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme = ExtResource("1_pm5wk")
|
||||||
|
text = "Main Menu
|
||||||
|
"
|
||||||
|
|
@ -11,8 +11,12 @@ func _process(_delta: float) -> void:
|
||||||
#var player = get_parent().get_node("player")
|
#var player = get_parent().get_node("player")
|
||||||
var player = get_parent()
|
var player = get_parent()
|
||||||
update_score(player.score)
|
update_score(player.score)
|
||||||
|
update_life(player.life / player.life_max * 100.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func update_score(score: int) -> void:
|
func update_score(score: int) -> void:
|
||||||
$ScoreLabel.text = "Score: " + str(score)
|
$ScoreLabel.text = "Score: " + str(score)
|
||||||
|
|
||||||
|
func update_life(life_percentage : float):
|
||||||
|
$LifeProgressBar.value = life_percentage
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://cmkaxwj67x6o4" path="res://Player/hud.gd" id="1_ns4kc"]
|
[ext_resource type="Script" uid="uid://cmkaxwj67x6o4" path="res://Player/hud.gd" id="1_ns4kc"]
|
||||||
|
|
||||||
[node name="CanvasLayer" type="CanvasLayer"]
|
[node name="Hud" type="CanvasLayer"]
|
||||||
script = ExtResource("1_ns4kc")
|
script = ExtResource("1_ns4kc")
|
||||||
|
|
||||||
[node name="ScoreLabel" type="Label" parent="."]
|
[node name="ScoreLabel" type="Label" parent="."]
|
||||||
|
|
@ -11,3 +11,12 @@ anchor_right = 1.0
|
||||||
offset_bottom = 23.0
|
offset_bottom = 23.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
text = "Score:"
|
text = "Score:"
|
||||||
|
|
||||||
|
[node name="LifeProgressBar" type="ProgressBar" parent="."]
|
||||||
|
anchors_preset = 2
|
||||||
|
anchor_top = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
offset_top = -27.0
|
||||||
|
offset_right = 235.0
|
||||||
|
grow_vertical = 0
|
||||||
|
rounded = true
|
||||||
|
|
|
||||||
7
Player/widgets/button_ui_atlas.tres
Normal file
7
Player/widgets/button_ui_atlas.tres
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://rmwiww4alman"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://5dvacveeuaef" path="res://Player/widgets/spritesheet-double.png" id="1_lby2n"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
atlas = ExtResource("1_lby2n")
|
||||||
|
region = Rect2(768.0559, -0.000233531, 128.0304, 128.29752)
|
||||||
1243
Player/widgets/game_theme.tres
Normal file
1243
Player/widgets/game_theme.tres
Normal file
File diff suppressed because one or more lines are too long
BIN
Player/widgets/spritesheet-double.png
Normal file
BIN
Player/widgets/spritesheet-double.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 95 KiB |
40
Player/widgets/spritesheet-double.png.import
Normal file
40
Player/widgets/spritesheet-double.png.import
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://5dvacveeuaef"
|
||||||
|
path="res://.godot/imported/spritesheet-double.png-e59a887731eae35a20be130d358e60d4.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://Player/widgets/spritesheet-double.png"
|
||||||
|
dest_files=["res://.godot/imported/spritesheet-double.png-e59a887731eae35a20be130d358e60d4.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
Loading…
Reference in New Issue
Block a user