diff --git a/Art/star.png b/Art/star.png new file mode 100644 index 0000000..b112c3b Binary files /dev/null and b/Art/star.png differ diff --git a/Art/star.png.import b/Art/star.png.import new file mode 100644 index 0000000..fbf968b --- /dev/null +++ b/Art/star.png.import @@ -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 diff --git a/HoverableNode.cs b/HoverableNode.cs index f663ac2..e60fe53 100644 --- a/HoverableNode.cs +++ b/HoverableNode.cs @@ -31,6 +31,10 @@ public partial class HoverableNode : Node2D { EmitSignal(SignalName.Click, this, 2); } + if (Input.IsActionJustPressed("middleClick")) + { + EmitSignal(SignalName.Click, this, 1); + } } } diff --git a/Map.cs b/Map.cs index 9e5d45d..46d26e0 100644 --- a/Map.cs +++ b/Map.cs @@ -72,6 +72,7 @@ public partial class Map : TileMapLayer public override void _Ready() { base._Ready(); + // GD.Print(GlobalPosition); List 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(); 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; diff --git a/MapCell.cs b/MapCell.cs index b25d5da..2713553 100644 --- a/MapCell.cs +++ b/MapCell.cs @@ -5,4 +5,11 @@ public partial class MapCell : Node2D { public Vector2I _address; public MapCellOccupant _occupant; + + public override void _Ready() + { + base._Ready(); + } + } + diff --git a/Peg.cs b/Peg.cs index 675b87b..a578f22 100644 --- a/Peg.cs +++ b/Peg.cs @@ -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 _path = new(); + public List _path = new(); public PegController _pegController; public Map _map; public List _actions; @@ -45,28 +46,15 @@ public partial class Peg : MapCellOccupant } - public virtual List GetBestPath(bool PARTIAL = false) + public virtual List GetBestPath(bool PARTIAL = false) { - // Map map = _pegController._playArea._map; - // List goals = Target(); - - // for (int i = 0; i < goals.Count; i++) - // { - // List 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 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 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 visible = GetVisibleCells(); Dictionary unoccupied = visible.Where(c => !map._astar.IsPointSolid(c.Key)).ToDictionary(); - Dictionary closest = unoccupied.OrderByDescending(c => c.Value._address.Y * (int)_disposition).ThenByDescending(c => Math.Abs(c.Value._address.X - _address.X)).ToDictionary(); + Dictionary enemyTerritory = map._cells.Where(c => _map.GetCellDisposition(c.Value._address) == -(int)_disposition).ToDictionary(); + Dictionary closest = enemyTerritory.OrderByDescending(c => c.Value._address.Y).ThenByDescending(c => Math.Abs(c.Value._address.X - _address.X)).ToDictionary(); + + // Dictionary closest = unoccupied.OrderByDescending(c => c.Value._address.Y * -(int)_disposition).ThenByDescending(c => Math.Abs(c.Value._address.X - _address.X)).ToDictionary(); + // Dictionary closest = furthest.Where(c => _map.GetCellDisposition(c.Value._address) == -(int)_disposition).ToDictionary(); return closest.ElementAt(0).Value; } diff --git a/PegController.cs b/PegController.cs index dbeb2ad..955f1d5 100644 --- a/PegController.cs +++ b/PegController.cs @@ -153,13 +153,7 @@ public partial class PegController : TurnController } if (CLICK_TYPE == 0) { - List 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("PathLayer"); List pl = [.. pathLayer.GetUsedCells()]; @@ -172,10 +166,22 @@ public partial class PegController : TurnController } } + else if (CLICK_TYPE == 1) + { + TileMapLayer pathLayer = _playArea.GetNode("PathLayer"); + List 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 fPositions = [.. positions.Where(c => (int)init.GetCellTileData(c).GetCustomData("disposition") == 1)]; AddHostilePegs(hPositions); AddFriendlyPegs(fPositions); + _playArea.HighlightCells(); } public void ProcessTween() @@ -227,7 +234,10 @@ public partial class PegController : TurnController Peg peg = step.Item1; PegAction action = step.Item2; Tween tween = action.CreateAnimation(peg); - _tween.Parallel().TweenSubtween(tween); + 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; } diff --git a/Pegs/Actions/BasicMovement.cs b/Pegs/Actions/BasicMovement.cs index 6ef5267..ee4d942 100644 --- a/Pegs/Actions/BasicMovement.cs +++ b/Pegs/Actions/BasicMovement.cs @@ -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 path = PEG.GetBestPath(true); + List 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 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 bestPath = PEG.GetBestPath(true); + return base.MeetsCriteria(PEG) && bestPath.Count > 0; } diff --git a/Pegs/Actions/ThrustSpear.cs b/Pegs/Actions/ThrustSpear.cs index 404fabc..2bb4d28 100644 --- a/Pegs/Actions/ThrustSpear.cs +++ b/Pegs/Actions/ThrustSpear.cs @@ -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(); } - } diff --git a/Pegs/Actions/thrust_spear.tscn b/Pegs/Actions/thrust_spear.tscn index dbde826..dac33a3 100644 --- a/Pegs/Actions/thrust_spear.tscn +++ b/Pegs/Actions/thrust_spear.tscn @@ -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") diff --git a/Pegs/FriendlyPegs/Spearman.cs b/Pegs/FriendlyPegs/Spearman.cs index 3434f0e..629d020 100644 --- a/Pegs/FriendlyPegs/Spearman.cs +++ b/Pegs/FriendlyPegs/Spearman.cs @@ -14,11 +14,10 @@ public partial class Spearman : FriendlyPeg public override MapCell Goal() { - Map map = _pegController._playArea._map; Dictionary enemies = GetVisibleEnemies(); if (enemies.Count == 0) { - return _map._cells[_address]; + return _cell; } Dictionary closest = enemies.OrderBy(e => (e.Value._occupant._address - _address).Length()).ToDictionary(); return closest.ElementAt(0).Value; diff --git a/Pegs/HostilePegs/infantry.tscn b/Pegs/HostilePegs/infantry.tscn index e81873f..68bd4e6 100644 --- a/Pegs/HostilePegs/infantry.tscn +++ b/Pegs/HostilePegs/infantry.tscn @@ -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"] diff --git a/PlayArea.cs b/PlayArea.cs index c1f51ec..2ce7121 100644 --- a/PlayArea.cs +++ b/PlayArea.cs @@ -20,8 +20,7 @@ public partial class PlayArea : Node2D CollisionShape2D regionBounds = _region.GetNode("Bounds"); _map = GetNode("Map"); - // TileMapLayer occupiedSpaces = GetNode("OccupiedSpaces"); - // occupiedSpaces.SetCell(Vector2I.Zero, 0, new Vector2I(4,0)); + TileMapLayer occupiedSpaces = GetNode("OccupiedSpaces"); } public override void _Process(double delta) @@ -32,21 +31,23 @@ public partial class PlayArea : Node2D public void HighlightCells() { TileMapLayer occupiedSpaces = GetNode("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)); + } + } } } diff --git a/map_cell.tscn b/map_cell.tscn index b0c6d30..0e7ed03 100644 --- a/map_cell.tscn +++ b/map_cell.tscn @@ -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") diff --git a/play_area.tscn b/play_area.tscn index 54473e1..0ee3aab 100644 --- a/play_area.tscn +++ b/play_area.tscn @@ -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") diff --git a/project.godot b/project.godot index 7ae815b..617cfc8 100644 --- a/project.godot +++ b/project.godot @@ -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]