96 lines
2.2 KiB
C#
96 lines
2.2 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
/// TODO alter code to player vs computer to account for differing logic
|
|
public partial class Manager : Node
|
|
{
|
|
public bool _dead, _ready;
|
|
public int _health = 10, _healthMax, _placeLimit = 8;
|
|
public string _imagePath;
|
|
public Cue _cue;
|
|
public Dictionary<int, Worker> _workers = new();
|
|
public Dictionary<int, Ball> _balls = new();
|
|
public Dictionary<int, PlaceholderBall> _placeholderBalls = new();
|
|
public Ball _selectedBall = null;
|
|
public CollisionShape2D _startArea;
|
|
|
|
|
|
public PackedScene _ballScene = ResourceLoader.Load<PackedScene>("res://Gameplay/ball.tscn");
|
|
public PackedScene _placeholdeBallScene = ResourceLoader.Load<PackedScene>("res://Gameplay/ball.tscn");
|
|
public PackedScene _cueScene = ResourceLoader.Load<PackedScene>("res://Gameplay/cue.tscn");
|
|
public PackedScene _workerScene = ResourceLoader.Load<PackedScene>("res://Gameplay/worker.tscn");
|
|
|
|
|
|
public override void _Ready()
|
|
{
|
|
_healthMax = _health;
|
|
_cue = GetNode<Cue>("Cue");
|
|
}
|
|
|
|
public virtual void ChangeHealth(int CHANGE)
|
|
{
|
|
_health += CHANGE;
|
|
_health = Math.Min(_health, _healthMax);
|
|
|
|
if (_health < 0)
|
|
{
|
|
_dead = true;
|
|
_health = 0;
|
|
}
|
|
}
|
|
|
|
public void PlaceBall(Ball BALL, Vector2 POSITION)
|
|
{
|
|
|
|
BALL._available = true;
|
|
BALL.Position = POSITION;
|
|
BALL._active = true;
|
|
BALL._placed = true;
|
|
BALL._potted = false;
|
|
BALL._active = true;
|
|
AddChild(BALL);
|
|
|
|
// _placeholderBalls[BALLNUMBER]._active = false;
|
|
// RemoveChild(_placeholderBalls[BALLNUMBER]);
|
|
}
|
|
|
|
public void PotBall(Ball BALL)
|
|
{
|
|
BALL.Sleeping = true;
|
|
BALL._available = false;
|
|
BALL._moving = false;
|
|
BALL._active = false;
|
|
BALL._placed = false;
|
|
BALL._potted = true;
|
|
BALL._active = false;
|
|
RemoveChild(BALL);
|
|
|
|
// _placeholderBalls[BALLNUMBER]._active = true;
|
|
// AddChild(_placeholderBalls[BALLNUMBER]);
|
|
}
|
|
|
|
public void SetSprite(string PATH)
|
|
{
|
|
_imagePath = PATH;
|
|
}
|
|
|
|
public virtual void Start()
|
|
{
|
|
|
|
}
|
|
|
|
private void OnCueShoot(Vector2 IMPULSE)
|
|
{
|
|
if (_selectedBall != null && _selectedBall._placed)
|
|
{
|
|
_selectedBall.GetNode<Ball>("Ball").ApplyCentralImpulse(IMPULSE);
|
|
_selectedBall._selected = false;
|
|
_selectedBall.Launch();
|
|
_selectedBall = null;
|
|
_cue.Doff();
|
|
}
|
|
}
|
|
}
|