third commit

This commit is contained in:
2026-05-28 00:06:51 -04:00
parent a6db45300c
commit 4266625390
16 changed files with 145 additions and 46 deletions
+4 -2
View File
@@ -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);
}
}
+2 -2
View File
@@ -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<Attack>();
_currentAttack._playerOwner = this;
_currentAttack._commanderOwner = this;
_currentAttack.GravityScale = 0;
AddChild(_currentAttack);
}
View File
+16 -25
View File
@@ -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)]);
}
}
+34
View File
@@ -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<List<GridMarker>> _gridMarkers = new();
public override void _Ready()
{
base._Ready();
_playArea = GetNode<Area2D>("PlayArea");
_gridMarker = GetNode<GridMarker>("GridMarker");
CollisionShape2D bounds = _playArea.GetNode<CollisionShape2D>("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();
}
}
+1
View File
@@ -0,0 +1 @@
uid://bnaxgcafcvtfv
+8
View File
@@ -0,0 +1,8 @@
using Godot;
using System;
public partial class GridMarker : Marker2D
{
public Vector2 _address;
public Node _occupant;
}
+1
View File
@@ -0,0 +1 @@
uid://cob0pwghnubxa
+26 -11
View File
@@ -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<PackedScene>("res://Enemy.tscn");
public List<Enemy> _enemies = new();
public Random _rng = new();
public override void _Ready()
{
base._Ready();
_player = GetNode<Player>("Player");
_player.TurnDone += ChangeTurn;
_commander = GetNode<Commander>("Commander");
_grid = GetNode<GridMap>("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<Enemy>();
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);
}
+3
View File
@@ -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]
+2 -2
View File
@@ -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")
+2 -1
View File
@@ -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")
+18
View File
@@ -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")]
+11
View File
@@ -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")
+6 -3
View File
@@ -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)
+11
View File
@@ -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]