Skip to content

Commit

Permalink
#6: Introduce the first version of on screen indicator to notify play…
Browse files Browse the repository at this point in the history
…er about incoming agents
  • Loading branch information
Danil Ko committed Feb 8, 2021
1 parent 332468b commit bb772d3
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 13 deletions.
5 changes: 4 additions & 1 deletion agents/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,12 @@ public void Explode()
_gameWorld.GetNode("RemainEffectManager").AddChild(remainParticles);

AgentExplosionParticle agentExplosionParticle = (AgentExplosionParticle)GetNode("AgentExplosionParticle");
agentExplosionParticle.Connect(nameof(AgentExplosionParticle.EffectCompleteSignal), this, nameof(_OnExplosionAnimationFinished));
agentExplosionParticle.SetTrigger(true);

AnimatedSprite animatedSprite = (AnimatedSprite)GetNode("Explosion");
animatedSprite.Show();
animatedSprite.Play("fire");

AudioManager audioManager = (AudioManager)GetNode("/root/AUDIOMANAGER");
audioManager.playSoundEffect(explosionMusicClip);
}
Expand Down
12 changes: 8 additions & 4 deletions agents/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,22 @@ public void SetHUD(HUD hud)
Connect(nameof(Agent.HealthChangedSignal), _hud, nameof(HUD.UpdateHealth));
Connect(nameof(Agent.DefeatedAgentChangedSignal), _hud, nameof(HUD.UpdateDefeatedAgent));

ConnectWeapon( ((Weapon)RightWeapons[currentRightWeaponIndex]), Weapon.WeaponOrder.Right);
ConnectWeapon( ((Weapon)LeftWeapons[currentLeftWeaponIndex]), Weapon.WeaponOrder.Left);
ConnectWeapon(((Weapon)RightWeapons[currentRightWeaponIndex]), Weapon.WeaponOrder.Right);
ConnectWeapon(((Weapon)LeftWeapons[currentLeftWeaponIndex]), Weapon.WeaponOrder.Left);

// # notify about current weapon to HUD
EmitSignal(nameof(RightWeaponChangeSignal), ((Weapon)RightWeapons[currentRightWeaponIndex]).CurrentWeaponType);
// Emit signal to update info
((Weapon)RightWeapons[currentRightWeaponIndex]).EmitSignal(nameof(Weapon.AmmoChangeSignal), ((Weapon)RightWeapons[currentRightWeaponIndex]).getAmmo(), ((Weapon)RightWeapons[currentRightWeaponIndex]).getMaxAmmo());

EmitSignal(nameof(LeftWeaponChangeSignal), ((Weapon)LeftWeapons[currentLeftWeaponIndex]).CurrentWeaponType);
// Emit signal to update info
((Weapon)LeftWeapons[currentLeftWeaponIndex]).EmitSignal(nameof(Weapon.AmmoChangeSignal), ((Weapon)LeftWeapons[currentLeftWeaponIndex]).getAmmo(), ((Weapon)LeftWeapons[currentLeftWeaponIndex]).getMaxAmmo());


// Set up the player indicator screen
ScreenIndicator screenIndicator = (ScreenIndicator)((PackedScene)GD.Load("res://ui/ScreenIndicator.tscn")).Instance();
AddChild(screenIndicator);
screenIndicator.Initialize(this);
}

protected override void DisconnectWeapon(Weapon currentWeapon, Weapon.WeaponOrder weaponOrder)
Expand Down
6 changes: 6 additions & 0 deletions ai/AI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ public void Control(float delta)
_agent.LeftWeaponAction = (int)GameStates.PlayerInput.InputAction.TRIGGER;
}
}

// Chanse engaged agent closer if possible
if(_agent.GlobalPosition.DistanceTo(_targetAgent.GlobalPosition) > 200.0f)
{
_agent.MoveToward(_agent.GlobalPosition.DirectionTo(_targetAgent.GlobalPosition), delta);
}
}
break;

Expand Down
5 changes: 4 additions & 1 deletion ai/TeamMapAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ private void _assignNextCapturableBaseToUnits(CapturableBase capturableBase)
{
AI agentAI = ((AIAgent)node).GetAI();
agentAI.SetNextBase(capturableBase);
agentAI.SetState(AI.State.ADVANCE);
if (agentAI.getState() != AI.State.ENGAGE)
{
agentAI.SetState(AI.State.ADVANCE);
}
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions effects/Explosion.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=2]
[gd_scene load_steps=13 format=2]

[ext_resource path="res://assets/explosion_6.png" type="Texture" id=1]
[ext_resource path="res://assets/explosion_3.png" type="Texture" id=2]
Expand All @@ -11,7 +11,10 @@
[ext_resource path="res://assets/explosion_1.png" type="Texture" id=9]
[ext_resource path="res://assets/explosion_10.png" type="Texture" id=10]

[sub_resource type="SpriteFrames" id=1]
[sub_resource type="CanvasItemMaterial" id=1]
blend_mode = 1

[sub_resource type="SpriteFrames" id=2]
animations = [ {
"frames": [ ExtResource( 8 ), ExtResource( 5 ), ExtResource( 3 ), ExtResource( 6 ), ExtResource( 4 ) ],
"loop": true,
Expand All @@ -25,5 +28,6 @@ animations = [ {
} ]

[node name="Explosion" type="AnimatedSprite"]
frames = SubResource( 1 )
material = SubResource( 1 )
frames = SubResource( 2 )
animation = "fire"
2 changes: 1 addition & 1 deletion environments/Obstacle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void explode()

AnimatedSprite animatedSprite = (AnimatedSprite)GetNode("Explosion");
animatedSprite.Show();
animatedSprite.Play("smoke");
animatedSprite.Play("fire");

RemainParticles remainParticles = (RemainParticles)((PackedScene)GD.Load("res://effects/RemainParticles.tscn")).Instance();
remainParticles.GlobalPosition = this.GlobalPosition;
Expand Down
1 change: 1 addition & 0 deletions godot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ui\MiniMap.cs" />
<Compile Include="ui\PopUpMessage.cs" />
<Compile Include="ui\ScreenIndicator.cs" />
<Compile Include="weapons\Shield.cs" />
<Compile Include="singletons\audios\AudioManager.cs" />
<Compile Include="agents\AIAgent.cs" />
Expand Down
31 changes: 28 additions & 3 deletions ui/HUD.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=13 format=2]
[gd_scene load_steps=14 format=2]

[ext_resource path="res://ui/HUD.cs" type="Script" id=1]
[ext_resource path="res://assets/ui/green_button00.png" type="Texture" id=2]
Expand All @@ -9,6 +9,7 @@
[ext_resource path="res://assets/fonts/Kenney Rocket Square.ttf" type="DynamicFontData" id=7]
[ext_resource path="res://ui/MiniMap.tscn" type="PackedScene" id=8]
[ext_resource path="res://ui/PopUpMessage.tscn" type="PackedScene" id=9]
[ext_resource path="res://assets/ui/grey_panel.png" type="Texture" id=10]

[sub_resource type="DynamicFont" id=1]
size = 20
Expand Down Expand Up @@ -221,6 +222,18 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="Background" type="TextureRect" parent="controlGame/LeftWeaponControl"]
self_modulate = Color( 0.254902, 0.254902, 0.254902, 0.254902 )
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 44.0
texture = ExtResource( 10 )
expand = true
stretch_mode = 1
__meta__ = {
"_edit_use_anchors_": false
}

[node name="lblWeaponLabel" type="Label" parent="controlGame/LeftWeaponControl"]
margin_left = 150.597
margin_top = 3.43382
Expand Down Expand Up @@ -293,6 +306,18 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="Background" type="TextureRect" parent="controlGame/RightWeaponControl"]
self_modulate = Color( 0.254902, 0.254902, 0.254902, 0.254902 )
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 44.0
texture = ExtResource( 10 )
expand = true
stretch_mode = 1
__meta__ = {
"_edit_use_anchors_": false
}

[node name="lblWeaponLabel" type="Label" parent="controlGame/RightWeaponControl"]
margin_left = 150.597
margin_top = 3.43382
Expand Down Expand Up @@ -357,9 +382,9 @@ __meta__ = {
}

[node name="MiniMap" parent="controlGame" instance=ExtResource( 8 )]
margin_left = 729.324
margin_left = 744.189
margin_top = 96.4272
margin_right = 984.325
margin_right = 999.19
margin_bottom = 351.427

[node name="controlOverallMessage" type="Control" parent="."]
Expand Down
121 changes: 121 additions & 0 deletions ui/ScreenIndicator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using Godot;
using System;

