Import 2D Level
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using Platformer.Core;
|
||||
using Platformer.Model;
|
||||
|
||||
namespace Platformer.Gameplay
|
||||
{
|
||||
/// <summary>
|
||||
/// This event is fired when user input should be enabled.
|
||||
/// </summary>
|
||||
public class EnablePlayerInput : Simulation.Event<EnablePlayerInput>
|
||||
{
|
||||
PlatformerModel model = Simulation.GetModel<PlatformerModel>();
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
var player = model.player;
|
||||
player.controlEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Platformer.Core;
|
||||
using Platformer.Mechanics;
|
||||
|
||||
namespace Platformer.Gameplay
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when the health component on an enemy has a hitpoint value of 0.
|
||||
/// </summary>
|
||||
/// <typeparam name="EnemyDeath"></typeparam>
|
||||
public class EnemyDeath : Simulation.Event<EnemyDeath>
|
||||
{
|
||||
public EnemyController enemy;
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
enemy._collider.enabled = false;
|
||||
enemy.control.enabled = false;
|
||||
if (enemy._audio && enemy.ouch)
|
||||
enemy._audio.PlayOneShot(enemy.ouch);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Platformer.Core;
|
||||
using Platformer.Mechanics;
|
||||
using static Platformer.Core.Simulation;
|
||||
|
||||
namespace Platformer.Gameplay
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when the player health reaches 0. This usually would result in a
|
||||
/// PlayerDeath event.
|
||||
/// </summary>
|
||||
/// <typeparam name="HealthIsZero"></typeparam>
|
||||
public class HealthIsZero : Simulation.Event<HealthIsZero>
|
||||
{
|
||||
public Health health;
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
Schedule<PlayerDeath>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Platformer.Core;
|
||||
using Platformer.Model;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Platformer.Gameplay
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when the player has died.
|
||||
/// </summary>
|
||||
/// <typeparam name="PlayerDeath"></typeparam>
|
||||
public class PlayerDeath : Simulation.Event<PlayerDeath>
|
||||
{
|
||||
PlatformerModel model = Simulation.GetModel<PlatformerModel>();
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
var player = model.player;
|
||||
if (player.health.IsAlive)
|
||||
{
|
||||
player.health.Die();
|
||||
model.virtualCamera.Follow = null;
|
||||
model.virtualCamera.LookAt = null;
|
||||
// player.collider.enabled = false;
|
||||
player.controlEnabled = false;
|
||||
|
||||
if (player.audioSource && player.ouchAudio)
|
||||
player.audioSource.PlayOneShot(player.ouchAudio);
|
||||
player.animator.SetTrigger("hurt");
|
||||
player.animator.SetBool("dead", true);
|
||||
Simulation.Schedule<PlayerSpawn>(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Platformer.Core;
|
||||
using Platformer.Mechanics;
|
||||
using Platformer.Model;
|
||||
using UnityEngine;
|
||||
using static Platformer.Core.Simulation;
|
||||
|
||||
namespace Platformer.Gameplay
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a Player collides with an Enemy.
|
||||
/// </summary>
|
||||
/// <typeparam name="EnemyCollision"></typeparam>
|
||||
public class PlayerEnemyCollision : Simulation.Event<PlayerEnemyCollision>
|
||||
{
|
||||
public EnemyController enemy;
|
||||
public PlayerController player;
|
||||
|
||||
PlatformerModel model = Simulation.GetModel<PlatformerModel>();
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
var willHurtEnemy = player.Bounds.center.y >= enemy.Bounds.max.y;
|
||||
|
||||
if (willHurtEnemy)
|
||||
{
|
||||
var enemyHealth = enemy.GetComponent<Health>();
|
||||
if (enemyHealth != null)
|
||||
{
|
||||
enemyHealth.Decrement();
|
||||
if (!enemyHealth.IsAlive)
|
||||
{
|
||||
Schedule<EnemyDeath>().enemy = enemy;
|
||||
player.Bounce(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Bounce(7);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Schedule<EnemyDeath>().enemy = enemy;
|
||||
player.Bounce(2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Schedule<PlayerDeath>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Platformer.Core;
|
||||
using Platformer.Mechanics;
|
||||
using Platformer.Model;
|
||||
|
||||
namespace Platformer.Gameplay
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when a player enters a trigger with a DeathZone component.
|
||||
/// </summary>
|
||||
/// <typeparam name="PlayerEnteredDeathZone"></typeparam>
|
||||
public class PlayerEnteredDeathZone : Simulation.Event<PlayerEnteredDeathZone>
|
||||
{
|
||||
public DeathZone deathzone;
|
||||
|
||||
PlatformerModel model = Simulation.GetModel<PlatformerModel>();
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
Simulation.Schedule<PlayerDeath>(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Platformer.Core;
|
||||
using Platformer.Mechanics;
|
||||
using Platformer.Model;
|
||||
|
||||
namespace Platformer.Gameplay
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This event is triggered when the player character enters a trigger with a VictoryZone component.
|
||||
/// </summary>
|
||||
/// <typeparam name="PlayerEnteredVictoryZone"></typeparam>
|
||||
public class PlayerEnteredVictoryZone : Simulation.Event<PlayerEnteredVictoryZone>
|
||||
{
|
||||
public VictoryZone victoryZone;
|
||||
|
||||
PlatformerModel model = Simulation.GetModel<PlatformerModel>();
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
model.player.animator.SetTrigger("victory");
|
||||
model.player.controlEnabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using Platformer.Core;
|
||||
using Platformer.Mechanics;
|
||||
|
||||
namespace Platformer.Gameplay
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when the player performs a Jump.
|
||||
/// </summary>
|
||||
/// <typeparam name="PlayerJumped"></typeparam>
|
||||
public class PlayerJumped : Simulation.Event<PlayerJumped>
|
||||
{
|
||||
public PlayerController player;
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
if (player.audioSource && player.jumpAudio)
|
||||
player.audioSource.PlayOneShot(player.jumpAudio);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Platformer.Core;
|
||||
using Platformer.Mechanics;
|
||||
|
||||
namespace Platformer.Gameplay
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when the player character lands after being airborne.
|
||||
/// </summary>
|
||||
/// <typeparam name="PlayerLanded"></typeparam>
|
||||
public class PlayerLanded : Simulation.Event<PlayerLanded>
|
||||
{
|
||||
public PlayerController player;
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Platformer.Core;
|
||||
using Platformer.Mechanics;
|
||||
using Platformer.Model;
|
||||
|
||||
namespace Platformer.Gameplay
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when the player is spawned after dying.
|
||||
/// </summary>
|
||||
public class PlayerSpawn : Simulation.Event<PlayerSpawn>
|
||||
{
|
||||
PlatformerModel model = Simulation.GetModel<PlatformerModel>();
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
var player = model.player;
|
||||
player.collider2d.enabled = true;
|
||||
player.controlEnabled = false;
|
||||
if (player.audioSource && player.respawnAudio)
|
||||
player.audioSource.PlayOneShot(player.respawnAudio);
|
||||
player.health.Increment();
|
||||
player.Teleport(model.spawnPoint.transform.position);
|
||||
player.jumpState = PlayerController.JumpState.Grounded;
|
||||
player.animator.SetBool("dead", false);
|
||||
model.virtualCamera.Follow = player.transform;
|
||||
model.virtualCamera.LookAt = player.transform;
|
||||
Simulation.Schedule<EnablePlayerInput>(2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Platformer.Core;
|
||||
using Platformer.Mechanics;
|
||||
|
||||
namespace Platformer.Gameplay
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when the Jump Input is deactivated by the user, cancelling the upward velocity of the jump.
|
||||
/// </summary>
|
||||
/// <typeparam name="PlayerStopJump"></typeparam>
|
||||
public class PlayerStopJump : Simulation.Event<PlayerStopJump>
|
||||
{
|
||||
public PlayerController player;
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Platformer.Core;
|
||||
using Platformer.Mechanics;
|
||||
using Platformer.Model;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Platformer.Gameplay
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when a player collides with a token.
|
||||
/// </summary>
|
||||
/// <typeparam name="PlayerCollision"></typeparam>
|
||||
public class PlayerTokenCollision : Simulation.Event<PlayerTokenCollision>
|
||||
{
|
||||
public PlayerController player;
|
||||
public TokenInstance token;
|
||||
|
||||
PlatformerModel model = Simulation.GetModel<PlatformerModel>();
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(token.tokenCollectAudio, token.transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user