Skip to content
Snippets Groups Projects
Commit f6edd27c authored by Robin Halseth Sandvik's avatar Robin Halseth Sandvik
Browse files

Moved handling IFrames to separate function.

parent 164f9a54
No related branches found
No related tags found
1 merge request!34Dodge
......@@ -6,7 +6,10 @@ using UnityEngine.InputSystem;
using BigSock.Item;
namespace BigSock {
// Common class for all characters.
/*
Common class for all characters.
*/
public partial class Character : Entity {
/*
......@@ -74,27 +77,6 @@ namespace BigSock {
public int level;
/*
Indicates whether or not the characer is a live.
*/
public bool Alive { get; private set; } = true;
/*
Stores the next time the character can recieve damage.
*/
public DateTime NextTimeCanTakeDamage { get; private set; } = DateTime.Now;
/*
How long between each time the character can take damage.
*/
public TimeSpan IFrameDuration {
get => _iFrameDuration;
private set => _iFrameDuration = value;
}
public TimeSpan _iFrameDuration = new TimeSpan(0, 0, 0, 0, 333);
protected Rigidbody2D rb;
......@@ -194,11 +176,11 @@ namespace BigSock {
if(!attack.IsCalculated) throw new ArgumentException("Attack needs to be calculated.", nameof(attack));
// Check if player has IFrames
if(NextTimeCanTakeDamage > DateTime.Now)
if(HasIFrames)
return false;
// Start new IFrames
NextTimeCanTakeDamage = DateTime.Now + IFrameDuration;
SetIFrames(IFrameDuration);
// Trigger the event for taking damage.
OnTakeDamage?.Invoke(this, attack.Actor, attack);
......@@ -285,6 +267,8 @@ namespace BigSock {
/*
Items
*/
......@@ -464,4 +448,73 @@ namespace BigSock {
}
/*
Status effects.
*/
public partial class Character {
/*
Indicates whether or not the characer is a live.
*/
public bool Alive { get; private set; } = true;
/*
Indicates whether or not the characer is a live.
*/
public bool HasIFrames => NextTimeCanTakeDamage > DateTime.Now;
/*
Stores the next time the character can recieve damage.
*/
public DateTime NextTimeCanTakeDamage { get; private set; } = DateTime.Now;
/*
How long between each time the character can take damage.
*/
public TimeSpan IFrameDuration {
get => _iFrameDuration;
private set => _iFrameDuration = value;
}
public TimeSpan _iFrameDuration = new TimeSpan(0, 0, 0, 0, 333);
/*
Sets IFrames for the character.
*/
public bool SetIFrames(TimeSpan amount) {
// Get when the IFrames would expire.
var nextCanTakeDamage = DateTime.Now + IFrameDuration;
// Only if that's later than current.
if(nextCanTakeDamage > NextTimeCanTakeDamage) {
// If character currently doesn't have the status effect.
if(NextTimeCanTakeDamage < DateTime.Now) {
ApplyIFrames();
}
// Set new time.
NextTimeCanTakeDamage = nextCanTakeDamage;
return true;
}
return false;
}
/*
Appies IFrames to the character.
*/
private void ApplyIFrames() {
}
/*
Removes IFrames for the character.
*/
private void RemoveIFrames() {
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment