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

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();