finished reowrking grid maps, polished astar pathfinding, started work on aiming functions --todo: change launch speed to constant, change aim function to take into account the angle it would need to launch at to hit mouse position like in peggle, add raycasting

This commit is contained in:
2026-06-03 02:44:13 -04:00
parent 7b5cd9d5f6
commit c97b0e5cc2
24 changed files with 1108 additions and 1104 deletions
+46 -16
View File
@@ -1,46 +1,76 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Diagnostics;
public partial class Tower : Sprite2D
{
public bool _hovered, _aiming;
public Commander _commander;
public Vector2 _aimOffset;
public Marker2D _offset, _attackSpawn;
public Area2D _area;
public Commander _commander;
public override void _Ready()
{
base._Ready();
_area = GetNode<Area2D>("Area");
_offset = GetNode<Marker2D>("Offset");
_attackSpawn = GetNode<Marker2D>("AttackSpawn");
}
public override void _Process(double delta)
{
base._Process(delta);
if (_commander?._actions > 0)
{
if (_aiming)
{
if (Input.IsActionJustPressed("rightClick"))
{
_commander.UnloadAttack();
_aiming = false;
}
else if (Input.IsActionJustPressed("leftClick"))
{
_aimOffset = GetGlobalMousePosition() - GlobalPosition;
_commander.ShootCurrentAttack(_aimOffset);
_aiming = false;
}
}
if (Input.IsActionJustPressed("leftClick"))
{
if (_hovered)
{
_aiming = true;
_commander.LoadAttack();
}
}
if (_aiming)
{
if (Input.IsActionJustReleased("rightClick"))
{
Vector2 offset = (GlobalPosition - GetGlobalMousePosition()) * 500;
_commander.ShootCurrentAttack(offset);
_aiming = false;
}
else if (Input.IsActionJustReleased("leftClick"))
{
_commander.UnloadAttack();
_aiming = false;
_commander.LoadAttack(_attackSpawn.Position);
}
}
}
}
public List<Vector2> PredictPath()
{
Vector2 velocity = _aimOffset;
float timeBetweenSteps = 0.05f;
Vector2 startPosition = _attackSpawn.Position;
float gravity = -(float)ProjectSettings.GetSetting("physics/2d/default_gravity", 980.0f);
float drag = (float)ProjectSettings.GetSetting("physics/2d/default_linear_damp", 0.0f);
List<Vector2> points = [startPosition];
for (int i = 0; i < 151; i++)
{
velocity.Y += gravity * timeBetweenSteps;
// GD.Print(velocity);
velocity *= (float)Math.Clamp(1.0 - drag * timeBetweenSteps, 0, 1);
points.Add(points[^1] + velocity);
}
return points;
}
// public Dictionary<> Ra
public void OnMouseEntered(){
_hovered = true;
}