Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mr BigSock
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gard Aleksander Furre
Mr BigSock
Commits
f6edd27c
Commit
f6edd27c
authored
2 years ago
by
Robin Halseth Sandvik
Browse files
Options
Downloads
Patches
Plain Diff
Moved handling IFrames to separate function.
parent
164f9a54
No related branches found
Branches containing commit
No related tags found
1 merge request
!34
Dodge
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MrBigsock/Assets/Code/Character.cs
+77
-24
77 additions, 24 deletions
MrBigsock/Assets/Code/Character.cs
with
77 additions
and
24 deletions
MrBigsock/Assets/Code/Character.cs
+
77
−
24
View file @
f6edd27c
...
...
@@ -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
()
{
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment