我想提出一個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