mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-11 04:05:54 +00:00
working spder bomb
This commit is contained in:
parent
6125565d8c
commit
f1f40a91dd
17 changed files with 400 additions and 105 deletions
|
|
@ -13,7 +13,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
{
|
||||
[Export]
|
||||
public int Speed { get; set; } = 400;
|
||||
|
||||
|
||||
[Export]
|
||||
public int StrafeSpeed { get; set; } = 200;
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
[Export]
|
||||
public string GameOverScene { get; set; }
|
||||
|
||||
|
||||
[Export]
|
||||
public Texture2D WingsSprite { get; set; }
|
||||
|
||||
|
|
@ -42,14 +42,14 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private Vector2 _movementDirection { get; set; }
|
||||
private Vector2 _facingDirection { get; set; }
|
||||
|
||||
|
||||
private Vector2 _rightStickInput { get; set; }
|
||||
|
||||
private Sprite2D _crosshair;
|
||||
|
||||
[Export] public float MaxHealth = 32f;
|
||||
[Export] public float MaxShield = 32f;
|
||||
[Export] public Shader BlinkShader {get;set;}
|
||||
[Export] public Shader BlinkShader { get; set; }
|
||||
[Export] public Sprite2D HitboxSprite { get; set; }
|
||||
[Export] public BulletOwner BulletGroup { get; set; } = BulletOwner.Player;
|
||||
|
||||
|
|
@ -67,10 +67,10 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
public Array<Weapon> EquippedWeapons { get; set; } = new Array<Weapon>();
|
||||
|
||||
public int CurrentWeaponIndex { get; set; } = 0;
|
||||
|
||||
|
||||
//private float _currentHealth = 0f;
|
||||
//private float _currentShield = 0f;
|
||||
|
||||
|
||||
private bool _isDestroyed = false;
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
|
@ -79,14 +79,14 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private ActorResourceProvider _healthProvider;
|
||||
private ActorResourceProvider _shieldProvider;
|
||||
|
||||
|
||||
private bool _isStrafing { get; set; }
|
||||
|
||||
|
||||
private bool _canMove = true;
|
||||
|
||||
|
||||
[Signal]
|
||||
public delegate void HealthChangedEventHandler(float newHealth, float maxHealth);
|
||||
|
||||
|
||||
[Signal]
|
||||
public delegate void ShieldChangedEventHandler(float newShield, float maxShield);
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
[Signal]
|
||||
public delegate void InteractableAreaExitedEventHandler(Interactable interactable);
|
||||
|
||||
|
||||
[Signal]
|
||||
public delegate void DeathEventHandler();
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
get => _healthProvider.CurrentResource;
|
||||
set => _healthProvider.CurrentResource = value;
|
||||
}
|
||||
|
||||
|
||||
public float CurrentShield
|
||||
{
|
||||
get => _shieldProvider.CurrentResource;
|
||||
|
|
@ -126,7 +126,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("./Smoothing2D/AnimatedSprite2D");
|
||||
_crosshair = GetNode<Sprite2D>("./Smoothing2D/Crosshair");
|
||||
|
||||
|
||||
_healthProvider = GetNode<ActorResourceProvider>("HealthProvider");
|
||||
_shieldProvider = GetNode<ActorResourceProvider>("ShieldProvider");
|
||||
|
||||
|
|
@ -154,18 +154,18 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
_inventoryManager = this.GetInventoryManager();
|
||||
|
||||
_gameManager.GameStateChange += GameManagerOnGameStateChange;
|
||||
|
||||
|
||||
if (SelectorScene != null)
|
||||
{
|
||||
_selector = this.CreateSibling<Selector>(SelectorScene, this.GlobalPosition);
|
||||
_selector.Visible = false;
|
||||
}
|
||||
|
||||
|
||||
_lastCheckPointPosition = GlobalPosition;
|
||||
|
||||
_ = UnTeleport();
|
||||
}
|
||||
|
||||
|
||||
private void GameManagerOnGameStateChange(GameState state)
|
||||
{
|
||||
switch (state)
|
||||
|
|
@ -181,7 +181,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
case GameState.Dialogue:
|
||||
_canMove = false;
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +200,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
_canMove = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void AddWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapons.Add(weapon);
|
||||
|
|
@ -215,7 +215,44 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
EquipWeapon(weapon);
|
||||
}
|
||||
|
||||
|
||||
public void UseItem(LootItem item, int currentAmount)
|
||||
{
|
||||
GD.Print($"Used item on player {item.ItemKey}");
|
||||
|
||||
switch (item.Item)
|
||||
{
|
||||
case ItemTypes.FrogBomb:
|
||||
|
||||
_inventoryManager.RemoveItem(item.ItemKey, 1);
|
||||
// emit projectile
|
||||
var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, item.WeaponData.BulletData.BulletScene, this.GlobalPosition);
|
||||
|
||||
var bulletData = item.WeaponData.MakeBullet(this.GlobalPosition);
|
||||
|
||||
bullet.Initialize(bulletData, _gameManager);
|
||||
|
||||
//bullet.SetDirection(ShootDirection);
|
||||
bullet.SetDirection(_facingDirection);
|
||||
bullet.Speed = item.WeaponData.BulletData.BulletSpeed;
|
||||
RequestMovementDisable(true);
|
||||
// set camera
|
||||
_gameManager.CameraTargetObject(bullet);
|
||||
// set event destroy
|
||||
bullet.OnDestroy += () =>
|
||||
{
|
||||
_gameManager.CameraTargetPlayer();
|
||||
RequestMovementDisable(false);
|
||||
};
|
||||
// go back
|
||||
break;
|
||||
|
||||
}
|
||||
//var item = _inventoryManager.getitem
|
||||
|
||||
}
|
||||
|
||||
// Triggered by event in inventorymanager
|
||||
public void EquipWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapon = weapon;
|
||||
|
|
@ -229,10 +266,10 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
{
|
||||
CurrentWeaponIndex = EquippedWeapons.Count - 1;
|
||||
}
|
||||
|
||||
|
||||
EquipWeapon(EquippedWeapons[CurrentWeaponIndex]);
|
||||
}
|
||||
|
||||
|
||||
public void PreviousWeapon()
|
||||
{
|
||||
CurrentWeaponIndex -= 1;
|
||||
|
|
@ -240,7 +277,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
{
|
||||
CurrentWeaponIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
EquipWeapon(EquippedWeapons[CurrentWeaponIndex]);
|
||||
}
|
||||
|
||||
|
|
@ -309,11 +346,11 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
{
|
||||
return Input.GetVector("left", "right", "up", "down");
|
||||
}
|
||||
|
||||
|
||||
private Vector2 GetRightStickInput()
|
||||
{
|
||||
return new Vector2(
|
||||
Input.GetAxis("aim_left","aim_right"),
|
||||
Input.GetAxis("aim_left", "aim_right"),
|
||||
Input.GetAxis("aim_up", "aim_down")
|
||||
);
|
||||
}
|
||||
|
|
@ -328,7 +365,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
//var cPos = new Vector2(this.Position.X + CrosshairDistance * Godot.Mathf.Cos(angle), this.Position.Y + CrosshairDistance * Godot.Mathf.Sin(angle));
|
||||
}
|
||||
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_isDestroyed)
|
||||
|
|
@ -336,8 +373,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
if (Input.IsActionJustPressed(_shootActionName))
|
||||
Respawn();
|
||||
return;
|
||||
};
|
||||
|
||||
}
|
||||
;
|
||||
|
||||
SetAnimation();
|
||||
if (!_canMove) return;
|
||||
|
||||
|
|
@ -349,9 +387,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
{
|
||||
HitboxSprite.Visible = _isStrafing;
|
||||
}
|
||||
|
||||
|
||||
_rightStickInput = GetRightStickInput();
|
||||
|
||||
|
||||
// Update Facing Direction
|
||||
if (!_isStrafing)
|
||||
{
|
||||
|
|
@ -377,8 +415,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
{
|
||||
PreviousWeapon();
|
||||
}
|
||||
|
||||
_crosshair.Position = CalculateCrosshairPosition();
|
||||
|
||||
_crosshair.Position = CalculateCrosshairPosition();
|
||||
}
|
||||
|
||||
public void Respawn()
|
||||
|
|
@ -394,8 +432,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
{
|
||||
if (_isDestroyed) return;
|
||||
if (!_canMove) return;
|
||||
|
||||
Velocity = _movementDirection * MovementSpeed;
|
||||
|
||||
Velocity = _movementDirection * MovementSpeed;
|
||||
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
|
@ -415,19 +453,19 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
_selector.AddInteractable(interactable);
|
||||
|
||||
//_selector.SelectedInteractable = interactable;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void _on_interaction_controller_area_exited(Area2D area)
|
||||
{
|
||||
if (!_canMove) return;
|
||||
if (area.IsInGroup("Interactable") && area is Interactable interactable)
|
||||
if (area.IsInGroup("Interactable") && area is Interactable interactable)
|
||||
{
|
||||
Debug.WriteLine($"Interactable {area.Name} Exited");
|
||||
|
||||
EmitSignal(nameof(InteractableAreaExited), interactable);
|
||||
|
||||
|
||||
if (_selector == null) return;
|
||||
_selector.RemoveInteractable(interactable);
|
||||
}
|
||||
|
|
@ -458,20 +496,25 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
GD.Print($"Player damaged for {damage}");
|
||||
if (_isDestroyed) return;
|
||||
|
||||
if (CurrentShield > 0 && type is not DamageType.Explosive or DamageType.Acid) {
|
||||
if (CurrentShield > 0 && type is not DamageType.Explosive or DamageType.Acid)
|
||||
{
|
||||
// Reduce shield
|
||||
PlayShieldAnimation();
|
||||
CurrentShield -= damage;
|
||||
if (CurrentShield < 0 ) {
|
||||
if (CurrentShield < 0)
|
||||
{
|
||||
CurrentHealth -= Math.Abs(CurrentShield);
|
||||
CurrentShield = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (type is DamageType.Fire) {
|
||||
else
|
||||
{
|
||||
if (type is DamageType.Fire)
|
||||
{
|
||||
CurrentHealth -= damage * 2;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
CurrentHealth -= damage;
|
||||
}
|
||||
|
||||
|
|
@ -483,13 +526,13 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
Explode();
|
||||
}
|
||||
|
||||
private void PlayShieldAnimation()
|
||||
private void PlayShieldAnimation()
|
||||
{
|
||||
if (_shieldParticles is null) return;
|
||||
_shieldParticles.Emitting = true;
|
||||
}
|
||||
|
||||
public void Blink()
|
||||
public void Blink()
|
||||
{
|
||||
if (BlinkShader != null)
|
||||
{
|
||||
|
|
@ -506,7 +549,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
await ToSignal(tween, "finished");
|
||||
}
|
||||
|
||||
public async Task Teleport()
|
||||
public async Task Teleport()
|
||||
{
|
||||
((ShaderMaterial)_animatedSprite.Material).Shader = BlinkShader;
|
||||
|
||||
|
|
@ -516,7 +559,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
await ToSignal(tween, "finished");
|
||||
}
|
||||
|
||||
public async Task UnTeleport()
|
||||
public async Task UnTeleport()
|
||||
{
|
||||
((ShaderMaterial)_animatedSprite.Material).Shader = BlinkShader;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue