HealthBar

pull/26/head
Sascha 2023-10-30 22:02:18 +07:00
parent fd2c37f30b
commit 95710fc450
6 changed files with 113 additions and 7 deletions

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 100 125" enable-background="new 0 0 100 100" xml:space="preserve"><g><path d="M50.7,59.2c0.4,0,0.9-0.1,1.2-0.3l16.3-7.7c1.4-0.7,2-2.4,1.3-3.8l-0.7-1.5c-0.5-1-1.5-1.6-2.6-1.6c-0.4,0-0.9,0.1-1.3,0.3 l-12.2,5.7l-5.8-12.1c-0.5-1-1.5-1.6-2.6-1.6c-0.4,0-0.9,0.1-1.3,0.3l-1.5,0.7c-1.4,0.7-2,2.4-1.3,3.8L48,57.6 C48.5,58.5,49.6,59.2,50.7,59.2z"/><path d="M88.7,42.1C86.1,30,73.5,17.5,61.3,14.8c-2.7-0.6-5.4-0.9-8.1-0.9c-0.3,0-0.7,0-1,0c-17.7,0.5-32.8,14.1-34.9,31.8 l-0.1,0.4h-4.5c-0.8,0-1.3,0.5-1.5,1c-0.3,0.6-0.5,1.6,0,2.6l8,9.4c0.9,1,2.1,1.6,3.3,1.6c1.2,0,2.4-0.6,3.3-1.6l7.7-9.2 c0,0,0.1-0.1,0.1-0.1c0.1-0.1,0.1-0.1,0.2-0.2c0,0,0.1-0.1,0.1-0.1c0.5-0.9,0.3-1.9,0-2.5c-0.4-0.7-1-1.1-1.6-1.1h-4.9l0.1-0.6 c2.2-12.2,12.3-21,24.7-21.4c0.3,0,0.6,0,1,0h0.4c14,0.2,25.6,11.8,25.8,25.8c0.1,7-2.6,13.7-7.5,18.7c-5,5-11.6,7.8-18.7,7.8h-2.3 c-1.4,0-2.6,1.2-2.6,2.6v5.1c0,1.4,1.2,2.6,2.6,2.6h2.5c11,0,21.3-4.9,28.2-13.4C88.5,64.4,91.1,53.2,88.7,42.1z"/></g><text x="0" y="115" fill="#000000" font-size="5px" font-weight="bold" font-family="'Helvetica Neue', Helvetica, Arial-Unicode, Arial, Sans-serif">Created by Luis Rodrigues</text><text x="0" y="120" fill="#000000" font-size="5px" font-weight="bold" font-family="'Helvetica Neue', Helvetica, Arial-Unicode, Arial, Sans-serif">from the Noun Project</text></svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b8gy1u2i0jkyd"
path="res://.godot/imported/restart.svg-98c792bd948b9b683b245e78c0930bfc.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Images/restart.svg"
dest_files=["res://.godot/imported/restart.svg-98c792bd948b9b683b245e78c0930bfc.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
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/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
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

@ -13,7 +13,7 @@
[sub_resource type="SphereShape3D" id="SphereShape3D_330dr"]
radius = 0.87
[node name="PlayerShip" type="Node3D" node_paths=PackedStringArray("cpulaser", "gpulaser", "jet", "PlayerRb", "shots")]
[node name="PlayerShip" type="Node3D" node_paths=PackedStringArray("cpulaser", "gpulaser", "jet", "PlayerRb", "shots", "healthBar")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74227e-08, 0, -1, 0, 0, 0)
script = ExtResource("1_cpbf1")
cpulaser = NodePath("RigidBody3D/CollisionShape3D/LaserBeamParticles/CPUParticles3D")
@ -23,6 +23,7 @@ jet = NodePath("RigidBody3D/CollisionShape3D/Jet")
laser = ExtResource("9_kbdnc")
PlayerRb = NodePath("RigidBody3D")
shots = NodePath("Shots")
healthBar = NodePath("ProgressBar")
[node name="RigidBody3D" type="RigidBody3D" parent="."]
mass = 100.0
@ -85,3 +86,23 @@ radius = 0.88
current = true
[node name="Shots" type="Node3D" parent="."]
[node name="ProgressBar" type="ProgressBar" parent="."]
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -238.0
offset_top = -1241.0
offset_right = 251.0
offset_bottom = -1214.0
grow_horizontal = 2
grow_vertical = 0
size_flags_horizontal = 4
size_flags_vertical = 8
max_value = 10.0
step = 1.0
value = 7.0
rounded = true
show_percentage = false

@ -1,4 +1,4 @@
[gd_scene load_steps=16 format=3 uid="uid://det8556rpxhbv"]
[gd_scene load_steps=19 format=3 uid="uid://det8556rpxhbv"]
[ext_resource type="PackedScene" uid="uid://tlr55u0gn20l" path="res://Packed-Scenes/PlayerShip.tscn" id="1_njb5h"]
[ext_resource type="Texture2D" uid="uid://cg6n1hh3lj7rn" path="res://Textures/tile_nebula_green_dff.png" id="2_43vix"]
@ -14,9 +14,17 @@
[ext_resource type="AudioStream" uid="uid://bspwjmgsoxkbn" path="res://Sounds/gameover2.wav" id="9_rtdps"]
[ext_resource type="AudioStream" uid="uid://dlml6o3xscxqf" path="res://Sounds/weapon_player.wav" id="11_bbedd"]
[ext_resource type="Script" path="res://Scripts/GameArea.cs" id="11_p0rh7"]
[ext_resource type="Texture2D" uid="uid://b8gy1u2i0jkyd" path="res://Images/restart.svg" id="15_nxptg"]
[sub_resource type="BoxShape3D" id="BoxShape3D_bw288"]
[sub_resource type="InputEventKey" id="InputEventKey_gjrl7"]
device = -1
keycode = 4194309
[sub_resource type="Shortcut" id="Shortcut_soxs4"]
events = [SubResource("InputEventKey_gjrl7")]
[node name="SpaceShooter" type="Node3D"]
[node name="PlayerShip" parent="." instance=ExtResource("1_njb5h")]
@ -95,8 +103,9 @@ stream = ExtResource("9_rtdps")
[node name="LaserSound" type="AudioStreamPlayer3D" parent="SoundManager"]
stream = ExtResource("11_bbedd")
[node name="GameManager" type="Node" parent="." node_paths=PackedStringArray("asteroidsContainer", "labelAsteroids", "labelLevel", "labelLifes", "labelNextLevel", "labelPoints", "labelDebug", "labelGameOver")]
[node name="GameManager" type="Node" parent="." node_paths=PackedStringArray("asteroidsContainer", "labelAsteroids", "labelLevel", "labelLifes", "labelNextLevel", "labelPoints", "labelDebug", "labelGameOver", "restartButton", "reachedPointsLabel")]
script = ExtResource("9_rsrr5")
debug = false
asteroids = Array[PackedScene]([ExtResource("5_do6ba"), ExtResource("6_tqoe7"), ExtResource("7_v6ul2")])
asteroidsContainer = NodePath("../Asteroids")
labelAsteroids = NodePath("../Control/LabelAsteroids")
@ -106,6 +115,8 @@ labelNextLevel = NodePath("../Control/LabelNextLevel")
labelPoints = NodePath("../Control/LabelPoints")
labelDebug = NodePath("../Control/LabelDebug")
labelGameOver = NodePath("../Control/LabelGameOver")
restartButton = NodePath("../Control/RestartButton")
reachedPointsLabel = NodePath("../Control/ReachedPointsLabel")
[node name="Asteroids" type="Node3D" parent="."]
@ -178,7 +189,6 @@ scroll_active = false
shortcut_keys_enabled = false
[node name="LabelGameOver" type="RichTextLabel" parent="Control"]
visible = false
layout_mode = 2
offset_left = 12.0
offset_top = 437.0
@ -189,3 +199,22 @@ bbcode_enabled = true
text = "[center][shake rate=30 level=10 connected=1][rainbow freq=1.0 sat=0.8 val=0.8]Game Over[/rainbow][/shake][/center]"
scroll_active = false
shortcut_keys_enabled = false
[node name="RestartButton" type="Button" parent="Control"]
layout_mode = 0
offset_left = 354.0
offset_top = 644.0
offset_right = 462.0
offset_bottom = 777.0
shortcut = SubResource("Shortcut_soxs4")
icon = ExtResource("15_nxptg")
icon_alignment = 1
[node name="ReachedPointsLabel" type="RichTextLabel" parent="Control"]
layout_mode = 0
offset_left = 173.0
offset_top = 600.0
offset_right = 652.0
offset_bottom = 626.0
bbcode_enabled = true
text = "[center]You have reached level 1 and 0 points![/center]"

@ -19,8 +19,11 @@ public partial class GameManager : Node {
[Export] private RichTextLabel labelPoints;
[Export] private RichTextLabel labelDebug;
[Export] private RichTextLabel labelGameOver;
[Export] private Button restartButton;
[Export] private RichTextLabel reachedPointsLabel;
private int level = 1;
public int MaxLives { get; private set; } = 10;
private int lives = 10;
private int nextLevelPoints = 11;
private int points;
@ -42,6 +45,7 @@ public partial class GameManager : Node {
lives = value;
if (lives <= 0) SetGameOver();
RefreshUi();
PlayerShip.Instance.RefreshUi();
}
}
@ -83,11 +87,16 @@ public partial class GameManager : Node {
public override void _Ready() {
Instance = this;
Lives = MaxLives;
spawnTimer = spawnRate;
SoundManager.Instance.Play(SoundManager.Sound.BackgroundMusic);
restartButton.Pressed += RestartButtonOnPressed;
RefreshUi();
PlayerShip.Instance.RefreshUi();
}
private void RestartButtonOnPressed() => GetTree().ReloadCurrentScene();
public override void _Process(double delta) {
spawnTimer -= (float)delta;
if (spawnTimer < 0) {
@ -95,7 +104,6 @@ public partial class GameManager : Node {
spawnTimer = spawnRate;
}
}
private void SpawnNewAsteroid() {
if (GameOver) return;
GD.Print("Spawn new asteroid");
@ -113,6 +121,8 @@ public partial class GameManager : Node {
labelLevel.Text = $"Actual Level: {Level}";
labelDebug.Visible = debug;
labelGameOver.Visible = GameOver;
restartButton.Visible = GameOver;
reachedPointsLabel.Visible = GameOver;
}
private void NextLevel() {
@ -129,6 +139,7 @@ public partial class GameManager : Node {
private void SetGameOver() {
GameOver = true;
reachedPointsLabel.Text = $"[center]You have reached level {Level} and {Points} points![/center]";
SoundManager.Instance.Stop(SoundManager.Sound.BackgroundMusic);
SoundManager.Instance.Play(SoundManager.Sound.GameOver);
}

@ -28,6 +28,8 @@ public partial class PlayerShip : Node3D {
private bool shooting;
[Export] private Node3D shots;
[Export] private ProgressBar healthBar;
public static PlayerShip Instance { get; private set; }
public override void _Ready() {
@ -35,10 +37,14 @@ public partial class PlayerShip : Node3D {
Instance = this;
}
public override void _Process(double delta) {
public void RefreshUi() {
healthBar.MaxValue = GameManager.Instance.MaxLives;
healthBar.Value = GameManager.Instance.Lives;
}
public override void _Process(double delta) {
if (GameManager.Instance.GameOver) return;
moveDir = Vector3.Zero;
rotDir = Vector3.Zero;
@ -79,6 +85,7 @@ public partial class PlayerShip : Node3D {
else {
jet.Visible = false;
}
//Rotation
PlayerRb.RotationDegrees = rotDir;
}