任务:搭建基本的系统

1.编写以撒的受击逻辑
(1.利用基类的受击逻辑
(2.具有开关表示此时是否狂暴
(3.重写以撒的onBeHit
((1.当此时狂暴,能够被攻击,模仿其他怪物受击逻辑,并触发狂暴解除函数
((2.当未狂暴,虽然击中,但是无事发生
(4.完善解救男童逻辑,当有男童被解救且未处于狂暴状态,使其狂暴
(5.编写狂暴函数,当触发狂暴时:
((1.将其攻击间隔时间改为狂暴时攻击间隔
((2.修改生成鬼魂时的逻辑,使其生成时加上一个颜色向量,控制其红色通道。通常状态向量为0,狂暴状态修改向量为红色。
((3.石像开始高频率低幅度震动
(6.编写狂暴解除功能
((1.恢复攻击间隔至普通攻击间隔
((2.修改狂暴颜色向量为零向量
((3.停止石像震动

2.修改鬼魂的攻击逻辑,只有当冲撞的时候会开启碰撞体

*:修复Bug:
(1.修复鬼魂使用落雷时,无法正确找到场景内的落雷物体的问题
(2.修复被攻击时仍能继续解救男童的问题

至此,以撒的Boss逻辑基本开发完毕
至此,三个Boss的逻辑均基本开发完毕
This commit is contained in:
Roman 2021-12-17 19:54:50 +08:00
parent ca9a746b76
commit 7914126975
7 changed files with 224 additions and 23 deletions

View File

@ -12,6 +12,7 @@ GameObject:
- component: {fileID: 7242342954004886429}
- component: {fileID: 7242342954004886427}
- component: {fileID: 7242342954004886424}
- component: {fileID: 6762530813879066500}
m_Layer: 0
m_Name: "\u4EE5\u6492\u9B3C\u9B42"
m_TagString: Untagged
@ -91,7 +92,7 @@ CapsuleCollider2D:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7242342954004886428}
m_Enabled: 1
m_Enabled: 0
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
@ -114,3 +115,24 @@ MonoBehaviour:
m_EditorClassIdentifier:
rushTime: 0.6
lightning: {fileID: 0}
--- !u!50 &6762530813879066500
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7242342954004886428}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 7

View File

@ -1099,12 +1099,12 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1355032012}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -2.8158715, y: 0.4, z: 0}
m_LocalScale: {x: 2.84, y: 23.24, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 16
m_Father: {fileID: 1562252750}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &1355032015
BoxCollider2D:
@ -1754,6 +1754,37 @@ PolygonCollider2D:
- {x: -5.707261, y: 3.5044587}
- {x: 5.7573247, y: 3.5044587}
- {x: 5.7573247, y: 7.86}
--- !u!1 &1562252749
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1562252750}
m_Layer: 0
m_Name: "\u843D\u96F7"
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1562252750
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1562252749}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1355032014}
m_Father: {fileID: 0}
m_RootOrder: 16
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1740401870
GameObject:
m_ObjectHideFlags: 0
@ -1894,7 +1925,7 @@ GameObject:
- component: {fileID: 1776031628}
- component: {fileID: 1776031627}
- component: {fileID: 1776031626}
m_Layer: 0
m_Layer: 3
m_Name: "\u73A9\u5BB6"
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -2188,7 +2219,9 @@ GameObject:
- component: {fileID: 1784345427}
- component: {fileID: 1784345426}
- component: {fileID: 1784345428}
m_Layer: 0
- component: {fileID: 1784345429}
- component: {fileID: 1784345430}
m_Layer: 11
m_Name: "\u4EE5\u6492\u96D5\u50CF"
m_TagString: Untagged
m_Icon: {fileID: 0}
@ -2279,9 +2312,57 @@ MonoBehaviour:
canBeHit: 1
state: 0
HPLeft: 0
timeBetweenAttacks: 1
goust: {fileID: 7242342954004886428, guid: b115139c858522e4284c9609bb70fd44, type: 3}
atkOffsetDistance: 2
crazyGoustTimeBetweenAttacks: 0.2
normalGoustTimeBetweenAttacks: 3
--- !u!61 &1784345429
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1784345425}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 2.2533333, y: 3.5733333}
newSize: {x: 3.38, y: 5.36}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1.56, y: 3.5733333}
m_EdgeRadius: 0
--- !u!50 &1784345430
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1784345425}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 7
--- !u!1 &1813717210 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 7242342954004886428, guid: b115139c858522e4284c9609bb70fd44, type: 3}
@ -2369,9 +2450,9 @@ MonoBehaviour:
autoGenerate: 1
isActive: 1
isValid: 1
target: {fileID: 1813717212}
target: {fileID: 1813717216}
animationType: 1
targetType: 11
targetType: 9
forcedTargetType: 0
autoPlay: 1
useTargetAsV3: 0
@ -2394,9 +2475,9 @@ MonoBehaviour:
optionalRotationMode: 0
optionalScrambleMode: 0
optionalString:
--- !u!4 &1813717212 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 7242342954004886426, guid: b115139c858522e4284c9609bb70fd44, type: 3}
--- !u!50 &1813717216 stripped
Rigidbody2D:
m_CorrespondingSourceObject: {fileID: 6762530813879066500, guid: b115139c858522e4284c9609bb70fd44, type: 3}
m_PrefabInstance: {fileID: 7242342955549758278}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1873098828
@ -2835,6 +2916,10 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7242342954004886427, guid: b115139c858522e4284c9609bb70fd44, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7242342954004886428, guid: b115139c858522e4284c9609bb70fd44, type: 3}
propertyPath: m_Name
value: "\u4EE5\u6492\u9B3C\u9B42"
@ -2847,5 +2932,17 @@ PrefabInstance:
propertyPath: m_Color.a
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7242342954004886429, guid: b115139c858522e4284c9609bb70fd44, type: 3}
propertyPath: m_Color.b
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7242342954004886429, guid: b115139c858522e4284c9609bb70fd44, type: 3}
propertyPath: m_Color.g
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7242342954004886429, guid: b115139c858522e4284c9609bb70fd44, type: 3}
propertyPath: m_Color.r
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: b115139c858522e4284c9609bb70fd44, type: 3}

View File

@ -16,11 +16,7 @@ public class YiSa : Enemy
// | | | |_| | |_) | | | (__
// |_| \__,_|_.__/|_|_|\___|
/// <summary>
/// 攻击之间的间隔时间
/// </summary>
[Header("攻击之间的间隔时间")][FoldoutGroup("以撒")]
public float timeBetweenAttacks;
/// <summary>
/// 攻击用鬼魂的预制体
/// </summary>
@ -31,6 +27,16 @@ public class YiSa : Enemy
/// </summary>
[Header("鬼魂攻击玩家时,生成位置离玩家的距离")][FoldoutGroup("以撒")]
public float atkOffsetDistance;
/// <summary>
/// 疯狂的鬼魂的攻击间隔时间
/// </summary>
[Header("疯狂的鬼魂的攻击间隔时间")][FoldoutGroup("以撒")]
public float crazyGoustTimeBetweenAttacks;
/// <summary>
/// 正常的鬼魂的攻击间隔时间
/// </summary>
[Header("正常的鬼魂的攻击间隔时间")][FoldoutGroup("以撒")]
public float normalGoustTimeBetweenAttacks;
// _____ _ _
// | __ \ (_) | |
@ -38,12 +44,30 @@ public class YiSa : Enemy
// | ___/ '__| \ \ / / _` | __/ _ \
// | | | | | |\ V / (_| | || __/
// |_| |_| |_| \_/ \__,_|\__\___|
/// <summary>
/// 攻击之间的间隔时间
/// </summary>
private float timeBetweenAttacks;
/// <summary>
/// 返回类型为协程、参数为空的委托类型
/// </summary>
private delegate IEnumerator Action();
private MyPlayer player;
/// <summary>
/// 目前是否处于狂暴状态
/// </summary>
[Header("目前是否处于狂暴状态")][FoldoutGroup("状态")][ReadOnly]
private bool isCrazy;
/// <summary>
/// 颜色补正,主要在狂暴系统中更改
/// </summary>
private Color colorOffset;
/// <summary>
/// 震动动画
/// </summary>
private Tweener shakeTweener;
// _____ _ _ ____ _
// / ____| | | | _ \ | |
@ -55,6 +79,7 @@ public class YiSa : Enemy
void Start(){
Init();
//测试用开启
InCrazy();
StartCoroutine(StartAATK());
}
@ -69,6 +94,10 @@ public class YiSa : Enemy
private void Init(){
//找到必要的物体和组件
player = FindObjectOfType<MyPlayer>();
//初始化攻击间隔时间
timeBetweenAttacks = normalGoustTimeBetweenAttacks;
//初始化颜色补正
colorOffset = Color.white;
}
/// <summary>
@ -117,8 +146,10 @@ public class YiSa : Enemy
appearPos,
Quaternion.identity
).GetComponent<YiSaGoust>();
//给鬼魂以颜色补正
t.GetComponent<SpriteRenderer>().DOColor(colorOffset,2f);
//让鬼魂淡出
Tweener tweener = t.GetComponent<SpriteRenderer>().DOFade(1,0.5f);
//Tweener tweener = t.GetComponent<SpriteRenderer>().DOFade(1,0.5f);
//记录一下本次攻击的冲撞方向
Vector2 rushDir = player.transform.position - t.transform.position;
//告知该鬼魂执行冲撞攻击
@ -135,8 +166,10 @@ public class YiSa : Enemy
goust,player.transform.position +
new Vector3(0,2f,0),Quaternion.identity
).GetComponent<YiSaGoust>();
//0.5秒淡入显示鬼魂
Tweener tweener = t.GetComponent<SpriteRenderer>().DOFade(1,0.5f);
//给鬼魂以颜色补正
t.GetComponent<SpriteRenderer>().DOColor(colorOffset,2f);
// //0.5秒淡入显示鬼魂
// Tweener tweener = t.GetComponent<SpriteRenderer>().DOFade(1,0.5f);
//给玩家一秒的反应时间
yield return new WaitForSeconds(1f);
t.LightningATK();
@ -148,6 +181,34 @@ public class YiSa : Enemy
/// </summary>
public void ATKEnd(){StartCoroutine(StartAATK());}
/// <summary>
/// 进入狂暴状态
/// </summary>
private void InCrazy(){
//修改标记表示开始狂暴
isCrazy = true;
//修改攻击间隔时间
timeBetweenAttacks = crazyGoustTimeBetweenAttacks;
//修改鬼魂颜色补正
colorOffset = Color.red;
//让石像震动
shakeTweener = transform.DOShakePosition(0.5f,0.1f,50,90,false,false).SetLoops(-1);
}
/// <summary>
/// 脱离狂暴装填
/// </summary>
private void OutCrazy(){
//消除狂暴标记
isCrazy = false;
//修改攻击间隔时间
timeBetweenAttacks = normalGoustTimeBetweenAttacks;
//修改鬼魂颜色补正
colorOffset = Color.white;
//让石像停止震动
shakeTweener.Kill();
}
// ______ _
// | ____| | |
// | |____ _____ _ __ | |_
@ -159,6 +220,18 @@ public class YiSa : Enemy
/// 当有男童被救的时候从男童触发
/// </summary>
public void OnSave(Boy boy){
//当有男童被救,触发狂暴
InCrazy();
}
public override void OnBeHit(MyPlayer.AtkMethod hitMethod, int hitDir){
//只有狂暴状态会受击
if(isCrazy){
//结算生命值
HPLeft -= MyPlayer.atkMethodMagnification[hitMethod];
//解除狂暴
OutCrazy();
}
}

View File

@ -18,20 +18,24 @@ public class YiSaGoust : MonoBehaviour
/// <summary>
/// 落雷的游戏物体
/// </summary>
[Header("落雷的游戏物体")]
[Header("落雷的游戏物体")][HideInInspector]
public GameObject lightning;
private CapsuleCollider2D capsuleCollider2D;
void Start(){
Init();
}
private void Init(){
//找到必要的组件和物体
owner = FindObjectOfType<YiSa>();
capsuleCollider2D = GetComponent<CapsuleCollider2D>();
//如果落雷没有落雷组件,则添加一个
lightning = GameObject.Find("落雷").transform.GetChild(0).gameObject;
if(!lightning.TryGetComponent<Lightning>(out Lightning t))
lightning.AddComponent<Lightning>();
}
public void RushATK(Vector2 rushDir){
//创建并执行一段冲锋的动画
capsuleCollider2D.enabled = true;
Tweener tweener = transform.DOMove(
transform.position + (Vector3)rushDir * 2,
rushTime
@ -39,6 +43,7 @@ public class YiSaGoust : MonoBehaviour
tweener.SetEase(Ease.InElastic);
//结束后,鬼魂逐渐消隐
TweenCallback action = () => {
capsuleCollider2D.enabled = false;
GetComponent<SpriteRenderer>().DOFade(0,1);
//消隐结束后删除自己
Invoke("DestroySelf",1.1f);

View File

@ -461,6 +461,10 @@ public class MyPlayer : MonoBehaviour, Boomer.I_CanBeBoomedObj
BeHitToFly(dir);
//标记自身不受控制
inControl = false;
//交互中断
isInteractive = false;
if(catching != null)
catching.OnCallCancel();
//掉血
HPLeft -= atk;
//震动屏幕和手柄

View File

@ -53,4 +53,4 @@ Physics2DSettings:
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
m_LayerCollisionMatrix: bfffffffbfffffffbbfeffffbfffffffbfffffffbfffffff00ffffff3ffdfffffbffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_LayerCollisionMatrix: bfffffffbfffffffbbfeffffbff7ffffbfffffffbfffffff00ffffff3ffdfffffbffffff7ffffffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

View File

@ -18,7 +18,7 @@ TagManager:
- "\u5730\u9762"
- "\u7A7A\u6C14\u5899"
- "\u53CD\u5F39\u70B8\u5F39"
-
- "\u4EE5\u6492\u96D5\u50CF"
-
-
-