diff --git a/Attack.cs b/Attack.cs index 064b542..03927ba 100644 --- a/Attack.cs +++ b/Attack.cs @@ -5,7 +5,7 @@ public partial class Attack : RigidBody2D public bool _hovered = false; public int _damage = 1; public Vector2 _speed; - public Player _playerOwner; + public Commander _commanderOwner; public override void _PhysicsProcess(double delta) { @@ -23,9 +23,11 @@ public partial class Attack : RigidBody2D public void TakeAction(Node BODY) { + GD.Print("Body Entered"); if (BODY is Enemy enemy) { - enemy.TakeDamage(_damage, _playerOwner); + GD.Print("Body Entered is enemy"); + enemy.TakeDamage(_damage, _commanderOwner); } } diff --git a/Player.cs b/Commander.cs similarity index 94% rename from Player.cs rename to Commander.cs index a8e92ed..e499f34 100644 --- a/Player.cs +++ b/Commander.cs @@ -1,7 +1,7 @@ using Godot; using System; -public partial class Player : Sprite2D +public partial class Commander : Sprite2D { [Signal] public delegate void TurnDoneEventHandler(); @@ -39,7 +39,7 @@ public partial class Player : Sprite2D if (_currentAttack == null){ GD.Print("Loading attack"); _currentAttack = _attackScene.Instantiate(); - _currentAttack._playerOwner = this; + _currentAttack._commanderOwner = this; _currentAttack.GravityScale = 0; AddChild(_currentAttack); } diff --git a/Player.cs.uid b/Commander.cs.uid similarity index 100% rename from Player.cs.uid rename to Commander.cs.uid diff --git a/Enemy.cs b/Enemy.cs index 1ce023d..7362707 100644 --- a/Enemy.cs +++ b/Enemy.cs @@ -5,39 +5,30 @@ public partial class Enemy : StaticBody2D { [Signal] public delegate void TurnDoneEventHandler(); - public bool _toMove = false; - public int _speed = 100, _reach = 200, _damage = 1, _health = 2; + public int _damage = 1, _health = 2; + public Vector2 _speed = Vector2.Up, _range = Vector2.Up; public float _movement = 0; - public Player _player; + public GridMap _grid; + public GridMarker _gridMarker; + public Commander _commander; public override void _PhysicsProcess(double delta) { base._PhysicsProcess(delta); - if (_toMove) - { - Vector2 moveVector = (_player.Position - Position) * (float)delta; - if ((_movement += moveVector.Length()) <= _speed ) - { - MoveAndCollide(moveVector); - } - else - { - if ((_player.Position - Position).Length() <= _reach) - { - Attack(_player); - } - _toMove = false; - _movement = 0; - } - } + } - public void Attack(Player PLAYER) + public void Attack(Commander COMMANDER) { - PLAYER.TakeDamage(_damage, this); - QueueFree(); + COMMANDER.TakeDamage(_damage, this); } - public void TakeDamage(int DAMAGE, Player ATTACKER) + public void PlaceOrMove(GridMarker GRIDMARKER) + { + _gridMarker = GRIDMARKER; + GlobalPosition = _gridMarker.GlobalPosition; + } + + public void TakeDamage(int DAMAGE, Commander ATTACKER) { _health -= DAMAGE; GD.Print($"Taking {DAMAGE}, Health is now {_health}"); @@ -49,6 +40,6 @@ public partial class Enemy : StaticBody2D public void TakeTurn() { - _toMove = true; + PlaceOrMove(_grid._gridMarkers[(int)(_gridMarker._address.Y + _speed.Y)][(int)(_gridMarker._address.X + _speed.X)]); } } diff --git a/GridMap.cs b/GridMap.cs new file mode 100644 index 0000000..346fa19 --- /dev/null +++ b/GridMap.cs @@ -0,0 +1,34 @@ +using Godot; +using System; +using System.Collections.Generic; + +public partial class GridMap : Node2D +{ + public int _cellSize = 16; + public Area2D _playArea; + public GridMarker _gridMarker; + public List> _gridMarkers = new(); + + public override void _Ready() + { + base._Ready(); + _playArea = GetNode("PlayArea"); + _gridMarker = GetNode("GridMarker"); + CollisionShape2D bounds = _playArea.GetNode("Bounds"); + int gridCellsX = (int)bounds.Shape.GetRect().Size.X / _cellSize, gridCellsY = (int)bounds.Shape.GetRect().Size.Y / _cellSize; + for (int i = 0; i < gridCellsY; i++) + { + _gridMarkers.Add([]); + for (int j = 0; j < gridCellsX; j++) + { + GridMarker newGridMarker = (GridMarker)_gridMarker.Duplicate(); + newGridMarker._address = new Vector2(j, i); + newGridMarker.Position = new Vector2(_playArea.Position.X - bounds.Shape.GetRect().Size.X / 2 + (j+.5f)*_cellSize, _playArea.Position.Y - bounds.Shape.GetRect().Size.Y / 2 + (i+.5f)*_cellSize); + newGridMarker.Modulate = new Color((i+j)%2 == 0 ? "#ffffff" : "#000000"); + _gridMarkers[i].Add(newGridMarker); + AddChild(newGridMarker); + } + } + _gridMarker.QueueFree(); + } +} diff --git a/GridMap.cs.uid b/GridMap.cs.uid new file mode 100644 index 0000000..0a907a2 --- /dev/null +++ b/GridMap.cs.uid @@ -0,0 +1 @@ +uid://bnaxgcafcvtfv diff --git a/GridMarker.cs b/GridMarker.cs new file mode 100644 index 0000000..c0d015b --- /dev/null +++ b/GridMarker.cs @@ -0,0 +1,8 @@ +using Godot; +using System; + +public partial class GridMarker : Marker2D +{ + public Vector2 _address; + public Node _occupant; +} diff --git a/GridMarker.cs.uid b/GridMarker.cs.uid new file mode 100644 index 0000000..e7a20fc --- /dev/null +++ b/GridMarker.cs.uid @@ -0,0 +1 @@ +uid://cob0pwghnubxa diff --git a/Main.cs b/Main.cs index 7a66061..4cde227 100644 --- a/Main.cs +++ b/Main.cs @@ -1,30 +1,43 @@ using Godot; using System; using System.Collections.Generic; +using System.Linq; public partial class Main : Node { - public bool _isPlayerTurn = true; - public Player _player; + public bool _isCommanderTurn = true; + public Commander _commander; + public GridMap _grid; public PackedScene _enemyScene = GD.Load("res://Enemy.tscn"); public List _enemies = new(); public Random _rng = new(); public override void _Ready() { base._Ready(); - _player = GetNode("Player"); - _player.TurnDone += ChangeTurn; + _commander = GetNode("Commander"); + _grid = GetNode("GridMap"); + _commander.GlobalPosition = _grid.GlobalPosition; + _commander.TurnDone += ChangeTurn; AddEnemy(); - _player.StartTurn(); + _commander.StartTurn(); + } + + public override void _Process(double delta) + { + base._Process(delta); + if (Input.IsActionJustPressed("escape")) + { + GetTree().Quit(); + } } public void ChangeTurn() { - _isPlayerTurn = !_isPlayerTurn; - if (_isPlayerTurn) + _isCommanderTurn = !_isCommanderTurn; + if (_isCommanderTurn) { - GD.Print("Starting Player turn"); - _player.StartTurn(); + GD.Print("Starting Commander turn"); + _commander.StartTurn(); } else { @@ -33,6 +46,7 @@ public partial class Main : Node { _enemies[i].TakeTurn(); } + AddEnemy(); ChangeTurn(); } @@ -42,8 +56,9 @@ public partial class Main : Node { Enemy newEnemy = _enemyScene.Instantiate(); newEnemy.TurnDone += ChangeTurn; - newEnemy.Position = new Vector2(_rng.Next((int)_player.GetViewportRect().Size.X), _player.GetViewportRect().Size.Y - 100); - newEnemy._player = _player; + newEnemy.PlaceOrMove(_grid._gridMarkers.Last()[_rng.Next(_grid._gridMarkers.Last().Count)]); + newEnemy._commander = _commander; + newEnemy._grid = _grid; _enemies.Add(newEnemy); AddChild(newEnemy); } diff --git a/attack.tscn b/attack.tscn index e8d04a8..6539129 100644 --- a/attack.tscn +++ b/attack.tscn @@ -7,7 +7,10 @@ radius = 25.0 [node name="Attack" type="RigidBody2D" unique_id=1225359241] +scale = Vector2(0.56, 0.56) input_pickable = true +contact_monitor = true +max_contacts_reported = 100 script = ExtResource("1_63pi1") [node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1448070524] diff --git a/player.tscn b/commander.tscn similarity index 61% rename from player.tscn rename to commander.tscn index 8eb1457..dce1ded 100644 --- a/player.tscn +++ b/commander.tscn @@ -1,6 +1,6 @@ [gd_scene format=3 uid="uid://c78e3u1owgiek"] -[ext_resource type="Script" uid="uid://b2kj0rc3g1hkm" path="res://Player.cs" id="1_4flbx"] +[ext_resource type="Script" uid="uid://b2kj0rc3g1hkm" path="res://Commander.cs" id="1_4flbx"] -[node name="Player" type="Sprite2D" unique_id=1378094015] +[node name="Commander" type="Sprite2D" unique_id=1378094015] script = ExtResource("1_4flbx") diff --git a/enemy.tscn b/enemy.tscn index 13f7325..ad03dac 100644 --- a/enemy.tscn +++ b/enemy.tscn @@ -1,4 +1,4 @@ -[gd_scene format=3 uid="uid://drt7w0eqp13tu"] +[gd_scene format=3 uid="uid://bpce6ise18ks"] [ext_resource type="Script" uid="uid://dfba4vq6jv0a6" path="res://Enemy.cs" id="1_4gyqm"] [ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://circle25r.png" id="1_7k104"] @@ -10,6 +10,7 @@ bounce = 0.5 radius = 25.0 [node name="Enemy" type="StaticBody2D" unique_id=1417697759] +scale = Vector2(0.56, 0.56) physics_material_override = SubResource("PhysicsMaterial_7k104") script = ExtResource("1_4gyqm") diff --git a/grid_map.tscn b/grid_map.tscn new file mode 100644 index 0000000..bda39c6 --- /dev/null +++ b/grid_map.tscn @@ -0,0 +1,18 @@ +[gd_scene format=3 uid="uid://la8pwcc0tjuu"] + +[ext_resource type="Script" uid="uid://bnaxgcafcvtfv" path="res://GridMap.cs" id="1_lq4m8"] +[ext_resource type="PackedScene" uid="uid://bxqhci3fya80t" path="res://grid_marker.tscn" id="2_gc0wv"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_q4dkg"] +size = Vector2(1600, 800) + +[node name="GridMap" type="Node2D" unique_id=1123610167] +position = Vector2(960, 510) +script = ExtResource("1_lq4m8") + +[node name="PlayArea" type="Area2D" parent="." unique_id=1719758298] + +[node name="Bounds" type="CollisionShape2D" parent="PlayArea" unique_id=1902214362] +shape = SubResource("RectangleShape2D_q4dkg") + +[node name="GridMarker" parent="." unique_id=1390656323 instance=ExtResource("2_gc0wv")] diff --git a/grid_marker.tscn b/grid_marker.tscn new file mode 100644 index 0000000..e7710e6 --- /dev/null +++ b/grid_marker.tscn @@ -0,0 +1,11 @@ +[gd_scene format=3 uid="uid://bxqhci3fya80t"] + +[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://circle25r.png" id="1_0j65c"] +[ext_resource type="Script" uid="uid://cob0pwghnubxa" path="res://GridMarker.cs" id="1_u0re5"] + +[node name="GridMarker" type="Marker2D" unique_id=1390656323] +script = ExtResource("1_u0re5") + +[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1491405727] +scale = Vector2(0.1, 0.1) +texture = ExtResource("1_0j65c") diff --git a/main.tscn b/main.tscn index 4db2287..463f088 100644 --- a/main.tscn +++ b/main.tscn @@ -1,10 +1,13 @@ [gd_scene format=3 uid="uid://dcp7p6al4i0b7"] [ext_resource type="Script" uid="uid://cg1m762ed04kv" path="res://Main.cs" id="1_ig7tw"] -[ext_resource type="PackedScene" uid="uid://c78e3u1owgiek" path="res://player.tscn" id="2_0xm2m"] +[ext_resource type="PackedScene" uid="uid://c78e3u1owgiek" path="res://commander.tscn" id="2_0xm2m"] +[ext_resource type="PackedScene" uid="uid://la8pwcc0tjuu" path="res://grid_map.tscn" id="3_h2yge"] [node name="Main" type="Node" unique_id=535208469] script = ExtResource("1_ig7tw") -[node name="Player" parent="." unique_id=203629164 instance=ExtResource("2_0xm2m")] -position = Vector2(576, 100) +[node name="Commander" parent="." unique_id=203629164 instance=ExtResource("2_0xm2m")] + +[node name="GridMap" parent="." unique_id=1123610167 instance=ExtResource("3_h2yge")] +position = Vector2(960, 510) diff --git a/project.godot b/project.godot index de16239..74a703a 100644 --- a/project.godot +++ b/project.godot @@ -15,6 +15,12 @@ run/main_scene="uid://dcp7p6al4i0b7" config/features=PackedStringArray("4.6", "C#", "Forward Plus") config/icon="res://icon.svg" +[display] + +window/size/viewport_width=1920 +window/size/viewport_height=1080 +window/size/mode=3 + [dotnet] project/assembly_name="PeggleRoguelike" @@ -26,6 +32,11 @@ leftClick={ "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":1,"position":Vector2(74, 17),"global_position":Vector2(83, 65),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) ] } +escape={ +"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":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +] +} [physics]