プレーヤーがブロックに当たったときに完全に停止するようにしようとしていますが、特定のキーを押すと動かなくなることがあります。例: プレイヤーがダウン中にブロックにぶつかった。彼は停止しますが、W、A、または D を押すと、上、左、または右に移動できます。これが私が現在持っているコードです。
この場合、sp は速度を意味し、blocksp はブロックされているときの速度を意味します。(This.Sprite) は、この場合、彼を止めるブロックを参照しています。
bool Blocked = false;
float Bottom = -32;
float Left = -32;
float Right = This.Sprite.GetWidth() - 32;
float Top = This.Sprite.GetHeight() - 32;
int x = 0;
int y = 0;
float sp = 1.59f;
float blocksp = 0.00f;
Sprite Player = This.Game.FindSprite("GuySprite");
if (This.Sprite.CollisionWithSprite("GuySprite") != null)
{
if (Player.Position.Y > Top)
{
Blocked = true;
Player.Velocity = new Point2D(x, y) * blocksp;
Player.Animation = 0;
if (This.Game.IsPressed(InputKey.W) || This.Game.IsPressed(InputKey.A) || This.Game.IsPressed(InputKey.D))
{
Blocked = false;
Player.Velocity = new Point2D(x, y) * sp;
Player.Position.Y -= 0.85f;
}
}
if (Player.Position.Y < Bottom)
{
Blocked = true;
Player.Velocity = new Point2D(x, y) * blocksp;
Player.Animation = 0;
if (This.Game.IsPressed(InputKey.S) || This.Game.IsPressed(InputKey.A) || This.Game.IsPressed(InputKey.D))
{
Blocked = false;
Player.Velocity = new Point2D(x, y) * sp;
Player.Position.Y += 0.85f;
}
}
if (Player.Position.Y < Right)
{
Blocked = true;
Player.Velocity = new Point2D(x, y) * blocksp;
Player.Animation = 0;
if (This.Game.IsPressed(InputKey.S) || This.Game.IsPressed(InputKey.A) || This.Game.IsPressed(InputKey.W))
{
Blocked = false;
Player.Velocity = new Point2D(x, y) * sp;
Player.Position.Y -= 0.85f;
}
}
if (Player.Position.Y > Left)
{
Blocked = true;
Player.Velocity = new Point2D(x, y) * blocksp;
Player.Animation = 0;
if (This.Game.IsPressed(InputKey.S) || This.Game.IsPressed(InputKey.W) || This.Game.IsPressed(InputKey.D))
{
Blocked = false;
Player.Velocity = new Point2D(x, y) * sp;
Player.Position.X += 0.85f;
}
}
}
現在、プレーヤーがブロックのいずれかの側面に触れ、ブロックが停止するまで動き続けると、プレーヤーは不規則な方向に移動し、ブロックで停止しません。何か案は?