Main menu, ZX Spectrum-like font, Death screen, Fixed typo, Game Manager
This commit is contained in:
parent
602df1ed1d
commit
b0caf99373
24 changed files with 497 additions and 17 deletions
|
@ -10,5 +10,5 @@ public static class Constants
|
|||
public const float MaxFlashlightDistance = 96;
|
||||
public const float MinFlashlightDistance = 16;
|
||||
public const float MaxFlashlightEnergy = 100;
|
||||
public const float FlashlightEneregyPerCharge = 5;
|
||||
public const float FlashlightEnergyPerCharge = 5;
|
||||
}
|
||||
|
|
59
scripts/DeathScreen.cs
Normal file
59
scripts/DeathScreen.cs
Normal file
|
@ -0,0 +1,59 @@
|
|||
using Godot;
|
||||
|
||||
public partial class DeathScreen : TextureRect
|
||||
{
|
||||
public static DeathScreen Instance { get; private set; }
|
||||
|
||||
[Export] public GameCamera Camera;
|
||||
|
||||
private Timer _timer;
|
||||
private TextureRect _playerSprite;
|
||||
private TextureRect _monsterSprite;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
Visible = false;
|
||||
|
||||
_timer = (Timer)FindChild("Timer");
|
||||
_playerSprite = (TextureRect)FindChild("PlayerSprite");
|
||||
_monsterSprite = (TextureRect)FindChild("MonsterSprite");
|
||||
}
|
||||
|
||||
public void Timeout()
|
||||
{
|
||||
GD.Print("Timer end");
|
||||
|
||||
GetTree().ReloadCurrentScene();
|
||||
}
|
||||
|
||||
public void Killed(Node2D killer)
|
||||
{
|
||||
GD.Print($"DeathScreen {killer is null}");
|
||||
|
||||
_playerSprite.Position = Player.Instance.Position - Camera.Position + Constants.HalfScreenSize;
|
||||
_monsterSprite.Position = killer.Position - Camera.Position + Constants.HalfScreenSize;
|
||||
|
||||
if (Player.Instance.FindChild("AnimatedSprite2D") is AnimatedSprite2D animatedSprite2D)
|
||||
{
|
||||
GD.Print("Found AnimatedSprite2D for Player");
|
||||
_playerSprite.Texture =
|
||||
animatedSprite2D.SpriteFrames.GetFrameTexture(animatedSprite2D.Animation, animatedSprite2D.Frame);
|
||||
_playerSprite.Position -= _playerSprite.Texture.GetSize() / 2;
|
||||
}
|
||||
|
||||
if (killer.FindChild("AnimatedSprite2D") is AnimatedSprite2D killerAnimatedSprite2D)
|
||||
{
|
||||
GD.Print("Found AnimatedSprite2D for Monster");
|
||||
_monsterSprite.Texture =
|
||||
killerAnimatedSprite2D.SpriteFrames.GetFrameTexture(killerAnimatedSprite2D.Animation, killerAnimatedSprite2D.Frame);
|
||||
_monsterSprite.Position -= _monsterSprite.Texture.GetSize() / 2;
|
||||
}
|
||||
|
||||
Visible = true;
|
||||
_timer.Start();
|
||||
|
||||
GD.Print("Timer start");
|
||||
}
|
||||
}
|
|
@ -80,7 +80,7 @@ public partial class Flashlight : Node
|
|||
if (Input.IsActionJustPressed("flashlight_charge") && FlashlightChargeTimeout <= 0)
|
||||
{
|
||||
FlashlightChargeTimeout = 1;
|
||||
FlashlightEnergy += Constants.FlashlightEneregyPerCharge;
|
||||
FlashlightEnergy += Constants.FlashlightEnergyPerCharge;
|
||||
var rng = new RandomNumberGenerator();
|
||||
CrankSoundPlayer.PitchScale = rng.RandfRange(1f, 1.15f);
|
||||
CrankSoundPlayer.Play();
|
||||
|
|
|
@ -21,7 +21,6 @@ public partial class GameCamera : Camera2D
|
|||
var halfCameraFollowBounds = CameraFollowBounds / 2;
|
||||
var hardLimit = relativePlayerPosition.Clamp(-halfCameraBounds, halfCameraBounds);
|
||||
difference = relativePlayerPosition - hardLimit;
|
||||
//GD.Print($"HardDiff {difference}");
|
||||
if (difference.IsZeroApprox())
|
||||
{
|
||||
float x = 0, y = 0;
|
||||
|
@ -36,7 +35,6 @@ public partial class GameCamera : Camera2D
|
|||
}
|
||||
|
||||
difference = new Vector2(x, y);
|
||||
//GD.Print($"SmoothDiff {difference}");
|
||||
}
|
||||
|
||||
Position = (Position + difference).Round();
|
||||
|
|
38
scripts/GameManager.cs
Normal file
38
scripts/GameManager.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using Godot;
|
||||
|
||||
public partial class GameManager : Node
|
||||
{
|
||||
public static bool IsPlaying = true;
|
||||
|
||||
public ulong GameStart = 0;
|
||||
public ulong GameEnd = 0;
|
||||
public int Attempts = 0;
|
||||
public Node2D Checkpoint = null;
|
||||
|
||||
[Signal]
|
||||
public delegate void GameOverEventHandler();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (!IsPlaying)
|
||||
{
|
||||
IsPlaying = true;
|
||||
}
|
||||
|
||||
StartGame();
|
||||
}
|
||||
|
||||
public void StartGame() => GameStart = Time.GetTicksMsec();
|
||||
|
||||
public void EndGame()
|
||||
{
|
||||
GameEnd = Time.GetTicksMsec();
|
||||
|
||||
EmitSignal(SignalName.GameOver);
|
||||
}
|
||||
|
||||
public string GetFormattedTimeElapsed() => TimeSpan.FromMilliseconds(GameEnd - GameStart).ToString(@"hh\:mm\:ss.fff");
|
||||
|
||||
public void OnPlayerDied() => Attempts++;
|
||||
}
|
29
scripts/Menu.cs
Normal file
29
scripts/Menu.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using Godot;
|
||||
|
||||
public partial class Menu : Node2D
|
||||
{
|
||||
private Timer _timer;
|
||||
private AudioStreamPlayer2D _thunderclap;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_timer = (Timer)FindChild("Timer");
|
||||
_thunderclap = (AudioStreamPlayer2D)FindChild("Thunderclap");
|
||||
|
||||
GameManager.IsPlaying = false;
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed("ui_confirm") && _timer.IsStopped())
|
||||
{
|
||||
_thunderclap.Play();
|
||||
_timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeScene()
|
||||
{
|
||||
GetTree().ChangeSceneToFile("res://scenes/main_scene.tscn");
|
||||
}
|
||||
}
|
16
scripts/PlayZone.cs
Normal file
16
scripts/PlayZone.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class PlayZone : Node2D
|
||||
{
|
||||
[Export] public Node2D TopLeftCorner;
|
||||
[Export] public Node2D BottomRightCorner;
|
||||
|
||||
public Rect2I Bounds = new Rect2I(0, 0, 0, 0);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
var size = BottomRightCorner.Position - TopLeftCorner.Position;
|
||||
Bounds = new Rect2I((int)TopLeftCorner.Position.X, (int)TopLeftCorner.Position.Y, (int)size.X, (int)size.Y);
|
||||
}
|
||||
}
|
|
@ -22,6 +22,9 @@ public partial class Player : CharacterBody2D
|
|||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (!Alive)
|
||||
return;
|
||||
|
||||
Vector2 velocity = Velocity;
|
||||
|
||||
// Get the input direction and handle the movement/deceleration.
|
||||
|
@ -63,5 +66,7 @@ public partial class Player : CharacterBody2D
|
|||
GD.Print($"Killed by {killer.Name}");
|
||||
Alive = false;
|
||||
EmitSignal(SignalName.Killed);
|
||||
|
||||
DeathScreen.Instance.Killed(killer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Watcher : Node2D
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue