ahoj,dělám hru zde je kod:
#include <cstdlib>
#include <windows.h>
#include <iostream>
#include <ctime>
void gotoxy(int x,int y)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = {x, y};
SetConsoleCursorPosition(handle, position);
}
using namespace std;
int main(int argc, char *argv[])
{
HANDLE hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx = new CONSOLE_FONT_INFOEX() ;
lpConsoleCurrentFontEx-> cbSize = sizeof (CONSOLE_FONT_INFOEX);
GetCurrentConsoleFontEx(hConsole,0,lpConsoleCurrentFontEx);
lpConsoleCurrentFontEx->dwFontSize.X = 8;
lpConsoleCurrentFontEx->dwFontSize.Y = 16;
SetCurrentConsoleFontEx(hConsole,0,lpConsoleCurrentFontEx);
int cislo=0;
int maxcislo=3;
system("mode 200");
int a=50;
int b=50;
int q=50;
int w=0;
while(1)
{
w=w+1;
srand( (unsigned)time( NULL ) );
cislo = rand() % maxcislo;
if (cislo==1)
{
q=q+1;
}
if (cislo==2)
{
q=q-1;
}
if (a==w)
{
w=0;
Beep(75,300);
}
if (a>92)
{
a=90;
}
if (a<1)
{
a=3;
}
gotoxy(q,w);
SetConsoleTextAttribute(hOut,BACKGROUND_RED |BACKGROUND_INTENSITY);
cout<<"|*|";
SetConsoleTextAttribute(hOut,FOREGROUND_RED);
gotoxy(a,b);
SetConsoleTextAttribute(hOut,BACKGROUND_BLUE |BACKGROUND_INTENSITY);
cout<<"|";
SetConsoleTextAttribute(hOut,FOREGROUND_RED);
SetConsoleTextAttribute(hOut,BACKGROUND_GREEN |BACKGROUND_INTENSITY);
cout<<"||||||";
SetConsoleTextAttribute(hOut,FOREGROUND_RED);
SetConsoleTextAttribute(hOut,BACKGROUND_BLUE |BACKGROUND_INTENSITY);
cout<<"|";
SetConsoleTextAttribute(hOut,FOREGROUND_RED);
cout<<"\n\n\n\n\n\n\n\n "<<"A: "<<a<<" B: "<<b<<" "<<" Q: "<<q<<" W: "<<w;
if (GetAsyncKeyState(VK_RIGHT))
{
a=a+1;
}
if (GetAsyncKeyState(VK_LEFT))
{
a=a-1;
}
if (w>60)
{
w=0;
Beep(2000,400);
}
system("cls");
}
system("PAUSE>null");
return EXIT_SUCCESS;
}
jak bych mohl udělat kolizi mezi míčem a hráčem? zkoušel jsem to if (a==b) .... ale to funguje špatně,Dík za odpovědi.