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
Merge requests
!36
Added close to complete skeleton boss
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Added close to complete skeleton boss
alexander
into
main
Overview
0
Commits
1
Pipelines
0
Changes
24
Merged
Alexander Gatland
requested to merge
alexander
into
main
2 years ago
Overview
0
Commits
1
Pipelines
0
Changes
24
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
1cb77b57
1 commit,
2 years ago
24 files
+
2591
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
24
Search (e.g. *.vue) (Ctrl+P)
MrBigsock/Assets/Code/Bosses/SkeletonBossController.cs
0 → 100644
+
161
−
0
Options
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
System.Linq
;
using
System
;
namespace
BigSock
{
public
partial
class
SkeletonBossController
:
EnemyController
{
protected
EmptyCollider
chargeCollider
;
public
SkeletonBossState
State
{
get
;
protected
set
;
}
=
SkeletonBossState
.
Idle
;
protected
bool
isInCharge
=
false
;
protected
DateTime
timer
=
DateTime
.
Now
;
protected
DateTime
nextChargeTime
=
DateTime
.
Now
;
protected
static
readonly
TimeSpan
CHARGE_COOLDOWN
=
new
TimeSpan
(
0
,
0
,
0
,
5
,
0
);
protected
static
readonly
TimeSpan
CHARGE_WAIT_TIME
=
new
TimeSpan
(
0
,
0
,
0
,
0
,
25
);
protected
static
readonly
TimeSpan
SECOND_CHARGE_WAIT_TIME
=
new
TimeSpan
(
0
,
0
,
0
,
0
,
800
);
protected
static
readonly
TimeSpan
FINISH_CHARGE_WAIT_TIME
=
new
TimeSpan
(
0
,
0
,
0
,
0
,
450
);
public
double
LeapForce
=>
MovementSpeed
*
8
;
protected
override
void
Start
()
{
base
.
Start
();
chargeCollider
=
transform
.
Find
(
"ChargeCollider"
).
GetComponent
<
EmptyCollider
>();
chargeCollider
.
OnColliderEnter2D_Action
+=
Charge_OnColliderEnter2D
;
chargeCollider
.
OnColliderStay2D_Action
+=
Charge_OnColliderStay2D
;
chargeCollider
.
OnColliderExit2D_Action
+=
Charge_OnColliderExit2D
;
}
protected
override
void
Update
()
{
Regenerate
();
if
(
target
!=
null
&&
(
State
==
SkeletonBossState
.
Idle
||
State
==
SkeletonBossState
.
Walking
)){
/* //walk
float step = speed * Time.deltaTime;
transform.position = Vector2.MoveTowards(transform.position, target.position, step);
//distance = Vector3.Distance (transform.position, target.position);
//roter
RotateAnimation();
*/
var
movement
=
(
new
Vector2
(
target
.
position
.
x
,
target
.
position
.
y
)
-
rb
.
position
).
normalized
;
TryMove
(
movement
);
RotateAnimation
(
movement
);
}
else
if
(
State
==
SkeletonBossState
.
Charge
&&
DateTime
.
Now
>=
timer
)
{
var
pos
=
target
.
position
;
//target.position;
var
temp
=
(
pos
-
rb
.
transform
.
position
);
temp
.
z
=
0
;
var
direction
=
temp
.
normalized
;
//rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse);
Charge
(
direction
,
LeapForce
);
timer
=
DateTime
.
Now
+
SECOND_CHARGE_WAIT_TIME
;
State
=
SkeletonBossState
.
SecondCharge
;
}
else
if
(
State
==
SkeletonBossState
.
SecondCharge
&&
DateTime
.
Now
>=
timer
)
{
var
pos
=
target
.
position
;
//target.position;
var
temp
=
(
pos
-
rb
.
transform
.
position
);
temp
.
z
=
0
;
var
direction
=
temp
.
normalized
;
//rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse);
Charge
(
direction
,
LeapForce
*
2
);
timer
=
DateTime
.
Now
+
FINISH_CHARGE_WAIT_TIME
;
State
=
SkeletonBossState
.
FinishAttack
;
}
else
if
(
State
==
SkeletonBossState
.
FinishAttack
&&
DateTime
.
Now
>=
timer
)
{
State
=
SkeletonBossState
.
Walking
;
m_Animator
.
SetTrigger
(
"walk"
);
}
}
protected
virtual
bool
Charge
(
Vector2
direction
,
double
leapForce
)
{
if
(
direction
!=
Vector2
.
zero
)
{
rb
.
AddForce
((
float
)
leapForce
*
direction
,
ForceMode2D
.
Impulse
);
return
true
;
}
return
false
;
}
}
/*
Attack
*/
public
partial
class
SkeletonBossController
{
protected
virtual
void
Charge_OnColliderEnter2D
(
Collider2D
other
)
{
if
(
other
.
gameObject
.
tag
==
"Player"
)
isInCharge
=
!
isInCharge
;
}
protected
virtual
void
Charge_OnColliderStay2D
(
Collider2D
other
)
{
var
player
=
other
.
gameObject
.
GetComponent
<
PlayerController
>();
if
(
player
!=
null
)
{
if
(
DateTime
.
Now
>=
nextChargeTime
)
{
m_Animator
.
SetTrigger
(
"attack"
);
timer
=
DateTime
.
Now
+
CHARGE_WAIT_TIME
;
State
=
SkeletonBossState
.
Charge
;
nextChargeTime
=
DateTime
.
Now
+
CHARGE_COOLDOWN
;
}
}
}
protected
virtual
void
Charge_OnColliderExit2D
(
Collider2D
other
)
{
if
(
other
.
gameObject
.
tag
==
"Player"
)
isInCharge
=
!
isInCharge
;
//State = SkeletonBossState.Walking;
}
}
public
partial
class
SkeletonBossController
{
protected
override
void
Move_OnColliderEnter2D
(
Collider2D
other
)
{
//Debug.Log("enter");
if
(
other
.
gameObject
.
tag
==
"Player"
&&
State
!=
SkeletonBossState
.
Charge
&&
State
!=
SkeletonBossState
.
SecondCharge
&&
State
!=
SkeletonBossState
.
FinishAttack
){
//Debug.Log("enter if");
m_Animator
.
SetTrigger
(
"walk"
);
target
=
other
.
transform
;
}
}
protected
override
void
Move_OnColliderExit2D
(
Collider2D
other
)
{
if
(
other
.
gameObject
.
tag
==
"Player"
){
m_Animator
.
SetTrigger
(
"idle"
);
target
=
other
.
transform
;
target
=
null
;
}
}
}
public
partial
class
SkeletonBossController
{
}
/*
The different states the slime can be in.
*/
public
enum
SkeletonBossState
{
Idle
,
Walking
,
Attacking
,
Charge
,
SecondCharge
,
FinishAttack
,
Death
}
}
Loading