我有一个几乎完整的玩家类的游戏,但这是我的问题。当我按下 control + K 时,玩家会自杀(有意)。现在,当他死时,它会在玩家的位置(也是有意的)产生一滴血溅现在这是问题所在,一旦玩家重新产生,血溅仍然可见,但现在它会跟随玩家,这有点怪异如果你问我
所以这里是主要代码:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace Teir_Tactical_2A
{
public class Player
{
Random random = new Random();
public Texture2D playerunarmed;
public Texture2D playerM1911;
public Texture2D bloodspatter2;
public Texture2D playerM4;
public KeyboardState keyState;
public SpriteFont Font1;
public KeyboardState oldKeyboardState;
public Vector2 playerPosition;
public SpriteBatch spriteBatch;
public float Angle { get; set; }
public float AngularVelocity { get; set; }
public Vector2 playerVelocity = Vector2.One;
public bool M1911;
public bool M4;
String[] strs = new String[] { "You suicided. Way to go Genius.", "I saw your limbs blow off with that one.", "Click to Respawn", "HAHAHAHAHAHA-Sorry Click to Respawn" };
String suicideStr;
public bool player;
public bool suicide;
public bool LMBpressed;
public bool RMBpressed;
public bool isplayeralive;
public bool isplayerdead;
public bool respawnscreen;
public bool bloodspatter;
float angle;
public Player(ContentManager content, Vector2 location)
{
this.playerunarmed = content.Load<Texture2D>("PLAYER");
this.playerM1911 = content.Load<Texture2D>("PLAYERM1911");
this.playerM4 = content.Load<Texture2D>("PLAYERM4");
this.bloodspatter2 = content.Load<Texture2D>("blood");
playerPosition = location;
suicideStr = strs[random.Next(strs.Length)];
M1911 = true;
M4 = true;
player = true;
LMBpressed = false;
suicide = false;
RMBpressed = false;
isplayeralive = true;
isplayerdead = false;
respawnscreen = false;
bloodspatter = false;
Font1 = content.Load<SpriteFont>("Font1");
}
public void Update()
{
MouseState curMouse = Mouse.GetState();
if (bloodspatter == true)
{
blood();
}
if (suicide == true)
{
suicided();
}
if (isplayeralive == true)
{
alive();
}
if (isplayerdead == true)
{
dead();
}
if (M1911 == true)
{
armedM1911();
}
if (M4 == true)
{
armedM4();
}
if (player == true)
{
unarmed();
}
if (LMBpressed == true)
{
LMBpressedA();
}
if (RMBpressed == true)
{
RMBpressedA();
}
Vector2 mouseLoc = new Vector2(curMouse.X, curMouse.Y);
Vector2 direction = mouseLoc - playerPosition;
angle = (float)(Math.Atan2(direction.Y, direction.X));
if (curMouse.LeftButton == ButtonState.Pressed)
{
LMBpressed = true;
}
if (curMouse.RightButton == ButtonState.Pressed)
{
RMBpressed = true;
}
keyState = Keyboard.GetState();
if (isplayeralive == false && LMBpressed == true)
{
isplayeralive = true;
isplayerdead = false;
suicide = false;
suicideStr = strs[random.Next(strs.Length)];
}
if (keyState.IsKeyDown(Keys.LeftControl) && keyState.IsKeyDown(Keys.K))
{
isplayeralive = false;
isplayerdead = true;
bloodspatter = true;
suicide = true;
}
if (keyState.IsKeyDown(Keys.D1))
{
M1911 = false;
M4 = false;
player = true;
}
if (keyState.IsKeyDown(Keys.D2))
{
M1911 = true;
player = false;
}
if (keyState.IsKeyDown(Keys.D3))
{
M4 = true;
M1911 = false;
player = false;
}
if (keyState.IsKeyDown(Keys.D))
playerPosition.X += playerVelocity.X + 1;
if (keyState.IsKeyDown(Keys.A))
playerPosition.X -= playerVelocity.X + 1;
if (keyState.IsKeyDown(Keys.W))
playerPosition.Y -= playerVelocity.Y + 1;
if (keyState.IsKeyDown(Keys.S))
playerPosition.Y += playerVelocity.Y + 1;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Begin();
{
Rectangle sourceRectangle = new Rectangle(0, 0, playerunarmed.Width, playerunarmed.Height);
Vector2 origin = new Vector2(playerunarmed.Width / 2, playerunarmed.Height / 2);
if (M1911 == true)
{
spriteBatch.Draw(playerM1911, new Rectangle((int)playerPosition.X, (int)playerPosition.Y, playerunarmed.Width, playerunarmed.Height), null, Color.White, angle + 90, new Vector2(86, 88), SpriteEffects.None, 0f);
}
if (suicide == true)
{
spriteBatch.DrawString(Font1, suicideStr, new Vector2(10, 670), Color.Red);
}
}
if (bloodspatter == true)
{
spriteBatch.Draw(bloodspatter2, new Rectangle((int)playerPosition.X, (int)playerPosition.Y, bloodspatter2.Width, bloodspatter2.Height), Color.White);
}
if (player == true)
{
spriteBatch.Draw(playerunarmed, new Rectangle((int)playerPosition.X, (int)playerPosition.Y, playerunarmed.Width, playerunarmed.Height), null, Color.White, angle + 90, new Vector2(86, 88), SpriteEffects.None, 0f);
}
if (M4 == true)
{
spriteBatch.Draw(playerM4, new Rectangle((int)playerPosition.X, (int)playerPosition.Y, playerunarmed.Width, playerunarmed.Height), null, Color.White, angle + 90, new Vector2(86, 88), SpriteEffects.None, 0f);
}
if (LMBpressed == true)
{
spriteBatch.DrawString(Font1, "LMB PRESSED (shot taken prototype)", new Vector2(1000, 22), Color.GreenYellow);
}
if (RMBpressed == true)
{
spriteBatch.DrawString(Font1, "RMB PRESSED (grenade thrown prototype)", new Vector2(968, 34), Color.Red);
}
if (RMBpressed == true && LMBpressed == true)
{
spriteBatch.DrawString(Font1, "If you are seeing this, the mouse is functioning correctly", new Vector2(810, 45), Color.Black);
}
spriteBatch.End();
}
public void armedM1911()
{
M1911 = true;
M4 = false;
player = false;
}
public void armedM4()
{
M4 = true;
M1911 = false;
player = false;
}
public void unarmed()
{
M1911 = false;
M4 = false;
}
public void LMBpressedA()
{
LMBpressed = false;
}
public void RMBpressedA()
{
RMBpressed = false;
}
public void alive()
{
M1911 = false;
player = true;
M4 = false;
respawnscreen = false;
}
public void dead()
{
M1911 = false;
player = false;
M4 = false;
respawnscreen = true;
}
public void blood()
{
bloodspatter = true;
}
public void suicided()
{
suicide = true;
}
}
}
这就是我认为问题所在(95% 肯定)我需要获取玩家坐标并将它们设置为血迹的位置(并在必要时生成更多)。
if (bloodspatter == true)
{
spriteBatch.Draw(bloodspatter2, new Rectangle((int)playerPosition.X, (int)playerPosition.Y, bloodspatter2.Width, bloodspatter2.Height), Color.White);
}
这可能是因为我使用坐标playerPosition
作为X/Y
坐标的方式,但我不知道如何告诉它先获取它们,然后将血溅位置设置为玩家自杀的位置。
编辑:似乎有一个误解,我不希望血液纹理消失,我希望它留在玩家最后死亡的地方(在这种情况下,自杀,直到我可以添加调用它的子弹)基本上,性能是不是问题,因为它的分辨率非常低,此外,我只希望它们在游戏结束或关卡发生变化时消失(这里不是问题)