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
ea61cd41
Commit
ea61cd41
authored
2 years ago
by
Robin Halseth Sandvik
Browse files
Options
Downloads
Patches
Plain Diff
Rewrote code to use AbilityEntity for managing player's abilities.
parent
c9b130b0
No related branches found
Branches containing commit
No related tags found
1 merge request
!84
Merge, ability cluster
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MrBigsock/Assets/Code/PlayerController.cs
+119
-23
119 additions, 23 deletions
MrBigsock/Assets/Code/PlayerController.cs
with
119 additions
and
23 deletions
MrBigsock/Assets/Code/PlayerController.cs
+
119
−
23
View file @
ea61cd41
...
@@ -38,12 +38,21 @@ namespace BigSock {
...
@@ -38,12 +38,21 @@ namespace BigSock {
bool
canMove
=
true
;
bool
canMove
=
true
;
// The abilities of the player.
private
List
<
AbilityEntity
>
_abilities
=
new
List
<
AbilityEntity
>();
// A list of the keycodes that correspond to each of the player's abilities.
private
List
<
List
<
KeyCode
>>
_keyMapping
=
new
List
<
List
<
KeyCode
>>
{
new
List
<
KeyCode
>{
KeyCode
.
Space
,
KeyCode
.
Mouse0
},
new
List
<
KeyCode
>{
KeyCode
.
Z
},
new
List
<
KeyCode
>{
KeyCode
.
C
},
new
List
<
KeyCode
>{
KeyCode
.
LeftShift
},
};
//protected IAttack _testAttack;
protected
IAttack
_testAttack
;
//protected IAttack _testAttack2;
protected
IAttack
_testAttack2
;
//protected IAttack _testAttack3;
protected
IAttack
_testAttack3
;
//protected IAbility _dodge;
protected
IAbility
_dodge
;
public
DateTime
NextTimeCanAttack
{
get
;
private
set
;
}
=
DateTime
.
Now
;
public
DateTime
NextTimeCanAttack
{
get
;
private
set
;
}
=
DateTime
.
Now
;
...
@@ -56,6 +65,22 @@ namespace BigSock {
...
@@ -56,6 +65,22 @@ namespace BigSock {
TryPickUpItem
(
ItemService
.
SINGLETON
.
Get
(
101
));
TryPickUpItem
(
ItemService
.
SINGLETON
.
Get
(
101
));
}
}
/*
Updates the list of the user's abilities.
*/
protected
void
SetAbilities
(
List
<
IAbility
>
neo
)
{
var
res
=
new
List
<
AbilityEntity
>();
for
(
int
i
=
0
;
i
<
neo
.
Count
;
++
i
)
res
.
Add
(
new
AbilityEntity
(
neo
[
i
],
i
,
_keyMapping
[
i
]));
_abilities
=
res
;
//!! Put in updating he ui here.
foreach
(
var
ability
in
_abilities
)
{
// AbilityUI.SetAbility(ability.Index, ability); ???
}
}
// Start is called before the first frame update
// Start is called before the first frame update
protected
override
void
Start
()
protected
override
void
Start
()
{
{
...
@@ -81,10 +106,21 @@ namespace BigSock {
...
@@ -81,10 +106,21 @@ namespace BigSock {
//var tmp = PrefabService.SINGLETON;
//var tmp = PrefabService.SINGLETON;
//var tmp = SpriteService.SINGLETON;
//var tmp = SpriteService.SINGLETON;
_testAttack
=
(
IAttack
)
AbilityService
.
SINGLETON
.
Get
(
104
);
_testAttack2
=
(
IAttack
)
AbilityService
.
SINGLETON
.
Get
(
102
);
// Get the abilities and set them up.
_testAttack3
=
(
IAttack
)
AbilityService
.
SINGLETON
.
Get
(
101
);
var
aService
=
AbilityService
.
SINGLETON
;
_dodge
=
AbilityService
.
SINGLETON
.
Get
(
201
);
var
abilities
=
new
List
<
IAbility
>
{
aService
.
Get
(
104
),
aService
.
Get
(
102
),
aService
.
Get
(
101
),
aService
.
Get
(
201
),
};
SetAbilities
(
abilities
);
//_testAttack = (IAttack)AbilityService.SINGLETON.Get(104);
//_testAttack2 = (IAttack)AbilityService.SINGLETON.Get(102);
//_testAttack3 = (IAttack)AbilityService.SINGLETON.Get(101);
//_dodge = AbilityService.SINGLETON.Get(201);
_
=
AudioService
.
SINGLETON
;
_
=
AudioService
.
SINGLETON
;
_
=
SpriteService
.
SINGLETON
;
_
=
SpriteService
.
SINGLETON
;
...
@@ -131,34 +167,90 @@ namespace BigSock {
...
@@ -131,34 +167,90 @@ namespace BigSock {
}
}
// Dictionary that holds start times for charging abilities.
// Dictionary that holds start times for charging abilities.
Dictionary
<
KeyCode
,
float
>
chargeStarts
=
new
Dictionary
<
KeyCode
,
float
>();
//
Dictionary<KeyCode, float> chargeStarts = new Dictionary<KeyCode, float>();
/*
/*
Triggers an ability if it should be.
Triggers an ability if it should be.
Need to add support for mouse buttons n shiet
Need to add support for mouse buttons n shiet
*/
*/
private
void
CheckAbilityInput
(
KeyCode
key
,
IAbility
ability
)
{
private
void
CheckAbilityInput
(
AbilityEntity
ability
)
{
var
par
=
GetAbilityParam
(
Camera
.
main
.
ScreenToWorldPoint
(
Input
.
mousePosition
));
// Check input on each key, stop if one was a success.
foreach
(
var
key
in
ability
.
Keys
)
if
(
CheckAbilityInput
(
key
,
ability
))
break
;
// Update the UI.
//> AbilityUI?.UpdateCharge(ability.Index, ability.ChargePercent);
//> AbilityUI?.UpdateCooldown(ability.Index, ability.CooldownPercent);
}
private
bool
CheckAbilityInput
(
KeyCode
key
,
AbilityEntity
ability
)
{
var
par
=
GetAbilityParam
(
Camera
.
main
.
ScreenToWorldPoint
(
Input
.
mousePosition
));
switch
(
ability
.
Ability
.
FireType
)
{
// Standard: Press to fire.
case
FireType
.
Standard
:
if
(
Input
.
GetKeyDown
(
key
))
{
ability
.
Ability
.
Use
(
par
);
return
true
;
}
break
;
// FullAuto: Keep firing while key is down.
case
FireType
.
FullAuto
:
if
(
Input
.
GetKey
(
key
))
{
ability
.
Ability
.
Use
(
par
);
return
true
;
}
break
;
// Charge: Fire when let go.
case
FireType
.
Charge
:
// If pressed down: Store start time.
if
(
Input
.
GetKeyDown
(
key
))
{
ability
.
ChargeStarted
=
Time
.
time
;
return
true
;
}
// If let go: Activate
else
if
(
Input
.
GetKeyUp
(
key
))
{
par
.
ChargeTime
=
ability
.
ChargeTime
;
var
t
=
ability
.
Ability
.
Use
(
par
);
if
(!
t
)
{
if
(
par
.
ChargeTime
<
ability
.
Ability
.
MinCharge
)
Debug
.
Log
(
$"[PlayerController.CheckAbilityInput(
{
key
}
)]
{
ability
.
Ability
.
Name
}
not fired (
{
par
.
ChargeTime
:
N3
}
<
{
ability
.
Ability
.
MinCharge
:
N3
}
)"
);
}
return
true
;
}
break
;
default
:
break
;
}
return
false
;
}
private
void
CheckAbilityInput2
(
KeyCode
key
,
IAbility
ability
)
{
var
par
=
GetAbilityParam
(
Camera
.
main
.
ScreenToWorldPoint
(
Input
.
mousePosition
));
var
par
=
GetAbilityParam
(
Camera
.
main
.
ScreenToWorldPoint
(
Input
.
mousePosition
));
switch
(
ability
.
FireType
)
{
switch
(
ability
.
FireType
)
{
// Standard: Press to fire.
// Standard: Press to fire.
case
FireType
.
Standard
:
case
FireType
.
Standard
:
if
(
Input
.
GetKeyDown
(
key
))
ability
.
Use
(
par
);
if
(
Input
.
GetKeyDown
(
key
))
ability
.
Use
(
par
);
break
;
break
;
// FullAuto: Keep firing while key is down.
// FullAuto: Keep firing while key is down.
case
FireType
.
FullAuto
:
case
FireType
.
FullAuto
:
if
(
Input
.
GetKey
(
key
))
ability
.
Use
(
par
);
if
(
Input
.
GetKey
(
key
))
ability
.
Use
(
par
);
break
;
break
;
// Charge: Fire when let go.
// Charge: Fire when let go.
case
FireType
.
Charge
:
case
FireType
.
Charge
:
// If pressed down: Store start time.
// If pressed down: Store start time.
if
(
Input
.
GetKeyDown
(
key
))
chargeStarts
[
key
]
=
Time
.
time
;
if
(
Input
.
GetKeyDown
(
key
))
chargeStarts
[
key
]
=
Time
.
time
;
// If let go: Activate
// If let go: Activate
else
if
(
Input
.
GetKeyUp
(
key
))
{
else
if
(
Input
.
GetKeyUp
(
key
))
{
par
.
ChargeTime
=
Time
.
time
-
chargeStarts
[
key
];
par
.
ChargeTime
=
Time
.
time
-
chargeStarts
[
key
];
var
t
=
ability
.
Use
(
par
);
var
t
=
ability
.
Use
(
par
);
if
(!
t
)
{
if
(!
t
)
{
if
(
par
.
ChargeTime
<
ability
.
MinCharge
)
if
(
par
.
ChargeTime
<
ability
.
MinCharge
)
Debug
.
Log
(
$"[PlayerController.CheckAbilityInput(
{
key
}
)]
{
ability
.
Name
}
not fired (
{
par
.
ChargeTime
:
N3
}
<
{
ability
.
MinCharge
:
N3
}
)"
);
Debug
.
Log
(
$"[PlayerController.CheckAbilityInput(
{
key
}
)]
{
ability
.
Name
}
not fired (
{
par
.
ChargeTime
:
N3
}
<
{
ability
.
MinCharge
:
N3
}
)"
);
}
}
}
}
...
@@ -187,14 +279,18 @@ namespace BigSock {
...
@@ -187,14 +279,18 @@ namespace BigSock {
// _testAttack.Use(par);
// _testAttack.Use(par);
//}
//}
// Check and update all abilities.
foreach
(
var
ability
in
_abilities
)
{
CheckAbilityInput
(
ability
);
}
// Check ability 1.
// Check ability 1.
CheckAbilityInput
(
KeyCode
.
Space
,
_testAttack
);
//
CheckAbilityInput(KeyCode.Space, _testAttack);
CheckAbilityInput
(
KeyCode
.
Mouse0
,
_testAttack
);
//
CheckAbilityInput(KeyCode.Mouse0, _testAttack);
// Check ability 2.
// Check ability 2.
CheckAbilityInput
(
KeyCode
.
Z
,
_testAttack2
);
//
CheckAbilityInput(KeyCode.Z, _testAttack2);
// Check ability 3.
// Check ability 3.
CheckAbilityInput
(
KeyCode
.
LeftShift
,
_dodge
);
//
CheckAbilityInput(KeyCode.LeftShift, _dodge);
CheckAbilityInput
(
KeyCode
.
C
,
_testAttack3
);
//
CheckAbilityInput(KeyCode.C, _testAttack3);
//if(Input.GetKeyDown(KeyCode.Z)) Debug.Log($"[PlayerController.Update()] Z was pressed.");
//if(Input.GetKeyDown(KeyCode.Z)) Debug.Log($"[PlayerController.Update()] Z was pressed.");
...
...
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