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

Commit

Permalink
Merge branch '51-make-player-damaging-if-a-bullet-hits-him' into 'mas…
Browse files Browse the repository at this point in the history
…ter'

Resolve "Make player damaging if a bullet hits him"

Closes #51

See merge request seprojekt/game!37
  • Loading branch information
mariusschaab committed Jun 24, 2019
2 parents dbe4fe6 + f4017f2 commit 8fdee2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
10 changes: 6 additions & 4 deletions godot/src/scripts/Bullet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override void _Ready()
/// </summary>
/// <param name="body"> The node, wich collides </param>
/// <returns> If the bullet collides with a player, the name of that player else an empty string</returns>
private string onCollision(Node body)
private Player onCollision(Node body)
{
//creates the collision animation;
collisionAnimation();
Expand All @@ -36,12 +36,14 @@ private string onCollision(Node body)
GetParent().RemoveChild(this);

//Return the players name, if the bullet collide with a player.
if (false)
if (body is Player)
{

Player player = (Player)body;
player.Health -= Damage;
return player;
}

return "";
return null;
}


Expand Down
15 changes: 12 additions & 3 deletions godot/src/scripts/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,21 @@ public double Health
get => health;
set
{
if ((value >= 0 && value <= 100) || value == double.PositiveInfinity)
if(value < 0)
{
health = 0;
}
else if(value > 100)
{
health = 100;
}
else
{
health = value;
//sends an signal about
EmitSignal(nameof(HealthChangeSignal), Health);
}

//sends an signal about
EmitSignal(nameof(HealthChangeSignal), Health);
}
}

Expand Down

0 comments on commit 8fdee2a

Please sign in to comment.