Add stuff
This commit is contained in:
@@ -21,7 +21,6 @@ public partial class MainMenu : Node2D
|
||||
private void OnStartButtonPressed()
|
||||
{
|
||||
_player.Play("FirstLevel");
|
||||
var main = GetTree().Root.GetNode<Main>("/root/Main");
|
||||
Hide();
|
||||
_player.AnimationFinished += OnAnimationFinished;
|
||||
}
|
||||
|
||||
81
Scripts/Player2.cs
Normal file
81
Scripts/Player2.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user