Roman 74f926815e 任务:搭建前置关卡,编写演出逻辑
1.编写基督前置关卡
(1.放置平台、怪物和男童
(2.修改男童类,外加OnSaveEvent,OnSave时若有事件则触发该Event
(3.编写开幕演出,与yi前置类似
(4.编写男童解救演出
((1.触发Fungus对话
((2.对话结束后,开启通往上层的门

2.搭建村场景
(1.放置平台和元素
(2.为可动元素制作动画

3.为玩家添加static属性,进度。0:刚开,1进村,2通佛,3通伊,4.通基

4.制作死亡重开功能
(1.当玩家生命值降到0及以下,触发死亡事件
(2.死亡后reload当前场景,并设记录员,关闭某些事件和演出不再执行

*优化和修复
(1.尝试制作击中卡肉效果,目前打击感太弱。也可以尝试粒子效果

*至此,全部前置关卡搭建完毕,村场景搭建完毕。
*明天可以完成流程化,接下来就是填充剧情、UI、死亡标记和留言板等系统了

下班
2021-12-20 23:33:14 +08:00

257 lines
9.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
/// <summary>
/// 爱欲品类,继承自三关都有的那个小怪类
/// </summary>
public class AiYuPin : NormalEnemy
{
// _____ _ _ _
// | __ \ | | | (_)
// | |__) | _| |__ | |_ ___
// | ___/ | | | '_ \| | |/ __|
// | | | |_| | |_) | | | (__
// |_| \__,_|_.__/|_|_|\___|
/// <summary>
/// 爱欲品抓住玩家后贴在玩家身上时的位置偏移量
/// </summary>
[FoldoutGroup("爱欲品")][Header("爬到玩家身上的时候的位置偏移量")]
public Vector3 catchOffset;
/// <summary>
/// 玩家挣脱爱欲品需要多少次方向转换操作
/// </summary>
[Header("玩家挣脱爱欲品需要多少次方向转换操作")][FoldoutGroup("爱欲品")]
public int breakFreeCount;
/// <summary>
/// 玩家挣脱爱欲品还需要多少次方向转换操作
/// </summary>
[Header("玩家挣脱爱欲品还需要多少次方向转换操作")][FoldoutGroup("爱欲品")][ReadOnly]
public int breakFreeCountLeft;
/// <summary>
/// 这个爱欲品有主人吗?也就是地藏
/// </summary>
[HideInInspector]
public bool hasOwner;
/// <summary>
/// 打死后掉落的钱的预制体
/// </summary>
[Header("打死后掉落的钱的预制体")][FoldoutGroup("预制体")]
public GameObject coinObj;
// _____ _ _
// | __ \ (_) | |
// | |__) | __ ___ ____ _| |_ ___
// | ___/ '__| \ \ / / _` | __/ _ \
// | | | | | |\ V / (_| | || __/
// |_| |_| |_| \_/ \__,_|\__\___|
/// <summary>
/// 爱欲品发动Seek后追击的目标
/// </summary>
//虽说是目标,但爱欲品只会抓玩家吧。直接初始化成玩家了
protected Transform target;
/// <summary>
/// 记录当前自己是否抓着玩家
/// </summary>
private bool isCatching = false;
private Animator aiYuPinAnimator;
// _____ _ _ ____ _
// / ____| | | | _ \ | |
// | | __ _| | | |_) | __ _ ___| | __
// | | / _` | | | _ < / _` |/ __| |/ /
// | |___| (_| | | | |_) | (_| | (__| <
// \_____\__,_|_|_|____/ \__,_|\___|_|\_\
void Update(){
//如果在Seek状态则Seek
if(state == State.seek) Seek(target);
if(isCatching){
//将自身位置和玩家位置同步但是需要一个附身offset二维向量
//因为玩家的图片不在游戏物体的中心
transform.position = target.position + catchOffset;
}
}
// _ _ _
// | \ | | | |
// | \| | ___ _ __ _ __ ___ __ _| |
// | . ` |/ _ \| '__| '_ ` _ \ / _` | |
// | |\ | (_) | | | | | | | | (_| | |
// |_| \_|\___/|_| |_| |_| |_|\__,_|_|
protected override void Init()
{
//找到必要的游戏物体和组件
aiYuPinAnimator = GetComponent<Animator>();
//初始化基础属性
base.Init();
//初始化爱欲品属性
breakFreeCountLeft = breakFreeCount;//初始化挣脱需要的操作次数
target = FindObjectOfType<MyPlayer>().transform;//初始化追踪目标为玩家
if(FindObjectOfType<DiZang>()) hasOwner = true;
}
/// <summary>
/// 控制爱欲品追踪传入的Transform每帧调用一次
/// </summary>
/// <param name="target">要追踪的目标的transform组件</param>
protected virtual void Seek(Transform target){
Vector3 moveDir = (target.transform.position - transform.position).normalized;
// //给刚体添加位移
// m_rigidbody.position += (Vector2)moveDir * speed * Time.deltaTime * Vector2.right;
//给刚体以速度
if(canBeHit)
m_rigidbody.velocity = new Vector2(
((moveDir.x > 0) ? 1 : -1) * speed,
m_rigidbody.velocity.y
);
//将面部朝向与速度同步
transform.rotation = Quaternion.
Euler
(transform.rotation.x,
((target.position.x - transform.position.x > 0) ? 0:-180),
transform.rotation.z);
}
/// <summary>
/// 制造一个特殊的钱,用来塞钱的那种
/// </summary>
private void MakeAnCoin(){
GameObject coin = Instantiate(
coinObj,
transform.position,
Quaternion.identity
);
coin.GetComponent<Rigidbody2D>().velocity = new Vector2(
Random.Range(-1f,1f),
Random.Range(-1f,1f)
).normalized * (5f);
}
// ______ _
// | ____| | |
// | |____ _____ _ __ | |_
// | __\ \ / / _ \ '_ \| __|
// | |___\ V / __/ | | | |_
// |______\_/ \___|_| |_|\__|
/// <summary>
/// 当爱欲品发现玩家
/// </summary>
protected override void OnFindThePlayer(Transform target){
//如果没死
if(state == State.wander)
{
//标记自身状态
state = State.seek;
//赋予自身目标以玩家Transform
this.target = target;
//关闭巡逻动画
doTweenPath.DOPause();
}
}
/// <summary>
/// 当爱欲品抓住玩家
/// </summary>
protected override void OnTouchThePlayer(MyPlayer player)
{
//如果玩家没有被抓住,才执行抓住
if(!player.isCatching){
//通知玩家,你被爱欲品附身了
player.BeCatchedByAiYuPin(this);
//暂停Path动画
doTweenPath.DOPause();
//改变自身状态为ATK
state = State.atk;
//关闭自身碰撞体,因为要贴在玩家身上
GetComponent<BoxCollider2D>().enabled = false;
//将自身位置和玩家位置同步但是需要一个附身offset二维向量
//因为玩家的图片不在游戏物体的中心
transform.position = target.position + catchOffset;
//暂时清空重力系数
m_rigidbody.gravityScale = 0;
//清除一下刚体速度,不然怪物可能被创飞
m_rigidbody.velocity = Vector2.zero;
//清除角动量,不然可能会转起来
m_rigidbody.angularVelocity = 0;
//标记自身正抓着玩家
isCatching = true;
//执行抓住动画
if(aiYuPinAnimator != null) aiYuPinAnimator.SetBool("isBeHit",false);
if(aiYuPinAnimator != null) aiYuPinAnimator.SetBool("isATK",true);
}
//如果玩家正被抓着则执行父类——普通小怪的Touch即击飞玩家
else{
base.OnTouchThePlayer(player);
//同时,清空当前附身着的爱欲品的挣脱次数
player.catingAiYuPin.breakFreeCountLeft = breakFreeCount;
}
}
/// <summary>
/// 当爱欲品被攻击了
/// </summary>
/// <param name="hitMethod">攻击方式</param>
/// <param name="hitDir">攻击来袭方向</param>
public override void OnBeHit(MyPlayer.AtkMethod hitMethod, int hitDir){
//被打飞在着地前都不会挨打了
canBeHit = false;
//执行被击飞、死亡检查等事宜
base.OnBeHit(hitMethod, hitDir);
//爱欲品会额外触发发现玩家事件
target = FindObjectOfType<MyPlayer>().transform;//将目标指向玩家
OnFindThePlayer(target);//触发发现玩家事件
//执行受击动画
if(aiYuPinAnimator != null) aiYuPinAnimator.SetBool("isBeHit",true);
}
//原先会触发自动返回记录起点,但是不能,所以重写空的重新着地事件
public override void OnRetouchedTheGround(){
canBeHit = true;
//解除受击动画
if(aiYuPinAnimator != null) aiYuPinAnimator.SetBool("isBeHit",false);
}
/// <summary>
/// 完全挣脱的时候触发
/// </summary>
protected void OnBreakFreeCompletely(){
//恢复一下抓到玩家的时候消除的重力系数
m_rigidbody.gravityScale = 1;
//随机一个死亡面部朝向
deadDir = (Random.Range(-1f,1f) > 0) ? 1: -1;
//标记自身不再抓着玩家
isCatching = false;
//触发死亡事件
OnDead();
//给一个击飞
BeHitToFly((Random.Range(-1f,1f) > 0) ? 1: -1);
//通知玩家
FindObjectOfType<MyPlayer>().BreakFreeCompletely();
}
protected override void OnDead(){
//停止攻击动画,执行受击动画
if(aiYuPinAnimator != null) aiYuPinAnimator.SetBool("isATK",false);
if(aiYuPinAnimator != null) aiYuPinAnimator.SetBool("isBeHit",true);
base.OnDead();
if(
hasOwner &&
target.GetComponent<MyPlayer>().specialMoneyCount == 0 &&
FindObjectOfType<Coin>() == null
)MakeAnCoin();
}
/// <summary>
/// 玩家尝试挣脱的时候触发这个
/// </summary>
public void OnBreakFree(){
if(--breakFreeCountLeft <= 0) OnBreakFreeCompletely();
}
}