我的 ascii 游戏碰撞需要帮助。我已经知道当玩家击中另一个物体时它会做些什么。但是当我想让玩家在玩家击中物体时停止时,我有点困惑。
当玩家与另一个物体发生碰撞时,我会使用它。
if(player.x == object.x && player.y == object.y)
{
//Does something
}
因此,如果您能帮助我,那就太棒了,因为我已经研究了一段时间的碰撞问题,并且我想将它实现到我的游戏中,所以它可能是一个类似迷宫的游戏。感谢阅读:3
这是我的游戏“全码”的结构:
public static void Main(string[] args)
{
int x = 40;
int y = 12;
int ax = 23;
int ay = 7;
int apple = 0;
int starX = 64;
int starY = 5;
int score = 0;
int total = 0;
int time = 100;
int xt;
int yt;
bool quit = false;
Console.Title = "Catch and Run";
while (quit == false)
{
Console.BackgroundColor = ConsoleColor.DarkGreen;
//Blocks
Console.SetCursorPosition(29, 18);
Console.BackgroundColor = ConsoleColor.DarkGreen;
//Clear Screen
Console.Clear();
//Players
Console.SetCursorPosition(x, y);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("☻");
Console.SetCursorPosition(ax, ay);
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("o");
Console.SetCursorPosition(starX, starY);
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("☻");
Console.ResetColor();
//score
Console.SetCursorPosition(0, 0);
Console.WriteLine("People: " + score);
//apples
Console.SetCursorPosition(20, 0);
Console.WriteLine("Apples: " + apple);
//Total
Console.SetCursorPosition(40, 0);
total = apple + score;
Console.WriteLine("Total: " + total);
//Timer
Console.SetCursorPosition(0, 23);
Console.WriteLine("Steps Left: "+time);
time--;
ConsoleKeyInfo keyInfo = Console.ReadKey(false);
//key controlls
switch (keyInfo.Key)
{
case ConsoleKey.Escape:
quit = true;
break;
case ConsoleKey.UpArrow:
if (y > 1)
y--;
break;
case ConsoleKey.DownArrow:
if (y < 22)
y++;
break;
case ConsoleKey.LeftArrow:
if (x > 0)
x--;
break;
case ConsoleKey.RightArrow:
if (x < 79)
x++;
break;
}
// Randomize Blacks
if (x == starX && y == starY)
{
Random random = new Random();
starX = random.Next(0, 80);
starY = random.Next(1, 22);
score += 10;
time += 30;
}
//Randomize Apples
if (x == ax && y == ay)
{
Random random = new Random();
ax = random.Next(0, 80);
ay = random.Next(1, 22);
apple += 5;
time += 20;
}
// Game Over timer set to 0
if (time == 0)
{
Console.Clear();
Console.SetCursorPosition(40, 0);
Console.WriteLine("GAME OVER");
Console.WriteLine("Score" + total);
Console.WriteLine("Press any key to continue");
Console.ReadKey();
quit = true;
}
if (x == 29 && y == 18)
{
x = 0;
y = 1;
}
}
}
}
}