Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
🩹 UPDATE 2: Major bug fixes & crash resolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
LennyPhoenix committed Dec 5, 2020
1 parent b88fefb commit 882ee0a
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 145 deletions.
5 changes: 5 additions & 0 deletions Source/Buildings/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ public void _OnDeconstructAnimationFinished(string animName)
{
if (deconstructBuilding == Globals.HoveringBuilding)
{
foreach (Item item in deconstructBuilding.Refunds.Keys)
{
Globals.Core.Items[item] += deconstructBuilding.Refunds[item];
Globals.Core.Items[item] = Mathf.Min(Globals.Core.Items[item], Globals.Core.MaxStorage[item]);
}
deconstructBuilding.Destroy();
deconstructBuilding = null;
DeconstructAnimationPlayer.Play("Deleted");
Expand Down
1 change: 1 addition & 0 deletions Source/Buildings/Building.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Building : StaticBody2D

[Export] public Dictionary<Item, int> MaxStorage = new Dictionary<Item, int>();
[Export] public Dictionary<Item, int> Outputs = new Dictionary<Item, int>();
[Export] public Dictionary<Item, int> Refunds = new Dictionary<Item, int>();

[Export] public int MaxInput = 4;
[Export] public int MaxOutput = 4;
Expand Down
13 changes: 8 additions & 5 deletions Source/Buildings/Drills/SmallDrill.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,30 @@ Outputs = {
1: 1,
7: 1
}
Refunds = {
0: 50
}
MiningAmount = 0.03

[node name="HealthManager" parent="." index="2"]
[node name="HealthManager" parent="." index="5"]
MaxHealth = 150.0
Collider = SubResource( 1 )

[node name="Sprite" parent="." index="4"]
[node name="Sprite" parent="." index="7"]
texture = ExtResource( 2 )
hframes = 11

[node name="AnimationPlayer" parent="Sprite" index="0"]
autoplay = "Default"
anims/Default = SubResource( 2 )

[node name="CollisionShape2D" parent="." index="5"]
[node name="CollisionShape2D" parent="." index="8"]
shape = SubResource( 3 )

[node name="LightOccluder2D" parent="." index="6"]
[node name="LightOccluder2D" parent="." index="9"]
occluder = SubResource( 4 )

[node name="Warning" parent="." index="7"]
[node name="Warning" parent="." index="10"]
scale = Vector2( 3, 3 )

[node name="InputConnection" parent="Highlights" index="0"]
Expand Down
26 changes: 13 additions & 13 deletions Source/Buildings/Turrets/Minigun.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
[ext_resource path="res://Source/Projectiles/ProjectileEmitter.tscn" type="PackedScene" id=4]
[ext_resource path="res://Assets/Buildings/Turrets/Minigun.png" type="Texture" id=5]

[sub_resource type="CircleShape2D" id=1]
radius = 192.0

[sub_resource type="RectangleShape2D" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 25, 25 )

[sub_resource type="CircleShape2D" id=2]
radius = 192.0

[sub_resource type="Animation" id=3]
length = 0.15
step = 0.013
Expand Down Expand Up @@ -52,17 +52,17 @@ RotationSpeed = 5.0
ProjectileEmitters = [ NodePath("Rotate/Top/TopEmitter"), NodePath("Rotate/Top/MiddleEmitter"), NodePath("Rotate/Top/BottomEmitter") ]

[node name="ShootTimer" parent="." index="0"]
wait_time = 0.05
wait_time = 0.075

[node name="HealthManager" parent="." index="6"]
MaxHealth = 300.0
Collider = SubResource( 1 )

[node name="CircleRenderer" parent="TargetArea" index="0"]
Radius = 192.0

[node name="CollisionShape2D" parent="TargetArea" index="1"]
shape = SubResource( 1 )

[node name="HealthManager" parent="." index="7"]
MaxHealth = 300.0
Collider = SubResource( 2 )
shape = SubResource( 2 )

[node name="Sprite" parent="." index="9"]
texture = ExtResource( 5 )
Expand All @@ -78,24 +78,24 @@ anims/Shoot = SubResource( 3 )

[node name="TopEmitter" parent="Rotate/Top" index="1" instance=ExtResource( 4 )]
position = Vector2( 18, -3 )
Projectile = ExtResource( 2 )
AccuracySteps = 10
AccuracyAngle = 6
VelocityModifier = 150
Projectile = ExtResource( 2 )

[node name="MiddleEmitter" parent="Rotate/Top" index="2" instance=ExtResource( 4 )]
position = Vector2( 18, 0 )
Projectile = ExtResource( 2 )
AccuracySteps = 10
AccuracyAngle = 6
VelocityModifier = 150
Projectile = ExtResource( 2 )

[node name="BottomEmitter" parent="Rotate/Top" index="3" instance=ExtResource( 4 )]
position = Vector2( 18, 3 )
Projectile = ExtResource( 2 )
AccuracySteps = 10
AccuracyAngle = 6
VelocityModifier = 150
Projectile = ExtResource( 2 )

[node name="CollisionShape2D" parent="." index="11"]
shape = SubResource( 4 )
Expand Down
2 changes: 1 addition & 1 deletion Source/Entities/Enemies/Enemy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public async void RecalculatePath()

if (!IsInstanceValid(closest))
{
RecalculatePath();
CallDeferred("RecalculatePath");
return;
}

Expand Down
2 changes: 2 additions & 0 deletions Source/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class Globals
public static Building LastBuilding;

public static Core Core;
public static Minimap Minimap;

public static Dictionary<Ore, Item> OreToItem = new Dictionary<Ore, Item>()
{
Expand All @@ -69,5 +70,6 @@ public static void Reset()
LastBuilding = null;

Core = null;
Minimap = null;
}
}
65 changes: 11 additions & 54 deletions Source/NavigationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class NavigationManager : Navigation2D
{
public Node2D LastAgent;
public Vector2 LastTarget;
public Godot.Collections.Array<Vector2> LastPath;
public Vector2[] LastPath;

private Dictionary<Node2D, NavQueueItem> navQueue = new Dictionary<Node2D, NavQueueItem>();

Expand All @@ -24,9 +24,7 @@ public override void _Ready()
{
base._Ready();

#if !(GODOT_WEB || GODOT_HTML5)
pathThread = new Thread();
#endif

Start();
}
Expand Down Expand Up @@ -57,14 +55,10 @@ public void RemoveAgent(Node2D agent)

public void Start()
{
#if GODOT_WEB || GODOT_HTML5
CalculatePathsAsync();
#else
if (!pathThread.IsActive())
{
pathThread.Start(this, "CalculatePathsThreaded");
pathThread.Start(this, "CalculatePaths");
}
#endif
run = true;
}

Expand All @@ -73,7 +67,7 @@ public void Stop()
run = false;
}

public async void CalculatePathsAsync()
public void CalculatePaths(object userData)
{
while (run)
{
Expand All @@ -82,65 +76,28 @@ public async void CalculatePathsAsync()
Node2D nextAgent = navQueue.Keys.First();
NavQueueItem queueItem = navQueue[nextAgent];

Godot.Collections.Array<Vector2> newPath;
Vector2[] points;
if (LastAgent != null && IsInstanceValid(LastAgent) && LastTarget.Round() == queueItem.Target.Round() && LastAgent.GlobalPosition.DistanceTo(nextAgent.GlobalPosition) < 256)
{
newPath = LastPath;
points = LastPath;
}
else
{
Vector2[] points = GetSimplePath(nextAgent.GlobalPosition, queueItem.Target);

newPath = new Godot.Collections.Array<Vector2>();
foreach (Vector2 point in points)
{
newPath.Add(point);
}
GD.Print("Calculating.");
points = GetSimplePath(nextAgent.GlobalPosition, queueItem.Target);
}

navQueue.Remove(nextAgent);

LastAgent = nextAgent;
LastTarget = queueItem.Target;
LastPath = newPath;

queueItem.Callback(newPath);
}
await ToSignal(GetTree().CreateTimer(0.05f), "timeout");
}
}

