????
This commit is contained in:
@@ -18,9 +18,9 @@ public partial class AreaExit : Node3D
|
||||
{
|
||||
if (node is Character)
|
||||
{
|
||||
if (node.GetType() == typeof(Character1))
|
||||
if (node.GetType() == typeof(Character1) || node.GetType() == typeof(Capricorn))
|
||||
_gameManager.RemoveCharacterAndAddToExit((Character1)node);
|
||||
if (node.GetType() == typeof(Character2))
|
||||
if (node.GetType() == typeof(Character2) || node.GetType() == typeof(Capricorn2))
|
||||
_gameManager.RemoveCharacterAndAddToExit((Character2)node);
|
||||
|
||||
GD.Print("Exit reached");
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Capricorn : CharacterBody3D
|
||||
public partial class Capricorn : Character1
|
||||
{
|
||||
private AnimatedSprite3D _sprite;
|
||||
|
||||
@@ -97,9 +96,9 @@ public partial class Capricorn : CharacterBody3D
|
||||
private async void Fire()
|
||||
{
|
||||
IsShooting = true;
|
||||
var projectile = _fireProjectile.Instantiate<Projectile>();
|
||||
projectile.Position = Position + new Vector3(0f, 1f, 0f);
|
||||
GetParent().AddChild(projectile);
|
||||
//var projectile = _fireProjectile.Instantiate<Projectile>();
|
||||
//projectile.Position = Position + new Vector3(0f, 1f, 0f);
|
||||
//GetParent().AddChild(projectile);
|
||||
CanShoot = false;
|
||||
await ToSignal(GetTree().CreateTimer(2.0f), "timeout");
|
||||
CanShoot = true;
|
||||
@@ -109,9 +108,9 @@ public partial class Capricorn : CharacterBody3D
|
||||
private async void AltFire()
|
||||
{
|
||||
IsShooting = true;
|
||||
var projectile = _altFireProjectile.Instantiate<Projectile>();
|
||||
projectile.Position = Position + new Vector3(0f, 1f, 0f);
|
||||
GetParent().AddChild(projectile);
|
||||
//var projectile = _altFireProjectile.Instantiate<Projectile>();
|
||||
//projectile.Position = Position + new Vector3(0f, 1f, 0f);
|
||||
//GetParent().AddChild(projectile);
|
||||
CanShoot = false;
|
||||
await ToSignal(GetTree().CreateTimer(2.0f), "timeout");
|
||||
CanShoot = true;
|
||||
|
||||
147
Scripts/Capricorn2.cs
Normal file
147
Scripts/Capricorn2.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using Godot;
|
||||
|
||||
public partial class Capricorn2 : Character2
|
||||
{
|
||||
private AnimatedSprite3D _sprite;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_sprite = GetNode<AnimatedSprite3D>("Pivot/Sprite");
|
||||
CanShoot = true;
|
||||
_gameManager = GetTree().Root.GetNode<GameManager>("Main/GameManager");
|
||||
}
|
||||
|
||||
[Export]
|
||||
private PackedScene _fireProjectile;
|
||||
[Export]
|
||||
private PackedScene _altFireProjectile;
|
||||
|
||||
[Export]
|
||||
private float _speed = 3.0f;
|
||||
|
||||
public bool CanShoot { get; private set; }
|
||||
|
||||
public bool IsShooting = false;
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
Velocity = CalculateCharacterMovement(delta);
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (Input.IsActionJustPressed("exit"))
|
||||
GetTree().Quit();
|
||||
|
||||
if (Input.IsActionJustPressed($"p2_fire") && CanShoot)
|
||||
Fire();
|
||||
if (Input.IsActionJustPressed($"p2_altfire") && CanShoot)
|
||||
AltFire();
|
||||
}
|
||||
|
||||
private Vector3 CalculateCharacterMovement(double delta)
|
||||
{
|
||||
var velocity = Velocity;
|
||||
|
||||
var inputDir = Input.GetVector($"p2_left", $"p2_right", $"p2_up", $"p2_down");
|
||||
var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
|
||||
if (direction != Vector3.Zero)
|
||||
{
|
||||
velocity.X = direction.X * _speed;
|
||||
velocity.Z = direction.Z * _speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity.X = Mathf.MoveToward(Velocity.X, 0, _speed);
|
||||
velocity.Z = Mathf.MoveToward(Velocity.Z, 0, _speed);
|
||||
}
|
||||
|
||||
if (IsShooting)
|
||||
AttackSprite(direction);
|
||||
else
|
||||
WalkSprite(direction);
|
||||
|
||||
if (!IsShooting && direction.IsEqualApprox(Vector3.Zero))
|
||||
{
|
||||
_sprite.Play("WalkForward");
|
||||
_sprite.Stop();
|
||||
}
|
||||
|
||||
return velocity;
|
||||
}
|
||||
|
||||
private void WalkSprite(Vector3 direction)
|
||||
{
|
||||
var roundedDirection = direction.Round();
|
||||
|
||||
if (roundedDirection == Vector3.Right)
|
||||
{
|
||||
_sprite.Play("WalkSide");
|
||||
_sprite.FlipH = false;
|
||||
}
|
||||
if (roundedDirection == Vector3.Left)
|
||||
{
|
||||
_sprite.Play("WalkSide");
|
||||
_sprite.FlipH = true;
|
||||
}
|
||||
if (roundedDirection == Vector3.Forward)
|
||||
_sprite.Play("WalkForward");
|
||||
if (roundedDirection == Vector3.Back)
|
||||
_sprite.Play("WalkBack");
|
||||
}
|
||||
|
||||
private async void Fire()
|
||||
{
|
||||
IsShooting = true;
|
||||
var projectile = _fireProjectile.Instantiate<Projectile>();
|
||||
projectile.Position = Position + new Vector3(0f, 1f, 0f);
|
||||
GetParent().AddChild(projectile);
|
||||
CanShoot = false;
|
||||
await ToSignal(GetTree().CreateTimer(2.0f), "timeout");
|
||||
CanShoot = true;
|
||||
IsShooting = false;
|
||||
}
|
||||
|
||||
private async void AltFire()
|
||||
{
|
||||
IsShooting = true;
|
||||
var projectile = _altFireProjectile.Instantiate<Projectile>();
|
||||
projectile.Position = Position + new Vector3(0f, 1f, 0f);
|
||||
GetParent().AddChild(projectile);
|
||||
CanShoot = false;
|
||||
await ToSignal(GetTree().CreateTimer(2.0f), "timeout");
|
||||
CanShoot = true;
|
||||
IsShooting = false;
|
||||
}
|
||||
|
||||
private void AttackSprite(Vector3 direction)
|
||||
{
|
||||
var roundedDirection = direction.Round();
|
||||
|
||||
if (roundedDirection == Vector3.Right)
|
||||
{
|
||||
_sprite.Play("AttackSide");
|
||||
_sprite.FlipH = false;
|
||||
}
|
||||
if (roundedDirection == Vector3.Left)
|
||||
{
|
||||
_sprite.Play("AttackSide");
|
||||
_sprite.FlipH = true;
|
||||
}
|
||||
if (roundedDirection == Vector3.Forward)
|
||||
_sprite.Play("AttackForward");
|
||||
if (roundedDirection == Vector3.Back)
|
||||
_sprite.Play("AttackBack");
|
||||
|
||||
if (direction.IsEqualApprox(Vector3.Zero))
|
||||
_sprite.Play("AttackForward");
|
||||
}
|
||||
|
||||
public void OnHit(Node3D node)
|
||||
{
|
||||
_gameManager.CallDeferred(GameManager.MethodName.RemoveCharacter, this);
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public partial class GameManager : Node
|
||||
if (!P1CharactersOut.Any() && !Players.ElementAt(0).CharactersLeftOnStage.Any())
|
||||
SetGameOver(Players.ElementAt(0), true);
|
||||
|
||||
if (!P2CharactersOut.Any() && !Players.ElementAt(1).CharactersLeftOnStage.Any())
|
||||
if (Players.Count() == 2 && !P2CharactersOut.Any() && !Players.ElementAt(1).CharactersLeftOnStage.Any())
|
||||
SetGameOver(Players.ElementAt(1), true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user