Roman ca9a746b76 任务:搭建基本的系统
1.编写以撒逻辑
(1.继承于Enemy
(2.编写OnSave(男童)事件,当有男童被解救,会触发以撒的这个事件,后续逻辑等待讨论
(3.具有冲撞和闪电两种攻击方式,通过类似地藏的方式轮回随机决定攻击方式
(4.编写冲撞攻击逻辑
((*.创建鬼魂脚本
((*.创建鬼魂预制体,需要内含触发器
((1.当执行,以玩家为中心向周围一圈固定距离随机方向的某处召唤鬼魂,并记录下此时自身到玩家的方向
((2.等待一小段时间,令鬼魂以记录方向冲撞出去,利用Tweener动画营造一种先抖一下然后猛地创过来的感觉
((3.动画结束后,鬼魂逐渐消隐
((4.消隐结束后,删除游戏物体
((5.冲撞过程中具有攻击判定,若创到玩家,触发玩家的受击事件,同时获取主人的攻击力传给玩家
(3.编写闪电攻击逻辑
((1.当执行,在玩家头顶一定距离处生成鬼魂
((2.淡入显示鬼魂,一小段时间后,命令鬼魂发动落雷攻击
((3.发动时,激活场景内的巨型落雷,同时更改落雷的x位置到鬼魂的x,子物体具有触发器,(每帧)检测到玩家在内则对玩家造成伤害
((4.在极短的时间后关闭落雷同时开始淡出鬼魂
((5.淡出结束后删除游戏物体

2.编写男童逻辑
(1.继承于Interactive
(2.编写解救男童逻辑
((*.修改Interactive基类,新增OnCallCancel事件,当交互键抬起时触发一次
((*.新增男童状态的枚举类型,包含:wait、saving、OK三个状态
((*:新增一个变量记录男童状态
((1.重写OnCall事件,当OnCall,修改状态至saving
((2.Update回调中,若处于saving状态,则开始减少CDLeft,同时判断CDLeft是否耗尽,若耗尽,触发OnSave
((3.编写OnSave函数,修改状态至OK,通知owner自己已经OnSave
((4.重写OnCallCancel事件,当触发,判定状态,若处于saving状态,则修改状态至wait,恢复CDLeft
((*.使得玩家救人的时候无法移动,而当交互键抬起,重新获得移动能力
((*.修改可交互基类,当玩家交互过程中丢失catching,触发可交互物体的中断,同时告知玩家交互中断,触发中断事件
((5.解救结束后,通知玩家解救结束

至此,以撒的Boss逻辑还差首尾部分
加速吧
2021-12-17 01:27:10 +08:00

195 lines
7.1 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 YiSiLan : Enemy, Boomer.I_CanBeBoomedObj
{
// _____ _ _ _
// | __ \ | | | (_)
// | |__) | _| |__ | |_ ___
// | ___/ | | | '_ \| | |/ __|
// | | | |_| | |_) | | | (__
// |_| \__,_|_.__/|_|_|\___|
[FoldoutGroup("其他",false,0)][Header("怪物死后旋转速度的随机区间")]
public float deadRotationRangeMax;
[FoldoutGroup("其他",false,0)]
public float deadRotationRangeMin;
/// <summary>
/// 抓到玩家后多长事件触发爆炸
/// </summary>
[Header("抓到玩家后多长事件触发爆炸")][FoldoutGroup("伊斯兰")]
public float boomTime;
/// <summary>
/// 被击飞力度的调整值
/// </summary>
[Header("被攻击后击飞的力度调整值")][FoldoutGroup("其他",false,0)]
public Vector2 hitToflyParameter;
// _____ _ _
// | __ \ (_) | |
// | |__) | __ ___ ____ _| |_ ___
// | ___/ '__| \ \ / / _` | __/ _ \
// | | | | | |\ V / (_| | || __/
// |_| |_| |_| \_/ \__,_|\__\___|
private Rigidbody2D m_rigidbody;
/// <summary>
/// seek函数中的追踪目标
/// </summary>
private Transform target;
/// <summary>
/// 记录此时玩家是否在爆炸范围内
/// </summary>
[Header("记录此时玩家是否在爆炸范围内")][SerializeField][FoldoutGroup("伊斯兰")][ReadOnly]
private bool canHitPlayer;
// _____ _ _ ____ _
// / ____| | | | _ \ | |
// | | __ _| | | |_) | __ _ ___| | __
// | | / _` | | | _ < / _` |/ __| |/ /
// | |___| (_| | | | |_) | (_| | (__| <
// \_____\__,_|_|_|____/ \__,_|\___|_|\_\
void Start(){Init();}//初始化
void FixedUpdate(){if(state == State.seek)Seek();}//seek
// _ _ _
// | \ | | | |
// | \| | ___ _ __ _ __ ___ __ _| |
// | . ` |/ _ \| '__| '_ ` _ \ / _` | |
// | |\ | (_) | | | | | | | | (_| | |
// |_| \_|\___/|_| |_| |_| |_|\__,_|_|
private void Init(){
//初始化状态为Seek
state = State.seek;
//找到必要的组件
m_rigidbody = GetComponent<Rigidbody2D>();
target = FindObjectOfType<MyPlayer>().transform;
}
/// <summary>
/// 寻找函数每Fixed调用
/// </summary>
private void Seek(){
//构造一个方向1代表向右-1代表向左
int dir = (target.position.x - transform.position.x > 0) ? 1:-1;
//使刚体水平方向上获得速度
m_rigidbody.velocity = new Vector2(speed * dir,
m_rigidbody.velocity.y);
//矫正一下faceDir的问题,使其始终朝向玩家
transform.rotation = Quaternion.
Euler
(transform.rotation.x,
((dir == 1) ? 0:-180),
transform.rotation.z);
}
/// <summary>
/// 碰到玩家的时候触发,伊斯兰爆炸的时候Call这个通过协程触发因为爆炸有个延时
/// </summary>
private void Boom(){
//
deadRotationRangeMax *= 3;
deadRotationRangeMin *= 3;
hitToflyParameter *= 3;
state = State.dead;
OnBeHit(MyPlayer.AtkMethod.,(target.position.x - transform.position.x > 0) ? 1:-1);
// //让自己去世
// OnDead();
//判定能否攻击到玩家
if(canHitPlayer){
FindObjectOfType<MyPlayer>().OnBeHit(ATK,(target.position.x - transform.position.x > 0) ? -1:1);
// //加一个扭矩,营造死亡的效果
// m_rigidbody.AddTorque(Random.Range(deadRotationRangeMin,deadRotationRangeMax) *
// ((target.position.x - transform.position.x > 0) ? -1:1));
}
}
/// <summary>
/// 被击飞的击飞效果处理
/// </summary>
/// <param name="dir">被击方向</param>
public void BeHitToFly(int dir){
m_rigidbody.velocity += new Vector2( //给予自身一个
-1 * dir * hitToflyParameter.x,//X方向为力度系数乘以受击方向
hitToflyParameter.y//Y方向为力度系数
//的绝对的速度
);
}
/// <summary>
/// 协程用,删除自己这个游戏物体
/// </summary>
protected void Dead(){Destroy(gameObject);}
// ______ _
// | ____| | |
// | |____ _____ _ __ | |_
// | __\ \ / / _ \ '_ \| __|
// | |___\ V / __/ | | | |_
// |______\_/ \___|_| |_|\__|
protected override void OnTouchThePlayer(MyPlayer player){Invoke("Boom",boomTime);}
protected override void OnDead(){
//标记当前状态为死亡
state = State.dead;
//加一个扭矩,营造死亡的效果
m_rigidbody.AddTorque(Random.Range(deadRotationRangeMin,deadRotationRangeMax) *
((target.position.x - transform.position.x > 0) ? -1 : 1));
//关掉自己的碰撞体
GetComponent<BoxCollider2D>().enabled = false;
//两秒后自己毁灭
Invoke("Dead",2f);
}
public override void OnBeHit(MyPlayer.AtkMethod hitMethod, int hitDir){
//让自己被击飞
BeHitToFly(hitDir);
//结算生命值
HPLeft -= MyPlayer.atkMethodMagnification[hitMethod];
//看下死了没
//死了就记录下死亡时候的面部朝向用来做死亡翻滚效果然后再Call一下死亡事件
if(CheckDead()) {OnDead();}
//被打飞了在着地前都不会挨打了
canBeHit = false;
}
// _____ _ _ _ _
// / ____| | | (_) (_)
// | | ___ | | |_ ___ _ ___ _ __
// | | / _ \| | | / __| |/ _ \| '_ \
// | |___| (_) | | | \__ \ | (_) | | | |
// \_____\___/|_|_|_|___/_|\___/|_| |_|
//触发器代表炸弹范围,进入说明能炸到,离开说明炸不到了
protected override void OnTriggerEnter2D(Collider2D other){
base.OnTriggerEnter2D(other);
if(other.gameObject.TryGetComponent<MyPlayer>(out MyPlayer player))
canHitPlayer = true;
}
void OnTriggerExit2D(Collider2D other){
if(other.gameObject.TryGetComponent<MyPlayer>(out MyPlayer player))
canHitPlayer = false;
}
// _____ _ __
// |_ _| | | / _|
// | | _ __ | |_ ___ _ __| |_ __ _ ___ ___
// | | | '_ \| __/ _ \ '__| _/ _` |/ __/ _ \
// _| |_| | | | || __/ | | || (_| | (_| __/
// |_____|_| |_|\__\___|_| |_| \__,_|\___\___|
public void BeBoomed(float atk, int dir, Boomer boomer){
//需要重写
OnBeHit(MyPlayer.AtkMethod.,dir);
}
public Transform ObjTransform(){return transform;}
}