Files
hotdesking/Gameplay/Ball.cs
2025-07-19 01:16:38 -04:00

82 lines
1.5 KiB
C#

using Godot;
using System;
using System.Data;
public partial class Ball : RigidBody2D
{
public bool _placed = false, _potted = false, _available = false, _hovered = false, _selected = false, _aimed = false, _moving = false, _isCue = false;
public int _defense, _defenseMax;
public float _moveThreshold = 5.0f;
public static Ball _Create(int NUMBER)
{
PackedScene scene = ResourceLoader.Load<PackedScene>("res://Gameplay/ball.tscn");
Ball newBall = scene.Instantiate<Ball>();
string fileName;
if (NUMBER == 0)
{
fileName = "res://art/cue_ball.png";
newBall._isCue = true;
}
else
{
fileName = "res://art/ball_" + NUMBER + ".png";
newBall._isCue = false; ;
}
Texture2D image = GD.Load<Texture2D>(fileName);
newBall.GetNode<Sprite2D>("Image").Texture = image;
return newBall;
}
public override void _Process(double DELTA_)
{
if (LinearVelocity.Length() > 0 && LinearVelocity.Length() < _moveThreshold)
{
Sleeping = true;
if (_moving)
{
_moving = false;
}
}
else if (LinearVelocity.Length() >= _moveThreshold)
{
if (!_moving)
{
_moving = true;
}
}
if (Globals.Instance._anyMovement)
{
if (_available)
{
_available = false;
}
}
else
{
if (!_available)
{
_available = true;
}
}
}
public void Place(Vector2 POSITION)
{
_placed = true;
Position = POSITION;
}
private void OnMouseEntered()
{
_hovered = true;
}
private void OnMouseExited()
{
_hovered = false;
}
}