我想提出一个2D射击游戏在XNA 4.0子弹碰撞
我有一颗子弹在我的游戏,我试图让它与敌人发生冲突,但是当我试图检查其位置等于敌人它不
子弹射击:
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();
请帮助!
我没有看到您的标签所谈论的C代码。 – 2013-03-14 22:24:21
当这成为一个C? – 2013-03-14 22:24:28
看起来子弹增加了“速度”值,所以他们可能跳过“蜜蜂”的位置? – 2013-03-14 22:26:28