내 ascii 게임 충돌에 도움이 필요합니다. 나는 이미 플레이어가 다른 물건을 때리면 무언가를하는 법을 이미 알고 있습니다. 하지만 플레이어가 오브젝트를 때릴 때 플레이어를 멈추게하려면 혼란 스럽습니다.C# ascii 게임 충돌
플레이어가 다른 물체와 충돌 할 때 사용합니다.
if(player.x == object.x && player.y == object.y)
{
//Does something
}
그래서 당신은 I'v 잠시 동안 충돌 일에되어 있기 때문에 좋지 않을까 그런 나를 도울 수 있고 나는 그것이 가능한 게임 같은 미로가 될 수 있도록 내 게임으로 구현하려는 경우. 읽어 주셔서 감사합니다 : 여기
3 내 게임 "전체가 CODE"의 구조입니다 : 당신의 C#/객체 지향 프로그래밍에 익숙처럼
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;
}
}
}
}
}
어떻게 플레이어를 이동합니까? 당신의 선수는 단지 속도로 움직일 것입니다 그리고 당신은 단지 그것을 0으로 설정할 수 있습니다 – Sayse