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

Commit 8fdee2a

Browse files
committed
Merge branch '51-make-player-damaging-if-a-bullet-hits-him' into 'master'
Resolve "Make player damaging if a bullet hits him" Closes #51 See merge request seprojekt/game!37
2 parents dbe4fe6 + f4017f2 commit 8fdee2a

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

godot/src/scripts/Bullet.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override void _Ready()
2727
/// </summary>
2828
/// <param name="body"> The node, wich collides </param>
2929
/// <returns> If the bullet collides with a player, the name of that player else an empty string</returns>
30-
private string onCollision(Node body)
30+
private Player onCollision(Node body)
3131
{
3232
//creates the collision animation;
3333
collisionAnimation();
@@ -36,12 +36,14 @@ private string onCollision(Node body)
3636
GetParent().RemoveChild(this);
3737

3838
//Return the players name, if the bullet collide with a player.
39-
if (false)
39+
if (body is Player)
4040
{
41-
41+
Player player = (Player)body;
42+
player.Health -= Damage;
43+
return player;
4244
}
4345

44-
return "";
46+
return null;
4547
}
4648

4749

godot/src/scripts/Player.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,21 @@ public double Health
4242
get => health;
4343
set
4444
{
45-
if ((value >= 0 && value <= 100) || value == double.PositiveInfinity)
45+
if(value < 0)
46+
{
47+
health = 0;
48+
}
49+
else if(value > 100)
50+
{
51+
health = 100;
52+
}
53+
else
4654
{
4755
health = value;
48-
//sends an signal about
49-
EmitSignal(nameof(HealthChangeSignal), Health);
5056
}
57+
58+
//sends an signal about
59+
EmitSignal(nameof(HealthChangeSignal), Health);
5160
}
5261
}
5362

0 commit comments

Comments
 (0)