我正在 Xna 4.0 中制作 2D 射击游戏
我的游戏中有一颗子弹,我试图让它与敌人相撞,但是当我尝试检查它的位置是否等于敌人时,它没有
子弹射击:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
namespace Moba_Turtle1
{
class Bullet
{
Texture2D bulText;
float timer;
float interval = 2;
public bool shot = false;
public Vector2 velocity;
bool canChange = true;
public Vector2 position;
public Vector2 lastPosition;
Vector2 orgin;
public Bullet (Texture2D newText, Vector2 newPos)
{
bulText = newText;
position = newPos;
}
public void Update (GameTime gameTime)
{
if (Moba_Turtle1.Character.direction == true && canChange == true)
{
canChange = false;
velocity.X = 50f;
}
if (Moba_Turtle1.Character.direction == false && canChange == true)
{
canChange = false;
velocity.X = -50f;
}
position = position + velocity;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(bulText, position, null, Color.White, 0f, orgin, 1.0f, SpriteEffects.None, 0);
}
}
}
碰撞检查:
foreach (BeeAi bee in Bees)
{
{
if (bullet.position == bee.position)
bulCol = true;
}
}
if (bulCol == true)
bullets.Clear();
请帮忙!