public class ScreenIndicator : Node2D
{

private float _zoom = 1.5f;

private Agent _player;
private Godot.Collections.Dictionary<String, Agent> _agents;

private Godot.Collections.Dictionary<String, Node2D> _agentMarkers;

private Node2D _agentMarker;

private Godot.Collections.Dictionary<String, Team.TeamCode> _targetAgents;
private Agent _targetAgent = null;
private Agent _agent = null;

public override void _Ready()
{
_agentMarker = (Node2D)GetNode("AgentMarker");
}

public void Initialize(Agent agent)
{
_agent = agent;
_agents = new Godot.Collections.Dictionary<String, Agent>();
_agentMarkers = new Godot.Collections.Dictionary<String, Node2D>();
_targetAgents = new Godot.Collections.Dictionary<String, Team.TeamCode>();
}

public void SetPlayer(Agent agent)
{
_player = agent;
}

public void RemovePlayer()
{
_player = null;
}

public void AddAgent(Agent agent)
{
if (!_agents.ContainsKey(agent.GetUnitName()))
{
Node2D agentMarker = (Node2D)_agentMarker.Duplicate();
agentMarker.Name = agent.GetUnitName() + "_marker";

agentMarker.Modulate = Team.TeamColor[(int)agent.GetCurrentTeam()];

AddChild(agentMarker);

agentMarker.Show();

// Add agent to dictonary
_agents.Add(agent.GetUnitName(), agent);

// Add marker to dictionary
_agentMarkers.Add(agent.GetUnitName(), agentMarker);
}
}

public void RemoveAgent(Agent agent)
{
if (_agents.ContainsKey(agent.GetUnitName()))
{
// Add agent to dictonary
_agents.Remove(agent.GetUnitName());

Node2D agentMarker = _agentMarkers[agent.GetUnitName()];

// Add marker to dictionary
_agentMarkers.Remove(agent.GetUnitName());

agentMarker.QueueFree();
}
}

public override void _Process(float delta)
{
if(_agent == null || ! IsInstanceValid(_agent))
{
return;
}

foreach (Agent agent in _agents.Values)
{
if (agent != null && IsInstanceValid(agent))
{
Node2D agentMarker = _agentMarkers[agent.GetUnitName()];
agentMarker.GlobalRotation = agent.GlobalRotation + Mathf.Pi / 2.0f;

// Update marker
agentMarker.LookAt(agent.GlobalPosition);
float distance = agentMarker.GlobalPosition.DistanceTo(agent.GlobalPosition);
((Label)agentMarker.GetNode("Text")).Text = agent.GetUnitName() + " " + distance;
}
}
}


private void _onDetectionZoneBodyEntered(Node body)
{

if (body.HasMethod(nameof(Agent.GetCurrentTeam)) && body != _agent)
{
AddAgent((Agent)body);
}
}

private void _onDetectionZoneBodyExited(Node body)
{
if (body.HasMethod(nameof(Agent.GetCurrentTeam)) && body != _agent)
{
RemoveAgent((Agent)body);
}
}


}
41 changes: 41 additions & 0 deletions ui/ScreenIndicator.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://assets/ui/grey_sliderUp.png" type="Texture" id=1]
[ext_resource path="res://ui/ScreenIndicator.cs" type="Script" id=2]

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

[node name="ScreenIndicator" type="Node2D"]
script = ExtResource( 2 )

[node name="AgentMarker" type="Node2D" parent="."]
visible = false

[node name="Indicator" type="TextureRect" parent="AgentMarker"]
margin_left = 300.0
margin_right = 340.0
margin_bottom = 42.0
rect_rotation = 90.0
rect_pivot_offset = Vector2( 10, 0 )
texture = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Text" type="Label" parent="AgentMarker"]
margin_left = 522.0
margin_top = -4.0
margin_right = 861.0
margin_bottom = 10.0
text = "500"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="DetectionZone" type="Area2D" parent="."]

[node name="CollisionShape2D" type="CollisionShape2D" parent="DetectionZone"]
shape = SubResource( 1 )
[connection signal="body_entered" from="DetectionZone" to="." method="_onDetectionZoneBodyEntered"]
[connection signal="body_exited" from="DetectionZone" to="." method="_onDetectionZoneBodyExited"]

0 comments on commit bb772d3

Please sign in to comment.