有了子弹,子弹想有个飞机能发射子弹了。好,现在我们就实现玩家的战机
/// <summary>
/// Description of GamePlayer.
/// </summary>
public class GamePlayer : GameObject
{
private GameScene mScene = null;
private Vector2 InitPosition;
public Vector2 Speed;
public bool IsLive;
private float ShootDelay = 0;
private float ShootDelayTime = 0;
private int PlayerSpriteIndex;
private int Life = 0; // 生命值
private float ReliveTime = 0; // 重生时间
private float GodTime = 0; // 无敌时间
}
这是玩家类的定义,当然也是继承自GameObject的。
我们可以看到,玩家类定义的东西比GameBullet明显多了一点。但大体上差不多的。
然后是具体的实例化和一些基本函数
public GamePlayer(GameScene scene, Vector2 position, Vector2 speed)
{
this.mScene = scene;
this.InitPosition = position;
this.Position = position;
this.Speed = speed;
this.BoxCollider = new Box((int)position.X, (int)position.Y, 8, 8);
this.

本文介绍了如何在C#中实现一个弹幕类射击游戏的玩家战机,包括战机的定义、实例化、基本功能如生命值管理、绘制、更新逻辑等。在Update方法中,处理了重生、无敌状态、碰撞检测、按键响应和射击冷却。通过创建子弹对象并赋予适当数据,实现了玩家战机的射击功能。
最低0.47元/天 解锁文章
7832

被折叠的 条评论
为什么被折叠?



