Skip to content

Commit

Permalink
feat: Added team parameter to Hitbox Initialize.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Initialize now takes a team parameter. Useful in case you want to assign entities to teams and define who they can attack.
  • Loading branch information
christides11 committed Aug 18, 2020
1 parent 77d6a90 commit 56a2699
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Assets/CAF/Combat/Boxes/Hitbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public abstract class Hitbox : SimObject
public List<IHurtable> ignoreList = null;
public List<GameObject> hitHurtables = new List<GameObject>();

public abstract void Initialize(GameObject owner, Transform directionOwner, BoxShapes shape,
HitInfoBase hitInfo, BoxDefinition boxDefinition, List<IHurtable> ignoreList = null);
public abstract void Initialize(GameObject owner, Transform directionOwner, int team,
BoxShapes shape, HitInfoBase hitInfo, BoxDefinition boxDefinition, List<IHurtable> ignoreList = null);

public virtual void Activate()
{
Expand Down
4 changes: 2 additions & 2 deletions Assets/CAF/Combat/Boxes/Hitbox2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class Hitbox2D : Hitbox

protected Collider2D coll;

public override void Initialize(GameObject owner, Transform directionOwner, BoxShapes shape,
HitInfoBase hitInfo, BoxDefinition boxDefinition, List<IHurtable> ignoreList = null)
public override void Initialize(GameObject owner, Transform directionOwner, int team,
BoxShapes shape, HitInfoBase hitInfo, BoxDefinition boxDefinition, List<IHurtable> ignoreList = null)
{
this.owner = owner;
this.directionOwner = directionOwner;
Expand Down
4 changes: 2 additions & 2 deletions Assets/CAF/Combat/Boxes/Hitbox3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class Hitbox3D : Hitbox
{
protected Collider coll;

public override void Initialize(GameObject owner, Transform directionOwner, BoxShapes shape,
HitInfoBase hitInfo, BoxDefinition boxDefinition, List<IHurtable> ignoreList = null)
public override void Initialize(GameObject owner, Transform directionOwner, int team,
BoxShapes shape, HitInfoBase hitInfo, BoxDefinition boxDefinition, List<IHurtable> ignoreList = null)
{
this.owner = owner;
this.directionOwner = directionOwner;
Expand Down
5 changes: 2 additions & 3 deletions Assets/CAF/Entities/Managers/EntityHitboxManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CAF.Combat;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

Expand Down Expand Up @@ -148,8 +147,8 @@ public virtual void CreateHitboxGroup(int index)
hitbox.transform.SetParent(manager.transform, true);
}

hitbox.Initialize(manager.gameObject, manager.visual.transform, currentGroup.boxes[i].shape,
currentGroup.hitboxHitInfo, hitboxDefinition, hurtablesHit[currentGroup.ID]);
hitbox.Initialize(manager.gameObject, manager.visual.transform, manager.CombatManager.GetTeam(),
currentGroup.boxes[i].shape, currentGroup.hitboxHitInfo, hitboxDefinition, hurtablesHit[currentGroup.ID]);
int cID = currentGroup.ID;
int groupIndex = index;
hitbox.OnHurt += (hurtable, hitInfo) => { OnHitboxHurt(hurtable, hitInfo, cID, groupIndex); };
Expand Down
2 changes: 2 additions & 0 deletions Assets/CAF/Samples/TDAction/Characters/Boxer/Boxer.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ MonoBehaviour:
healthManager: {fileID: 1715174515004957371}
hitboxPrefab: {fileID: 8701306930311813587, guid: 615623af5916ce74fbef98bec30a2efd,
type: 3}
hitstopShakeAmt: 0.02
hitstopShakeInv: 1
--- !u!114 &5384823916746293231
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
4 changes: 2 additions & 2 deletions Assets/CAF/Samples/TDAction/Scenes/PlayScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -4084,7 +4084,7 @@ GameObject:
- component: {fileID: 1629233911}
- component: {fileID: 1629233913}
- component: {fileID: 1629233912}
m_Layer: 0
m_Layer: 9
m_Name: Slope_128x64_Grey
m_TagString: Untagged
m_Icon: {fileID: 0}
Expand Down Expand Up @@ -4842,7 +4842,7 @@ GameObject:
- component: {fileID: 2142067202}
- component: {fileID: 2142067204}
- component: {fileID: 2142067203}
m_Layer: 0
m_Layer: 9
m_Name: Slope_64x64_Grey
m_TagString: Untagged
m_Icon: {fileID: 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ public override void SimStart()
{
base.SimStart();
SetupStates();
CombatManager.OnExitHitStop += (self) => { visual.transform.localPosition = Vector3.zero; };
}

public override void SimUpdate(float deltaTime)
{
// Shake during hitstop (only when you got hit by an attack).
if(CombatManager.HitStop > 0
&& CombatManager.HitStun > 0)
{
Vector3 pos = visual.transform.localPosition;
pos.x = (Mathf.Sign(pos.x) > 0 ? -1 : 0) * .02f;
visual.transform.localPosition = pos;
}

base.SimUpdate(deltaTime);
}

protected virtual void SetupStates()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ public override void OnUpdate()
return;
}

// Process events.
bool eventCancel = false;
for (int i = 0; i < currentAttack.events.Count; i++)
{
if (HandleEvents(currentAttack.events[i]))
{
// Event wants us to stall on the current frame.
eventCancel = true;
return;
}
Expand Down

0 comments on commit 56a2699

Please sign in to comment.