Roman 5a5a0e220b 任务:替换美术素材,实装动画
1.替换一些美术素材
(1.替换炸弹贴图

2.实装一些新动画
(1.制作地藏之手拿钱的时候的动画
(2.制作爱欲品小怪动画
(3.制作伊斯兰小怪动画
(4.制作玩家开始交互和交互中动画
(5.制作镰刀飞行动画
(6.制作男童动画

*.优化和修复
(1.使木马喷射炸弹时,炸弹有扭矩
2021-12-17 23:33:40 +08:00

201 lines
7.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 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;
private Animator animator;
// _____ _ _ ____ _
// / ____| | | | _ \ | |
// | | __ _| | | |_) | __ _ ___| | __
// | | / _` | | | _ < / _` |/ __| |/ /
// | |___| (_| | | | |_) | (_| | (__| <
// \_____\__,_|_|_|____/ \__,_|\___|_|\_\
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;
animator = GetComponent<Animator>();
}
/// <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);
//播放爆炸动画
animator.SetBool("isBoom",true);
}
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;}
}