Compare commits
2 Commits
ef4d128869
...
bf11d6a9cb
Author | SHA1 | Date | |
---|---|---|---|
bf11d6a9cb | |||
dfa8a17ba1 |
@@ -1,5 +1,6 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
namespace Mr.BrickAdventures.Autoloads;
|
||||
|
||||
@@ -8,22 +9,28 @@ public partial class SaveSystem : Node
|
||||
[Export] public string SavePath { get; set; } = "user://savegame.save";
|
||||
[Export] public int Version { get; set; } = 1;
|
||||
|
||||
//private GM _gm;
|
||||
private GameManager _gameManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
//_gm = GetNode<GM>("/root/GameManager");
|
||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
||||
}
|
||||
|
||||
public void SaveGame()
|
||||
{
|
||||
//TODO: Implement saving logic
|
||||
var saveData = new Dictionary
|
||||
{
|
||||
{ "player_state", _gameManager.PlayerState},
|
||||
{ "version", Version}
|
||||
};
|
||||
|
||||
using var file = FileAccess.Open(SavePath, FileAccess.ModeFlags.Write);
|
||||
file.StoreVar(saveData);
|
||||
GD.Print("Game state saved to: ", SavePath);
|
||||
}
|
||||
|
||||
public bool LoadGame()
|
||||
{
|
||||
//TODO: Implement loading logic
|
||||
|
||||
if (!FileAccess.FileExists(SavePath))
|
||||
return false;
|
||||
|
||||
@@ -38,7 +45,15 @@ public partial class SaveSystem : Node
|
||||
|
||||
GD.Print("Game state loaded from: ", SavePath);
|
||||
GD.Print("Player state: ", saveDataObj["player_state"]);
|
||||
_gameManager.PlayerState = (Dictionary)saveDataObj["player_state"];
|
||||
|
||||
var skills = new Array<SkillData>();
|
||||
foreach (var skill in (Array<SkillData>)_gameManager.PlayerState["unlocked_skills"])
|
||||
{
|
||||
skills.Add(skill);
|
||||
}
|
||||
|
||||
_gameManager.UnlockSkills(skills);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
70
scripts/Resources/ChargeThrowInputResource.cs
Normal file
70
scripts/Resources/ChargeThrowInputResource.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
public partial class ChargeThrowInputResource : ThrowInputResource
|
||||
{
|
||||
[Export] public float MinPower { get; set; } = 0.5f;
|
||||
[Export] public float MaxPower { get; set; } = 2.0f;
|
||||
[Export] public float MaxChargeTime { get; set; } = 2.0f;
|
||||
[Export] public float MinChargeDuration { get; set; } = 0.1f;
|
||||
|
||||
private bool _isCharging = false;
|
||||
private float _chargeStartTime = 0f;
|
||||
|
||||
[Signal] public delegate void ChargeStartedEventHandler();
|
||||
[Signal] public delegate void ChargeUpdatedEventHandler(float chargeRatio);
|
||||
[Signal] public delegate void ChargeStoppedEventHandler();
|
||||
|
||||
public override void ProcessInput(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed("attack"))
|
||||
{
|
||||
_isCharging = true;
|
||||
_chargeStartTime = Time.GetTicksMsec() / 1000f;
|
||||
EmitSignalChargeStarted();
|
||||
}
|
||||
|
||||
if (@event.IsActionReleased("attack") && _isCharging)
|
||||
{
|
||||
var power = CalculatePower();
|
||||
_isCharging = false;
|
||||
EmitSignalThrowRequested(power);
|
||||
EmitSignalChargeStopped();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(double delta)
|
||||
{
|
||||
if (!_isCharging) return;
|
||||
|
||||
var t = Mathf.Clamp(GetChargeRatio(), MinPower, MaxPower);
|
||||
EmitSignalChargeUpdated(t);
|
||||
}
|
||||
|
||||
public override bool SupportsCharging()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private float CalculatePower()
|
||||
{
|
||||
var now = Time.GetTicksMsec() / 1000f;
|
||||
var heldTime = now - _chargeStartTime;
|
||||
if (heldTime < MinChargeDuration)
|
||||
return MinPower;
|
||||
|
||||
var t = Mathf.Clamp(heldTime / MaxChargeTime, 0f, 1f);
|
||||
return Mathf.Lerp(MinPower, MaxPower, t);
|
||||
}
|
||||
|
||||
private float GetChargeRatio()
|
||||
{
|
||||
if (!_isCharging) return MinPower;
|
||||
|
||||
var now = Time.GetTicksMsec() / 1000f;
|
||||
var heldTime = now - _chargeStartTime;
|
||||
var t = Mathf.Clamp(heldTime / MaxChargeTime, 0f, 1f);
|
||||
return Mathf.Lerp(MinPower, MaxPower, t);
|
||||
}
|
||||
}
|
20
scripts/Resources/TapThrowInputResource.cs
Normal file
20
scripts/Resources/TapThrowInputResource.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.scripts.interfaces;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
public partial class TapThrowInputResource : ThrowInputResource
|
||||
{
|
||||
public override void Update(double delta)
|
||||
{
|
||||
if (Input.IsActionPressed("attack"))
|
||||
{
|
||||
EmitSignalThrowRequested(1f);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool SupportsCharging()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
24
scripts/Resources/ThrowInputResource.cs
Normal file
24
scripts/Resources/ThrowInputResource.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.scripts.interfaces;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
public abstract partial class ThrowInputResource : Resource, IThrowInput
|
||||
{
|
||||
[Signal] public delegate void ThrowRequestedEventHandler(float powerMultiplier = 1f);
|
||||
|
||||
public virtual void ProcessInput(InputEvent @event)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual void Update(double delta)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual bool SupportsCharging()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
70
scripts/components/BrickThrowComponent.cs
Normal file
70
scripts/components/BrickThrowComponent.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.scripts.interfaces;
|
||||
using Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class BrickThrowComponent : Node
|
||||
{
|
||||
[Export] public PackedScene BrickScene { get; set; }
|
||||
[Export] public float FireRate { get; set; } = 1.0f;
|
||||
[Export] public PlayerController PlayerController { get; set; }
|
||||
[Export] public ThrowInputResource ThrowInputBehavior { get; set; }
|
||||
|
||||
private bool _canThrow = true;
|
||||
private Timer _timer;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
SetupTimer();
|
||||
_canThrow = true;
|
||||
|
||||
if (ThrowInputBehavior != null) ThrowInputBehavior.ThrowRequested += ThrowBrick;
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
ThrowInputBehavior?.ProcessInput(@event);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
ThrowInputBehavior?.Update(delta);
|
||||
}
|
||||
|
||||
private void SetupTimer()
|
||||
{
|
||||
_timer.WaitTime = FireRate;
|
||||
_timer.OneShot = false;
|
||||
_timer.Autostart = false;
|
||||
_timer.Timeout += OnTimerTimeout;
|
||||
}
|
||||
|
||||
private void OnTimerTimeout()
|
||||
{
|
||||
_canThrow = true;
|
||||
}
|
||||
|
||||
private void ThrowBrick(float powerMultiplier = 1f)
|
||||
{
|
||||
if (!_canThrow || PlayerController == null || BrickScene == null)
|
||||
return;
|
||||
|
||||
var instance = BrickScene.Instantiate<Node2D>();
|
||||
var init = instance.GetNodeOrNull<ProjectileInitComponent>("ProjectileInitComponent");
|
||||
if (init != null && PlayerController.CurrentMovement is PlatformMovementComponent)
|
||||
{
|
||||
init.Initialize(new ProjectileInitParams()
|
||||
{
|
||||
Position = PlayerController.GlobalPosition,
|
||||
Rotation = PlayerController.Rotation,
|
||||
Direction = PlayerController.CurrentMovement.LastDirection,
|
||||
PowerMultiplier = powerMultiplier,
|
||||
});
|
||||
}
|
||||
|
||||
GetTree().CurrentScene.AddChild(instance);
|
||||
_canThrow = false;
|
||||
_timer.Start();
|
||||
}
|
||||
}
|
45
scripts/components/BulletComponent.cs
Normal file
45
scripts/components/BulletComponent.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class BulletComponent : Node
|
||||
{
|
||||
[Export] public Area2D Area { get; set; }
|
||||
[Export] public TerrainHitFx TerrainHitFx { get; set; }
|
||||
[Export] public Sprite2D BulletSprite { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Area.BodyEntered += OnBodyEntered;
|
||||
}
|
||||
|
||||
private void OnBodyEntered(Node2D body)
|
||||
{
|
||||
if (body is TileMapLayer)
|
||||
{
|
||||
if (BulletSprite != null)
|
||||
{
|
||||
BulletSprite.Visible = false;
|
||||
}
|
||||
|
||||
PlayTerrainHitFx();
|
||||
return;
|
||||
}
|
||||
|
||||
Owner.QueueFree();
|
||||
}
|
||||
|
||||
private void OnAreaEntered(Area2D area)
|
||||
{
|
||||
Owner.QueueFree();
|
||||
}
|
||||
|
||||
private void PlayTerrainHitFx()
|
||||
{
|
||||
if (TerrainHitFx == null) return;
|
||||
|
||||
TerrainHitFx.TriggerFx();
|
||||
|
||||
Owner.QueueFree();
|
||||
}
|
||||
}
|
47
scripts/components/CageComponent.cs
Normal file
47
scripts/components/CageComponent.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class CageComponent : Node
|
||||
{
|
||||
[Export] public LeverComponent Lever { get; set; }
|
||||
[Export] public Vector2 MoveValue { get; set; } = new(0, -100f);
|
||||
[Export] public float TweenDuration { get; set; } = 0.5f;
|
||||
[Export] public bool ShouldFree { get; set; } = true;
|
||||
|
||||
private const string LeverGroupName = "levers";
|
||||
|
||||
public override async void _Ready()
|
||||
{
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
if (Lever == null)
|
||||
{
|
||||
var leverNodes = GetTree().GetNodesInGroup(LeverGroupName);
|
||||
foreach (var leverNode in leverNodes)
|
||||
{
|
||||
var lever = leverNode.GetNodeOrNull<LeverComponent>("LeverComponent");
|
||||
if (lever != null) lever.Activated += OnLeverActivated;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLeverActivated()
|
||||
{
|
||||
var tween = CreateTween();
|
||||
if (Owner is Node2D root)
|
||||
{
|
||||
var endPosition = root.Position + MoveValue;
|
||||
tween.TweenProperty(root, "position", endPosition, TweenDuration);
|
||||
}
|
||||
|
||||
tween.TweenCallback(Callable.From(OnTweenCompleted));
|
||||
|
||||
}
|
||||
|
||||
private void OnTweenCompleted()
|
||||
{
|
||||
if (!ShouldFree) return;
|
||||
Owner.QueueFree();
|
||||
}
|
||||
}
|
8
scripts/components/CannotStompComponent.cs
Normal file
8
scripts/components/CannotStompComponent.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class CannotStompComponent : Node
|
||||
{
|
||||
|
||||
}
|
79
scripts/components/ChaseLevelComponent.cs
Normal file
79
scripts/components/ChaseLevelComponent.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class ChaseLevelComponent : Node
|
||||
{
|
||||
[Export] public float ChaseSpeed { get; set; } = 200.0f;
|
||||
[Export] public Marker2D ChaseTarget { get; set; }
|
||||
[Export] public GodotObject PhantomCamera { get; set; }
|
||||
[Export] public float MinimumDistance { get; set; } = 10f;
|
||||
|
||||
[Signal]
|
||||
public delegate void ChaseStartedEventHandler();
|
||||
|
||||
[Signal]
|
||||
public delegate void ChaseStoppedEventHandler();
|
||||
|
||||
private bool _isChasing = false;
|
||||
private Node2D _previousCameraFollowTarget = null;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!_isChasing) return;
|
||||
if (ChaseTarget == null) return;
|
||||
|
||||
if (CheckIfReachedTarget())
|
||||
{
|
||||
StopChasing();
|
||||
return;
|
||||
}
|
||||
|
||||
var targetPosition = ChaseTarget.GlobalPosition;
|
||||
|
||||
if (Owner is not Node2D root) return;
|
||||
|
||||
var direction = (targetPosition - root.GlobalPosition).Normalized();
|
||||
root.GlobalPosition += direction * ChaseSpeed * (float)delta;
|
||||
}
|
||||
|
||||
public void OnShipEntered()
|
||||
{
|
||||
if (ChaseTarget == null || PhantomCamera == null)
|
||||
return;
|
||||
|
||||
if (_isChasing) return;
|
||||
|
||||
_previousCameraFollowTarget = (Node2D)PhantomCamera.Call("get_follow_target");
|
||||
PhantomCamera.Call("set_follow_target", Owner as Node2D);
|
||||
EmitSignalChaseStarted();
|
||||
_isChasing = true;
|
||||
}
|
||||
|
||||
public void OnShipExited()
|
||||
{
|
||||
StopChasing();
|
||||
}
|
||||
|
||||
private bool CheckIfReachedTarget()
|
||||
{
|
||||
if (ChaseTarget == null)
|
||||
return false;
|
||||
|
||||
if (Owner is not Node2D root) return false;
|
||||
|
||||
var targetPosition = ChaseTarget.GlobalPosition;
|
||||
var currentPosition = root.GlobalPosition;
|
||||
return currentPosition.DistanceTo(targetPosition) <= MinimumDistance;
|
||||
|
||||
}
|
||||
|
||||
private void StopChasing()
|
||||
{
|
||||
if (PhantomCamera == null) return;
|
||||
|
||||
PhantomCamera.Call("set_follow_target", _previousCameraFollowTarget);
|
||||
EmitSignalChaseStopped();
|
||||
_isChasing = false;
|
||||
}
|
||||
}
|
11
scripts/components/CleanupComponent.cs
Normal file
11
scripts/components/CleanupComponent.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class CleanupComponent : Node
|
||||
{
|
||||
public void CleanUp()
|
||||
{
|
||||
Owner.QueueFree();
|
||||
}
|
||||
}
|
@@ -1,9 +1,10 @@
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.Autoloads;
|
||||
using Mr.BrickAdventures.scripts.interfaces;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class ExitDoorComponent : Node
|
||||
public partial class ExitDoorComponent : Node, IUnlockable
|
||||
{
|
||||
[Export] public bool Locked { get; set; } = true;
|
||||
[Export] public Area2D ExitArea { get; set; }
|
||||
@@ -33,7 +34,7 @@ public partial class ExitDoorComponent : Node
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private void Unlock()
|
||||
public void Unlock()
|
||||
{
|
||||
Locked = false;
|
||||
if (DoorSprite != null)
|
||||
|
@@ -17,6 +17,7 @@ public partial class ShipMovementComponent : Node, IMovement
|
||||
private Vector2 _velocity = Vector2.Zero;
|
||||
|
||||
public Vector2 Velocity => _velocity;
|
||||
public Vector2 LastDirection => _velocity.Normalized();
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
|
70
scripts/components/SkillUnlockedComponent.cs
Normal file
70
scripts/components/SkillUnlockedComponent.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using Mr.BrickAdventures.Autoloads;
|
||||
using Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class SkillUnlockedComponent : Node
|
||||
{
|
||||
[Export] public SkillManager SkillManager { get; set; }
|
||||
|
||||
[Signal]
|
||||
public delegate void SkillUnlockedEventHandler(SkillData skill);
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
||||
}
|
||||
|
||||
private bool HasEnoughCoins(int amount)
|
||||
{
|
||||
return _gameManager != null && _gameManager.GetCoins() >= amount;
|
||||
}
|
||||
|
||||
public bool TryUnlockSkill(SkillData skill)
|
||||
{
|
||||
if (_gameManager == null) return false;
|
||||
if (_gameManager.IsSkillUnlocked(skill)) return false;
|
||||
if (!HasEnoughCoins(skill.Cost)) return false;
|
||||
|
||||
skill.Level = 1;
|
||||
skill.IsActive = true;
|
||||
_gameManager.RemoveCoins(skill.Cost);
|
||||
|
||||
var skillsUnlocked = (Array<SkillData>)_gameManager.CurrentSessionState["skills_unlocked"];
|
||||
skillsUnlocked.Add(skill);
|
||||
SkillManager.AddSkill(skill);
|
||||
EmitSignalSkillUnlocked(skill);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void UnlockAllSkills()
|
||||
{
|
||||
var availableSkills = SkillManager.AvailableSkills;
|
||||
|
||||
foreach (var skill in availableSkills)
|
||||
{
|
||||
EmitSignalSkillUnlocked(skill);
|
||||
}
|
||||
|
||||
_gameManager.UnlockSkills(availableSkills);
|
||||
SkillManager.ApplyUnlockedSkills();
|
||||
}
|
||||
|
||||
public bool TryUpgradeSkill(SkillData skill)
|
||||
{
|
||||
if (_gameManager == null) return false;
|
||||
if (!_gameManager.IsSkillUnlocked(skill)) return false;
|
||||
if (!HasEnoughCoins(skill.Cost)) return false;
|
||||
if (skill.Level >= skill.MaxLevel) return false;
|
||||
|
||||
_gameManager.RemoveCoins(skill.Cost);
|
||||
skill.Level++;
|
||||
EmitSignalSkillUnlocked(skill);
|
||||
return true;
|
||||
}
|
||||
}
|
21
scripts/components/SpaceshipEnterComponent.cs
Normal file
21
scripts/components/SpaceshipEnterComponent.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class SpaceshipEnterComponent : Node
|
||||
{
|
||||
[Export] public Area2D Area { get; set; }
|
||||
[Signal] public delegate void SpaceshipEnteredEventHandler();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Area.BodyEntered += OnBodyEntered;
|
||||
}
|
||||
|
||||
private void OnBodyEntered(Node2D body)
|
||||
{
|
||||
if (body is not PlayerController) return;
|
||||
EmitSignalSpaceshipEntered();
|
||||
Owner.QueueFree();
|
||||
}
|
||||
}
|
20
scripts/components/SpaceshipExitComponent.cs
Normal file
20
scripts/components/SpaceshipExitComponent.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class SpaceshipExitComponent : Node
|
||||
{
|
||||
[Export] public Area2D Area { get; set; }
|
||||
[Signal] public delegate void SpaceshipExitEventHandler();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Area.BodyEntered += OnBodyEntered;
|
||||
}
|
||||
|
||||
private void OnBodyEntered(Node2D body)
|
||||
{
|
||||
if (body is not PlayerController) return;
|
||||
EmitSignalSpaceshipExit();
|
||||
}
|
||||
}
|
23
scripts/components/SpinComponent.cs
Normal file
23
scripts/components/SpinComponent.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class SpinComponent : Node
|
||||
{
|
||||
[Export] public float SpinSpeed { get; set; } = 8f;
|
||||
[Export] public Vector2 SpinDirection { get; set; } = Vector2.Right;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
Spin((float)delta);
|
||||
}
|
||||
|
||||
private void Spin(float delta)
|
||||
{
|
||||
var rotationSpeed = SpinSpeed * SpinDirection.X * delta;
|
||||
if (Owner is Node2D root)
|
||||
{
|
||||
root.Rotation += rotationSpeed;
|
||||
}
|
||||
}
|
||||
}
|
43
scripts/components/StompDamageComponent.cs
Normal file
43
scripts/components/StompDamageComponent.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class StompDamageComponent : Node
|
||||
{
|
||||
[Export] public float Damage { get; set; } = 0.25f;
|
||||
[Export] public Area2D Area { get; set; }
|
||||
[Export] public PlayerController Root { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Area.BodyEntered += OnBodyEntered;
|
||||
}
|
||||
|
||||
private async void OnBodyEntered(Node2D body)
|
||||
{
|
||||
var health = body.GetNodeOrNull<HealthComponent>("HealthComponent");
|
||||
if (health == null) return;
|
||||
|
||||
var cannotStompComponent = body.GetNodeOrNull<CannotStompComponent>("CannotStompComponent");
|
||||
if (cannotStompComponent != null) return;
|
||||
|
||||
if (!(Root.GlobalPosition.Y < body.GlobalPosition.Y)) return;
|
||||
|
||||
var velocity = Root.CurrentMovement.PreviousVelocity;
|
||||
if (!(velocity.Y > 0f)) return;
|
||||
|
||||
DealDamage(health);
|
||||
|
||||
var damageComponent = body.GetNodeOrNull<DamageComponent>("DamageComponent");
|
||||
if (damageComponent == null) return;
|
||||
|
||||
damageComponent.SetProcess(false);
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
damageComponent.SetProcess(true);
|
||||
}
|
||||
|
||||
private void DealDamage(HealthComponent target)
|
||||
{
|
||||
target.DecreaseHealth(Damage);
|
||||
}
|
||||
}
|
19
scripts/components/StraightMotionComponent.cs
Normal file
19
scripts/components/StraightMotionComponent.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class StraightMotionComponent : Node
|
||||
{
|
||||
[Export] public LaunchComponent LaunchComponent { get; set; }
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var root = Owner as Node2D;
|
||||
if (root == null || LaunchComponent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
root.Position += LaunchComponent.GetInitialVelocity() * (float)delta;
|
||||
}
|
||||
}
|
33
scripts/components/TerrainHitFx.cs
Normal file
33
scripts/components/TerrainHitFx.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class TerrainHitFx : Node
|
||||
{
|
||||
private List<GpuParticles2D> _gpuParticles = [];
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Owner is GpuParticles2D gpuParticle) _gpuParticles.Add(gpuParticle);
|
||||
|
||||
foreach (var child in GetChildren())
|
||||
{
|
||||
if (child is GpuParticles2D p)
|
||||
{
|
||||
_gpuParticles.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TriggerFx()
|
||||
{
|
||||
foreach (var fx in _gpuParticles.Where(fx => fx != null))
|
||||
{
|
||||
fx.Restart();
|
||||
fx.Emitting = true;
|
||||
}
|
||||
}
|
||||
}
|
39
scripts/components/TooltipComponent.cs
Normal file
39
scripts/components/TooltipComponent.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class TooltipComponent : Node
|
||||
{
|
||||
[Export] public Area2D Area { get; set; }
|
||||
[Export] public Control UiRoot { get; set; }
|
||||
[Export] public string Text { get; set; } = string.Empty;
|
||||
[Export] public Label TooltipLabel { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
TooltipLabel.Text = Text;
|
||||
UiRoot.Visible = false;
|
||||
Area.BodyEntered += OnBodyEntered;
|
||||
Area.BodyExited += OnBodyExited;
|
||||
}
|
||||
|
||||
private void OnBodyEntered(Node2D body)
|
||||
{
|
||||
ShowTooltip();
|
||||
}
|
||||
|
||||
private void OnBodyExited(Node2D body)
|
||||
{
|
||||
HideTooltip();
|
||||
}
|
||||
|
||||
private void ShowTooltip()
|
||||
{
|
||||
UiRoot.Visible = true;
|
||||
}
|
||||
|
||||
private void HideTooltip()
|
||||
{
|
||||
UiRoot.Visible = false;
|
||||
}
|
||||
}
|
22
scripts/components/TrailComponent.cs
Normal file
22
scripts/components/TrailComponent.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class TrailComponent : Line2D
|
||||
{
|
||||
[Export] public int MaxPoints { get; set; } = 100;
|
||||
|
||||
private readonly Queue<Vector2> _queue = new();
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Owner is Node2D root) _queue.Enqueue(root.GlobalPosition);
|
||||
|
||||
if (_queue.Count > MaxPoints) _queue.Dequeue();
|
||||
|
||||
ClearPoints();
|
||||
|
||||
foreach (var point in _queue) AddPoint(point);
|
||||
}
|
||||
}
|
25
scripts/components/UnlockOnRequirementComponent.cs
Normal file
25
scripts/components/UnlockOnRequirementComponent.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.scripts.interfaces;
|
||||
using Mr.BrickAdventures.scripts.Resources;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
public partial class UnlockOnRequirementComponent : Node
|
||||
{
|
||||
[Export] public RequirementComponent RequirementComponent { get; set; }
|
||||
[Export] public Node UnlockTarget { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
RequirementComponent.RequirementMet += OnRequirementMet;
|
||||
}
|
||||
|
||||
private void OnRequirementMet(CollectableType requirementType)
|
||||
{
|
||||
if (requirementType != RequirementComponent.RequirementType) return;
|
||||
if (UnlockTarget is IUnlockable unlockable)
|
||||
{
|
||||
unlockable.Unlock();
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,6 +7,7 @@ public interface IMovement
|
||||
string MovementType { get; }
|
||||
bool Enabled { get; set; }
|
||||
Vector2 PreviousVelocity { get; set; }
|
||||
Vector2 LastDirection { get; }
|
||||
|
||||
void _Process(double delta);
|
||||
void _PhysicsProcess(double delta);
|
||||
|
10
scripts/interfaces/IThrowInput.cs
Normal file
10
scripts/interfaces/IThrowInput.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.interfaces;
|
||||
|
||||
public interface IThrowInput
|
||||
{
|
||||
public void ProcessInput(InputEvent @event);
|
||||
public void Update(double delta);
|
||||
public bool SupportsCharging();
|
||||
}
|
6
scripts/interfaces/IUnlockable.cs
Normal file
6
scripts/interfaces/IUnlockable.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Mr.BrickAdventures.scripts.interfaces;
|
||||
|
||||
public interface IUnlockable
|
||||
{
|
||||
void Unlock();
|
||||
}
|
Reference in New Issue
Block a user