简体   繁体   English

Xna我应该在武器类中创建子弹吗

[英]Xna Should I create bullets inside the weapon class

I have my gameplay.cs that spawns everything basically including bullets. 我有我的gameplay.cs,它产生的所有内容基本上都包括子弹。

the gameplay needs access to the bullets to hit detection with terrain or other characters. 游戏玩法需要访问子弹才能通过地形或其他角色进行命中检测。

I would rather instantiate the bullet inside the weapon class rather than the gameplay class. 我宁愿实例化武器类而不是游戏类中的项目符号。

But that would mean I cannot keep track of my bullet to do the hittest.... 但这意味着我无法跟踪我的子弹来进行最快速的测试。

Need some guidance here, expect me to be a total noob in C# and xna. 这里需要一些指导,希望我对C#和xna完全了解。

Why not expose a gameplay member to add new entities from the outside (eg the weapon class)? 为什么不公开游戏成员从外部添加新实体(例如武器类)?

Essentially something like this: 本质上是这样的:

private void OnAttack(object sender, SomeEventArg e)
{
    gameplay.CreateEntity(BazookaProjectileClass, x, y, z, dx, dy, dz);
}

Edit: You shouldn't create your bullets in the gameplay class cause that should be under the weapon's control only. 编辑:您不应该在游戏类中创建子弹,因为该子弹只能在武器的控​​制之下。 The weapon defines the kind of projectiles or effects to add. 武器定义要添加的弹丸或效果的类型。 If you'd handle that in the gameplay class, why use different/custom weapon class(es) at all? 如果您要在游戏类中进行处理,为什么要完全使用其他/自定义武器类?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM