Skip to content

Commit

Permalink
enemy health
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikue committed Oct 25, 2021
1 parent 0bb18e1 commit 37f97ed
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 9 deletions.
29 changes: 26 additions & 3 deletions Assets/Prefabs/skeleton.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GameObject:
- component: {fileID: 6311582435455102422}
- component: {fileID: 1224655538279616733}
- component: {fileID: 4365934258713016456}
- component: {fileID: 6968240672213199400}
m_Layer: 0
m_Name: skeleton
m_TagString: Damage
Expand Down Expand Up @@ -127,10 +128,10 @@ Rigidbody2D:
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 0
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_SleepingMode: 0
m_CollisionDetection: 0
m_Constraints: 4
--- !u!114 &4365934258713016456
Expand All @@ -145,4 +146,26 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a112af16eeb6ce34f855be195b900870, type: 3}
m_Name:
m_EditorClassIdentifier:
hits: 1
hits: 2
--- !u!68 &6968240672213199400
EdgeCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6311582435455102426}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_EdgeRadius: 0
m_Points:
- {x: -0.25, y: -0.5}
- {x: 0.25, y: -0.5}
m_AdjacentStartPoint: {x: 0, y: 0}
m_AdjacentEndPoint: {x: 0, y: 0}
m_UseAdjacentStartPoint: 0
m_UseAdjacentEndPoint: 0
40 changes: 36 additions & 4 deletions Assets/Scripts/Enemy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

public class Enemy : MonoBehaviour
{
private const float hurtInvincibleTime = 0.2f;

private bool hurtInvincible = false;
private float hurtInvincibleTimer;
private int health;

public int hits;

private void Start()
{

health = hits;
}

private void OnTriggerEnter2D(Collider2D collision)
Expand All @@ -18,11 +24,37 @@ private void OnTriggerEnter2D(Collider2D collision)
Attack attack = collider.GetComponent<Attack>();
if (attack != null)
{
/*if (!hurtInvincible)
if (!hurtInvincible)
{
Damage();
}*/
Destroy(gameObject); //TODO
}
}
}

private void FixedUpdate()
{
if (hurtInvincible)
{
hurtInvincibleTimer += Time.fixedDeltaTime;
if (hurtInvincibleTimer >= hurtInvincibleTime)
{
hurtInvincible = false;
}
}
}

private void Damage()
{
//TODO effects
health--;
if (health <= 0)
{
Destroy(gameObject);
}
else
{
hurtInvincible = true;
hurtInvincibleTimer = 0;
}
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Castle of Cth??????

- Character
- Attack
- attacking spikes shouldn't hurt player
- attacking damage sources shouldn't hurt player
- power & knockback depends on sacrifices
- Health
- Player has 3 hearts, lose one for contacting enemy/spikes
Expand All @@ -23,7 +23,7 @@ Castle of Cth??????
- follow player on X axis only
- screen shake
- Enemies
- hurt by attacks, knockback, iframes
- knockback on attacked
- skeleton- walk back and forth, turn around at edge of platform
- flying eye- fly towards player
- zombie?- walk towards player
Expand Down

0 comments on commit 37f97ed

Please sign in to comment.