Skip to content

Commit

Permalink
#11: Continue to improve the raycast logic for damage to target + col…
Browse files Browse the repository at this point in the history
…lision shape for bullet to bullet dmanage. Also Update better bullet logic/speed/collision shape and adjustment to other weapon.
  • Loading branch information
Danil Ko committed Jun 23, 2021
1 parent 6ed20dc commit 2359123
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 51 deletions.
18 changes: 9 additions & 9 deletions agents/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public bool EquipWeapon(PackedScene weaponScene, Weapon.WeaponOrder weaponOrder,
return false;
}

Position2D weaponHolder = GetWeaponsHolder(weaponOrder);
Node2D weaponHolder = GetWeaponsHolder(weaponOrder);
Weapon weapon = (Weapon)(weaponScene.Instance());
weaponHolder.AddChild(weapon);
weapon.Initialize(_gameWorld, this, weaponOrder);
Expand Down Expand Up @@ -256,14 +256,9 @@ public Godot.Collections.Array<Weapon> GetWeapons(Weapon.WeaponOrder weaponOrder
}
}

public Position2D GetWeaponsHolder(Weapon.WeaponOrder weaponOrder)
public Node2D GetWeaponsHolder(Weapon.WeaponOrder weaponOrder)
{
return ((Position2D)GetNode(weaponOrder + "WeaponHolder"));
}

public Position2D GetCentralWeaponsHolder()
{
return ((Position2D)GetNode("CentralWeaponHolder"));
return ((Node2D)GetNode(weaponOrder + "WeaponHolder"));
}

