Tuesday, 16 September 2025 12:26:13
This commit is contained in:
7
Gameplay/Cell.cs
Normal file
7
Gameplay/Cell.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Cell : Sprite2D
|
||||
{
|
||||
public int _row, _column;
|
||||
}
|
||||
1
Gameplay/Cell.cs.uid
Normal file
1
Gameplay/Cell.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cmw4772lmwms0
|
||||
@@ -5,31 +5,41 @@ using System.Collections.Generic;
|
||||
public partial class Desk : Node2D
|
||||
{
|
||||
public Vector2 _topLeft, _cellDimensions, _gridDimensions;
|
||||
public Sprite2D _light, _dark;
|
||||
public Cell _light, _dark;
|
||||
Node2D _grid;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_grid = GetNode<Node2D>("Cells");
|
||||
_light = GetNode<Sprite2D>("Light");
|
||||
_dark = GetNode<Sprite2D>("Dark");
|
||||
_light = GetNode<Cell>("Light");
|
||||
_dark = GetNode<Cell>("Dark");
|
||||
|
||||
_cellDimensions = new Vector2(50, 50);
|
||||
|
||||
}
|
||||
|
||||
public Vector2 GetPositionFromAddress(int ROW, int COLUMN)
|
||||
public Cell GetCellFromAddress(int ROW, int COLUMN)
|
||||
{
|
||||
|
||||
if (_grid.HasNode("R" + ROW))
|
||||
{
|
||||
Node2D row = _grid.GetNode<Node2D>("R" + ROW);
|
||||
if (row.HasNode("C" + COLUMN))
|
||||
{
|
||||
Sprite2D column = row.GetNode<Sprite2D>("C" + COLUMN);
|
||||
return column.GlobalPosition;
|
||||
Cell column = row.GetNode<Cell>("C" + COLUMN);
|
||||
return column;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Vector2 GetPositionFromAddress(int ROW, int COLUMN)
|
||||
{
|
||||
|
||||
Cell cell = GetCellFromAddress(ROW, COLUMN);
|
||||
if (cell != null)
|
||||
{
|
||||
return cell.GlobalPosition;
|
||||
}
|
||||
return new Vector2(-1, -1);
|
||||
}
|
||||
|
||||
@@ -39,7 +49,7 @@ public partial class Desk : Node2D
|
||||
_topLeft = Globals.Instance._screenCenter - _cellDimensions * _gridDimensions / 2 + _cellDimensions / 2;
|
||||
Vector2 position;
|
||||
Node2D row;
|
||||
Sprite2D column;
|
||||
Cell column;
|
||||
for (int i = 0; i < _gridDimensions.Y; i++)
|
||||
{
|
||||
if (i <= _grid.GetChildCount())
|
||||
@@ -51,10 +61,12 @@ public partial class Desk : Node2D
|
||||
for (int j = 0; j < _gridDimensions.X; j++)
|
||||
{
|
||||
position = _topLeft + new Vector2(_cellDimensions.X * j, _cellDimensions.Y * i);
|
||||
column = (Sprite2D)((i + j) % 2 == 0 ? _light : _dark).Duplicate();
|
||||
column = (Cell)((i + j) % 2 == 0 ? _light : _dark).Duplicate();
|
||||
column.Name = "C" + (j + 1);
|
||||
column.GlobalPosition = position;
|
||||
column.Visible = true;
|
||||
column._row = i + 1;
|
||||
column._column = j + 1;
|
||||
row = _grid.GetNode<Node2D>("R" + (i + 1));
|
||||
row.AddChild(column);
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ public partial class Manager : Node2D
|
||||
public bool _dead, _ready, _moving;
|
||||
public int _ballsMoving = 0, _health = 10, _healthMax, _speed = 5;
|
||||
public string _imagePath;
|
||||
public Vector2 _deskPosition;
|
||||
public List<Vector2> _movements = new();
|
||||
public CollisionShape2D _startArea;
|
||||
public ManagerPanel _managerPanel = null;
|
||||
public Sprite2D _image;
|
||||
public Desk _desk = null;
|
||||
public Cell _cell;
|
||||
public List<Cell> _moves = new();
|
||||
public Manager _opponent;
|
||||
public List<Worker> _workers = new();
|
||||
public Node _workerNode;
|
||||
@@ -31,11 +31,11 @@ public partial class Manager : Node2D
|
||||
// _managerPanel = GetNode<ManagerPanel>("Panel");
|
||||
_desk = GetNode<Desk>("Desk");
|
||||
_desk.Setup(15, 20);
|
||||
|
||||
_deskPosition = new Vector2(1, 1);
|
||||
_cell = _desk.GetCellFromAddress(1, 1);
|
||||
|
||||
// _movements.Insert(0, _deskPosition);
|
||||
_image = GetNode<Sprite2D>("Image");
|
||||
_image.GlobalPosition = _desk.GetPositionFromAddress(1, 1);
|
||||
_image.GlobalPosition = _cell.GlobalPosition;
|
||||
|
||||
// _managerPanel.SetManager(this);
|
||||
for (int i = 0; i < Globals.Instance._random.Next(3, 6); i++)
|
||||
@@ -53,12 +53,13 @@ public partial class Manager : Node2D
|
||||
public void AddWorker(Worker NEWWORKER)
|
||||
{
|
||||
Worker newWorker = NEWWORKER ?? Globals.Instance._workerScene.Instantiate<Worker>();
|
||||
newWorker._deskPosition = new Vector2(1, 1);
|
||||
newWorker.Position = _desk.GetPositionFromAddress(1, 1);
|
||||
newWorker._cell = _desk.GetCellFromAddress(1, 1);
|
||||
newWorker.Position = newWorker._cell.GlobalPosition;
|
||||
newWorker._manager = this;
|
||||
_workers.Add(newWorker);
|
||||
_workerNode.AddChild(newWorker);
|
||||
newWorker.SetHovered += SetHoveredWorker;
|
||||
|
||||
// newWorker.SetHovered += SetHoveredWorker;
|
||||
}
|
||||
|
||||
public void ChainMovement()
|
||||
@@ -83,66 +84,70 @@ public partial class Manager : Node2D
|
||||
|
||||
if (direction != Vector2.Zero)
|
||||
{
|
||||
Vector2 newPostion = _desk.GetPositionFromAddress((int)(_deskPosition.Y + direction.Y), (int)(_deskPosition.X + direction.X));
|
||||
if (newPostion != new Vector2(-1, -1))
|
||||
GD.Print(_cell._row + (int)direction.Y, _cell._column + (int)direction.X);
|
||||
Cell newCell = _desk.GetCellFromAddress(_cell._row + (int)direction.Y, _cell._column + (int)direction.X);
|
||||
if (newCell != null)
|
||||
{
|
||||
if (_movements.Count > 0)
|
||||
GD.Print(_cell._row, _cell._column);
|
||||
if (_moves.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < _workers.Count && i < _movements.Count; i++)
|
||||
for (int i = 0; i < _workers.Count && i < _moves.Count; i++)
|
||||
{
|
||||
_workers[i]._deskPosition = _movements[i];
|
||||
_workers[i].GlobalPosition = _desk.GetPositionFromAddress((int)_movements[i].Y, (int)_movements[i].X);
|
||||
_workers[i]._cell = _moves[i];
|
||||
_workers[i].GlobalPosition = _workers[i]._cell.GlobalPosition;
|
||||
}
|
||||
}
|
||||
_deskPosition += direction;
|
||||
_movements.Insert(0, _deskPosition);
|
||||
_image.GlobalPosition = newPostion;
|
||||
_cell = newCell;
|
||||
_moves.Insert(0, newCell);
|
||||
_image.GlobalPosition = _cell.GlobalPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ChainSelection()
|
||||
{
|
||||
if (_heldWorker != null)
|
||||
{
|
||||
_heldWorker.GlobalPosition = GetGlobalMousePosition();
|
||||
if (_hoveredWorker != null && _heldWorker != _hoveredWorker)
|
||||
{
|
||||
SwapPositions(_heldWorker, _hoveredWorker);
|
||||
_hoveredWorker._hovered = false;
|
||||
_hoveredWorker = null;
|
||||
}
|
||||
if (Input.IsActionJustReleased("left_click"))
|
||||
{
|
||||
_heldWorker.GlobalPosition = _desk.GetPositionFromAddress((int)_heldWorker._deskPosition.Y, (int)_heldWorker._deskPosition.X);
|
||||
_heldWorker._held = false;
|
||||
_heldWorker = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_selectedWorker != null)
|
||||
{
|
||||
if (Input.IsActionPressed("left_click") && (GetGlobalMousePosition() - _selectedWorker._chainPosition).Length() > 5)
|
||||
{
|
||||
// if (_heldWorker != null)
|
||||
// {
|
||||
// _heldWorker.GlobalPosition = GetGlobalMousePosition();
|
||||
// if (_hoveredWorker != null && _heldWorker != _hoveredWorker)
|
||||
// {
|
||||
// SwapPositions(_heldWorker, _hoveredWorker);
|
||||
// _hoveredWorker._hovered = false;
|
||||
// _hoveredWorker = null;
|
||||
// }
|
||||
// if (Input.IsActionJustReleased("left_click"))
|
||||
// {
|
||||
// _heldWorker.GlobalPosition = _desk.GetPositionFromAddress((int)_heldWorker._deskPosition.Y, (int)_heldWorker._deskPosition.X);
|
||||
// _heldWorker._held = false;
|
||||
// _heldWorker = null;
|
||||
// _hoveredWorker._hovered = false;
|
||||
// _hoveredWorker = null;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (_selectedWorker != null)
|
||||
// {
|
||||
// if (Input.IsActionPressed("left_click") && (GetGlobalMousePosition() - _selectedWorker._chainPosition).Length() > 5)
|
||||
// {
|
||||
|
||||
_heldWorker = _selectedWorker;
|
||||
_heldWorker._held = true;
|
||||
_heldWorker._selected = false;
|
||||
_selectedWorker = null;
|
||||
}
|
||||
}
|
||||
if (_hoveredWorker != null)
|
||||
{
|
||||
if (Input.IsActionJustPressed("left_click"))
|
||||
{
|
||||
_selectedWorker = _hoveredWorker;
|
||||
_selectedWorker._selected = true;
|
||||
_selectedWorker._hovered = false;
|
||||
_hoveredWorker = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
// _heldWorker = _selectedWorker;
|
||||
// _heldWorker._held = true;
|
||||
// _heldWorker._selected = false;
|
||||
// _selectedWorker = null;
|
||||
// }
|
||||
// }
|
||||
// if (_hoveredWorker != null)
|
||||
// {
|
||||
// if (Input.IsActionJustPressed("left_click"))
|
||||
// {
|
||||
// _selectedWorker = _hoveredWorker;
|
||||
// _selectedWorker._selected = true;
|
||||
// _selectedWorker._hovered = false;
|
||||
// _hoveredWorker = null;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public void ChangeHealth(int CHANGE)
|
||||
@@ -169,20 +174,6 @@ public partial class Manager : Node2D
|
||||
// _workers[0].GlobalPosition = _desk.GetPositionFromAddress(1, 1);
|
||||
// }
|
||||
|
||||
public void SwapPositions(Worker A, Worker B)
|
||||
{
|
||||
Vector2 deskPositionA = A._deskPosition, deskPositionB = B._deskPosition;
|
||||
|
||||
B.GlobalPosition = _desk.GetPositionFromAddress((int)deskPositionA.Y, (int)deskPositionA.X);
|
||||
A._deskPosition = deskPositionB;
|
||||
B._deskPosition = deskPositionA;
|
||||
|
||||
int indexA = _workers.IndexOf(A), indexB = _workers.IndexOf(B);
|
||||
Worker C = A;
|
||||
_workers[indexA] = B;
|
||||
_workers[indexB] = C;
|
||||
}
|
||||
|
||||
private void SetHoveredWorker(Worker HOVEREDWORKER)
|
||||
{
|
||||
if (HOVEREDWORKER._hovered)
|
||||
|
||||
@@ -3,21 +3,20 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public partial class Worker : CharacterBody2D
|
||||
public partial class Worker : Area2D
|
||||
{
|
||||
[Signal]
|
||||
public delegate void SetHoveredEventHandler(Worker THIS);
|
||||
// [Signal]
|
||||
// public delegate void SwapPositionsEventHandler(Worker THIS);
|
||||
|
||||
public bool _dead = false, _hovered = false, _held = false, _selected = false;
|
||||
public int _size, _health, _healthMax;
|
||||
public float _distanceTraveled, _stamina, _staminaMax;
|
||||
public Stat _aptitude = new(), _agility = new(), _ardor = new(), _accumen = new(), _awareness = new(), _appeal = new();
|
||||
public float _rotationalForce = 0;
|
||||
public Vector2 _chainPosition = new Vector2(-1, -1), _deskPosition;
|
||||
public List<Vector2> _moves = new();
|
||||
public Sprite2D _image;
|
||||
public ProgressBar _healthBar;
|
||||
public Manager _manager;
|
||||
public Cell _cell;
|
||||
public List<Trait> _traits = new();
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -48,9 +47,22 @@ public partial class Worker : CharacterBody2D
|
||||
|
||||
public override void _Process(double DELTA_)
|
||||
{
|
||||
|
||||
// _chainPosition = GlobalPosition;
|
||||
|
||||
if (_hovered)
|
||||
{
|
||||
if (Input.IsActionJustPressed("left_click"))
|
||||
{
|
||||
Hold();
|
||||
}
|
||||
}
|
||||
if (_held)
|
||||
{
|
||||
GlobalPosition = GetGlobalMousePosition();
|
||||
if (Input.IsActionJustReleased("left_click"))
|
||||
{
|
||||
Drop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// public void ChangeHealth(int CHANGE, Node CHANGEMAKER)
|
||||
@@ -76,6 +88,7 @@ public partial class Worker : CharacterBody2D
|
||||
if (_held)
|
||||
{
|
||||
_held = false;
|
||||
GlobalPosition = _cell.GlobalPosition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,17 +129,40 @@ public partial class Worker : CharacterBody2D
|
||||
_appeal._effective = _appeal._default;
|
||||
}
|
||||
|
||||
public void SwapWith(Worker OTHERWORKER)
|
||||
{
|
||||
Cell thisCell = _cell, otherCell = OTHERWORKER._cell;
|
||||
|
||||
OTHERWORKER.GlobalPosition = thisCell.GlobalPosition;
|
||||
_cell = otherCell;
|
||||
OTHERWORKER._cell = thisCell;
|
||||
|
||||
int indexA = _manager._workers.IndexOf(this), indexB = _manager._workers.IndexOf(OTHERWORKER);
|
||||
Worker placeholder = this;
|
||||
_manager._workers[indexA] = OTHERWORKER;
|
||||
_manager._workers[indexB] = placeholder;
|
||||
}
|
||||
|
||||
// PRIVATE METHODS
|
||||
|
||||
private void OnAreaEntered(Area2D AREA)
|
||||
{
|
||||
if (AREA is Worker)
|
||||
{
|
||||
if (_held)
|
||||
{
|
||||
SwapWith((Worker)AREA);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void OnMouseEntered()
|
||||
{
|
||||
_hovered = true;
|
||||
EmitSignal(SignalName.SetHovered, this);
|
||||
}
|
||||
|
||||
private void OnMouseExited()
|
||||
{
|
||||
_hovered = false;
|
||||
EmitSignal(SignalName.SetHovered, this);
|
||||
}
|
||||
|
||||
// private void OnBodyEntered(Node NODE)
|
||||
|
||||
6
Gameplay/cell.tscn
Normal file
6
Gameplay/cell.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://b7yrd35gvisom"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cmw4772lmwms0" path="res://Gameplay/Cell.cs" id="1_kyub7"]
|
||||
|
||||
[node name="Cell" type="Sprite2D"]
|
||||
script = ExtResource("1_kyub7")
|
||||
@@ -1,17 +1,18 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://demwh8ek37mnx"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://demwh8ek37mnx"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://pxi753iie75t" path="res://Gameplay/Desk.cs" id="2_15p4t"]
|
||||
[ext_resource type="Texture2D" uid="uid://dy4lmwn1dit26" path="res://art/shade.png" id="2_21bwm"]
|
||||
[ext_resource type="PackedScene" uid="uid://b7yrd35gvisom" path="res://Gameplay/cell.tscn" id="2_ucfrb"]
|
||||
|
||||
[node name="Desk" type="Node2D"]
|
||||
script = ExtResource("2_15p4t")
|
||||
|
||||
[node name="Light" type="Sprite2D" parent="."]
|
||||
[node name="Light" parent="." instance=ExtResource("2_ucfrb")]
|
||||
visible = false
|
||||
scale = Vector2(0.195, 0.195)
|
||||
texture = ExtResource("2_21bwm")
|
||||
|
||||
[node name="Dark" type="Sprite2D" parent="."]
|
||||
[node name="Dark" parent="." instance=ExtResource("2_ucfrb")]
|
||||
visible = false
|
||||
modulate = Color(0, 0, 0, 1)
|
||||
scale = Vector2(0.195, 0.195)
|
||||
|
||||
@@ -4,12 +4,16 @@
|
||||
[ext_resource type="Texture2D" uid="uid://dmispjd3fmmks" path="res://art/worker_test.png" id="2_m3kx1"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_4poc8"]
|
||||
radius = 25.0799
|
||||
radius = 16.0
|
||||
|
||||
[node name="Worker" type="CharacterBody2D"]
|
||||
input_pickable = true
|
||||
[node name="Worker" type="Area2D"]
|
||||
script = ExtResource("1_e314i")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture_filter = 1
|
||||
scale = Vector2(0.5, 0.5)
|
||||
texture = ExtResource("2_m3kx1")
|
||||
|
||||
[node name="HealthBar" type="ProgressBar" parent="."]
|
||||
visible = false
|
||||
top_level = true
|
||||
@@ -20,14 +24,10 @@ step = 1.0
|
||||
[node name="Bounds" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_4poc8")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture_filter = 1
|
||||
scale = Vector2(0.5, 0.5)
|
||||
texture = ExtResource("2_m3kx1")
|
||||
|
||||
[node name="Actions" type="Node" parent="."]
|
||||
|
||||
[node name="Conditions" type="Node" parent="."]
|
||||
|
||||
[connection signal="area_entered" from="." to="." method="OnAreaEntered"]
|
||||
[connection signal="mouse_entered" from="." to="." method="OnMouseEntered"]
|
||||
[connection signal="mouse_exited" from="." to="." method="OnMouseExited"]
|
||||
|
||||
Reference in New Issue
Block a user