私は単純な飛行機のシューティングゲームを作っていて、同時に飛行機を自由に動かし、同時に発射したいと思いますが、左+火、右+火、左上+火、左下+火、右下+火、上+右+火の状態は機能していません。KeyState条件が働いていません
のKeyDown:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
GetKeyboardState(keys);
if ((keys[(int)Keys.Down] & 128) == 128)
{
moveDown = true;
if ((keys[(int)Keys.Down] & keys[(int)Keys.Right] & 128) == 128)
{
moveRight = true;
}
else if ((keys[(int)Keys.Down] & keys[(int)Keys.Left] & 128) == 128)
{
moveLeft = true;
}
if ((keys[(int)Keys.Space] & 128) == 128)
{
check = true;
Console.WriteLine("fire");
}
}
else if ((keys[(int)Keys.Up] & 128) == 128)
{
moveUp = true;
Console.WriteLine("up " + plane.Location.Y);
if ((keys[(int)Keys.Up] & keys[(int)Keys.Right] & 128) == 128)
{
moveRight = true;
Console.WriteLine("(" + plane.Location.X + "," + plane.Location.Y + ")");
}
else if ((keys[(int)Keys.Up] & keys[(int)Keys.Left] & 128) == 128)
{
moveLeft = true;
Console.WriteLine("(" + plane.Location.X + "," + plane.Location.Y + ")");
}
if ((keys[(int)Keys.Space] & 128) == 128)
{
check = true;
Console.WriteLine("fire");
}
}
else if ((keys[(int)Keys.Right] & 128) == 128)
{
moveRight = true;
if ((keys[(int)Keys.Space] & 128) == 128)
{
check = true;
}
}
else if ((keys[(int)Keys.Left] & 128) == 128)
{
moveLeft = true;
if ((keys[(int)Keys.Space] & 128) == 128)
{
check = true;
}
}
else if ((keys[(int)Keys.Space] & 128) == 128)
{
check = true;
}
}
タイマー:(ここでは、ブールチェックは火のためである)私のコードで、次の
private void shootTimer_Tick(object sender, EventArgs e)
{
if (check == true)
{
checkShots();
}
moveShot();
if (moveRight == true)
{
if (plane.Location.X < 545)
{
plane.Location = new Point(plane.Location.X + 4, plane.Location.Y);
restartShot.Location = new Point(restartShot.Location.X + 4, restartShot.Location.Y);
}
}
if (moveLeft == true)
{
if (plane.Location.X > 0)
{
plane.Location = new Point(plane.Location.X - 4, plane.Location.Y);
restartShot.Location = new Point(restartShot.Location.X + 4, restartShot.Location.Y);
}
}
if (moveUp == true)
{
if (plane.Location.Y > 0)
{
plane.Location = new Point(plane.Location.X, plane.Location.Y - 4);
restartShot.Location = new Point(restartShot.Location.X, restartShot.Location.Y - 4);
}
}
if (moveDown == true)
{
if (plane.Location.Y < 342)
{
plane.Location = new Point(plane.Location.X, plane.Location.Y + 4);
restartShot.Location = new Point(restartShot.Location.X, restartShot.Location.Y + 4);
}
}
}