/**
Expand All @@ -277,7 +272,7 @@ public void UnequipWeapon(Weapon.WeaponOrder weaponOrder, int index)

if (weapon != null)
{
Position2D weaponHolder = GetWeaponsHolder(weaponOrder);
Node2D weaponHolder = GetWeaponsHolder(weaponOrder);
weaponHolder.RemoveChild(weapon);
// Null the weapon
weapons[index] = null;
Expand Down Expand Up @@ -393,6 +388,11 @@ public void Sync(Vector2 position, float rotation, int rightWeapon, int leftWeap
public void RotateToward(Vector2 location, float delta)
{
GlobalRotation = Mathf.LerpAngle(GlobalRotation, GlobalPosition.DirectionTo(location).Angle(), RotationSpeed * delta);
Node2D weaponHolder = GetWeaponsHolder(Weapon.WeaponOrder.Right);
weaponHolder.GlobalRotation = Mathf.LerpAngle(weaponHolder.GlobalRotation, weaponHolder.GlobalPosition.DirectionTo(location).Angle(), RotationSpeed * delta);

weaponHolder = GetWeaponsHolder(Weapon.WeaponOrder.Left);
weaponHolder.GlobalRotation = Mathf.LerpAngle(weaponHolder.GlobalRotation, weaponHolder.GlobalPosition.DirectionTo(location).Angle(), RotationSpeed * delta);
}

public void Fire(Weapon.WeaponOrder weaponOrder, int weaponAction)
Expand Down
8 changes: 3 additions & 5 deletions agents/Agent.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,10 @@ rotation = 3.14159

[node name="UnitDisplay" parent="." instance=ExtResource( 5 )]

[node name="LeftWeaponHolder" type="Position2D" parent="."]
[node name="LeftWeaponHolder" type="Node2D" parent="."]
position = Vector2( 47, -32 )

[node name="CentralWeaponHolder" type="Position2D" parent="."]
position = Vector2( 50, 0 )

[node name="RightWeaponHolder" type="Position2D" parent="."]
[node name="RightWeaponHolder" type="Node2D" parent="."]
position = Vector2( 47, 32 )

[node name="Team" parent="." instance=ExtResource( 4 )]
Expand All @@ -162,6 +159,7 @@ shape = SubResource( 3 )
[node name="DamageEffectTimer" type="Timer" parent="."]
wait_time = 0.1
one_shot = true

[connection signal="HealthChangedSignal" from="." to="UnitDisplay" method="UpdateUnitBar"]
[connection signal="animation_finished" from="Explosion" to="." method="_OnExplosionAnimationFinished"]
[connection signal="timeout" from="DamageEffectTimer" to="." method="DamageEffectTimerTimeout"]
12 changes: 11 additions & 1 deletion ai/PathFinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ public class PathFinding : Node2D
[Export]
private int UpdateTRaversableTilesTime = 10;

// Debug flag
private bool debug = false;

public override void _Ready()
{
_aStar = new AStar2D();
_grid = (Node2D)GetNode("Grid");

if(!debug)
{
_grid.Visible = false;
}

_tilestoWorld = new Godot.Collections.Dictionary();
_gridRects = new Godot.Collections.Dictionary<int, ColorRect>();

Expand Down Expand Up @@ -224,11 +232,13 @@ private void _connectTraversableTiles(Godot.Collections.Array tiles)
if (!_aStar.ArePointsConnected(fromId, toId))
{
// Debug code
if(debug)
{
Line2D line2d = new Line2D();
Vector2[] points = { (Vector2)_tilestoWorld[fromId], (Vector2)_tilestoWorld[toId] };
line2d.Points = points;
_tileMap.AddChild(line2d);

}
_aStar.ConnectPoints(fromId, toId, true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion godot.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/3.2.3">
<Project Sdk="Godot.NET.Sdk/3.3.0">
<PropertyGroup>
<ProjectGuid>{AB169F36-8DEB-4605-A910-012F363E8DD7}</ProjectGuid>
<OutputType>Library</OutputType>
Expand Down
79 changes: 79 additions & 0 deletions godot.csproj.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<Project Sdk="Godot.NET.Sdk/3.2.3">
<PropertyGroup>
<ProjectGuid>{AB169F36-8DEB-4605-A910-012F363E8DD7}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>godot</RootNamespace>
<AssemblyName>godot</AssemblyName>
<GodotProjectGeneratorVersion>1.0.7374.17554</GodotProjectGeneratorVersion>
<TargetFramework>net472</TargetFramework>
<!--The following properties were overriden during migration to prevent errors.
Enabling them may require other manual changes to the project and its files.-->
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Deterministic>false</Deterministic>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="agents\GameCamera.cs" />
<Compile Include="ai\PathFinding.cs" />
<Compile Include="ai\AI.cs" />
<Compile Include="ai\TeamMapAI.cs" />
<Compile Include="ai\TeamMapAISetting.cs" />
<Compile Include="effects\AgentExplosionParticle.cs" />
<Compile Include="effects\RemainParticles.cs" />
<Compile Include="effects\Trail.cs" />
<Compile Include="environments\CapaturableBaseManager.cs" />
<Compile Include="environments\CapturableBase.cs" />
<Compile Include="environments\ObstacleManager.cs" />
<Compile Include="inventory\Inventory.cs" />
<Compile Include="inventory\InventoryManager.cs" />
<Compile Include="items\ItemResource.cs" />
<Compile Include="map\SimulateGameWorld.cs" />
<Compile Include="PostProcess\PostProcess.cs" />
<Compile Include="PostProcess\TestScene.cs" />
<Compile Include="projectiles\ExplosionRay.cs" />
<Compile Include="projectiles\Projectile.cs" />
<Compile Include="projectiles\LaserRay.cs" />
<Compile Include="projectiles\Missle.cs" />
<Compile Include="projectiles\ProjectileArea2D.cs" />
<Compile Include="projectiles\RifileBullet.cs" />
<Compile Include="environments\Obstacle.cs" />
<Compile Include="GameStates.cs" />
<Compile Include="items\Pickup.cs" />
<Compile Include="map\GameWorld.cs" />
<Compile Include="network\Network.cs" />
<Compile Include="network\NetworkPlayer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="inventory\InventoryDatabase.cs" />
<Compile Include="ui\InventoryUI.cs" />
<Compile Include="ui\ItemPanel.cs" />
<Compile Include="ui\MiniMap.cs" />
<Compile Include="ui\PopUpMessage.cs" />
<Compile Include="ui\ScreenIndicator.cs" />
<Compile Include="ui\TeamSettingPanel.cs" />
<Compile Include="ui\WeaponSlotPanel.cs" />
<Compile Include="weapons\Shield.cs" />
<Compile Include="singletons\audios\AudioManager.cs" />
<Compile Include="agents\AIAgent.cs" />
<Compile Include="agents\Observer.cs" />
<Compile Include="agents\Player.cs" />
<Compile Include="agents\Agent.cs" />
<Compile Include="Team.cs" />
<Compile Include="terrain\TileSetMaker.cs" />
<Compile Include="ui\EndGameScreen.cs" />
<Compile Include="ui\HealthBar.cs" />
<Compile Include="ui\HUD.cs" />
<Compile Include="ui\TitleScreen.cs" />
<Compile Include="ui\UIPlayerListEntry.cs" />
<Compile Include="ui\UnitDisplay.cs" />
<Compile Include="weapons\LaserGun.cs" />
<Compile Include="weapons\LightSaber.cs" />
<Compile Include="weapons\MissleLauncher.cs" />
<Compile Include="weapons\Rifile.cs" />
<Compile Include="weapons\ShieldPhysics.cs" />
<Compile Include="weapons\Weapon.cs" />
</ItemGroup>
<ItemGroup />
</Project>
22 changes: 5 additions & 17 deletions map/GameWorld.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=14 format=2]
[gd_scene load_steps=12 format=2]

[ext_resource path="res://terrain/terrain_tiles.tres" type="TileSet" id=1]
[ext_resource path="res://assets/ui/red_tick.png" type="Texture" id=2]
Expand All @@ -11,24 +11,14 @@
[ext_resource path="res://inventory/InventoryManager.tscn" type="PackedScene" id=10]
[ext_resource path="res://PostProcess/PostProcess.tscn" type="PackedScene" id=11]

[sub_resource type="Gradient" id=1]
offsets = PoolRealArray( 0, 0.699531, 1 )
colors = PoolColorArray( 0.217608, 0.184296, 0.257812, 1, 0.472656, 0.386399, 0.352646, 1, 1, 1, 1, 1 )

[sub_resource type="GradientTexture" id=2]
gradient = SubResource( 1 )

[sub_resource type="Environment" id=3]
[sub_resource type="Environment" id=1]
background_mode = 4
glow_enabled = true
glow_levels/1 = true
glow_levels/2 = true
glow_levels/4 = true
glow_intensity = 1.5
glow_bloom = 0.1
glow_intensity = 1.0
glow_blend_mode = 1
glow_hdr_threshold = 0.9
adjustment_color_correction = SubResource( 2 )

[node name="Map" type="Node2D"]
script = ExtResource( 3 )
Expand Down Expand Up @@ -91,9 +81,7 @@ zoom = Vector2( 4, 4 )

[node name="InventoryManager" parent="." instance=ExtResource( 10 )]

[node name="CanvasModulate" type="CanvasModulate" parent="."]
color = Color( 0.623529, 0.623529, 0.698039, 1 )

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 3 )
environment = SubResource( 1 )

[connection signal="timeout" from="Timer" to="." method="_onNetworkRateTimerUpdate"]
7 changes: 4 additions & 3 deletions map/SimulateGameWorld.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ position = Vector2( 11.1118, 10.3181 )

[node name="Pickups" type="Node2D" parent="."]

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 1 )

[node name="dot" type="Sprite" parent="."]
texture = ExtResource( 2 )

Expand Down Expand Up @@ -77,4 +74,8 @@ autostart = true
zoom = Vector2( 4, 4 )

[node name="InventoryManager" parent="." instance=ExtResource( 5 )]

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 1 )

[connection signal="timeout" from="ChangeAgentBehavior" to="." method="_changeAgentBehavior"]
4 changes: 2 additions & 2 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ config_version=4

_global_script_classes=[ ]
_global_script_class_icons={

}

[application]
Expand Down Expand Up @@ -105,7 +104,8 @@ inventory={

[rendering]

quality/2d/use_pixel_snap=true
2d/snapping/use_gpu_pixel_snap=true
vram_compression/import_etc=true
vram_compression/import_etc2=false
environment/default_environment="res://default_env.tres"
quality/2d/use_pixel_snap=true
3 changes: 3 additions & 0 deletions projectiles/RifileBullet.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ texture = ExtResource( 2 )
region_enabled = true
region_rect = Rect2( 653, 41, 30, 24 )

[node name="Explosion" parent="." index="2"]
scale = Vector2( 0.3, 0.3 )

[node name="ProjectileArea2D" parent="." index="3"]
visible = false
collision_layer = 4
Expand Down
1 change: 1 addition & 0 deletions ui/TitleScreen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ margin_left = 25.0
margin_top = 25.0
margin_right = 393.0
margin_bottom = 104.0

[connection signal="pressed" from="CanvasLayer/btnCreateServer" to="." method="_onbtnCreateServerPanel"]
[connection signal="pressed" from="CanvasLayer/btnJoinServer" to="." method="_onbtnJoinServerPanel"]
[connection signal="pressed" from="CanvasLayer/btnExit" to="." method="_onbtnExit"]
Expand Down
14 changes: 12 additions & 2 deletions weapons/LightSaber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@ public class LightSaber : Weapon
[Export]
int Damage = 50;

private AnimationPlayer animationPlayer;

public override void Initialize(GameWorld gameWorld, Agent agent, WeaponOrder weaponOrder)
{
base.Initialize(gameWorld, agent, weaponOrder);
animationPlayer = (AnimationPlayer)GetNode("AnimationPlayer");

// Rotated weapon
animationPlayer.Play("Attack_" + GetWeaponOrder());
}


public override bool Fire(Agent targetAgent)
{
if (Cooldown)
{
Cooldown = false;
AnimationPlayer animationPlayer = (AnimationPlayer)GetNode("AnimationPlayer");
animationPlayer.Play("Attack");
animationPlayer.Play("Attack_" + GetWeaponOrder());
}

return false;
Expand Down

0 comments on commit 2359123

Please sign in to comment.