基于C#弹幕类射击游戏的实现——(九)BOSS

这篇博客介绍了如何在C#中实现弹幕类射击游戏的BOSS设计。虽然BOSS类逻辑相对简单,但作者建议将其与Enemy类进行集成,并提出使用Lua作为脚本语言来控制更复杂的AI,以创造多样化的弹幕攻击模式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

BOSS类和Enemy差不多,其实貌似因该继承自GameEnemy才对??

public class GameBoss : GameObject
	{
		protected Box[] SubBoxCollider = null; // BoxCollider用作大范围的检测,SubBoxCollider是细节检测
		
		protected GameBarrage mBarrage = null; // 弹幕生成器
		
		protected int BossWidth;
		protected int BossHeight;
		protected int HalfBossWidth;
		protected int HalfBossHeight;
		
		protected Vector2 Speed;
		
		protected int Life; // 当前生命值
		protected int MaxLife; // 最大生命值
		public bool IsLive; // 是否存活
		
		protected float ShowLife; // 用于显示血条
		protected Rectangle HpRect = new Rectangle(10, 5, Config.ScreenWidth - 20, 8); // 血条显示位置
		
		protected int State = 0; // BOSS状态,也可理解为当前应该发射的弹幕状态
		
		public GameBoss(GameBarrage barrage)
		{
			this.mBarrage = barrage;
			this.Life = 1;
			this.MaxLife = 1;
			this.ShowLife = 1;
			this.IsLive = true;
		}
		
		public bool Collide(Box box)
		{
			// 先用大范围的碰撞盒检测
			if ( BoxCollider.Collide(box) == false )
			{
				return false;
			}
			
			foreach ( Box subBox in SubBoxCollider )
			{
				if ( subBox.Collide(box) == true )
				{
					return true;
				}
			}
			
			return false;
		}
		
		public void DecLife(int decLife)
		{
			Life -= decLife;
			
			if ( Life <= 0 )
			{
				IsLive = false;
				GameBombManager.AddBomb(Position, true, 1.0f);
			}
		}
		
		protected virtual void MoveLogic(float elapsedTime)
		{
			
		}
		
		protected virtual void ShootLogic(float elapsedTime)
		{
			
		}
		
		public override void Update(float elapsedTime)
		{
			float diff = Life -
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值