still working out movement
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c5jj7yhlnodxt"
|
||||
path="res://.godot/imported/star.png-7953868fbd7392e6e06ff69587708912.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Art/star.png"
|
||||
dest_files=["res://.godot/imported/star.png-7953868fbd7392e6e06ff69587708912.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
@@ -31,6 +31,10 @@ public partial class HoverableNode : Node2D
|
||||
{
|
||||
EmitSignal(SignalName.Click, this, 2);
|
||||
}
|
||||
if (Input.IsActionJustPressed("middleClick"))
|
||||
{
|
||||
EmitSignal(SignalName.Click, this, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ public partial class Map : TileMapLayer
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
// GD.Print(GlobalPosition);
|
||||
List<Vector2I> usedCells = [.. GetUsedCells()];
|
||||
_cellSize = TileSet.TileSize;
|
||||
for (int i = 0; i < usedCells.Count; i++)
|
||||
@@ -79,7 +80,8 @@ public partial class Map : TileMapLayer
|
||||
MapCell newMapCell = _mapCellScene.Instantiate<MapCell>();
|
||||
Vector2I usedCell = usedCells[i];
|
||||
newMapCell._address = usedCell;
|
||||
newMapCell.GlobalPosition = GetCellPositionFromAddress(newMapCell._address);
|
||||
newMapCell.GlobalPosition = newMapCell._address * _cellSize + _cellSize / 2;
|
||||
// GD.Print(GlobalPosition, newMapCell.GlobalPosition);
|
||||
newMapCell._occupant = null;
|
||||
_cells[usedCell] = newMapCell;
|
||||
AddChild(newMapCell);
|
||||
@@ -110,14 +112,10 @@ public partial class Map : TileMapLayer
|
||||
}
|
||||
return new Vector2I((int)Math.Floor(POSITION.X / _cellSize.X), (int)Math.Floor(POSITION.Y / _cellSize.Y));
|
||||
}
|
||||
public Vector2 GetCellPosition(MapCell CELL)
|
||||
{
|
||||
return CELL.GlobalPosition;
|
||||
}
|
||||
|
||||
public Vector2 GetCellPositionFromAddress(Vector2I CELL_ADDRESS)
|
||||
public int GetCellDisposition(Vector2I ADDRESS)
|
||||
{
|
||||
return GlobalPosition + CELL_ADDRESS * _cellSize + _cellSize / 2;
|
||||
return (int)GetCellTileData(ADDRESS).GetCustomData("disposition");
|
||||
}
|
||||
|
||||
public MapCellOccupant GetOccupant(Vector2I CELL_TO_CHECK)
|
||||
@@ -157,11 +155,12 @@ public partial class Map : TileMapLayer
|
||||
{
|
||||
if (PEG != null)
|
||||
{
|
||||
if (PEG._address != -Vector2I.One)
|
||||
if (PEG._cell != null)
|
||||
{
|
||||
CELL._occupant = null;
|
||||
PEG._cell._occupant = null;
|
||||
SetCellSolid(_cells[PEG._address]);
|
||||
}
|
||||
PEG._cell = CELL;
|
||||
PEG._address = CELL._address;
|
||||
}
|
||||
CELL._occupant = PEG;
|
||||
|
||||
@@ -5,4 +5,11 @@ public partial class MapCell : Node2D
|
||||
{
|
||||
public Vector2I _address;
|
||||
public MapCellOccupant _occupant;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
|
||||
public partial class Peg : MapCellOccupant
|
||||
@@ -8,7 +9,7 @@ public partial class Peg : MapCellOccupant
|
||||
[Signal]
|
||||
public delegate void DeathEventHandler(Peg THIS);
|
||||
public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _movement = 0, _visibility;
|
||||
public List<Vector2I> _path = new();
|
||||
public List<MapCell> _path = new();
|
||||
public PegController _pegController;
|
||||
public Map _map;
|
||||
public List<PegAction> _actions;
|
||||
@@ -45,28 +46,15 @@ public partial class Peg : MapCellOccupant
|
||||
|
||||
}
|
||||
|
||||
public virtual List<Vector2I> GetBestPath(bool PARTIAL = false)
|
||||
public virtual List<MapCell> GetBestPath(bool PARTIAL = false)
|
||||
{
|
||||
// Map map = _pegController._playArea._map;
|
||||
// List<Vector2I> goals = Target();
|
||||
|
||||
// for (int i = 0; i < goals.Count; i++)
|
||||
// {
|
||||
// List<Vector2I> path = map.GetPath(_address, goals[i], false, PARTIAL);
|
||||
// if (path.Count > 0)
|
||||
// {
|
||||
// return path;
|
||||
// }
|
||||
|
||||
// }
|
||||
MapCell goal = Goal();
|
||||
return _pegController._playArea._map.GetPath(_address, goal._address, false, PARTIAL);
|
||||
return [.. _map.GetPath(_address, goal._address, false, PARTIAL).Select(a => _map._cells[a])];
|
||||
}
|
||||
|
||||
public virtual Dictionary<Vector2I, MapCell> GetEnemies()
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
return map._cells.Where(c => (int)c.Value._occupant._disposition == -(int)_disposition).ToDictionary();
|
||||
return _map._cells.Where(c => (int)(c.Value._occupant?._disposition ?? Disposition.NONE) == -(int)_disposition).ToDictionary();
|
||||
}
|
||||
|
||||
public virtual Dictionary<Vector2I, MapCell> GetVisibleCells()
|
||||
@@ -83,17 +71,16 @@ public partial class Peg : MapCellOccupant
|
||||
return enemies.Keys.Intersect(visible.Keys).ToDictionary(e => e, e => enemies[e]);
|
||||
}
|
||||
|
||||
public Vector2 GetPositionFromAddress()
|
||||
{
|
||||
return _pegController._playArea._map.GetCellPositionFromAddress(_address);
|
||||
}
|
||||
|
||||
public virtual MapCell Goal()
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
Dictionary<Vector2I, MapCell> visible = GetVisibleCells();
|
||||
Dictionary<Vector2I, MapCell> unoccupied = visible.Where(c => !map._astar.IsPointSolid(c.Key)).ToDictionary();
|
||||
Dictionary<Vector2I, MapCell> closest = unoccupied.OrderByDescending(c => c.Value._address.Y * (int)_disposition).ThenByDescending(c => Math.Abs(c.Value._address.X - _address.X)).ToDictionary();
|
||||
Dictionary<Vector2I, MapCell> enemyTerritory = map._cells.Where(c => _map.GetCellDisposition(c.Value._address) == -(int)_disposition).ToDictionary();
|
||||
Dictionary<Vector2I, MapCell> closest = enemyTerritory.OrderByDescending(c => c.Value._address.Y).ThenByDescending(c => Math.Abs(c.Value._address.X - _address.X)).ToDictionary();
|
||||
|
||||
// Dictionary<Vector2I, MapCell> closest = unoccupied.OrderByDescending(c => c.Value._address.Y * -(int)_disposition).ThenByDescending(c => Math.Abs(c.Value._address.X - _address.X)).ToDictionary();
|
||||
// Dictionary<Vector2I, MapCell> closest = furthest.Where(c => _map.GetCellDisposition(c.Value._address) == -(int)_disposition).ToDictionary();
|
||||
return closest.ElementAt(0).Value;
|
||||
}
|
||||
|
||||
|
||||
+17
-7
@@ -153,13 +153,7 @@ public partial class PegController : TurnController
|
||||
}
|
||||
if (CLICK_TYPE == 0)
|
||||
{
|
||||
List<Vector2I> newPath = peg.GetBestPath();
|
||||
|
||||
// pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(c,0,Vector2I.Down*4));
|
||||
// for (int i = 0; i < newPath.Count; i++)
|
||||
// {
|
||||
// pathLayer.SetCell(newPath[i],0,Vector2I.One);
|
||||
// }
|
||||
Map map = _playArea._map;
|
||||
TileMapLayer pathLayer = _playArea.GetNode<TileMapLayer>("PathLayer");
|
||||
List<Vector2I> pl = [.. pathLayer.GetUsedCells()];
|
||||
@@ -172,10 +166,22 @@ public partial class PegController : TurnController
|
||||
|
||||
}
|
||||
}
|
||||
else if (CLICK_TYPE == 1)
|
||||
{
|
||||
TileMapLayer pathLayer = _playArea.GetNode<TileMapLayer>("PathLayer");
|
||||
List<MapCell> newPath = peg.GetBestPath(true);
|
||||
|
||||
pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(c,0,Vector2I.Down + Vector2I.Right*4));
|
||||
for (int i = 0; i < newPath.Count; i++)
|
||||
{
|
||||
pathLayer.SetCell(newPath[i]._address,0,Vector2I.One);
|
||||
}
|
||||
}
|
||||
else if (CLICK_TYPE == 2)
|
||||
{
|
||||
HandlePegRemoval(peg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void HandlePegRemoval(Peg PEG_TO_REMOVE)
|
||||
@@ -201,6 +207,7 @@ public partial class PegController : TurnController
|
||||
List<Vector2I> fPositions = [.. positions.Where(c => (int)init.GetCellTileData(c).GetCustomData("disposition") == 1)];
|
||||
AddHostilePegs(hPositions);
|
||||
AddFriendlyPegs(fPositions);
|
||||
_playArea.HighlightCells();
|
||||
}
|
||||
|
||||
public void ProcessTween()
|
||||
@@ -227,9 +234,12 @@ public partial class PegController : TurnController
|
||||
Peg peg = step.Item1;
|
||||
PegAction action = step.Item2;
|
||||
Tween tween = action.CreateAnimation(peg);
|
||||
if (tween != null)
|
||||
{
|
||||
_tween.Parallel().TweenSubtween(tween);
|
||||
}
|
||||
}
|
||||
}
|
||||
_tween.TweenCallback(Callable.From(EndTurn));
|
||||
|
||||
}
|
||||
@@ -245,12 +255,12 @@ public partial class PegController : TurnController
|
||||
HandlePegSort();
|
||||
|
||||
HandlePegTurn();
|
||||
_playArea.HighlightCells();
|
||||
}
|
||||
|
||||
public void SetPeg(Peg PEG, MapCell CELL)
|
||||
{
|
||||
_map.SetCellPeg(CELL, PEG);
|
||||
PEG._cell = CELL;
|
||||
PEG.GlobalPosition = CELL.GlobalPosition;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ public partial class BasicMovement : PegAction
|
||||
{
|
||||
PegController pegController = PEG._pegController;
|
||||
Map map = pegController._playArea._map;
|
||||
Vector2I cell = PEG._path[0];
|
||||
MapCell cell = PEG._path[0];
|
||||
|
||||
Tween subtween = CreateTween();
|
||||
Vector2 target = map.GetCellPositionFromAddress(cell);
|
||||
Vector2 target = cell.GlobalPosition;
|
||||
|
||||
subtween.TweenProperty(PEG, "global_position", target, 0.25f);
|
||||
PEG._path.RemoveAt(0);
|
||||
@@ -32,23 +32,23 @@ public partial class BasicMovement : PegAction
|
||||
|
||||
public override void DoImmediately(Peg PEG)
|
||||
{
|
||||
List<Vector2I> path = PEG.GetBestPath(true);
|
||||
List<MapCell> path = PEG.GetBestPath(true);
|
||||
PegController pegController = PEG._pegController;
|
||||
Map map = pegController._playArea._map;
|
||||
if (path?.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Vector2I cell = path[0];
|
||||
MapCell cell = path[0];
|
||||
|
||||
map.SetCellPeg(map._cells[cell], PEG);
|
||||
map.SetCellPeg(cell, PEG);
|
||||
PEG._path.Add(cell);
|
||||
}
|
||||
|
||||
public override bool MeetsCriteria(Peg PEG)
|
||||
{
|
||||
List<Vector2I> bestPath = PEG.GetBestPath(true);
|
||||
return base.MeetsCriteria(PEG) && bestPath.Count > 0 && (int)PEG._pegController._playArea._map.GetCellTileData(bestPath[0]).GetCustomData("disposition") != -(int)PEG._disposition;
|
||||
List<MapCell> bestPath = PEG.GetBestPath(true);
|
||||
return base.MeetsCriteria(PEG) && bestPath.Count > 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@ public partial class ThrustSpear : PegAction
|
||||
public override Tween CreateAnimation(Peg PEG)
|
||||
{
|
||||
MapCell target = Target(PEG);
|
||||
if (target == PEG._cell)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Tween subtween = CreateTween();
|
||||
|
||||
subtween.TweenProperty(_image, "visible", true, 0.0f);
|
||||
@@ -36,5 +40,4 @@ public partial class ThrustSpear : PegAction
|
||||
return PEG.Goal();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
script = ExtResource("1_revbx")
|
||||
|
||||
[node name="Image" type="Sprite2D" parent="." unique_id=1133735272]
|
||||
visible = false
|
||||
position = Vector2(0, -4.999999)
|
||||
scale = Vector2(0.1, 0.1)
|
||||
texture = ExtResource("2_nwcvh")
|
||||
|
||||
@@ -14,11 +14,10 @@ public partial class Spearman : FriendlyPeg
|
||||
|
||||
public override MapCell Goal()
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
Dictionary<Vector2I, MapCell> enemies = GetVisibleEnemies();
|
||||
if (enemies.Count == 0)
|
||||
{
|
||||
return _map._cells[_address];
|
||||
return _cell;
|
||||
}
|
||||
Dictionary<Vector2I, MapCell> closest = enemies.OrderBy(e => (e.Value._occupant._address - _address).Length()).ToDictionary();
|
||||
return closest.ElementAt(0).Value;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[ext_resource type="Script" uid="uid://xlg4cblo1vf1" path="res://Pegs/HostilePegs/Infantry.cs" id="1_wlksp"]
|
||||
[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="2_b77ka"]
|
||||
[ext_resource type="PackedScene" path="res://Pegs/Actions/swing_shortsword.tscn" id="3_b77ka"]
|
||||
[ext_resource type="PackedScene" uid="uid://c6df6ib0qan5g" path="res://Pegs/Actions/swing_shortsword.tscn" id="3_b77ka"]
|
||||
[ext_resource type="PackedScene" uid="uid://bup5oli00p3lg" path="res://Pegs/Actions/basic_movement.tscn" id="4_b77ka"]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_7k104"]
|
||||
|
||||
+18
-17
@@ -20,8 +20,7 @@ public partial class PlayArea : Node2D
|
||||
CollisionShape2D regionBounds = _region.GetNode<CollisionShape2D>("Bounds");
|
||||
|
||||
_map = GetNode<Map>("Map");
|
||||
// TileMapLayer occupiedSpaces = GetNode<TileMapLayer>("OccupiedSpaces");
|
||||
// occupiedSpaces.SetCell(Vector2I.Zero, 0, new Vector2I(4,0));
|
||||
TileMapLayer occupiedSpaces = GetNode<TileMapLayer>("OccupiedSpaces");
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
@@ -32,21 +31,23 @@ public partial class PlayArea : Node2D
|
||||
public void HighlightCells()
|
||||
{
|
||||
TileMapLayer occupiedSpaces = GetNode<TileMapLayer>("OccupiedSpaces");
|
||||
// _map._cells.ForEach(c =>
|
||||
// {
|
||||
// if (_map.HasOccupant(c))
|
||||
// {
|
||||
// occupiedSpaces.SetCell(c, 0, new Vector2I(4,0));
|
||||
// }
|
||||
// else if (_map._astar.IsPointSolid(c))
|
||||
// {
|
||||
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// occupiedSpaces.SetCell(c, 0, Vector2I.Down*4);
|
||||
// }
|
||||
// });
|
||||
for (int i = 0; i < _map._cells.Count; i++)
|
||||
{
|
||||
MapCell c = _map._cells.ElementAt(i).Value;
|
||||
if (c._occupant != null)
|
||||
{
|
||||
GD.Print(c._occupant);
|
||||
occupiedSpaces.SetCell(c._address, 0, new Vector2I(4,0));
|
||||
}
|
||||
else if (_map._astar.IsPointSolid(c._address))
|
||||
{
|
||||
occupiedSpaces.SetCell(c._address, 0, new Vector2I(3,1));
|
||||
}
|
||||
else
|
||||
{
|
||||
occupiedSpaces.SetCell(c._address, 0, new Vector2I(4,1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
-1
@@ -1,3 +1,11 @@
|
||||
[gd_scene format=3 uid="uid://bh28pqqlppt3a"]
|
||||
[gd_scene format=3 uid="uid://cqwi2kesqh5wt"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b8fx1wwyj30bg" path="res://MapCell.cs" id="1_jkeij"]
|
||||
[ext_resource type="Texture2D" uid="uid://c5jj7yhlnodxt" path="res://Art/star.png" id="2_ugbl7"]
|
||||
|
||||
[node name="MapCell" type="Node2D" unique_id=953237004]
|
||||
script = ExtResource("1_jkeij")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=733491629]
|
||||
scale = Vector2(0.025, 0.025)
|
||||
texture = ExtResource("2_ugbl7")
|
||||
|
||||
+2
-1
@@ -1,7 +1,7 @@
|
||||
[gd_scene format=4 uid="uid://dumcridek4xy3"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bnaxgcafcvtfv" path="res://PlayArea.cs" id="1_lq4m8"]
|
||||
[ext_resource type="PackedScene" uid="uid://mjinvqj25wha" path="res://Map.tscn" id="2_wqv88"]
|
||||
[ext_resource type="PackedScene" uid="uid://dqknim3lldrmv" path="res://Map.tscn" id="2_wqv88"]
|
||||
[ext_resource type="Texture2D" uid="uid://cf554xlykq1o4" path="res://Art/tile_set.png" id="3_md2b6"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_q4dkg"]
|
||||
@@ -95,6 +95,7 @@ tile_map_data = PackedByteArray("AAAAAAAAAAAAAAAAAAAAAAEAAAAAAAEAAAAAAAIAAAAAAAA
|
||||
tile_set = SubResource("TileSet_he03c")
|
||||
|
||||
[node name="InitialPositions" type="TileMapLayer" parent="." unique_id=555896823]
|
||||
visible = false
|
||||
tile_map_data = PackedByteArray("AAADAAcAAAABAAAAAAAEAAYAAAABAAAAAAAEAAgAAAABAAAAAAAFAAcAAAABAAAAAAAHAAwAAAABAAAAAAAIAA0AAAABAAAAAAAJAA4AAAABAAAAAAAKAA0AAAABAAAAAAALAAkAAAABAAAAAAALAA4AAAABAAAAAAAMAAgAAAABAAAAAAAMAA0AAAABAAAAAAANAAcAAAABAAAAAAANAA4AAAABAAAAAAAOAAgAAAABAAAAAAAOAA0AAAABAAAAAAAPAAgAAAABAAAAAAAPAA0AAAABAAAAAAAQAAcAAAABAAAAAAAQAA4AAAABAAAAAAARAAgAAAABAAAAAAARAA0AAAABAAAAAAASAAkAAAABAAAAAAASAA4AAAABAAAAAAATAA0AAAABAAAAAAAUAA4AAAABAAAAAAAVAA0AAAABAAAAAAAWAAwAAAABAAAAAAAYAAcAAAABAAAAAAAZAAYAAAABAAAAAAAZAAgAAAABAAAAAAAaAAcAAAABAAAAAAACAAAAAAACAAAAAAAHAAAAAAACAAAAAAAMAAAAAAACAAAAAAARAAAAAAACAAAAAAAWAAAAAAACAAAAAAAbAAAAAAACAAAAAAA=")
|
||||
tile_set = SubResource("TileSet_vqhsw")
|
||||
|
||||
|
||||
@@ -51,6 +51,11 @@ changeTurn={
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":true,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":84,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
middleClick={
|
||||
"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":4,"position":Vector2(222, 10),"global_position":Vector2(231, 58),"factor":1.0,"button_index":3,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[physics]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user