7-7-25 6:22
This commit is contained in:
817
Marble.cs
817
Marble.cs
@@ -1,797 +1,92 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Marble : CharacterBody2D
|
||||
public partial class Marble : Area2D
|
||||
{
|
||||
public bool _dead, _isTurn, _turnDone, _actionTaken, _isHero, _placed, _hovered, _selected, _aimed, _launched, _collided, _moving;
|
||||
public string _class, _id;
|
||||
public int _battle, _experience;
|
||||
public float _radius, _mass, _distanceMoved, _spin, _damping;
|
||||
public Vector2 _startPosition, _velocity, _pullback;
|
||||
// Don't forget to rebuild the project so the editor knows about the new signal.
|
||||
|
||||
public List<Condition> _conditions = new();
|
||||
public List<Action> _actions = new();
|
||||
public List<Trait> _traits = new();
|
||||
public Action _defaultAction;
|
||||
public Action _focusedAction;
|
||||
public ActionSelector _actionSelector;
|
||||
[Signal]
|
||||
public delegate void HitEventHandler();
|
||||
[Export]
|
||||
public int Speed { get; set; } = 400; // How fast the player will move (pixels/sec).
|
||||
|
||||
public Stats _stats;
|
||||
|
||||
public Player _owner;
|
||||
public object _lastCollisionObject;
|
||||
|
||||
//these may get implemented elsewhere eventually
|
||||
public const float _airDrag = 0.1f; // Air drag coefficient (0 = no drag)
|
||||
public const float _friction = 0.95f; // Friction coefficient (1 = no friction)
|
||||
|
||||
|
||||
public Marble(float RADIUS, float MASS) : base("Visuals\\basicMarble", new Vector2(-1, -1), new Vector2(RADIUS*2), new Vector2(8, 1), new Vector2(1.0f, 1.0f))
|
||||
{
|
||||
_class = this.GetType().ToString().Replace("CorporateLadder.", "");
|
||||
_id = Guid.NewGuid().ToString();
|
||||
_dead = false;
|
||||
_isTurn = false;
|
||||
_turnDone = false;
|
||||
_actionTaken = false;
|
||||
_isHero = false;
|
||||
_placed = false;
|
||||
_hovered = false;
|
||||
_selected = false;
|
||||
_aimed = false;
|
||||
_moving = false;
|
||||
_launched = false;
|
||||
_collided = false;
|
||||
|
||||
_battle = 1;
|
||||
_experience = 0;
|
||||
|
||||
_radius = RADIUS;
|
||||
_mass = MASS;
|
||||
_spin = 0; // 1 RPM = 360 DPM = 6 DPS @ 60FPS = .1 DPF // Divide RPM by 10 to get DPF
|
||||
_damping = 0.99f;
|
||||
public Vector2 ScreenSize; // Size of the game window.
|
||||
|
||||
_pullback = new Vector2(0, 0);
|
||||
_velocity = new Vector2(0, 0);
|
||||
|
||||
_rotation = 0;
|
||||
_distanceMoved = 0;
|
||||
|
||||
_stats = new Stats(_class);
|
||||
|
||||
_owner = null;
|
||||
_lastCollisionObject = null;
|
||||
|
||||
CreatePerFrameAnimations("Roll");
|
||||
SetAnimationByName("Roll");
|
||||
_frameAnimations = true;
|
||||
|
||||
Action tempAction = new Launch(this);
|
||||
tempAction.AddTo(this);
|
||||
tempAction = new Defend(this);
|
||||
tempAction.AddTo(this);
|
||||
tempAction = new RecklessLaunch(this);
|
||||
tempAction.AddTo(this);
|
||||
_defaultAction = _actions[0];
|
||||
_actionSelector = new ActionSelector(this);
|
||||
|
||||
ProcessOnCreation();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (_dead)
|
||||
public override void _Ready()
|
||||
{
|
||||
ScreenSize = GetViewportRect().Size;
|
||||
Hide();
|
||||
}
|
||||
|
||||
if (Globals._battle._turn == _owner && !_dead && _position.X > -1 && _position.Y > -1)
|
||||
{
|
||||
_actionSelector?.Update(_position);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_actionSelector != null && _actionSelector._active)
|
||||
{
|
||||
_actionSelector.Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
if (_position.X > -1 && _position.Y > -1)
|
||||
{
|
||||
base.Update();
|
||||
if (PassesInitialChecks())
|
||||
{
|
||||
TryHover();
|
||||
TrySelect();
|
||||
TryAim();
|
||||
|
||||
if (!_turnDone)
|
||||
{
|
||||
if (_actionTaken)
|
||||
{
|
||||
_turnDone = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
TryLaunch();
|
||||
TryCollision();
|
||||
TryMovement();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(Vector2 NEWPOSITION)
|
||||
{
|
||||
_position = NEWPOSITION;
|
||||
_actionSelector?.Update(_position);
|
||||
}
|
||||
|
||||
public virtual void ActionAdd(Action ACTION)
|
||||
{
|
||||
if (!_actions.Contains(ACTION))
|
||||
{
|
||||
_actions.Add(ACTION);
|
||||
ACTION.ProcessOnAdd();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ActionRemove(Action ACTION)
|
||||
{
|
||||
if (_actions.Contains(ACTION))
|
||||
{
|
||||
ACTION.ProcessOnRemove();
|
||||
_actions.Remove(ACTION);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void AddExperience(object INFO)
|
||||
{
|
||||
_experience += Globals.ConvertToInt(INFO);
|
||||
}
|
||||
|
||||
public virtual void ChangeHealth(Marble ATTACKER, int CHANGE)
|
||||
{
|
||||
_stats._health += CHANGE;
|
||||
_stats._health = Math.Min(_stats._health, _stats._healthMax);
|
||||
if (_stats._health <= 0)
|
||||
{
|
||||
_dead = true;
|
||||
//ATTACKER.AddExperience(GetExp());
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void CheckIfLevelUp()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual int CheckLevelExperience(int LEVEL)
|
||||
{
|
||||
return 2 * LEVEL + (int)Math.Pow(2.0, 1.0f + LEVEL * .2f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public virtual void CollideWithMarble(Marble OTHER)
|
||||
{
|
||||
// From: https://stackoverflow.com/q/345838/880990, author: mmcdole
|
||||
|
||||
Vector2 delta = _position - OTHER._position;
|
||||
float distance = delta.Length();
|
||||
if (distance <= _radius + OTHER._radius && distance > 1e-5)
|
||||
public override void _Process(double delta) //THIS IS LIKE THE UPDATE FUNCTION
|
||||
{
|
||||
// Minimum translation distance to push balls apart after intersecting
|
||||
Vector2 minTranslationDistance = delta * ((_radius + OTHER._radius - distance) / distance);
|
||||
var velocity = Vector2.Zero; // The player's movement vector.
|
||||
|
||||
// Resolve intersection - inverse mass quantities
|
||||
float inverseMass1 = 1 / _mass;
|
||||
float inverseMass2 = 1 / OTHER._mass;
|
||||
|
||||
// Push-pull them apart based off their mass
|
||||
_position += minTranslationDistance * (inverseMass1 / (inverseMass1 + inverseMass2));
|
||||
OTHER._position -= minTranslationDistance * (inverseMass1 / (inverseMass1 + inverseMass2));
|
||||
|
||||
// Impact speed
|
||||
Vector2 velocityDelta = _velocity - OTHER._velocity;
|
||||
Vector2 minTranslationDistanceNormalized = Vector2.Normalize(minTranslationDistance);
|
||||
float velocityNormalized = Vector2.Dot(velocityDelta, minTranslationDistanceNormalized);
|
||||
|
||||
// Sphere intersecting but moving away from each other already
|
||||
if (velocityNormalized > 0.0f) return;
|
||||
|
||||
// Collision impulse
|
||||
const float restitution = 1.0f; // perfectly elastic collision
|
||||
|
||||
float i = -(1.0f + restitution) * velocityNormalized / (inverseMass1 + inverseMass2);
|
||||
Vector2 impulse = minTranslationDistanceNormalized * i;
|
||||
|
||||
// Change in momentum
|
||||
_velocity += impulse * inverseMass1;
|
||||
_velocity *= _damping;
|
||||
OTHER._velocity -= impulse * inverseMass2;
|
||||
OTHER._velocity *= OTHER._damping;
|
||||
// Perform
|
||||
|
||||
_collided = !_launched;
|
||||
|
||||
ProcessOnCollisionMarble(OTHER);
|
||||
OTHER.ProcessOnCollisionMarble(this);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//public virtual void CollideWithWallInner(Rectangle WALL)
|
||||
//{
|
||||
// // Only reverse velocity if moving towards the walls
|
||||
|
||||
// if (_position.X + _radius >= WALL.Right && _velocity.X > 0 || _position.X - _radius < WALL.Left && _velocity.X < 0)
|
||||
// {
|
||||
// _velocity = new Vector2(-_velocity.X, _velocity.Y);
|
||||
// ProcessOnCollisionWall();
|
||||
// }
|
||||
// if (_position.Y + _radius >= WALL.Bottom && _velocity.Y > 0 || _position.Y - _radius < WALL.Top && _velocity.Y < 0)
|
||||
// {
|
||||
// _velocity = new Vector2(_velocity.X, -_velocity.Y);
|
||||
// ProcessOnCollisionWall();
|
||||
// }
|
||||
//}
|
||||
|
||||
public virtual void CollideWithWallOuter(Rectangle WALL)
|
||||
{
|
||||
// Only reverse velocity if moving towards the walls
|
||||
|
||||
if (!WALL.Contains(_position + Globals.LengthenVector(_velocity, _radius)))
|
||||
{
|
||||
if (_position.X + _radius >= WALL.Right || _position.X - _radius < WALL.Left)
|
||||
if (Input.IsActionPressed("move_right"))
|
||||
{
|
||||
_velocity = new Vector2(-_damping * _velocity.X, _velocity.Y);
|
||||
velocity.X += 1;
|
||||
}
|
||||
if (_position.Y + _radius >= WALL.Bottom || _position.Y - _radius < WALL.Top)
|
||||
|
||||
if (Input.IsActionPressed("move_left"))
|
||||
{
|
||||
_velocity = new Vector2(_velocity.X, -_damping * _velocity.Y);
|
||||
velocity.X -= 1;
|
||||
}
|
||||
ProcessOnCollisionWall();
|
||||
}
|
||||
//if (_position.X + _radius >= WALL.Right && _velocity.X > 0 || _position.X - _radius < WALL.Left && _velocity.X < 0)
|
||||
//{
|
||||
// _velocity = new Vector2(-_velocity.X, _velocity.Y);
|
||||
// ProcessOnCollisionWall();
|
||||
//}
|
||||
//if (_position.Y + _radius >= WALL.Bottom && _velocity.Y > 0 || _position.Y - _radius < WALL.Top && _velocity.Y < 0)
|
||||
//{
|
||||
// _velocity = new Vector2(_velocity.X, -_velocity.Y);
|
||||
// ProcessOnCollisionWall();
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
public virtual void ConditionAdd(Condition CONDITION)
|
||||
{
|
||||
if (!_conditions.Contains(CONDITION))
|
||||
{
|
||||
_conditions.Add(CONDITION);
|
||||
CONDITION.ProcessOnAdd();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ConditionRemove(Condition CONDITION)
|
||||
{
|
||||
if (_conditions.Contains(CONDITION))
|
||||
{
|
||||
CONDITION.ProcessOnRemove();
|
||||
_conditions.Remove(CONDITION);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int GetExp()
|
||||
{
|
||||
return _battle * 2;
|
||||
}
|
||||
|
||||
public virtual void Hide()
|
||||
{
|
||||
_position = new Vector2(-1, -1);
|
||||
}
|
||||
|
||||
public virtual bool IsFocal()
|
||||
{
|
||||
return Globals._battle._focalMarble == this;
|
||||
}
|
||||
|
||||
public virtual bool IsHovered()
|
||||
{
|
||||
return Globals.CalculateDistance(_position, Globals._mouse._newMousePosition) <= _radius;
|
||||
}
|
||||
|
||||
public virtual void LevelUp()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual bool PassesInitialChecks()
|
||||
{
|
||||
bool isNotPlaced = !_placed;
|
||||
if (isNotPlaced) { return false; }
|
||||
|
||||
bool isNotTurn = !(Globals._battle._turn == _owner);
|
||||
if (isNotTurn) { return false; }
|
||||
|
||||
if (_actionTaken) { return false; }
|
||||
|
||||
bool marblesMoving = Globals._battle._movementDetected;
|
||||
if (marblesMoving) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#region PROCS
|
||||
public virtual void ProcessOnAdd()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void ProcessOnBattleStart()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnBattleStart();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnBattleStart();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnBattleEnd()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnBattleEnd();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnBattleEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnCollisionMarble(Marble TARGET)
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnCollisionMarble(TARGET);
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnCollisionMarble(TARGET);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnCollisionWall()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnCollisionWall();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnCollisionWall();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnCreation()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnCreation();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnCreation();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnCritical()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnCritical();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnCritical();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnDeath()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnDeath();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnDeath();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnDefend()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnDefend();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnDefend();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnExpiration()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnExpiration();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnExpiration();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnLaunch()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnLaunch();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnLaunch();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnRemove()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnRemove();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnRemove();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnSell()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnSell();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnSell();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnStop()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnStop();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnStop();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnMovement()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnMovement();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnMovement();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnTurnEnd()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnTurnEnd();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnTurnEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessOnTurnStart()
|
||||
{
|
||||
for (int i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
_conditions[i].ProcessOnTurnStart();
|
||||
}
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
{
|
||||
_actions[i].ProcessOnTurnStart();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public virtual void Resurrect()
|
||||
{
|
||||
_dead = false;
|
||||
}
|
||||
|
||||
public virtual void SetOwner(Player OWNER)
|
||||
{
|
||||
_owner = OWNER;
|
||||
}
|
||||
|
||||
public virtual void SetPosition(Vector2 POSITION)
|
||||
{
|
||||
_position = POSITION;
|
||||
}
|
||||
|
||||
public virtual void TraitAdd(Trait TRAIT)
|
||||
{
|
||||
if (!_traits.Contains(TRAIT))
|
||||
{
|
||||
_traits.Add(TRAIT);
|
||||
TRAIT.ProcessOnAdd();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void TraitRemove(Trait TRAIT)
|
||||
{
|
||||
if (_traits.Contains(TRAIT))
|
||||
{
|
||||
TRAIT.ProcessOnRemove();
|
||||
_traits.Remove(TRAIT);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void TryAim()
|
||||
{
|
||||
if (!_hovered && _selected && IsFocal() && Globals._mouse.LeftClickDrag(_radius / 4) && !_actionSelector._active)
|
||||
{
|
||||
_aimed = true;
|
||||
}
|
||||
if (_aimed)
|
||||
{
|
||||
_selected = false;
|
||||
if (Globals._mouse.RightClickRelease())
|
||||
if (Input.IsActionPressed("move_down"))
|
||||
{
|
||||
return;
|
||||
velocity.Y += 1;
|
||||
}
|
||||
float pullbackX, pullbackY;
|
||||
if (Globals._keyboard.GetPress("LeftShift"))
|
||||
|
||||
if (Input.IsActionPressed("move_up"))
|
||||
{
|
||||
float pullbackAngle = Globals.CalculateAngle(_position, Globals._mouse._newMousePosition) * 180 / Globals._pi;
|
||||
velocity.Y -= 1;
|
||||
}
|
||||
|
||||
if ((pullbackAngle >= -22.5f && pullbackAngle <= 22.5f) || (pullbackAngle >= 157.5f || pullbackAngle <= -157.5f))
|
||||
{
|
||||
pullbackX = _position.X - Globals._mouse._newMousePosition.X;
|
||||
pullbackY = 0f;
|
||||
}
|
||||
else if ((pullbackAngle <= -67.5f && pullbackAngle >= -112.5f) || (pullbackAngle >= 67.5f && pullbackAngle <= 112.5f))
|
||||
{
|
||||
pullbackX = 0f;
|
||||
pullbackY = _position.Y - Globals._mouse._newMousePosition.Y;
|
||||
}
|
||||
else if ((pullbackAngle <= -22.5f && pullbackAngle >= -67.5f) || (pullbackAngle >= 112.5f && pullbackAngle <= 157.5f))
|
||||
{
|
||||
pullbackX = _position.X - Globals._mouse._newMousePosition.X;
|
||||
pullbackY = -pullbackX;
|
||||
}
|
||||
else
|
||||
{
|
||||
pullbackX = _position.X - Globals._mouse._newMousePosition.X;
|
||||
pullbackY = pullbackX;
|
||||
}
|
||||
var animatedSprite2D = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
|
||||
|
||||
if (velocity.Length() > 0)
|
||||
{
|
||||
velocity = velocity.Normalized() * Speed;
|
||||
animatedSprite2D.Play();
|
||||
}
|
||||
else
|
||||
{
|
||||
pullbackX = _position.X - Globals._mouse._newMousePosition.X;
|
||||
pullbackY = _position.Y - Globals._mouse._newMousePosition.Y;
|
||||
animatedSprite2D.Stop();
|
||||
}
|
||||
_pullback = new Vector2(pullbackX, pullbackY);
|
||||
_rotation = Globals.RotateTowards(_position, _position + _pullback);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void TryCollision()
|
||||
{
|
||||
if (_moving)
|
||||
{
|
||||
for (int i = 0; i < Globals._battle._marbles.Count; i++)
|
||||
|
||||
Position += velocity * (float)delta;
|
||||
Position = new Vector2(
|
||||
x: Mathf.Clamp(Position.X, 0, ScreenSize.X),
|
||||
y: Mathf.Clamp(Position.Y, 0, ScreenSize.Y)
|
||||
);
|
||||
|
||||
if (velocity.X != 0)
|
||||
{
|
||||
Marble tempMarble = Globals._battle._marbles[i];
|
||||
if (tempMarble == this)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (Globals.CalculateDistance(_position, tempMarble._position) <= (_radius + tempMarble._radius))
|
||||
{
|
||||
CollideWithMarble(tempMarble);
|
||||
break;
|
||||
}
|
||||
animatedSprite2D.Animation = "walk";
|
||||
animatedSprite2D.FlipV = false;
|
||||
// See the note below about the following boolean assignment.
|
||||
animatedSprite2D.FlipH = velocity.X < 0;
|
||||
}
|
||||
CollideWithWallOuter(Globals._battle._outerWall);
|
||||
//for (int i = 0; i < Globals._battle._innerWalls.Count; i++)
|
||||
//{
|
||||
// CollideWithInnerWall(Globals._battle._innerWalls[i]);
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void TryHover()
|
||||
{
|
||||
_hovered = IsHovered();
|
||||
if (_hovered && Globals._battle._focalMarble == null)
|
||||
{
|
||||
Globals._battle._focalMarble = this;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void TryLaunch()
|
||||
{
|
||||
if (_aimed && IsFocal() && !_hovered)
|
||||
{
|
||||
if (Globals._mouse.LeftClickRelease())
|
||||
else if (velocity.Y != 0)
|
||||
{
|
||||
_aimed = false;
|
||||
_actionTaken = true;
|
||||
_launched = true;
|
||||
_velocity = new Vector2(_pullback.X * 20 / _mass / 60, _pullback.Y * 20 / _mass / 60);
|
||||
_focusedAction ??= _defaultAction;
|
||||
ProcessOnLaunch();
|
||||
animatedSprite2D.Animation = "up";
|
||||
animatedSprite2D.FlipV = velocity.Y > 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public virtual void TryMovement()
|
||||
{
|
||||
if (_velocity.X != 0 || _velocity.Y != 0)
|
||||
{
|
||||
if (!_moving)
|
||||
{
|
||||
_moving = true;
|
||||
}
|
||||
ProcessOnMovement();
|
||||
|
||||
_rotation = Globals.RotateTowards(_position, _position + _velocity);
|
||||
_velocity = Globals.RotateAround(_velocity, Vector2.Zero, _spin * 360 / 60 / 60);
|
||||
|
||||
_position += _velocity;
|
||||
_distanceMoved += _velocity.Length();
|
||||
|
||||
_stats._stamina -= _velocity.Length() / 200;
|
||||
float staminaRemaining = _stats._stamina / _stats._staminaMax;
|
||||
|
||||
Vector2 acceleration = Vector2.Normalize(_velocity) * -5 / 60;
|
||||
|
||||
//// Air Drag not sure if I'll actually implement
|
||||
//float v2 = _velocity.LengthSquared();
|
||||
//float vAbs = MathF.Sqrt(v2);
|
||||
//float fDrag = _airDrag * v2;
|
||||
//Vector2 f = fDrag / vAbs * _velocity;
|
||||
//_velocity -= 1 / _mass * f;
|
||||
|
||||
float velocityX = (_velocity.X + acceleration.X) * staminaRemaining * _friction, velocityY = (_velocity.Y + acceleration.Y) * staminaRemaining * _friction;
|
||||
if (Math.Abs(acceleration.X) > Math.Abs(_velocity.X))
|
||||
{
|
||||
velocityX = 0;
|
||||
}
|
||||
if (Math.Abs(acceleration.X) > Math.Abs(_velocity.X))
|
||||
{
|
||||
velocityY = 0;
|
||||
}
|
||||
_velocity = new Vector2(velocityX, velocityY);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_moving)
|
||||
{
|
||||
ProcessOnStop();
|
||||
}
|
||||
_moving = false;
|
||||
_lastCollisionObject = null;
|
||||
_launched = false;
|
||||
}
|
||||
}
|
||||
public virtual void TrySelect()
|
||||
{
|
||||
if (_hovered && IsFocal())
|
||||
{
|
||||
if (Globals._mouse.LeftClick())
|
||||
{
|
||||
_selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (_selected)
|
||||
{
|
||||
if (_actionSelector != null && Globals._mouse.LeftClickRelease())
|
||||
{
|
||||
if (!_actionSelector._skipPress)
|
||||
{
|
||||
_actionSelector.Activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
_actionSelector._skipPress = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_hovered && !_actionSelector._hovered)
|
||||
{
|
||||
if (Globals._mouse.LeftClick())
|
||||
{
|
||||
_selected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_actionSelector != null)
|
||||
{
|
||||
if (!_actionSelector._hovered)
|
||||
{
|
||||
_actionSelector.Deactivate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void TurnComplete()
|
||||
{
|
||||
_turnDone = true;
|
||||
_isTurn = false;
|
||||
_focusedAction = null;
|
||||
ProcessOnTurnEnd();
|
||||
|
||||
//for (int i = 0; i < _actions.Count; i++)
|
||||
//{
|
||||
// _actions[i].NextTurn();
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
public virtual void TurnStart()
|
||||
{
|
||||
_turnDone = false;
|
||||
_isTurn = true;
|
||||
_actionTaken = false;
|
||||
_startPosition = _position;
|
||||
_stats._stamina = _stats._staminaMax;
|
||||
ProcessOnTurnStart();
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (_position.X > -1 && _position.Y > -1)
|
||||
// We also specified this function name in PascalCase in the editor's connection window.
|
||||
private void OnBodyEntered(Node2D body)
|
||||
{
|
||||
base.Draw();
|
||||
if (_actionSelector != null)
|
||||
{
|
||||
if (_actionSelector._active)
|
||||
{
|
||||
_actionSelector.Draw();
|
||||
}
|
||||
}
|
||||
Hide(); // Player disappears after being hit.
|
||||
EmitSignal(SignalName.Hit);
|
||||
// Must be deferred as we can't change physics properties on a physics callback.
|
||||
GetNode<CollisionShape2D>("CollisionShape2D").SetDeferred(CollisionShape2D.PropertyName.Disabled, true);
|
||||
}
|
||||
|
||||
public void Start(Vector2 position)
|
||||
{
|
||||
Position = position;
|
||||
Show();
|
||||
GetNode<CollisionShape2D>("CollisionShape2D").Disabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://xvxxxkoer7xw
|
||||
uid://b1bipn8tmpggr
|
||||
|
||||
53
marble.tscn
53
marble.tscn
@@ -1,19 +1,50 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dypthyut32ve5"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://c8n4lue2bn25n"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://xvxxxkoer7xw" path="res://Marble.cs" id="1_7ritg"]
|
||||
[ext_resource type="Script" uid="uid://b1bipn8tmpggr" path="res://Marble.cs" id="1_7ritg"]
|
||||
[ext_resource type="Texture2D" uid="uid://bfx7o0vsjshp2" path="res://playerGrey_up1.png" id="2_76m5q"]
|
||||
[ext_resource type="Texture2D" uid="uid://bqkvfdd2htfry" path="res://playerGrey_up2.png" id="3_4rms2"]
|
||||
[ext_resource type="Texture2D" uid="uid://emguskfoeupl" path="res://playerGrey_walk1.png" id="4_iy80h"]
|
||||
[ext_resource type="Texture2D" uid="uid://dimv2j24hgb1w" path="res://playerGrey_walk2.png" id="5_ryns1"]
|
||||
|
||||
[sub_resource type="ImageTexture" id="ImageTexture_sk24e"]
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_n7ghd"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("2_76m5q")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("3_4rms2")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"up",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("4_iy80h")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("5_ryns1")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"walk",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_60n0y"]
|
||||
radius = 19.2354
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_aa3e1"]
|
||||
radius = 27.0
|
||||
height = 68.0
|
||||
|
||||
[node name="Marble" type="CharacterBody2D"]
|
||||
[node name="Marble" type="Area2D"]
|
||||
script = ExtResource("1_7ritg")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = SubResource("ImageTexture_sk24e")
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
scale = Vector2(0.5, 0.5)
|
||||
sprite_frames = SubResource("SpriteFrames_n7ghd")
|
||||
animation = &"walk"
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_60n0y")
|
||||
shape = SubResource("CapsuleShape2D_aa3e1")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="OnBodyEntered"]
|
||||
|
||||
@@ -11,9 +11,42 @@ config_version=5
|
||||
[application]
|
||||
|
||||
config/name="Hotdesking"
|
||||
config/features=PackedStringArray("4.4", "Forward Plus")
|
||||
config/features=PackedStringArray("4.4", "C#", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[dotnet]
|
||||
|
||||
project/assembly_name="Hotdesking"
|
||||
|
||||
[editor]
|
||||
|
||||
version_control/plugin_name="GitPlugin"
|
||||
version_control/autoload_on_startup=true
|
||||
|
||||
[input]
|
||||
|
||||
move_right={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_left={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_up={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_down={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
click={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user