second commit
This commit is contained in:
@@ -1,35 +1,57 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Player : Node2D
|
||||
public partial class Player : Sprite2D
|
||||
{
|
||||
[Signal]
|
||||
public delegate void TurnDoneEventHandler();
|
||||
public bool _aiming = false;
|
||||
public int _health = 10;
|
||||
public PackedScene _attackScene = GD.Load<PackedScene>("res://Attack.tscn");
|
||||
public Attack _currentAttack;
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
base._Process(delta);
|
||||
if (_currentAttack != null)
|
||||
{
|
||||
if (Input.IsActionJustPressed("leftClick")){
|
||||
if (_currentAttack._hovered){
|
||||
_aiming = true;
|
||||
}
|
||||
}
|
||||
if (_aiming){
|
||||
Vector2 offset = (_currentAttack.GlobalPosition - GetGlobalMousePosition()) * 500;
|
||||
if (Input.IsActionJustReleased("leftClick")){
|
||||
ShootCurrentAttack(offset);
|
||||
}
|
||||
}
|
||||
if (_currentAttack.Position.Y > GetViewportRect().Size.Y + 50){
|
||||
_currentAttack.QueueFree();
|
||||
_currentAttack = null;
|
||||
EmitSignal(SignalName.TurnDone);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void StartTurn()
|
||||
{
|
||||
if (_currentAttack == null){
|
||||
GD.Print("Loading attack");
|
||||
_currentAttack = _attackScene.Instantiate<Attack>();
|
||||
_currentAttack._playerOwner = this;
|
||||
_currentAttack.GravityScale = 0;
|
||||
_currentAttack.Position = GetViewportRect().Size / 2;
|
||||
AddChild(_currentAttack);
|
||||
}
|
||||
if (Input.IsActionJustPressed("leftClick")){
|
||||
if (_currentAttack._hovered){
|
||||
_aiming = true;
|
||||
}
|
||||
}
|
||||
if (_aiming){
|
||||
Vector2 offset = (_currentAttack.GlobalPosition - GetGlobalMousePosition()) * 500;
|
||||
if (Input.IsActionJustReleased("leftClick")){
|
||||
ShootCurrentAttack(offset);
|
||||
}
|
||||
}
|
||||
if (_currentAttack.Position.Y > GetViewportRect().Size.Y + 50){
|
||||
_currentAttack.QueueFree();
|
||||
_currentAttack = null;
|
||||
}
|
||||
|
||||
public void TakeDamage(int DAMAGE, Enemy ATTACKER)
|
||||
{
|
||||
_health -= DAMAGE;
|
||||
if (_health <= 0)
|
||||
{
|
||||
GD.Print("GAME OVER");
|
||||
GetTree().Quit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user