Main Menu and Game Over

This commit is contained in:
MaddoScientisto 2024-08-24 15:25:30 +02:00
commit 9b7a426deb
5 changed files with 187 additions and 14 deletions

57
Scenes/GameOver.tscn Normal file
View file

@ -0,0 +1,57 @@
[gd_scene load_steps=4 format=3 uid="uid://kau3bi207f3e"]
[ext_resource type="Script" path="res://Scripts/MainMenu.cs" id="1_mkcsg"]
[ext_resource type="PackedScene" uid="uid://cwfaxgr8pgfga" path="res://Scenes/game.tscn" id="2_5sqk5"]
[ext_resource type="PackedScene" uid="uid://5xajclchk3my" path="res://Scenes/MainMenu.tscn" id="3_wt7j8"]
[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_mkcsg")
GameScene = ExtResource("2_5sqk5")
MainMenuScene = ExtResource("3_wt7j8")
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -63.5
offset_top = -64.0
offset_right = 63.5
offset_bottom = 64.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 38
text = "Game Over"
[node name="RestartButton" type="Button" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Restart"
[node name="MainMenuButton" type="Button" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Main Menu"
[node name="ExitButton" type="Button" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Exit
"
[connection signal="pressed" from="MarginContainer/VBoxContainer/RestartButton" to="." method="_on_start_button_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/MainMenuButton" to="." method="_on_mainmenu_button_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/ExitButton" to="." method="_on_exit_button_pressed"]

55
Scenes/MainMenu.tscn Normal file
View file

@ -0,0 +1,55 @@
[gd_scene load_steps=3 format=3 uid="uid://5xajclchk3my"]
[ext_resource type="Script" path="res://Scripts/MainMenu.cs" id="1_702nk"]
[ext_resource type="PackedScene" uid="uid://cwfaxgr8pgfga" path="res://Scenes/game.tscn" id="2_82hab"]
[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_702nk")
GameScene = ExtResource("2_82hab")
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -63.5
offset_top = -64.0
offset_right = 63.5
offset_bottom = 64.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 38
text = "CIRNO: No Brain"
[node name="StartButton" type="Button" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Start"
[node name="DebugButton" type="Button" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Debug"
[node name="ExitButton" type="Button" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Exit
"
[connection signal="pressed" from="MarginContainer/VBoxContainer/StartButton" to="." method="_on_start_button_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/DebugButton" to="." method="_on_debug_button_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/ExitButton" to="." method="_on_exit_button_pressed"]

View file

@ -1,10 +1,11 @@
[gd_scene load_steps=27 format=3 uid="uid://bghghp5ep4w2j"]
[gd_scene load_steps=28 format=3 uid="uid://bghghp5ep4w2j"]
[ext_resource type="Script" path="res://Scripts/PlayerMovement.cs" id="1_m27vu"]
[ext_resource type="Texture2D" uid="uid://la06powu57hu" path="res://Sprites/Cirno_Big.png" id="2_bwf6x"]
[ext_resource type="PackedScene" uid="uid://b1qnfiuokpvsr" path="res://Scenes/bullet.tscn" id="2_ov36d"]
[ext_resource type="PackedScene" uid="uid://chkpk7erlqajg" path="res://Scenes/Selector.tscn" id="3_8wt6s"]
[ext_resource type="Script" path="res://addons/smoothing/smoothing_2d.gd" id="4_j4xhu"]
[ext_resource type="PackedScene" uid="uid://kau3bi207f3e" path="res://Scenes/GameOver.tscn" id="4_qlhb6"]
[ext_resource type="Script" path="res://Scenes/CameraTarget.gd" id="5_cxvyt"]
[ext_resource type="PackedScene" uid="uid://cfb3nsay84xdb" path="res://Scenes/crosshair.tscn" id="6_l43rf"]
[ext_resource type="Script" path="res://Scenes/InteractionController.cs" id="7_uvgjg"]
@ -149,6 +150,7 @@ Speed = 2500
CrosshairDistance = 20.0
BulletScene = ExtResource("2_ov36d")
SelectorScene = ExtResource("3_8wt6s")
GameOverScene = ExtResource("4_qlhb6")
Muzzle = NodePath("Muzzle")
Health = 32.0
RateOfFire = 0.1

46
Scripts/MainMenu.cs Normal file
View file

@ -0,0 +1,46 @@
using Godot;
using System;
public partial class MainMenu : Control
{
[Export]
public PackedScene GameScene { get; set; }
[Export]
public PackedScene MainMenuScene { get; set; }
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
private void _on_start_button_pressed()
{
if (GameScene != null) {
GetTree().ChangeSceneToPacked(GameScene);
}
}
private void _on_debug_button_pressed()
{
}
private void _on_mainmenu_button_pressed()
{
if (MainMenuScene != null) {
GetTree().ChangeSceneToPacked(MainMenuScene);
}
}
private void _on_exit_button_pressed()
{
GetTree().Quit();
}
}

View file

@ -13,10 +13,13 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
[Export]
public PackedScene BulletScene { get; set; }
[Export]
public PackedScene SelectorScene { get; set; }
[Export]
public PackedScene GameOverScene { get; set; }
private Node2D _selector;
private Interactable _lastInteractable;
@ -27,7 +30,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
private AnimatedSprite2D _animatedSprite;
private Vector2 _movementDirection { get; set; }
private Vector2 _facingDirection { get; set; }
private Sprite2D _crosshair;
@ -78,7 +81,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
{
HandleShoot();
SetAnimation();
FindInteractable();
}
@ -88,9 +91,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
{
_lastInteractable.Activate();
}
//var spaceState = GetWorld2D().DirectSpaceState;
//var query = PhysicsRayQueryParameters2D.Create(Vector2.Zero, )
}
@ -156,9 +159,10 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
}
public override void _PhysicsProcess(double delta)
{
{
_movementDirection = GetInput();
if (_movementDirection != Vector2.Zero) {
if (_movementDirection != Vector2.Zero)
{
_facingDirection = _movementDirection;
}
Velocity = _movementDirection * (float)(Speed * delta);
@ -168,9 +172,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
_crosshair.Position = CalculateCrosshairPosition();
//FindInteractable();
}
private void _on_interaction_controller_area_entered(Area2D area)
{
// Replace with function body.
@ -192,14 +196,21 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
Debug.WriteLine("Ded");
//CreateParticles();
//CreateDebris();
QueueFree();
if (GameOverScene != null)
{
GetTree().ChangeSceneToPacked(GameOverScene);
}
else
{
QueueFree();
}
}
public void Hit(float damage)
{
GD.Print($"Player damaged for {damage}");
if (_isDestroyed) return;
_currentHealth -= damage;
if (!(_currentHealth <= 0)) return;
_isDestroyed = true;
@ -211,8 +222,10 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
return _isDestroyed;
}
private void _on_damage_hit_box_area_entered(Area2D area) {
if (area is Bullet bullet) {
private void _on_damage_hit_box_area_entered(Area2D area)
{
if (area is Bullet bullet)
{
GD.Print("Received damage manually");
this.Hit(bullet.Damage);
bullet.QueueFree();