This commit is contained in:
2023-09-06 14:43:12 -07:00
parent f8cca640a6
commit d536aa2014
41 changed files with 2747 additions and 1011 deletions

View File

@@ -1,25 +1,32 @@
using Godot;
using Godot;
public partial class P1Controls : Controls
public partial class Character : CharacterBody3D
{
[Export]
private PackedScene _fireProjectile;
protected PackedScene _fireProjectile;
[Export]
private PackedScene _altFireProjectile;
protected PackedScene _altFireProjectile;
protected Player _ownerPlayer;
[Export]
private float _speed = 3.0f;
protected float _speed = 3.0f;
public bool CanShoot { get; protected set; }
private GameManager _gameManager;
protected GameManager _gameManager;
public override void _Ready()
public override void _EnterTree()
{
CanShoot = true;
_gameManager = GetTree().Root.GetNode<GameManager>("Main/GameManager");
}
public void Initialize(Player ownerPlayer)
{
_ownerPlayer = ownerPlayer;
}
public override void _PhysicsProcess(double delta)
{
Velocity = CalculateCharacterMovement(delta);
@@ -31,9 +38,9 @@ public partial class P1Controls : Controls
if (Input.IsActionJustPressed("exit"))
GetTree().Quit();
if (Input.IsActionJustPressed($"p1_fire") && CanShoot)
if (Input.IsActionJustPressed(_ownerPlayer.PlayerInput.Fire()) && CanShoot)
Fire();
if (Input.IsActionJustPressed($"p1_altfire") && CanShoot)
if (Input.IsActionJustPressed(_ownerPlayer.PlayerInput.AltFire()) && CanShoot)
AltFire();
}
@@ -41,7 +48,7 @@ public partial class P1Controls : Controls
{
var velocity = Velocity;
var inputDir = Input.GetVector($"p1_left", $"p1_right", $"p1_up", $"p1_down");
var inputDir = Input.GetVector(_ownerPlayer.PlayerInput.Left(), _ownerPlayer.PlayerInput.Right(), _ownerPlayer.PlayerInput.Up(), _ownerPlayer.PlayerInput.Down());
var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
if (direction != Vector3.Zero)
{
@@ -82,6 +89,6 @@ public partial class P1Controls : Controls
public void OnHit(Node3D node)
{
if (this != null)
_gameManager.CallDeferred(GameManager.MethodName.RemoveCharacter, this);
_gameManager.CallDeferred(GameManager.MethodName.RemoveCharacter, _ownerPlayer);
}
}

View File

@@ -1,11 +0,0 @@
using Godot;
public partial class Controls : CharacterBody3D
{
private GameManager _gameManager;
public override void _Ready()
{
_gameManager = GetTree().Root.GetNode<GameManager>("Main/GameManager");
}
}

View File

@@ -1,85 +0,0 @@
using Godot;
public partial class P2Controls : Controls
{
[Export]
private PackedScene _fireProjectile;
[Export]
private PackedScene _altFireProjectile;
[Export]
private float _speed = 3.0f;
public bool CanShoot { get; protected set; }
private GameManager _gameManager;
public override void _Ready()
{
CanShoot = true;
_gameManager = GetTree().Root.GetNode<GameManager>("Main/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;
GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Up);
GetNode<Node3D>("CollisionShape3D").LookAt(Position + direction, Vector3.Up);
}
else
{
velocity.X = Mathf.MoveToward(Velocity.X, 0, _speed);
velocity.Z = Mathf.MoveToward(Velocity.Z, 0, _speed);
}
return velocity;
}
private async void Fire()
{
var projectile = _fireProjectile.Instantiate<Projectile>();
projectile.Position = Position + new Vector3(0f, 1f, 0f);
GetParent().AddChild(projectile);
CanShoot = false;
await ToSignal(GetTree().CreateTimer(projectile.Cooldown), "timeout");
CanShoot = true;
}
private async void AltFire()
{
var projectile = _altFireProjectile.Instantiate<Projectile>();
projectile.Position = Position + new Vector3(0f, 1f, 0f);
GetParent().AddChild(projectile);
CanShoot = false;
await ToSignal(GetTree().CreateTimer(projectile.Cooldown), "timeout");
CanShoot = true;
}
public void OnHit(Node3D node)
{
_gameManager.RemoveCharacter(this);
}
}

38
Player/Base/Player.cs Normal file
View File

@@ -0,0 +1,38 @@
using Godot;
using Godot.Collections;
public partial class Player : Node3D
{
[Export]
public SpawnPoint SpawnPoint;
[Export]
public Array<PackedScene> PlayableCharacterScenes;
[Export]
public PlayerInput PlayerInput;
[Export]
public int PlayerNumber;
public Array<Character> CharactersLeftOnStage = new Array<Character>();
public Array<Character> CharactersExited = new Array<Character>();
public Character SelectedCharacter;
public bool IsSelectingCharacter = false;
public int CharacterIndex = 0;
public bool GameOver = false;
public override void _Ready()
{
foreach (var character in PlayableCharacterScenes)
{
var instance = (Character)character.Instantiate();
instance.Initialize(this);
CharactersLeftOnStage.Add(instance);
}
}
}

View File

@@ -1,18 +1,23 @@
[gd_scene load_steps=7 format=3 uid="uid://xcmspevaqcrc"]
[gd_scene load_steps=8 format=3 uid="uid://xcmspevaqcrc"]
[ext_resource type="Script" path="res://Player/Base/PlayerManager.cs" id="1_mmi2c"]
[ext_resource type="PackedScene" uid="uid://b38hcomu4tpm5" path="res://Player/Pisces/P1PiscesWitch.tscn" id="2_g10gf"]
[ext_resource type="PackedScene" uid="uid://iempdafdn6ct" path="res://Player/Scorpio/P1PlayerScorpio.tscn" id="3_nsh6r"]
[ext_resource type="PackedScene" uid="uid://bgkqfamdiwrrw" path="res://Player/Sagittarius/P1Megami.tscn" id="4_vnhuv"]
[ext_resource type="PackedScene" uid="uid://crkon4c8ah1a2" path="res://Player/Capricorn/CapricornP1.tscn" id="5_ccoeb"]
[ext_resource type="Script" path="res://Player/Base/Player.cs" id="1_otv3t"]
[ext_resource type="PackedScene" uid="uid://b38hcomu4tpm5" path="res://Player/Pisces/Pisces.tscn" id="2_g10gf"]
[ext_resource type="PackedScene" uid="uid://iempdafdn6ct" path="res://Player/Scorpio/Scorpio.tscn" id="3_nsh6r"]
[ext_resource type="PackedScene" uid="uid://bgkqfamdiwrrw" path="res://Player/Sagittarius/Sagittarius.tscn" id="4_vnhuv"]
[ext_resource type="PackedScene" uid="uid://crkon4c8ah1a2" path="res://Player/Capricorn/Capricorn.tscn" id="5_ccoeb"]
[ext_resource type="Script" path="res://Player/Base/SpawnPoint.cs" id="6_lida8"]
[ext_resource type="PackedScene" uid="uid://dklmu3wwoukmw" path="res://Player/Base/Player1Input.tscn" id="7_nyh7j"]
[node name="Player1" type="Node3D" node_paths=PackedStringArray("SpawnPoint")]
script = ExtResource("1_mmi2c")
[node name="Player1" type="Node3D" node_paths=PackedStringArray("SpawnPoint", "PlayerInput")]
script = ExtResource("1_otv3t")
SpawnPoint = NodePath("Marker3D")
PlayableCharacterScenes = Array[PackedScene]([ExtResource("2_g10gf"), ExtResource("3_nsh6r"), ExtResource("4_vnhuv"), ExtResource("5_ccoeb")])
PlayerInput = NodePath("Player1Input")
PlayerNumber = 1
[node name="Marker3D" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.5, 0, 5.513)
gizmo_extents = 1.0
script = ExtResource("6_lida8")
[node name="Player1Input" parent="." instance=ExtResource("7_nyh7j")]

View File

@@ -0,0 +1,14 @@
public partial class Player1Input : PlayerInput
{
public override string Up() => "p1_up";
public override string Down() => "p1_down";
public override string Left() => "p1_left";
public override string Right() => "p1_right";
public override string Fire() => "p1_fire";
public override string AltFire() => "p1_altfire";
}

View File

@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://dklmu3wwoukmw"]
[ext_resource type="Script" path="res://Player/Base/Player1Input.cs" id="1_te7aw"]
[node name="Player1Input" type="Node"]
script = ExtResource("1_te7aw")

View File

@@ -1,15 +1,23 @@
[gd_scene load_steps=5 format=3 uid="uid://b57xus5rqasy8"]
[gd_scene load_steps=8 format=3 uid="uid://b57xus5rqasy8"]
[ext_resource type="Script" path="res://Player/Base/PlayerManager.cs" id="1_gttsr"]
[ext_resource type="Script" path="res://Player/Base/Player.cs" id="1_wlxdt"]
[ext_resource type="Script" path="res://Player/Base/SpawnPoint.cs" id="1_xs6nn"]
[ext_resource type="PackedScene" uid="uid://dfanwejjy3iue" path="res://Player/Pisces/P2PiscesWitch.tscn" id="2_78cal"]
[ext_resource type="PackedScene" uid="uid://cg6hdoeq70ke8" path="res://Player/Scorpio/P2PlayerScorpio.tscn" id="3_04rrx"]
[ext_resource type="PackedScene" uid="uid://b38hcomu4tpm5" path="res://Player/Pisces/Pisces.tscn" id="2_gtqii"]
[ext_resource type="PackedScene" uid="uid://iempdafdn6ct" path="res://Player/Scorpio/Scorpio.tscn" id="3_0k4g2"]
[ext_resource type="PackedScene" uid="uid://bgkqfamdiwrrw" path="res://Player/Sagittarius/Sagittarius.tscn" id="4_0vqor"]
[ext_resource type="PackedScene" uid="uid://crkon4c8ah1a2" path="res://Player/Capricorn/Capricorn.tscn" id="5_ke8lm"]
[ext_resource type="PackedScene" uid="uid://bsvjdu8ao1wva" path="res://Player/Base/Player2Input.tscn" id="5_u4w27"]
[node name="Player2" type="Node3D" groups=["Player"]]
script = ExtResource("1_gttsr")
PlayableCharacterScenes = Array[PackedScene]([ExtResource("2_78cal"), ExtResource("3_04rrx")])
[node name="Player2" type="Node3D" node_paths=PackedStringArray("SpawnPoint", "PlayerInput") groups=["Player"]]
script = ExtResource("1_wlxdt")
SpawnPoint = NodePath("Marker3D")
PlayableCharacterScenes = Array[PackedScene]([ExtResource("2_gtqii"), ExtResource("3_0k4g2"), ExtResource("4_0vqor"), ExtResource("5_ke8lm")])
PlayerInput = NodePath("Player2Input")
PlayerNumber = 2
[node name="Marker3D" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.5, 0, 5.513)
gizmo_extents = 1.0
script = ExtResource("1_xs6nn")
[node name="Player2Input" parent="." instance=ExtResource("5_u4w27")]

View File

@@ -0,0 +1,14 @@
public partial class Player2Input : PlayerInput
{
public override string Up() => "p2_up";
public override string Down() => "p2_down";
public override string Left() => "p2_left";
public override string Right() => "p2_right";
public override string Fire() => "p2_fire";
public override string AltFire() => "p2_altfire";
}

View File

@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://bsvjdu8ao1wva"]
[ext_resource type="Script" path="res://Player/Base/Player2Input.cs" id="1_j3rvl"]
[node name="Player2Input" type="Node"]
script = ExtResource("1_j3rvl")

View File

@@ -0,0 +1,35 @@
using Godot;
public partial class PlayerInput : Node
{
public virtual string Up()
{
GD.PrintErr("Using base type");
return string.Empty;
}
public virtual string Down()
{
GD.PrintErr("Using base type");
return string.Empty;
}
public virtual string Left()
{
GD.PrintErr("Using base type");
return string.Empty;
}
public virtual string Right()
{
GD.PrintErr("Using base type");
return string.Empty;
}
public virtual string Fire()
{
GD.PrintErr("Using base type");
return string.Empty;
}
public virtual string AltFire()
{
GD.PrintErr("Using base type");
return string.Empty;
}
}

View File

@@ -1,30 +0,0 @@
using Godot;
using Godot.Collections;
public partial class PlayerManager : Node3D
{
[Export]
public SpawnPoint SpawnPoint;
[Export]
public Array<PackedScene> PlayableCharacterScenes;
public Array<Controls> CharactersLeftOnStage = new Array<Controls>();
public Controls SelectedCharacter;
public bool IsSelectingCharacter = false;
public int _characterIndex = 0;
public bool GameOver = false;
public override void _Ready()
{
foreach (var character in PlayableCharacterScenes)
{
var instance = character.Instantiate();
CharactersLeftOnStage.Add((Controls)instance);
}
}
}

View File

@@ -7,10 +7,10 @@ public partial class Projectile : Node3D
[Export]
public AudioStream _soundEffect;
public Controls ParentCharacter;
public Character ParentCharacter;
[Export]
private float _projectileSpeed = 1f;
protected float _projectileSpeed = 1f;
public override void _Ready()
{