public void CalculatePathsThreaded(object userData)
{
while (run)
{
if (navQueue.Count > 0)
{
Node2D nextAgent = navQueue.Keys.First();
NavQueueItem queueItem = navQueue[nextAgent];

Godot.Collections.Array<Vector2> newPath;
if (LastAgent != null && IsInstanceValid(LastAgent) && LastTarget.Round() == queueItem.Target.Round() && LastAgent.GlobalPosition.DistanceTo(nextAgent.GlobalPosition) < 256)
{
newPath = LastPath;
}
else
var newPath = new Godot.Collections.Array<Vector2>();
foreach (Vector2 point in points)
{
GD.Print("Calculating.");
Vector2[] points = GetSimplePath(nextAgent.GlobalPosition, queueItem.Target);

newPath = new Godot.Collections.Array<Vector2>();
foreach (Vector2 point in points)
{
newPath.Add(point);
}
newPath.Add(point);
}

navQueue.Remove(nextAgent);

LastAgent = nextAgent;
LastTarget = queueItem.Target;
LastPath = newPath;
LastPath = points;

queueItem.Callback(newPath);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Projectiles/CopperBullet.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ height = 2.0
collision_mask = 5
Velocity = Vector2( 1200, 0 )
Lifetime = 0.5
Damage = 1.5
Damage = 3.0

[node name="CollisionShape2D" parent="." index="2"]
rotation = -1.5708
Expand Down
1 change: 1 addition & 0 deletions Source/Projectiles/PlayerBullet.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ height = 3.99999

[node name="PlayerBullet" instance=ExtResource( 1 )]
collision_mask = 5
Damage = 8.0

[node name="CollisionShape2D" parent="." index="2"]
rotation = -1.5708
Expand Down
Loading

0 comments on commit 882ee0a

Please sign in to comment.