Refactor Player and Character
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=27 format=3 uid="uid://bgkqfamdiwrrw"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/Player1.cs" id="1_onedk"]
|
||||
[ext_resource type="Script" path="res://Scripts/Character.cs" id="1_yxmbs"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_4qqwi"]
|
||||
resource_name = "Material.006"
|
||||
@@ -603,7 +603,7 @@ size = Vector3(0.822782, 0.527059, 0.80108)
|
||||
size = Vector3(1.19222, 2.13872, 1.37879)
|
||||
|
||||
[node name="Megami" type="CharacterBody3D"]
|
||||
script = ExtResource("1_onedk")
|
||||
script = ExtResource("1_yxmbs")
|
||||
|
||||
[node name="Pivot" type="Node3D" parent="."]
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://b38hcomu4tpm5"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/Player1.cs" id="1_6cdju"]
|
||||
[ext_resource type="PackedScene" uid="uid://cyn2wn6ffsnu7" path="res://Scenes/Weapons/Single.tscn" id="2_1c3c8"]
|
||||
[ext_resource type="PackedScene" uid="uid://bq40xbqibrk1y" path="res://Scenes/Weapons/ShotgunBullet.tscn" id="3_4eh4a"]
|
||||
[ext_resource type="Script" path="res://Scripts/Character.cs" id="1_gro0b"]
|
||||
[ext_resource type="PackedScene" uid="uid://cyn2wn6ffsnu7" path="res://Scenes/Weapons/Single.tscn" id="2_y0wmm"]
|
||||
[ext_resource type="PackedScene" uid="uid://bq40xbqibrk1y" path="res://Scenes/Weapons/ShotgunBullet.tscn" id="3_p4fqi"]
|
||||
[ext_resource type="PackedScene" uid="uid://yosw0j58nvrf" path="res://Models/Characters/fwitch.gltf" id="4_mtwuo"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_ayco3"]
|
||||
@@ -15,10 +15,9 @@ height = 1.67894
|
||||
|
||||
[node name="Pisces" type="CharacterBody3D" groups=["Player"]]
|
||||
transform = Transform3D(0.33, 0, 0, 0, 0.33, 0, 0, 0, 0.33, 0, 0, 0)
|
||||
script = ExtResource("1_6cdju")
|
||||
_speed = 2.0
|
||||
_fireProjectile = ExtResource("2_1c3c8")
|
||||
_altFireProjectile = ExtResource("3_4eh4a")
|
||||
script = ExtResource("1_gro0b")
|
||||
_fireProjectile = ExtResource("2_y0wmm")
|
||||
_altFireProjectile = ExtResource("3_p4fqi")
|
||||
|
||||
[node name="Pivot" type="Node3D" parent="."]
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://iempdafdn6ct"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/Player1.cs" id="1_mn5ui"]
|
||||
[ext_resource type="Script" path="res://Scripts/Character.cs" id="1_mn5ui"]
|
||||
[ext_resource type="PackedScene" uid="uid://dyhimd6qec8fu" path="res://Scenes/Characters/ScorpioAnimated.tscn" id="2_pahgr"]
|
||||
[ext_resource type="PackedScene" uid="uid://cxnek5wgpxbft" path="res://Scenes/Weapons/CutterShot.tscn" id="2_uayjr"]
|
||||
[ext_resource type="PackedScene" uid="uid://cwt4rum7tvyvb" path="res://Scenes/Weapons/CutterShotAltFire.tscn" id="3_tw078"]
|
||||
@@ -15,7 +15,6 @@ size = Vector3(0.822782, 0.527059, 0.80108)
|
||||
collision_layer = 0
|
||||
collision_mask = 4097
|
||||
script = ExtResource("1_mn5ui")
|
||||
_speed = 3.0
|
||||
_fireProjectile = ExtResource("2_uayjr")
|
||||
_altFireProjectile = ExtResource("3_tw078")
|
||||
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://cxj6yeddshy16"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://cxj6yeddshy16"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/GameManager.cs" id="1_ya2kt"]
|
||||
[ext_resource type="PackedScene" uid="uid://b38hcomu4tpm5" path="res://Scenes/Characters/PiscesWitch.tscn" id="2_am26u"]
|
||||
[ext_resource type="PackedScene" uid="uid://iempdafdn6ct" path="res://Scenes/Characters/PlayerScorpio.tscn" id="3_e5mhu"]
|
||||
[ext_resource type="PackedScene" uid="uid://bgkqfamdiwrrw" path="res://Scenes/Characters/Megami.tscn" id="4_1hwqs"]
|
||||
[ext_resource type="PackedScene" uid="uid://xcmspevaqcrc" path="res://Scenes/Player1.tscn" id="4_3fl70"]
|
||||
[ext_resource type="PackedScene" uid="uid://dq1gtd55p04do" path="res://Scenes/StageGUI.tscn" id="5_gsh7q"]
|
||||
[ext_resource type="Script" path="res://Scripts/SpawnPoint.cs" id="7_4n1rc"]
|
||||
[ext_resource type="PackedScene" uid="uid://jircpua5fl80" path="res://Scenes/Player2.tscn" id="8_sixv3"]
|
||||
|
||||
[node name="GameManager" type="Node3D"]
|
||||
script = ExtResource("1_ya2kt")
|
||||
_p1Characters = [ExtResource("2_am26u"), ExtResource("3_e5mhu"), ExtResource("4_1hwqs")]
|
||||
_p2Characters = [ExtResource("2_am26u"), ExtResource("3_e5mhu"), ExtResource("4_1hwqs")]
|
||||
PlayerScenes = Array[PackedScene]([ExtResource("4_3fl70"), ExtResource("8_sixv3")])
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.5, 0.866025, 0, -0.866025, 0.5, -0.527878, 10.966, 6.61121)
|
||||
@@ -37,4 +35,10 @@ script = ExtResource("7_4n1rc")
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, -0.504317, 0.863519, 0, -0.863519, -0.504317, 0, 19.9508, 0)
|
||||
|
||||
[connection signal="OnCharacterSelectionMade" from="StageGUI" to="." method="OnP1CharacterSelected"]
|
||||
[node name="Player1" parent="." node_paths=PackedStringArray("SpawnPoint") instance=ExtResource("4_3fl70")]
|
||||
SpawnPoint = NodePath("../P1SpawnPoint")
|
||||
|
||||
[node name="Player2" parent="." node_paths=PackedStringArray("SpawnPoint") instance=ExtResource("8_sixv3")]
|
||||
SpawnPoint = NodePath("../P2SpawnPoint")
|
||||
|
||||
[connection signal="OnCharacterSelectionMade" from="StageGUI" to="." method="OnCharacterSelected"]
|
||||
|
||||
15
Scenes/Player1.tscn
Normal file
15
Scenes/Player1.tscn
Normal file
@@ -0,0 +1,15 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://xcmspevaqcrc"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/Player.cs" id="1_ctl2x"]
|
||||
[ext_resource type="PackedScene" uid="uid://b38hcomu4tpm5" path="res://Scenes/Characters/PiscesWitch.tscn" id="2_7c6mk"]
|
||||
[ext_resource type="Script" path="res://Scripts/SpawnPoint.cs" id="2_mkhuu"]
|
||||
[ext_resource type="PackedScene" uid="uid://iempdafdn6ct" path="res://Scenes/Characters/PlayerScorpio.tscn" id="3_mtqa2"]
|
||||
[ext_resource type="PackedScene" uid="uid://bgkqfamdiwrrw" path="res://Scenes/Characters/Megami.tscn" id="4_1xs5f"]
|
||||
|
||||
[node name="Player1" type="Node3D" node_paths=PackedStringArray("SpawnPoint")]
|
||||
script = ExtResource("1_ctl2x")
|
||||
SpawnPoint = NodePath("Marker3D")
|
||||
PlayableCharacters = Array[PackedScene]([ExtResource("2_7c6mk"), ExtResource("3_mtqa2"), ExtResource("4_1xs5f")])
|
||||
|
||||
[node name="Marker3D" type="Marker3D" parent="."]
|
||||
script = ExtResource("2_mkhuu")
|
||||
15
Scenes/Player2.tscn
Normal file
15
Scenes/Player2.tscn
Normal file
@@ -0,0 +1,15 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://jircpua5fl80"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/Player.cs" id="1_k788q"]
|
||||
[ext_resource type="Script" path="res://Scripts/SpawnPoint.cs" id="1_xs6nn"]
|
||||
[ext_resource type="PackedScene" uid="uid://b38hcomu4tpm5" path="res://Scenes/Characters/PiscesWitch.tscn" id="2_ehwtn"]
|
||||
[ext_resource type="PackedScene" uid="uid://iempdafdn6ct" path="res://Scenes/Characters/PlayerScorpio.tscn" id="3_eamga"]
|
||||
[ext_resource type="PackedScene" uid="uid://bgkqfamdiwrrw" path="res://Scenes/Characters/Megami.tscn" id="4_uj8bq"]
|
||||
|
||||
[node name="Player2" type="Node3D" node_paths=PackedStringArray("SpawnPoint")]
|
||||
script = ExtResource("1_k788q")
|
||||
SpawnPoint = NodePath("Marker3D")
|
||||
PlayableCharacters = Array[PackedScene]([ExtResource("2_ehwtn"), ExtResource("3_eamga"), ExtResource("4_uj8bq")])
|
||||
|
||||
[node name="Marker3D" type="Marker3D" parent="."]
|
||||
script = ExtResource("1_xs6nn")
|
||||
@@ -15,6 +15,10 @@ _projectileSpeed = 10.0
|
||||
collision_layer = 2
|
||||
collision_mask = 0
|
||||
gravity_scale = 0.0
|
||||
continuous_cd = true
|
||||
max_contacts_reported = 1000
|
||||
contact_monitor = true
|
||||
can_sleep = false
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.644825, 0)
|
||||
|
||||
@@ -9,15 +9,16 @@ public partial class AreaExit : Node3D
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetTree().Root.GetNode<GameManager>("Main/GameManager");
|
||||
_gameManager = GetTree().Root.GetNode<GameManager>("Main/GameManager");
|
||||
}
|
||||
|
||||
|
||||
private void OnExitEntered(Node3D node)
|
||||
{
|
||||
GD.Print("Exit reached");
|
||||
var main = GetTree().Root.GetNode<Main>("/root/Main");
|
||||
main.LoadNextLevel(_levelIndex);
|
||||
_gameManager.ResetPlayerPosition();
|
||||
GD.Print("Exit reached");
|
||||
var main = GetTree().Root.GetNode<Main>("/root/Main");
|
||||
main.LoadNextLevel(_levelIndex);
|
||||
if (node is Player player)
|
||||
player.SpawnPoint.SetPlayerPosition(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
using Godot;
|
||||
using Godot;
|
||||
|
||||
public partial class Player1 : Character
|
||||
public partial class Character : CharacterBody3D
|
||||
{
|
||||
[Export]
|
||||
private float _speed = 5.0f;
|
||||
[Export]
|
||||
private PackedScene _fireProjectile;
|
||||
[Export]
|
||||
private PackedScene _altFireProjectile;
|
||||
|
||||
private GameManager _gameManager;
|
||||
[Export]
|
||||
private float _speed = 3.0f;
|
||||
|
||||
public bool CanShoot { get; private set; }
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
CanShoot = true;
|
||||
_gameManager = GetTree().Root.GetNode<GameManager>("Main/GameManager");
|
||||
_gameManager.SetP1GameOver(false);
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (!_gameManager.IsP1SelectingCharacter)
|
||||
if (!_gameManager.IsSelectingCharacter)
|
||||
{
|
||||
Velocity = CalculateCharacterMovement(delta);
|
||||
MoveAndSlide();
|
||||
@@ -34,11 +34,11 @@ public partial class Player1 : Character
|
||||
if (Input.IsActionJustPressed("exit"))
|
||||
GetTree().Quit();
|
||||
|
||||
if (!_gameManager.IsP1SelectingCharacter)
|
||||
if (!_gameManager.IsSelectingCharacter)
|
||||
{
|
||||
if (Input.IsActionJustPressed("p1_fire") && CanShoot)
|
||||
if (Input.IsActionJustPressed($"p1_fire") && CanShoot)
|
||||
Fire();
|
||||
if (Input.IsActionJustPressed("p1_altfire") && CanShoot)
|
||||
if (Input.IsActionJustPressed($"p1_altfire") && CanShoot)
|
||||
AltFire();
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public partial class Player1 : Character
|
||||
{
|
||||
var velocity = Velocity;
|
||||
|
||||
var inputDir = Input.GetVector("p1_left", "p1_right", "p1_up", "p1_down");
|
||||
var inputDir = Input.GetVector($"p1_left", $"p1_right", $"p1_up", $"p1_down");
|
||||
var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
|
||||
if (direction != Vector3.Zero)
|
||||
{
|
||||
@@ -82,20 +82,4 @@ public partial class Player1 : Character
|
||||
await ToSignal(GetTree().CreateTimer(projectile.Cooldown), "timeout");
|
||||
CanShoot = true;
|
||||
}
|
||||
|
||||
private void HitDebug()
|
||||
{
|
||||
var node = new Node3D();
|
||||
OnHit(node);
|
||||
}
|
||||
|
||||
private void OnHit(Node3D node)
|
||||
{
|
||||
_gameManager.RemoveP1Character();
|
||||
if (_gameManager._p1Characters.Count == 0)
|
||||
{
|
||||
GD.Print("Game over for P1");
|
||||
_gameManager.SetP1GameOver(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public partial class GameManager : Node
|
||||
@@ -7,88 +8,60 @@ public partial class GameManager : Node
|
||||
[Signal]
|
||||
public delegate void OnGameOverEventHandler();
|
||||
|
||||
[Signal]
|
||||
public delegate void OnP1GameOverEventHandler();
|
||||
[Signal]
|
||||
public delegate void OnP2GameOverEventHandler();
|
||||
public bool IsSelectingCharacter = true;
|
||||
|
||||
public int NumberOfPlayers;
|
||||
|
||||
public bool IsP1SelectingCharacter = true;
|
||||
public bool IsP2SelectingCharacter = true;
|
||||
private bool _gameOver = false;
|
||||
private int _characterIndex = 0;
|
||||
|
||||
[Export]
|
||||
public Array<PackedScene> _p1Characters;
|
||||
[Export]
|
||||
public Array<PackedScene> _p2Characters;
|
||||
private Array<PackedScene> PlayerScenes;
|
||||
|
||||
[Export]
|
||||
public Character _p1SelectedCharacter;
|
||||
public IEnumerable<Player> Players = new List<Player>();
|
||||
|
||||
[Export]
|
||||
public Character _p2SelectedCharacter;
|
||||
|
||||
private bool _p1GameOver = false;
|
||||
private bool _p2GameOver = false;
|
||||
|
||||
private int _p1CharacterIndex = 0;
|
||||
private int _p2CharacterIndex = 0;
|
||||
|
||||
public void SetP1ToNextCharacter() => _p1CharacterIndex = (++_p1CharacterIndex) % _p1Characters.Count();
|
||||
|
||||
public void SetP1ToPreviousCharacter() => _p1CharacterIndex = _p1CharacterIndex == 0 ? _p1Characters.Count() - 1 : --_p1CharacterIndex;
|
||||
|
||||
public void ResetPlayerPosition()
|
||||
public override void _Ready()
|
||||
{
|
||||
var playerSpawnPoint = GetNode<SpawnPoint>("P1SpawnPoint");
|
||||
playerSpawnPoint.SetPlayerPosition(_p1SelectedCharacter);
|
||||
foreach (var playerScene in PlayerScenes)
|
||||
{
|
||||
var player = playerScene.Instantiate();
|
||||
Players = Players.Append((Player)player);
|
||||
GD.Print("Players added");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnP1CharacterSelected()
|
||||
public void SetToNextCharacter(Player player) => _characterIndex = (++_characterIndex) % player.PlayableCharacters.Count();
|
||||
|
||||
public void SetToPreviousCharacter(Player player) => _characterIndex = _characterIndex == 0 ? player.PlayableCharacters.Count() - 1 : --_characterIndex;
|
||||
|
||||
public void ResetPlayerPosition(Player player)
|
||||
{
|
||||
player.SpawnPoint.SetPlayerPosition(player.SelectedCharacter);
|
||||
}
|
||||
|
||||
public void OnCharacterSelected(Player player)
|
||||
{
|
||||
GD.Print("Instancing...");
|
||||
var selectedPlayer = _p1Characters[_p1CharacterIndex].Instantiate();
|
||||
_p1SelectedCharacter = selectedPlayer as Character;
|
||||
GetTree().Root.AddChild(_p1SelectedCharacter);
|
||||
ResetPlayerPosition();
|
||||
GD.Print(player.PlayableCharacters.Count());
|
||||
var selectedCharacter = player.PlayableCharacters[_characterIndex].Instantiate();
|
||||
player.SelectedCharacter = selectedCharacter as Character;
|
||||
GetTree().Root.AddChild(player.SelectedCharacter);
|
||||
player.SpawnPoint.SetPlayerPosition(player.SelectedCharacter);
|
||||
}
|
||||
|
||||
public void RemoveP1Character()
|
||||
public void RemoveCharacter(Player player)
|
||||
{
|
||||
_p1Characters.Remove(_p1Characters.ElementAt(_p1CharacterIndex));
|
||||
_p1SelectedCharacter?.QueueFree();
|
||||
_p1CharacterIndex = 0;
|
||||
player.PlayableCharacters.Remove(player.PlayableCharacters.ElementAt(_characterIndex));
|
||||
player.SelectedCharacter?.QueueFree();
|
||||
_characterIndex = 0;
|
||||
}
|
||||
|
||||
public void SetP1GameOver(bool isGameOver)
|
||||
public void SetGameOver(bool isGameOver)
|
||||
{
|
||||
_p1GameOver = isGameOver;
|
||||
_gameOver = isGameOver;
|
||||
if (isGameOver)
|
||||
{
|
||||
EmitSignal(SignalName.OnP1GameOver);
|
||||
CheckForOverallGameOver();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsP1GameOver => _p1GameOver;
|
||||
|
||||
public void SetP2GameOver(bool isGameOver)
|
||||
{
|
||||
_p2GameOver = isGameOver;
|
||||
if (isGameOver)
|
||||
{
|
||||
EmitSignal(SignalName.OnP2GameOver);
|
||||
CheckForOverallGameOver();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckForOverallGameOver()
|
||||
{
|
||||
if (_p1GameOver && _p2GameOver)
|
||||
EmitSignal(SignalName.OnGameOver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Character : CharacterBody3D
|
||||
{
|
||||
public bool IsGameOver => _gameOver;
|
||||
}
|
||||
|
||||
13
Scripts/Player.cs
Normal file
13
Scripts/Player.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
public partial class Player : Node3D
|
||||
{
|
||||
[Export]
|
||||
public SpawnPoint SpawnPoint;
|
||||
|
||||
[Export]
|
||||
public Array<PackedScene> PlayableCharacters;
|
||||
|
||||
public Character SelectedCharacter;
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Player2 : CharacterBody3D
|
||||
{
|
||||
[Export]
|
||||
private float _speed = 5.0f;
|
||||
[Export]
|
||||
private PackedScene _fireProjectile;
|
||||
[Export]
|
||||
private PackedScene _altFireProjectile;
|
||||
|
||||
public bool CanShoot { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
CanShoot = true;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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, -1f);
|
||||
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, -1f);
|
||||
GetParent().AddChild(projectile);
|
||||
CanShoot = false;
|
||||
await ToSignal(GetTree().CreateTimer(projectile.Cooldown), "timeout");
|
||||
CanShoot = true;
|
||||
}
|
||||
|
||||
private void OnHit(Node3D node)
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ using Godot;
|
||||
|
||||
public partial class SpawnPoint : Marker3D
|
||||
{
|
||||
public void SetPlayerPosition(Character character)
|
||||
public void SetPlayerPosition(Node3D character)
|
||||
{
|
||||
GD.Print("Moving character to spawn point");
|
||||
character.Position = Position;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
|
||||
public partial class StageGUI : Control
|
||||
{
|
||||
[Signal]
|
||||
public delegate void OnCharacterSelectionMadeEventHandler();
|
||||
public delegate void OnCharacterSelectionMadeEventHandler(Player player);
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
||||
@@ -14,7 +15,7 @@ public partial class StageGUI : Control
|
||||
|
||||
public void OnCharacterSelect()
|
||||
{
|
||||
if (_gameManager.IsP1GameOver)
|
||||
if (_gameManager.IsGameOver)
|
||||
return;
|
||||
|
||||
var wheel1 = GetNode<TextureRect>("CharacterSelect/Wheel");
|
||||
@@ -23,27 +24,26 @@ public partial class StageGUI : Control
|
||||
wheel1.FocusMode = FocusModeEnum.All;
|
||||
wheel1.GrabFocus();
|
||||
wheel1.Visible = true;
|
||||
_gameManager.IsP1SelectingCharacter = true;
|
||||
_gameManager.IsSelectingCharacter = true;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
var wheel1 = GetNode<TextureRect>("CharacterSelect/Wheel");
|
||||
|
||||
if (wheel1.HasFocus())
|
||||
{
|
||||
if (Input.IsActionJustPressed("p1_right"))
|
||||
_gameManager.SetP1ToNextCharacter();
|
||||
_gameManager.SetToNextCharacter(_gameManager.Players.ElementAt(0));
|
||||
if (Input.IsActionJustPressed("p1_left"))
|
||||
_gameManager.SetP1ToPreviousCharacter();
|
||||
_gameManager.SetToPreviousCharacter(_gameManager.Players.ElementAt(0));
|
||||
|
||||
if (Input.IsActionJustPressed("p1_fire"))
|
||||
{
|
||||
GD.Print("Selected character");
|
||||
wheel1.ReleaseFocus();
|
||||
wheel1.Hide();
|
||||
_gameManager.IsP1SelectingCharacter = false;
|
||||
EmitSignal(SignalName.OnCharacterSelectionMade);
|
||||
_gameManager.IsSelectingCharacter = false;
|
||||
EmitSignal(SignalName.OnCharacterSelectionMade, _gameManager.Players.ElementAt(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ public partial class TestEnemy : RigidBody3D
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
var player = GetTree().GetFirstNodeInGroup("Player") as Player1;
|
||||
var player = GetTree().GetFirstNodeInGroup("Player") as Character;
|
||||
if (player != null)
|
||||
LookAt(player.Position);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public partial class TestLevel : Node3D
|
||||
public override void _Ready()
|
||||
{
|
||||
var players = GetTree().GetNodesInGroup("Player");
|
||||
foreach (Player1 player in players)
|
||||
foreach (Character player in players)
|
||||
player.Transform = _spawnPoint.Transform;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user