Witam, mam problem z programem.
Moja wiedza o C++ jest znikoma.
Nie wiem jak zrobić zeby “wzkazówki” nie skakały przy niektórych wspolrzednych y, to ze skacza wynika z matematyki lecz chciałbym się dokształcic i wiedzieć jak napisac program żeby nie skakały.
Program używa wzoru na okrag w układzie x,y:
x²+y²=r²
#include
#include
int main()
{
allegro_init();
install_keyboard();
set_color_depth(16);
set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,600,0,0);
install_mouse();
show_mouse(screen);
unscare_mouse();
BITMAP *bufor = NULL;
bufor = create_bitmap(800,600);
int x=0;
int x2=0;
int y=0;
int y2=0;
int x0=400;
int y0=300;
int pos=1;
int pos1=1;
int r=160;
int c=1;
int x3=0;
while (!key[KEY_ESC])
{
if (x==-r) { pos1=0; pos=0;}
if (x==r) { pos1=1; pos=1 ;};
if (pos1==0) x++;
if (pos1==1) x--;
if (!key[KEY_UP]) c--;
if (!key[KEY_DOWN]) c++;
if (c==-1) c=0;
rest(c);
if (pos==1)
{
x2=x*x;
y=sqrt(r*r-x2);
};
if (pos==0)
{
x2=x*x;
y=sqrt(r*r-x2);
y=y-y-y;
};
x3=y*y;
//x3=sqrt(r*r-x3);
clear_to_color(bufor, makecol(100,100,100));
circle(bufor, x0,y0,r, makecol(255,64,64));
line(bufor,x0,y0,x0+x,y0+ y, makecol(156,255,255));
textprintf_ex(bufor,font,20,18,makecol(200,200,200),-1,"x = %d", x);
textprintf_ex(bufor,font,85,18,makecol(200,200,200),-1," y= %d",y);
textprintf_ex(bufor,font,150,18,makecol(200,200,200),-1," c= %d",c);
textprintf_ex(bufor,font,200,18,makecol(200,200,200),-1," r= %d",r);
textprintf_ex(bufor,font,20,30,makecol(255,255,255),-1,"Press [ESC] to exit.");
textprintf_ex(bufor,font,760,568,makecol(255,0,0),-1,"v1.4");
textprintf_ex(bufor,font,730,580,makecol(255,0,0),-1,"by Hugol");
blit(bufor,screen,0,0,0,0,800,600);
clear_keybuf();
}
destroy_bitmap(bufor);
allegro_exit();
return 0;
}
END_OF_MAIN();
link do skompilowanego programu: