我正在尝试建立一个球类游戏,只需点击红色球,就会改变颜色。大理石是绘制球的函数调用。
#include<glut.h>
volatile GLint w1=GetSystemMetrics(SM_CXSCREEN),h1=GetSystemMetrics (SM_CYSCREEN);//get screen dimensions
......
......
......
void firstrow(int flag)
{
float i;
for(i=-0.25;i<0.25;i+=0.10)
{
count++;
if(flag>1)
c=medium();
if(flag>2)
c=difficult();
marble(i,0.4,-0.5, 0.06,0.12,0.12,c);
if(c==2)
{flag1[count]=count;}
Sleep(30);
}
}
void secondrow(int flag)
{
float i;
for(i=-0.25;i<0.25;i+=0.10)
{
count++;
c=2;
if(flag>2)
c=difficult1();
marble(i,0.1,-0.5, 0.06,0.12,0.12,c);
if(c==2)
{flag1[count]=count;}
Sleep(30);
}
}
void thirdrow(int flag)
{
float i;
for(i=-0.25;i<0.25;i+=0.10)
{
count++;
if(flag>1)
c=medium();
if(flag>2)
c=difficult();
marble(i,-0.2,-0.5, 0.06,0.12,0.12,c);
if(c==2)
{flag1[count]=count;}
Sleep(30);
}
}
void fourthrow(int flag)
{
float i;
for(i=-0.25;i<0.25;i+=0.10)
{
count++;
c=2;
/*if(flag>1)
c=medium();*/
if(flag>2)
c=difficult1();
marble(i,-0.5,-0.5, 0.06,0.12,0.12,c);
if(c==2)
{flag1[count]=count;}
Sleep(30);
}
}
现在打印4排球后。我正在使用鼠标的2D坐标来检测特定对象。
void drawCircle(int x,int y)
{
/*--------- Target count and color change for 1st Row ------------*/
if(x>573 && x<626 && y>235 && y<291 && flag1[1]==1)
{
marble(-0.25,0.4,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[1]=0;
}
if(x>655 && x<763 && y>235 && y<291 && flag1[2]==2)
{
marble(-0.15,0.4,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[2]=0;
}
if(x>736 && x<785 && y>235 && y<291 && flag1[3]==3)
{
marble(-0.05,0.4,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[3]=0;
}
if(x>815 && x<865 && y>235 && y<291 && flag1[4]==4)
{
marble(0.05,0.4,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[4]=0;
}
if(x>896 && x<945 && y>235 && y<291 && flag1[5]==5)
{
marble(0.15,0.4,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[5]=0;
}
if(x>976 && x<1025 && y>235 && y<291 && flag1[6]==6)
{
marble(0.25,0.4,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[6]=0;
}
/*--------- Target count and color change for 2nd Row ------------*/
if(x>573 && x<626 && y>370 && y<423 && flag1[7]==7)
{
marble(-0.25,0.1,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[7]=0;
}
if(x>655 && x<704 && y>370 && y<423 && flag1[8]==8)
{
marble(-0.15,0.1,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[8]=0;
}
if(x>736 && x<785 && y>370 && y<423 && flag1[9]==9)
{
marble(-0.05,0.1,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[9]=0;
}
if(x>815 && x<865 && y>370 && y<423 && flag1[10]==10)
{
marble(0.05,0.1,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[10]=0;
}
if(x>896 && x<945 && y>370 && y<423 && flag1[11]==11)
{
marble(0.15,0.1,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[11]=0;
}
if(x>976 && x<1025 && y>370 && y<423 && flag1[12]==12)
{
marble(0.25,0.1,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[12]=0;
}
/*--------- Target count and color change for 3rd Row ------------*/
if(x>573 && x<626 && y>502 && y<556 && flag1[13]==13)
{
marble(-0.25,-0.2,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[13]=0;
}
if(x>655 && x<763 && y>502 && y<556 && flag1[14]==14)
{
marble(-0.15,-0.2,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[14]=0;
}
if(x>736 && x<785 && y>502 && y<556 && flag1[15]==15)
{
marble(-0.05,-0.2,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[15]=0;
}
if(x>815 && x<865 && y>502 && y<556 && flag1[16]==16)
{
marble(0.05,-0.2,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[16]=0;
}
if(x>896 && x<945 && y>502 && y<556 && flag1[17]==17)
{
marble(0.15,-0.2,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[17]=0;
}
if(x>976 && x<1025 && y>502 && y<556 && flag1[18]==18)
{
marble(0.25,-0.2,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[18]=0;
}
/*--------- Target count and color change for 4th Row ------------*/
if(x>573 && x<626 && y>635 && y<689 && flag1[19]==19)
{
marble(-0.25,-0.5,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[19]=0;
}
if(x>655 && x<763 && y>635 && y<689 && flag1[20]==20)
{
marble(-0.15,-0.5,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[20]=0;
}
if(x>736 && x<785 && y>635 && y<689 && flag1[21]==21)
{
marble(-0.05,-0.5,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[21]=0;
}
if(x>815 && x<865 && y>635 && y<689 && flag1[22]==22)
{
marble(0.05,-0.5,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[22]=0;
}
if(x>896 && x<945 && y>635 && y<689 && flag1[23]==23)
{
marble(0.15,-0.5,-0.6,0.06,0.12,0.12,0);
targets++;
flag1[23]=0;
}
if(x>976 && x<1025 && y>635 && y<689 && flag1[24]==24)
{
marble(0.25,-0.5,-0.6,0.06,0.12,0.12,0);
targets++;
//flag1[24]=0;
}
cout<<targets<<endl;
cout<<x<<endl;
cout<<y<<endl;
glutIdleFunc(total);
}
如果程序在不同分辨率的不同计算机上运行,则用于检测点击的鼠标坐标在绘制圆圈中会有所不同。
flag1用红色存储球号。
void mymouse(int button,int state,int x,int y){
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
drawCircle(x,y);
}
&#34;如何在任何屏幕尺寸的任何系统上均匀工作?&#34;