182 lines
4.8 KiB
C#
182 lines
4.8 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public partial class Actor : Node2D
|
|
{
|
|
public bool _available = false, _hovered = false;
|
|
public int _health, _healthMax;
|
|
public CollisionShape2D _startArea;
|
|
public Cue _cue = null;
|
|
public List<Ball> _balls = new();
|
|
public Ball _hoveredBall = null;
|
|
public Ball _selectedBall = null;
|
|
public Ball _heldBall = null;
|
|
public ActorPanel _panel;
|
|
|
|
public Sprite2D _tempBallSprite = new();
|
|
|
|
public static Actor _Create()
|
|
{
|
|
PackedScene scene = ResourceLoader.Load<PackedScene>("res://Gameplay/actor.tscn");
|
|
Actor newActor = scene.Instantiate<Actor>();
|
|
|
|
newActor.GetNode<Sprite2D>("Sprite").Texture = GD.Load<Texture2D>("res://art/ness.png");
|
|
|
|
CueBall newCueBall = CueBall._Create();
|
|
newActor._balls.Add(newCueBall);
|
|
|
|
newCueBall = CueBall._Create();
|
|
newActor._balls.Add(newCueBall);
|
|
|
|
for (int i = 0; i < 7; i++)
|
|
{
|
|
SupportBall newBall = SupportBall._Create(i+1);
|
|
newActor._balls.Add(newBall);
|
|
}
|
|
|
|
Cue newCue = Cue._Create();
|
|
newActor.AddChild(newCue);
|
|
newActor._cue = newCue;
|
|
newActor._cue.Shoot += newActor.OnCueShoot;
|
|
|
|
newActor._health = 10;
|
|
newActor._healthMax = newActor._health;
|
|
|
|
ActorPanel newActorPanel = ActorPanel._Create(newActor);
|
|
newActor._panel = newActorPanel;
|
|
newActor.AddChild(newActorPanel);
|
|
|
|
return newActor;
|
|
}
|
|
|
|
public override void _Process(double DELTA_)
|
|
{
|
|
// if (_balls.Any(b => !b._placed))
|
|
// {
|
|
|
|
|
|
// Vector2 mousePosition = GetViewport().GetMousePosition();
|
|
// if (_tempBallSprite.Texture == null)
|
|
// {
|
|
// if (GetChildren().All(n => n != _tempBallSprite))
|
|
// {
|
|
// AddChild(_tempBallSprite);
|
|
// }
|
|
// _tempBallSprite.Texture = _heldBall.GetNode<Sprite2D>("Image").Texture;
|
|
// _tempBallSprite.ZIndex = 1;
|
|
// }
|
|
// if (_startArea == null)
|
|
// {
|
|
// _startArea = Globals.Instance._currentBattle.GetNode<Table>("Table").GetNode<Area2D>("PlayerStartArea").GetNode<CollisionShape2D>("CollisionShape2D");
|
|
// }
|
|
|
|
// _tempBallSprite.Position = mousePosition;
|
|
// if (_tempBallSprite.Position.X >= _startArea.GlobalPosition.X - ((RectangleShape2D)(_startArea.Shape)).Size.X / 2 && _tempBallSprite.Position.X <= _startArea.GlobalPosition.X + ((RectangleShape2D)(_startArea.Shape)).Size.X / 2 && _tempBallSprite.Position.Y >= _startArea.GlobalPosition.Y - ((RectangleShape2D)(_startArea.Shape)).Size.Y / 2 && _tempBallSprite.Position.Y <= _startArea.GlobalPosition.Y + ((RectangleShape2D)(_startArea.Shape)).Size.Y / 2)
|
|
// {
|
|
// if (Input.IsActionJustReleased("left_click"))
|
|
// {
|
|
// _heldBall.Place(_tempBallSprite.Position);
|
|
// int ballIndex = _ballReturn.IndexOf(_heldBall);
|
|
|
|
// AddChild(_heldBall);
|
|
|
|
// _ballReturn.Remove(_heldBall);
|
|
// _tempBallSprite.Texture = null;
|
|
// if (_ballReturn.Count > 0)
|
|
// {
|
|
// _heldBall = _ballReturn[ballIndex - (ballIndex > _ballReturn.Count ? 1 : 0)];
|
|
// }
|
|
// else
|
|
// {
|
|
// _heldBall = null;
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// for (int i = 0; i < _balls.Count; i++)
|
|
// {
|
|
// if (_balls[i]._potted)
|
|
// {
|
|
// _balls[i]._potted = false;
|
|
// _balls[i].Sleeping = true;
|
|
// _ballReturn.Add(_balls[i]);
|
|
// RemoveChild(_balls[i]);
|
|
|
|
// }
|
|
// }
|
|
// if (_balls.Any(b => b._hovered))
|
|
// {
|
|
// _hoveredBall = _balls.Single(b => b._hovered);
|
|
// }
|
|
// else
|
|
// {
|
|
// _hoveredBall = null;
|
|
// }
|
|
|
|
|
|
// if ((_selectedBall == null || _selectedBall != _hoveredBall) && (_hoveredBall?._available ?? false))
|
|
// {
|
|
// if (Input.IsActionJustReleased("left_click"))
|
|
// {
|
|
// _selectedBall = _hoveredBall;
|
|
// _selectedBall._selected = true;
|
|
// _cue.Don(_selectedBall);
|
|
// }
|
|
// }
|
|
// else if (Input.IsActionJustReleased("right_click"))
|
|
// {
|
|
// _selectedBall._selected = false;
|
|
// _selectedBall = null;
|
|
// _cue.Doff();
|
|
// }
|
|
// else if (_hoveredBall == null)
|
|
// {
|
|
// if (Input.IsActionJustReleased("left_click") && _selectedBall != null && _cue._power == 0)
|
|
// {
|
|
// _selectedBall._selected = false;
|
|
// _selectedBall = null;
|
|
// _cue.Doff();
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Start()
|
|
{
|
|
Panel ballReturn = _panel.GetNode<Panel>("BallReturn");
|
|
GD.Print(ballReturn.Position);
|
|
GD.Print(ballReturn.GlobalPosition);
|
|
|
|
for (int i = 0; i < _balls.Count; i++)
|
|
{
|
|
_balls[i].GetNode<CollisionShape2D>("Bounds").Disabled = true;
|
|
_balls[i].Position = new Vector2(ballReturn.Size.X/2, 50 * (i + 1));
|
|
|
|
_panel.GetNode<Panel>("BallReturn").AddChild(_balls[i]);
|
|
GD.Print(_balls[i].Position);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void OnCueShoot(Vector2 IMPULSE)
|
|
{
|
|
if (_selectedBall != null && _selectedBall._placed)
|
|
{
|
|
_selectedBall.ApplyCentralImpulse(IMPULSE);
|
|
_selectedBall._selected = false;
|
|
_selectedBall = null;
|
|
_cue.Doff();
|
|
}
|
|
}
|
|
}
|