-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into fillAnimForPlayer
- Loading branch information
Showing
10 changed files
with
776 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Monocle; | ||
using System; | ||
using Microsoft.Xna.Framework; | ||
|
||
namespace Celeste.Mod.Entities { | ||
/// <summary> | ||
/// Allows for Collision with any type of entity in the game, similar to a PlayerCollider or PufferCollider. | ||
/// Performs the Action provided on collision. | ||
/// </summary> | ||
/// <typeparam name="T">The specific type of Entity this component should try to collide with</typeparam> | ||
public class EntityCollider<T> : Component where T : Entity { | ||
/// <summary> | ||
/// The Action invoked on Collision, with the Entity collided with passed as a parameter | ||
/// </summary> | ||
public Action<T> OnEntityAction; | ||
|
||
public Collider Collider; | ||
|
||
public EntityCollider(Action<T> onEntityAction, Collider collider = null) | ||
: base(active: true, visible: true) { | ||
OnEntityAction = onEntityAction; | ||
Collider = collider; | ||
} | ||
|
||
public override void Added(Entity entity) { | ||
base.Added(entity); | ||
//Only called if Component is added post Scene Begin and Entity Adding and Awake time. | ||
if (Scene != null) { | ||
if (!Scene.Tracker.IsEntityTracked<T>()) { | ||
patch_Tracker.AddTypeToTracker(typeof(T)); | ||
} | ||
patch_Tracker.Refresh(Scene); | ||
} | ||
} | ||
|
||
public override void EntityAdded(Scene scene) { | ||
if (!scene.Tracker.IsEntityTracked<T>()) { | ||
patch_Tracker.AddTypeToTracker(typeof(T)); | ||
} | ||
base.EntityAdded(scene); | ||
} | ||
|
||
public override void EntityAwake() { | ||
patch_Tracker.Refresh(Scene); | ||
} | ||
|
||
public override void Update() { | ||
if (OnEntityAction == null) { | ||
return; | ||
} | ||
|
||
Collider collider = Entity.Collider; | ||
if (Collider != null) { | ||
Entity.Collider = Collider; | ||
} | ||
|
||
Entity.CollideDo(OnEntityAction); | ||
|
||
Entity.Collider = collider; | ||
} | ||
|
||
public override void DebugRender(Camera camera) { | ||
if (Collider != null) { | ||
Collider collider = Entity.Collider; | ||
Entity.Collider = Collider; | ||
Collider.Render(camera, Color.HotPink); | ||
Entity.Collider = collider; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using Monocle; | ||
using System; | ||
using Microsoft.Xna.Framework; | ||
|
||
namespace Celeste.Mod.Entities { | ||
/// <summary> | ||
/// Allows for Collision with any type of entity in the game, similar to a PlayerCollider or PufferCollider. | ||
/// Collision is done by component, as in, it will get all the components of the type and try to collide with their entities. | ||
/// Performs the Action provided on collision. | ||
/// </summary> | ||
/// <typeparam name="T">The specific type of Component this component should try to collide with</typeparam> | ||
public class EntityColliderByComponent<T> : Component where T : Component { | ||
/// <summary> | ||
/// The Action invoked on Collision, with the Component collided with passed as a parameter | ||
/// </summary> | ||
public Action<T> OnComponentAction; | ||
|
||
public Collider Collider; | ||
|
||
public EntityColliderByComponent(Action<T> onComponentAction, Collider collider = null) | ||
: base(active: true, visible: true) { | ||
OnComponentAction = onComponentAction; | ||
Collider = collider; | ||
} | ||
|
||
public override void Added(Entity entity) { | ||
base.Added(entity); | ||
//Only called if Component is added post Scene Begin and Entity Adding and Awake time. | ||
if (Scene != null) { | ||
if (!Scene.Tracker.IsComponentTracked<T>()) { | ||
patch_Tracker.AddTypeToTracker(typeof(T)); | ||
} | ||
patch_Tracker.Refresh(Scene); | ||
} | ||
} | ||
|
||
public override void EntityAdded(Scene scene) { | ||
if (!scene.Tracker.IsComponentTracked<T>()) { | ||
patch_Tracker.AddTypeToTracker(typeof(T)); | ||
} | ||
base.EntityAdded(scene); | ||
} | ||
|
||
public override void EntityAwake() { | ||
patch_Tracker.Refresh(Scene); | ||
} | ||
|
||
public override void Update() { | ||
if (OnComponentAction == null) { | ||
return; | ||
} | ||
|
||
Collider collider = Entity.Collider; | ||
if (Collider != null) { | ||
Entity.Collider = Collider; | ||
} | ||
|
||
Entity.CollideDoByComponent(OnComponentAction); | ||
|
||
Entity.Collider = collider; | ||
} | ||
|
||
public override void DebugRender(Camera camera) { | ||
if (Collider != null) { | ||
Collider collider = Entity.Collider; | ||
Entity.Collider = Collider; | ||
Collider.Render(camera, Color.HotPink); | ||
Entity.Collider = collider; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.