int TextInput::Input(char score[]) { Ocean2 ocean; ocean.ReadFigure(); Congratulation cong; cong.ReadFigure(); FsPollDevice(); while(FSKEY_NULL!=FsInkey() || 0!=FsInkeyChar()) { FsPollDevice(); } int count=0; for(;;) { FsPollDevice(); int key=FsInkey(); switch(key) { case FSKEY_ESC: return 0; case FSKEY_ENTER: return 1; case FSKEY_BS: str.BackSpace(); count--; break; } const char c=FsInkeyChar(); if(0!=c && 0!=isprint(c) && count<10) { str.Add(c); count++; } glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); cong.Drawcongratulation_png(); glRasterPos2d(460, 200); YsGlDrawFontBitmap20x32("SCORE"); glRasterPos2d(400, 200+50); YsGlDrawFontBitmap20x32(score); Drawocean2(450); ocean.Drawocean_png(); Draw(); FsSwapBuffers(); FsSleep(20); } return 0; }
void GameMenu::RunGameMenu2(void) { while(FSKEY_NULL!=FsInkey() || 0!=FsInkeyChar()) { FsPollDevice(); } key=FSKEY_NULL; for(;;) { FsPollDevice(); key=FsInkey(); if(key==FSKEY_ESC || key==FSKEY_S || key==FSKEY_M) { return; } glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); Initialize(); DrawBackground(); DrawObjects(); DrawWelcomeText(); DrawLogo(25, 575); FsSwapBuffers(); FsSleep(20); } }
void Show(int n,int x[],int toBeMoved1,int toBeMoved2) { FsPollDevice(); while(FSKEY_NULL==FsInkey()) { glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); VisualizeArrayContents(n,x,toBeMoved1,toBeMoved2); FsSwapBuffers(); FsPollDevice(); FsSleep(10); } }
void FsClearEventQueue(void) { for(;;) { int checkAgain=0; FsPollDevice(); int lb,mb,rb,mx,my; while(FSMOUSEEVENT_NONE!=FsGetMouseEvent(lb,mb,rb,mx,my) || FSKEY_NULL!=FsInkey() || 0!=FsInkeyChar() || 0!=FsCheckWindowExposure()) { checkAgain=1; } if(0!=lb || 0!=rb || 0!=mb) { checkAgain=1; } if(0!=FsCheckKeyHeldDown()) { checkAgain=1; } if(0==checkAgain) { break; } FsSleep(50); } }
int main(void) { int key; struct YsGLSLBitmapRenderer *bitmapRenderer; YsBitmap bmp; FsChangeToProgramDir(); bmp.LoadPng("flash01.png"); printf("Bitmap dimension %dx%d\n",bmp.GetWidth(),bmp.GetHeight()); FsOpenWindow(32,32,640,480,1); bitmapRenderer=YsGLSLCreateBitmapRenderer(); key=FSKEY_NULL; while(FSKEY_ESC!=key) { FsPollDevice(); key=FsInkey(); int mx,my,lb,mb,rb; FsGetMouseState(lb,mb,rb,mx,my); int wid,hei; FsGetWindowSize(wid,hei); glViewport(0,0,wid,hei); glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColor3ub(255,255,255); glBegin(GL_LINES); glVertex2i(270,240); glVertex2i(370,240); glVertex2i(320,190); glVertex2i(320,290); glEnd(); YsGLSLUseBitmapRenderer(bitmapRenderer); YsGLSLRenderRGBABitmap2D(bitmapRenderer,320,240,YSGLSL_HALIGN_RIGHT,YSGLSL_VALIGN_BOTTOM,bmp.GetWidth(),bmp.GetHeight(),bmp.GetRGBABitmapPointer()); YsGLSLEndUseBitmapRenderer(bitmapRenderer); FsSwapBuffers(); FsSleep(10); } YsGLSLDeleteBitmapRenderer(bitmapRenderer); return 0; }
void GameOver(int score) { int r=0; FsPollDevice(); while(FsInkey()!=0) { FsPollDevice(); } while(FsInkey()==0) { FsPollDevice(); int wid,hei; FsGetWindowSize(wid,hei); glViewport(0,0,wid,hei); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,(float)wid-1,(float)hei-1,0,-1,1); glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT); const char *msg1="Game Over"; char msg2[256]; glColor3ub(255,255,255); glRasterPos2i(32,32); glCallLists(strlen(msg1),GL_UNSIGNED_BYTE,msg1); sprintf(msg2,"Your score is %d",score); glRasterPos2i(32,48); glCallLists(strlen(msg2),GL_UNSIGNED_BYTE,msg2); FsSwapBuffers(); FsSleep(10); } }
int main(void) { FsOpenWindow(16,16,800,600,1); OglPrim a,b; a.AddVertex(100,100); a.AddVertex(200,100); a.AddVertex(120,170); a.AddVertex(150,65); a.AddVertex(180,170); b=a; a.Move(5,5); while(FSKEY_ESC!=FsInkey()) { FsPollDevice(); glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glColor3ub(0,0,0); a.Draw(GL_LINE_LOOP); if(0!=FsGetKeyState(FSKEY_LEFT)) { a.Move(-10,0); } if(0!=FsGetKeyState(FSKEY_RIGHT)) { a.Move(10,0); } if(0!=FsGetKeyState(FSKEY_UP)) { a.Move(0,-10); } if(0!=FsGetKeyState(FSKEY_DOWN)) { a.Move(0,10); } glColor3ub(0,0,255); b.Draw(GL_LINE_LOOP); FsSwapBuffers(); FsSleep(25); } return 0; }
int main(void) { FsOpenWindow(16,16,800,600,1); double rot=0.0; int fogEnabled=0; YsGLSLCreateSharedRenderer(); variColorRenderer=YsGLSLSharedVariColorMarkerByPointSprite3DRenderer(); monoColorRenderer=YsGLSLSharedMonoColorMarkerByPointSprite3DRenderer(); YsGLSLUse3DRenderer(variColorRenderer); YsGLSLSet3DRendererUniformMarkerDimension(variColorRenderer,10); YsGLSLSet3DRendererUniformMarkerType(variColorRenderer,YSGLSL_MARKER_TYPE_EMPTY_STAR); YsGLSLEndUse3DRenderer(variColorRenderer); YsGLSLUse3DRenderer(monoColorRenderer); YsGLSLSet3DRendererUniformMarkerDimension(monoColorRenderer,10); YsGLSLSet3DRendererUniformMarkerType(monoColorRenderer,YSGLSL_MARKER_TYPE_EMPTY_STAR); GLfloat col[4]={1,1,1,1}; YsGLSLSet3DRendererUniformColorfv(monoColorRenderer,col); YsGLSLEndUse3DRenderer(monoColorRenderer); for(int key=FSKEY_NULL; FSKEY_ESC!=key; FsSleep(10)) { FsPollDevice(); key=FsInkey(); FsSimpleWindowIntervalCallBack(); if(FSKEY_F==key) { fogEnabled=1-fogEnabled; //YsGLSLUse3DRenderer(flatRenderer); //YsGLSLSet3DRendererUniformFogEnabled(flatRenderer,fogEnabled); //YsGLSLSet3DRendererUniformFogDensity(flatRenderer,.07); //YsGLSLEndUse3DRenderer(flatRenderer); //YsGLSLUse3DRenderer(variColRenderer); //YsGLSLSet3DRendererUniformFogEnabled(variColRenderer,fogEnabled); //YsGLSLSet3DRendererUniformFogDensity(variColRenderer,.08); //YsGLSLEndUse3DRenderer(variColRenderer); } } YsGLSLDeleteSharedRenderer(); return 0; }
int main(int ac,char *av[]) { FsLazyWindowApplicationBase::GetApplication()->BeforeEverything(ac,av); FsOpenWindowOption owo; owo.useDoubleBuffer=true; FsLazyWindowApplicationBase::GetApplication()->GetOpenWindowOption(owo); FsOpenWindow(owo); FsLazyWindowApplicationBase::GetApplication()->Initialize(ac,av); // Memo: Don't register call backs before Initialize. // Some of the call-back functions may be accidentally fired from inside FsOpenWindow. FsRegisterIntervalCallBack(IntervalCallBack,nullptr); FsRegisterOnPaintCallBack(NeedRedrawCallBack,nullptr); FsRegisterCloseWindowCallBack(UserWantToCloseProgram,nullptr); auto t0=FsSubSecondTimer(); while(0!=FsCheckWindowOpen() && true!=FsLazyWindowApplicationBase::GetApplication()->MustTerminate()) { auto t=FsSubSecondTimer(); auto passed=t-t0; t0=t; FsPollDevice(); FsLazyWindowApplicationBase::GetApplication()->Interval(); if(0!=FsCheckWindowExposure() || true==FsLazyWindowApplicationBase::GetApplication()->NeedRedraw()) { FsLazyWindowApplicationBase::GetApplication()->Draw(); } auto sleepMS=FsLazyWindowApplicationBase::GetApplication()->GetMinimumSleepPerInterval(); if(sleepMS>passed) { FsSleep(sleepMS-(int)passed); } } FsLazyWindowApplicationBase::GetApplication()->BeforeTerminate(); FsCloseWindow(); return 0; }
int Game(void) { DWORD passedTime = 0; FsPassedTime(true); //////////// initial setting up the scene //////////////////////////////////////// int timeSpan = 33; // milliseconds double timeInc = (double)timeSpan * 0.001; // time increment in seconds FsGetWindowSize(width, height); int lb,mb,rb,mx,my; glViewport(0, 0, width, height); ////////////////////// main simulation loop ////////////////////////// while (1) { FsPollDevice(); FsGetMouseState(lb,mb,rb,mx,my); int key=FsInkey(); if(key == FSKEY_ESC) break; timeInc = (double)(passedTime) * 0.001; clocktime += timeInc; /////////// update physics ///////////////// updateNumPhysics(simBall1, timeInc); updatePrecisePhysics(realBall, timeInc); ///////////////////////////////////////// renderScene(); ////// update time lapse ///////////////// passedTime = FsPassedTime(); // Making it up to 50fps int timediff = timeSpan-passedTime; // printf("\ntimeInc=%f, passedTime=%d, timediff=%d", timeInc, passedTime, timediff); while(timediff >= timeSpan/3) { FsSleep(5); passedTime=FsPassedTime(); // Making it up to 50fps timediff = timeSpan-passedTime; // printf("--passedTime=%d, timediff=%d", passedTime, timediff); } passedTime=FsPassedTime(true); // Making it up to 50fps } return 0; }
int main(void) { FsOpenWindow(16,16,800,600,1); MouseChaser diamond; MovableByArrowKeys square; const int nMovable=2; Movable *movables[nMovable]={&diamond,&square}; for(int i=0; i<nMovable; ++i) { movables[i]->SetPosition(400,300); } for(;;) { FsPollDevice(); const int key=FsInkey(); if(FSKEY_ESC==key) { break; } for(int i=0; i<nMovable; ++i) { movables[i]->Move(); } glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); for(int i=0; i<nMovable; ++i) { movables[i]->Draw(); } FsSwapBuffers(); FsSleep(25); } return 0; }
int main () { srand(time(NULL)); FsOpenWindow(0,0,600, 800,1); glClearColor(0, 0, 0, 1); glShadeModel(GL_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); textureInit(); WeaponUpgrade::LoadTexture("pic/red.png", "pic/green.png", "pic/blue.png"); Plane *plane; plane = new WeaponUpgrade(); bool running = true; while(running) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); FsPollDevice(); int key=FsInkey(); int lb, mb, rb, mx, my; int mouse = FsGetMouseEvent(lb, mb, rb, mx, my); if(FSKEY_ESC==key) { running=false; } plane->Draw(); plane->Move(1.0); if (((Prize *)plane)->Dead()) { delete plane; plane = new WeaponUpgrade(); } FsSwapBuffers(); FsSleep(25); } return 0; }
int main() { double L,h; double x,y=0; printf("24-780 Engineering Computation Problem Set 2-2 – Mass-Spring System Enter L and h:"); scanf("%lf %lf",&L,&h); FsOpenWindow(100,100,800,600,0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); transform(x,y,L,h); drawwall(x,y); drawspring(x,y,L,h); drawbox(x,y,L,h); glEnd(); glFlush(); while(FSKEY_ESC!=FsInkey()) { FsPollDevice(); FsSleep(25); } return 0; }
int main (void) { const double YS_PI=3.1415927; FsOpenWindow(16, 16, 800, 600, 1); int ObstaclesState[5]; int x1[5], y1[5], x2[5], y2[5]; int Point[10000];//trajectory int p[10000],q[10000];//trajectory srand((unsigned)time(NULL)); // for(int i=0;i<10000;i++) // { // Point[i]=1; // }//draw points for(int i=0;i<5;++i) { x1[i]=rand()%720; y1[i]=rand()%520; x2[i]=x1[i]+80+rand()%70; y2[i]=y1[i]+80+rand()%70; ObstaclesState[i]=1; } int terminate=0; int y=0; int x=30; int a=55; int b=545; double m=1.0; double dt=0.025; int CannonballState=0; int angle=30; double vx; double vy; int Hit=0; int TargetState=1; while(0==terminate) { FsPollDevice(); angle++; if(angle>=90) angle=0; int key=FsInkey(); if(FSKEY_ESC==key) { terminate=1; } else if(FSKEY_SPACE==key) { if(0==CannonballState) { CannonballState=1; vx=cos(angle*YS_PI/180)*400; vy=-sin(angle*YS_PI/180)*400; } } //draw screen glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); if(0!=ObstaclesState) { for(int i=0; i<5; ++i) { if(0!=ObstaclesState[i]) { DrawObstacles(x1[i],y1[i],x2[i],y2[i]); if(0!=CannonballState && 0!=CheckCollision(a, b, x1[i], y1[i], x2[i], y2[i])) { printf("Hit An Obstacle!\n"); ObstaclesState[i]=0; CannonballState=0; Hit=1; a=55; b=545; } } if(0!=Hit) { DrawObstacles2(x1[i],y1[i],x2[i],y2[i]); } } } if(0!=TargetState) { if(0!=CannonballState && 0!=CheckHit(a, b, y)) { printf("HitTarget!\n"); TargetState=0; CannonballState=0; break; } } DrawCannonLine(x); RotateCannonline(x, 90); DrawCannon(); DrawTarget(y); MoveTarget(y, 600); if(0!=CannonballState) { DrawCannonball(a, b); MoveCannonball(a, b, vx, vy, m, dt); // for(int i=0;i<10000;i++) // { // Point[i]=1; // }//draw points // if(0!=Point)//not working // { for(int i=0; i<10000; ++i) { // if(0!=Point[i]) // { p[i]=a; // printf("%d\n",a); q[i]=b; // DrawTrajectory(p[i], q[i]); /// } // } } if(a>800||b>600) { CannonballState=0; a=55; b=545; } } FsSwapBuffers(); FsSleep(25); } return 0; }
int main(void) { Frame fra; int lb, mb, rb, rx, ry;//mouse variables int mode=0; int isWarp=1; // in the warp or compete mode int winner=0; int mouseDown=0; int winWid,winHei; Button Left[4]; Button Right[4]; Button Menu[6]; YsRawPngDecoder image1; YsRawPngDecoder image2; makegif gif; TextString FaceLocation[4]; TextString TemplateLocation[4]; int pos1[4]; int pos2[4]; int image2Pos[2][4]; //the first index is the image, the second index is the position int faceChosen; int templateChosen; //////////////////////////////////////////////////////////////////// // initialize the positions //////////////////////////////////////////////////////////////////// image2Pos[0][0]=95; image2Pos[0][1]=12; image2Pos[0][2]=153; image2Pos[0][3]=85; image2Pos[1][0]=290; image2Pos[1][1]=25; image2Pos[1][2]=410; image2Pos[1][3]=155; //////////////////////////////////////////////////////////////////// // initialize the face & template locations //////////////////////////////////////////////////////////////////// FaceLocation[0].Set("face0.png"); FaceLocation[1].Set("face1.png"); FaceLocation[2].Set("face2.png"); FaceLocation[3].Set("face3.png"); TemplateLocation[0].Set("template0.png"); TemplateLocation[1].Set("template1.png"); TemplateLocation[2].Set("GIF1/01.png"); TemplateLocation[3].Set("GIF2/01.png"); /////////////////////////////////////////////////////////////////////// // initialize the buttons /////////////////////////////////////////////////////////////////////// for (int i=0; i<4; i++) { Left[i].wid=160; Left[i].hei=120; Right[i].wid=160; Right[i].hei=120; } Left[0].init(20, 50, "Picture 1"); Left[1].init(20, 200, "Picture 2"); Left[2].init(20, 350, "Picture 3"); Left[3].init(20, 500, "Picture 4"); Right[0].init(1120, 50, "Template 1"); Right[1].init(1120, 200, "Template 2"); Right[2].init(1120, 350, "Gif 1"); Right[3].init(1120, 500, "Gif 2"); for (int i=0; i<6; i++) { Menu[i].wid=80; Menu[i].hei=20; } Menu[0].init(20, 5, "Start"); Menu[1].init(120, 5, "Compete"); Menu[2].init(220, 5, "Rotate"); Menu[3].init(320, 5, "Clear"); Menu[4].init(420, 5, "Exit"); Menu[5].init(520, 5, "Help"); FsOpenWindow(64,16,1300,700,1); fra.display(); FsGetWindowSize(winWid,winHei); while(1) { mouseDown=0; FsPollDevice(); glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); fra.DrawToolbox(); fra.DrawColum(); fra.DrawShowWindow(); fra.DrawExit(); for (int i=0; i<4; i++) { Left[i].draw(); Right[i].draw(); } for (int i=0; i<6; i++) { Menu[i].draw(); } //////////////////////////////////////////////////////////////////////// // get button states //////////////////////////////////////////////////////////////////////// if(FsGetMouseEvent(lb,mb,rb,rx,ry)==FSMOUSEEVENT_LBUTTONDOWN) { mouseDown=1; for (int i=0; i<4; i++) { Left[i].checkPressed(rx, ry); Right[i].checkPressed(rx, ry); } for (int i=0; i<6; i++) { Menu[i].checkPressed(rx, ry); } } if (Menu[3].state==1) { mode=WAIT_LEFTBUT; Menu[3].state=0; isWarp=1; Menu[1].state=0; winner=0; } if (Menu[1].state==1) { isWarp=0; } if (Menu[4].state==1) { break; } /////////////////////////////////////////////////////////////// // switch among different state of the game //////////////////////////////////////////////////////////////// if (isWarp==1) //in the warp mode { switch(mode) { case WAIT_LEFTBUT: { for (int i=0; i<4; i++) { if (Left[i].state==1) // if pressed { if(YSOK==image1.Decode(FaceLocation[i].GetPointer())) { printf(FaceLocation[i].GetPointer()); mode=WAIT_POS1; Left[i].state=0; faceChosen=i; break; } } } break; } case WAIT_POS1: { if (mouseDown==1) { if (rx-300<=image1.wid && 550-ry<=image1.hei && rx-300>0 && 550-ry>0) { pos1[0]=rx-300; pos1[1]=image1.hei-(550-ry); mouseDown=0; mode=WAIT_POS2; printf("first pos %d %d\n",pos1[0],pos1[1]); } } break; } case WAIT_POS2: { if (mouseDown==1) { if (rx-300<=image1.wid && 550-ry<=image1.hei && rx-300>0 && 550-ry>0) { pos1[2]=rx-300; pos1[3]=image1.hei-(550-ry); mouseDown=0; mode=WAIT_TEMPLATE; printf("second pos %d %d\n",pos1[2],pos1[3]); } } break; } case WAIT_TEMPLATE: { for (int i=0; i<2; i++) { if (Right[i].state==1) // if pressed { if(YSOK==image2.Decode(TemplateLocation[i].GetPointer())) { mode=WAIT_WARP; Right[i].state=0; templateChosen=i; pos2[0]=image2Pos[i][0]; pos2[1]=image2Pos[i][1]; pos2[2]=image2Pos[i][2]; pos2[3]=image2Pos[i][3]; break; } } } if (Right[2].state==1) { if(YSOK==image2.Decode(TemplateLocation[2].GetPointer())) { mode=WAIT_WARP; Right[2].state=0; templateChosen=2; //printf("GIF1\n"); //char *image1String=FaceLocation[faceChosen].GetPointer(); char gifString[]={"GIF1/01.png"}; //char gifString[]={"GIF2/01.png"}; gif.initial(gifString,image2,12,15,0,45,40); //initial the gif class //gif.initial(gifString,image2,4,160,50,260,165); //initial the gif class gif.setImage1(image1,FaceLocation[faceChosen].GetPointer()); // select the head picture gif.setImage1HeadLT(pos1[0],pos1[1]); // select the left top point of the head picture gif.setImage2HeadRB(pos1[2],pos1[3]); // select the right bottom point of the head picture gif.copyRGBA(image1,image2); break; } break; } if (Right[3].state==1) { if(YSOK==image2.Decode(TemplateLocation[3].GetPointer())) { mode=WAIT_WARP; Right[3].state=0; templateChosen=3; //printf("GIF1\n"); //char *image1String=FaceLocation[faceChosen].GetPointer(); //char gifString[]={"GIF1/01.png"}; char gifString[]={"GIF2/01.png"}; printf(FaceLocation[faceChosen].GetPointer()); //gif.initial(gifString,image2,12,15,0,45,40); //initial the gif class gif.initial(gifString,image2,4,160,50,260,165); //initial the gif class gif.setImage1(image1,FaceLocation[faceChosen].GetPointer()); // select the head picture gif.setImage1HeadLT(pos1[0],pos1[1]); // select the left top point of the head picture gif.setImage2HeadRB(pos1[2],pos1[3]); // select the right bottom point of the head picture gif.copyRGBA(image1,image2); break; } break; } break; } case WAIT_WARP: { if (Menu[0].state==1) { warpImage(image1, image2, pos1, pos2, 0.0); mode=FINISHED; Menu[0].state=0; } if (Menu[2].state==1) { warpImage(image1, image2, pos1, pos2,-20.0); mode=FINISHED; Menu[2].state=0; } break; } case FINISHED: { if (Menu[3].state==1) { mode=WAIT_LEFTBUT; Menu[3].state=0; } break; } } } else { switch(mode) { case WAIT_LEFTBUT: { for (int i=0; i<4; i++) { if (Left[i].state==1) // if pressed { if(YSOK==image1.Decode(FaceLocation[i].GetPointer())) { printf(FaceLocation[i].GetPointer()); mode=WAIT_TEMPLATE; Left[i].state=0; //faceChosen=i; break; } } } break; } case WAIT_TEMPLATE: { for (int i=0; i<4; i++) { if (Left[i].state==1) // if pressed { if(YSOK==image2.Decode(FaceLocation[i].GetPointer())) { printf(FaceLocation[i].GetPointer()); mode=WAIT_WARP; Left[i].state=0; //faceChosen=i; break; } } } break; } case WAIT_WARP: { if (Menu[0].state==1) { winner=BeautyCompetition(image1,image2); glRasterPos2d(300.0,(double)(winHei-50)); if (winner==1) { YsGlDrawFontBitmap20x32("PICTURE 1 WINS!"); } else if (winner==2) { YsGlDrawFontBitmap20x32("PICTURE 2 WINS!"); } printf("\nWINNER:%d!!!\n",winner); mode=FINISHED; Menu[0].state=0; } break; } case FINISHED: { if (Menu[3].state==1) { mode=WAIT_LEFTBUT; Menu[3].state=0; winner=0; } break; } } } /////////////////////////////////////////////////////////////// // actually draw ////////////////////////////////////////////////////////////// if (mode==WAIT_LEFTBUT) { //do nothing } else if (mode>WAIT_LEFTBUT && mode<=WAIT_TEMPLATE) { image1.Flip(); FsGetWindowSize(winWid,winHei); glRasterPos2d(300.0,(double)(winHei-150)); glDrawPixels(image1.wid,image1.hei,GL_RGBA,GL_UNSIGNED_BYTE,image1.rgba); image1.Flip(); } else if (mode>WAIT_TEMPLATE && mode<=FINISHED) { if (templateChosen<2) { image2.Flip(); FsGetWindowSize(winWid,winHei); glRasterPos2d(300.0,(double)(winHei-150)); glDrawPixels(image2.wid,image2.hei,GL_RGBA,GL_UNSIGNED_BYTE,image2.rgba); image2.Flip(); } else if(templateChosen==2 || templateChosen==3) { if (mode==FINISHED) { gif.draw(); } else { image2.Flip(); FsGetWindowSize(winWid,winHei); glRasterPos2d(300.0,(double)(winHei-150)); glDrawPixels(image2.wid,image2.hei,GL_RGBA,GL_UNSIGNED_BYTE,image2.rgba); image2.Flip(); } } if (winner==1) { glRasterPos2d(300.0,(double)(winHei-50)); YsGlDrawFontBitmap20x32("PICTURE 1 WINS!"); } else if (winner==2) { glRasterPos2d(300.0,(double)(winHei-50)); YsGlDrawFontBitmap20x32("PICTURE 2 WINS!"); } } FsSwapBuffers(); FsSleep(25); } return 0; }
void Button::Remap2() { FsClearEventQueue(); FsGetWindowSize (windowWid, windowHei); while(FSKEY_NULL!=FsInkey() || 0!=FsInkeyChar()) { FsPollDevice(); } //Initialize(); while(SF2==0 || checkGameControl(SF2) ) { FsPollDevice(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); DrawBackground(); DrawModeTitle2(); DrawKeyboardSetting(); double y=180.0; double dy=40.0; glColor3ub(255, 255, 255); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Up : (press key to remap)"); DrawLogo(25, 575); SF2=FsInkey(); FsSwapBuffers(); FsSleep(20); } while(SB2==0 || checkGameControl(SB2)) { FsPollDevice(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); DrawBackground(); DrawModeTitle2(); DrawKeyboardSetting(); double y=180.0; double dy=40.0; glColor3ub(155, 155, 155); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Up : (OK)"); y+=dy; glColor3ub(255, 255, 255); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Down : (press key to remap)"); DrawLogo(25, 575); SB2=FsInkey(); FsSwapBuffers(); FsSleep(20); } while(SL2==0 || checkGameControl(SL2)) { FsPollDevice(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); DrawBackground(); DrawModeTitle2(); DrawKeyboardSetting(); double y=180.0; double dy=40.0; glColor3ub(155, 155, 155); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Up : (OK)"); y+=dy; glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Down : (OK)"); y+=dy; glColor3ub(255, 255, 255); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Left : (press key to remap)"); DrawLogo(25, 575); SL2=FsInkey(); FsSwapBuffers(); FsSleep(20); } while(SR2==0 || checkGameControl(SR2)) { FsPollDevice(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); DrawBackground(); DrawModeTitle2(); DrawKeyboardSetting(); double y=180.0; double dy=40.0; glColor3ub(155, 155, 155); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Up : (OK)"); y+=dy; glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Down : (OK)"); y+=dy; glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Left : (OK)"); y+=dy; glColor3ub(255, 255, 255); glRasterPos2d(100,y); YsGlDrawFontBitmap16x20 ("Right : (press key to remap)"); DrawLogo(25, 575); SR2=FsInkey(); FsSwapBuffers(); FsSleep(20); } }
/* void MAP::SaveMap(char* nameOfNewMap) { char fn[256]; char ioBuffer[256]; FILE *fpp; //char nameOfNewMap[256]; //printf("Name the map you want to save: \n"); // create a new map name //scanf("%s", nameOfNewMap); strcpy(fn,nameOfNewMap); fpp=fopen(fn,"w"); if (fpp!=NULL) { for (int i=0;i<mapWidth;i++) { for(int j=0;j<mapHeight;j++) { _itoa(mapGrid[i][j],ioBuffer,10); fwrite(ioBuffer,1,strlen(ioBuffer),fpp); fwrite("\n",1,1,fpp); } } printf("%s is saved successfully.\n",fn); } if(fpp!=NULL) { fclose(fpp); } } bool MAP::ChangeMap(int x, int y, MONSTER monster[])//monster[2] { int findPath = 0; if ( !(x>=0 && x<mapWidth && y>=0 && y<mapHeight) ) { //printf("Mouse is not on the map.\n"); return false; } else if (mapGrid[x][y]==UNWALKABLE) // walkable=1; unwalkable=0 { //printf("Tower exsited at this position.\n"); return false; } int mapGridDuplicate[mapWidth][mapHeight]; // deep copy the current map for (int i=0; i<mapWidth; i++) { for (int j=0; j<mapHeight; j++) { mapGridDuplicate[i][j] = mapGrid[i][j]; } } mapGridDuplicate[x][y] = UNWALKABLE; // check if all monsters can walk out after building the new tower for (int m=0; m<2; m++) { if (monster[m].state==1) { findPath = finder.FindPath(monster[m].GetX(), monster[m].GetY(),75,59,mapGrid); if (findPath!=1) { //printf("Tentative tower location (%d, %d) is invalid.\n", x, y); return false; } } } mapGrid[x][y]=UNWALKABLE; //printf("Paths are found and map is changed.\n"); return true; } */ void MAP::DrawMap(int pngProjX,int pngProjY,int ExitX,int ExitY) { int ProjectionX=pngProjX,ProjectionY=600-pngProjY; FsPollDevice(); //printf("ProjectionX:%d ProjectionY:%d\n",pngProjX,pngProjY); int winWid,winHei; FsGetWindowSize(winWid,winHei); glViewport(0,0,winWid,winHei); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,(float)winWid-1,(float)winHei-1,0,-1,1); glRasterPos2d(0,(double)winHei-1); //glDrawPixels(800,600,GL_RGBA,GL_UNSIGNED_BYTE,grassfield.rgba); unsigned char *VisibleGrass; VisibleGrass=new unsigned char [800*600*4]; for(int j=0;j<600;j++) for(int i=0;i<800;i++) { VisibleGrass[(j*800+i)*4] =grassfield.rgba[((j+pngProjY)*grassfield.wid+i+pngProjX)*4]; VisibleGrass[(j*800+i)*4+1] =grassfield.rgba[((j+pngProjY)*grassfield.wid+i+pngProjX)*4+1]; VisibleGrass[(j*800+i)*4+2] =grassfield.rgba[((j+pngProjY)*grassfield.wid+i+pngProjX)*4+2]; VisibleGrass[(j*800+i)*4+3] =grassfield.rgba[((j+pngProjY)*grassfield.wid+i+pngProjX)*4+3]; } glDrawPixels(800,600,GL_RGBA,GL_UNSIGNED_BYTE,VisibleGrass); delete [] VisibleGrass; int TileSize=1600/mapWidth; for(int i=0;i<mapWidth;i++) { for(int j=0;j<mapHeight;j++) { if(mapGrid[i][j]==UNWALKABLE //&& i*TileSize>=ProjectionX-TileSize && i*TileSize<ProjectionX+800 //&& j*TileSize>=ProjectionY-TileSize && j*TileSize<ProjectionY+600 ) { int winWid,winHei; FsGetWindowSize(winWid,winHei); glViewport(0,0,winWid,winHei); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,(float)winWid-1,(float)winHei-1,0,-1,1); glRasterPos2d(-ProjectionX+TileSize*i,-ProjectionY+TileSize*j+TileSize-1);//+(double)stonewall.hei);//winHei); glDrawPixels(stonewall.wid,stonewall.hei,GL_RGBA,GL_UNSIGNED_BYTE,stonewall.rgba); /* glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glColor4ub(255,0,0,50); glBegin(GL_QUADS); glVertex2i(-ProjectionX+TileSize*i,-ProjectionY+TileSize*j); glVertex2i(-ProjectionX+TileSize*i+TileSize,-ProjectionY+TileSize*j); glVertex2i(-ProjectionX+TileSize*i+TileSize,-ProjectionY+TileSize*j+TileSize); glVertex2i(-ProjectionX+TileSize*i,-ProjectionY+TileSize*j+TileSize); glEnd(); glDisable(GL_BLEND); */ } /*else if(mapGrid[i][j]==WALKABLE) { glColor3ub(255,100,0); glBegin(GL_QUADS); glVertex2i(TileSize*i,TileSize*j); glVertex2i(TileSize*i+TileSize,TileSize*j); glVertex2i(TileSize*i+TileSize,TileSize*j+TileSize); glVertex2i(TileSize*i,TileSize*j+TileSize); glEnd(); }*/ } } //int winWid,winHei; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); FsGetWindowSize(winWid,winHei); glViewport(0,0,winWid,winHei); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,(float)winWid-1,(float)winHei-1,0,-1,1); //printf("ExitX/tile:%d,Y:%d",ExitX*2/TileSize,ExitY*2/TileSize); glRasterPos2d(-ProjectionX+(ExitX*2/TileSize)*TileSize,-ProjectionY+(ExitY*2/TileSize)*TileSize+(double)exit.hei);//winHei); glDrawPixels(exit.wid,exit.hei,GL_RGBA,GL_UNSIGNED_BYTE,exit.rgba); glDisable(GL_BLEND); /*glColor3ub(0,0,0); glRasterPos2d(720,585); YsGlDrawFontBitmap16x24("Back");*/ }
int main(void) { double cubeMatrix[16]= { 1.0,0.0,0.0,0.0, 0.0,1.0,0.0,0.0, 0.0,0.0,1.0,0.0, 0.0,0.0,0.0,1.0 }; FsOpenWindow(32,32,800,600,1); // 800x600 pixels, useDoubleBuffer=1 glEnable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDepthFunc(GL_LESS); FsPassedTime(); // Reset the timer while(FsInkey()==0) { int mx,my,lb,mb,rb,passed; double spinX,spinY; passed=FsPassedTime(); FsPollDevice(); FsGetMouseState(lb,mb,rb,mx,my); int wid,hei,cx,cy; FsGetWindowSize(wid,hei); cx=wid/2; cy=hei/2; spinX=(double)((mx-cx)/10)*(double)passed/1000.0; // 1 pixel = degrees/sec spinY=(double)((my-cy)/10)*(double)passed/1000.0; // 1 pixel = degrees/sec glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glViewport(0,0,wid,hei); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,(double)wid/(double)hei,1.0,20.0); glTranslated(0.0,0.0,-10.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotated(spinX,0.0,1.0,0.0); glRotated(spinY,1.0,0.0,0.0); glMultMatrixd(cubeMatrix); glGetDoublev(GL_MODELVIEW_MATRIX,cubeMatrix); glBegin(GL_QUADS); glColor3ub(0,0,255); glVertex3d(-2.5,-2.5,-2.5); glVertex3d(-2.5, 2.5,-2.5); glVertex3d( 2.5, 2.5,-2.5); glVertex3d( 2.5,-2.5,-2.5); glColor3ub(255,0,0); glVertex3d(-2.5,-2.5, 2.5); glVertex3d(-2.5, 2.5, 2.5); glVertex3d( 2.5, 2.5, 2.5); glVertex3d( 2.5,-2.5, 2.5); glColor3ub(255,0,255); glVertex3d(-2.5,-2.5,-2.5); glVertex3d(-2.5,-2.5, 2.5); glVertex3d(-2.5, 2.5, 2.5); glVertex3d(-2.5, 2.5,-2.5); glColor3ub(0,255,0); glVertex3d( 2.5,-2.5,-2.5); glVertex3d( 2.5,-2.5, 2.5); glVertex3d( 2.5, 2.5, 2.5); glVertex3d( 2.5, 2.5,-2.5); glColor3ub(0,255,255); glVertex3d(-2.5,-2.5,-2.5); glVertex3d(-2.5,-2.5, 2.5); glVertex3d( 2.5,-2.5, 2.5); glVertex3d( 2.5,-2.5,-2.5); glColor3ub(255,255,0); glVertex3d(-2.5, 2.5,-2.5); glVertex3d(-2.5, 2.5, 2.5); glVertex3d( 2.5, 2.5, 2.5); glVertex3d( 2.5, 2.5,-2.5); glEnd(); FsSwapBuffers(); FsSleep(20-passed); } return 0; }
void Button::Update() { // Updates stored values of the button object FsPollDevice(); // Intigers such as U and D correspond to up and down buttons being pressed // If it is being pressed, it is a 1, otherwise it is a 0 if(0!=FsGetKeyState(SF)) F=1; else F=0; if(0!=FsGetKeyState(SB)) B=1; else B=0; if(0!=FsGetKeyState(SL)) L=1; else L=0; if(0!=FsGetKeyState(SR)) R=1; else R=0; if(0!=FsGetKeyState(SU)) U=1; else U=0; if(0!=FsGetKeyState(SD)) D=1; else D=0; if(0!=FsGetKeyState(FSKEY_ESC)) E=1; else E=0; if(0!=FsGetKeyState(GR)) reset =1; else reset = 0; if(0 != FsGetKeyState(GC)) cont = 1; else cont = 0; if(0 != FsGetKeyState(GP)) { pause = 1; } else pause = 0; if(0 != FsGetKeyState(G1)) one = 1; else one = 0; if(0 != FsGetKeyState(G2)) { two = 1; } else two = 0; }
void Map::RunMap() { key = 0; int offset=0; char *story[] = { "Welcome to CMU Adventure!", "Whether you have made up your mind to come to CMU or", "you are still mulling over it, you are welcome to use", "this game to have a glimpse of life at CMU.", " ", "To familiarize yourself with the CMU environment,", "navigate through the satellite view map of CMU campus ", // changes by Chun Fan "to explore all the buildings.", // changes by Chun Fan " ", "Studying constitutes a large part of CMU student life.", "CMU tries to make learning fun.See how MechE students", "learn CAD & gear theory by playing the CAD & Gear games", "at Hammerschlag Hall and Hunts library.", " ", "Sometimes massive number of assignments could means ", "many sleepless nights. Play the StayAwake game to see", // changes by Chun Fan "how CMU lecturers and students fight off sleeping bugs", "during lectures in Margaret-Morrison Hall.", " ", "Student life is not just about studying, recreation is", "essential too. Have some fun by playing the Pool game", "at University Center.", " ", "At CMU, safety is utmost important.CMU provides shuttle", "buses to ferry students and staffs back home safely.", "Play the Shuttle game at Porter Hall to have a feel on", "how it is like to catch a shuttle bus at CMU.", " ", "Press Enter to start game!" }; Building building[5]; building[0].set("Uiversity Center", 1374, 1239, 110, 136); building[1].set("Hunts Hall", 1042, 662, 70, 35); building[2].set("Hammerschlag Hall", 454, 984, 111, 90); building[3].set("Porter Hall", 626, 805, 115, 75); building[4].set("Margaret-Morisson", 1489, 938, 50, 90); if(YSOK==png.Decode("instructions_background.png")) { // changes by Chun Fan //printf("Read Width=%d Height=%d\n",png.wid,png.hei); png.Flip(); } else { printf("Read Error!\n"); return ; } // Story Cover Page glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); int winWid,winHei; FsGetWindowSize(winWid, winHei); glRasterPos2d(0.0, (double)(winHei-1)); glDrawPixels(png.wid, png.hei, GL_RGBA, GL_UNSIGNED_BYTE, png.rgba); if(YSOK==png.Decode("map-with light.png")) { // changes by Chun Fan //printf("Read Width=%d Height=%d\n",png.wid,png.hei); png.Flip(); } else { printf("Read Error!\n"); return ; } glColor3ub(0,0,255); int n_line=1; glRasterPos2d(75,75); YsGlDrawFontBitmap20x32(story[0]); glColor3ub(0,0,0); for (int i=1; i<28; i++) { n_line++; glRasterPos2d(75,75+16*n_line); YsGlDrawFontBitmap12x16(story[i]); } n_line++; glColor3ub(255,0,0); glRasterPos2d(75,75+16*n_line); YsGlDrawFontBitmap12x16(story[28]); FsSwapBuffers(); while (key!=FSKEY_ENTER) { FsPollDevice(); key = FsInkey(); FsSleep(20); } key=FSKEY_NULL; int Mnumber=0; while(FSKEY_ESC!=key) { FsPollDevice(); key=FsInkey(); glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); if (key==FSKEY_M) { Mnumber++; } if (Mnumber%2==0) { DramMap();//Include check player's position(whether player can step on that part or not) and move //the map. CheckPlayersState(); player.DrawPlayerInMap(); player.DrawMovingPlayerInCorner(player.PlayersState); } if (Mnumber%2==1) { ShowShrinkMap(); } // check position int x=GetPlayersPositionX(); int y=GetPlayersPositionY(); //printf("x = %d,\t y = %d\n", x, y); srand((unsigned int)time(NULL) + rand()); for (int i=0; i<5; i++) { int x_min = building[i].getX() - building[i].getW() ; int x_max = building[i].getX() + building[i].getW() ; int y_min = building[i].getY() - building[i].getH() ; int y_max = building[i].getY() + building[i].getH() ; if (x>x_min && x<x_max && y>y_min && y<y_max) { //char name[256]; YsRawPngDecoder png4; int state0=0,state1=0,state2=0,state3=0,state4=0; FsPollDevice(); int MouseEvent; int lb,mb,rb,mx,my; //building[i].getName(name); //printf("I am in %s!\n", name); switch (i) { case 0: // pool if(YSOK==png4.Decode("ClickButton.png")) { png4.Flip(); int winWid,winHei; FsGetWindowSize(winWid,winHei); glRasterPos2d(400,300); glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba); // changes by Chun Fan //printf("%d %d",png4.wid,png4.hei); } MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my); switch(MouseEvent) { case FSMOUSEEVENT_LBUTTONDOWN: if(mx>=400 && mx<=600 && my>=200 && my<=300) { state0=1; } } if(state0==1) { score.setResult(0, poolgame.rungame()); // changes by Chun Fan //printf("Game 1: %d trials, %s\n", score.getCount(0), score.getResult(0)?"Passed":"Failed"); FsClearEventQueue(); } state0=0; //FsClearEventQueue(); break; case 1: // CAD if(YSOK==png4.Decode("ClickButton.png")) { png4.Flip(); int winWid,winHei; FsGetWindowSize(winWid,winHei); glRasterPos2d(400,300); glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba); // changes by Chun Fan //printf("%d %d",png4.wid,png4.hei); } MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my); switch(MouseEvent) { case FSMOUSEEVENT_LBUTTONDOWN: if(mx>=400 && mx<=600 && my>=200 && my<=300) { state1=1; } } if(state1==1) { score.setResult(1, cadclass.CADMain()); // changes by Chun Fan //printf("Game 2: %d trials, %s\n", score.getCount(1), score.getResult(1)?"Passed":"Failed"); FsClearEventQueue(); } state1=0; //FsClearEventQueue(); break; case 2: // gear game if(YSOK==png4.Decode("ClickButton.png")) { png4.Flip(); int winWid,winHei; FsGetWindowSize(winWid,winHei); glRasterPos2d(400,300); glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba); // changes by Chun Fan //printf("%d %d",png4.wid,png4.hei); } MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my); switch(MouseEvent) { case FSMOUSEEVENT_LBUTTONDOWN: if(mx>=400 && mx<=600 && my>=200 && my<=300) { state2=1; } } if(state2==1) { score.setResult(2, geargame.run()); // changes by Chun Fan //printf("Game 3: %d trials, %s\n", score.getCount(2), score.getResult(2)?"Passed":"Failed"); // changes by Chun Fan glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); FsClearEventQueue(); } state2=0; //FsClearEventQueue(); break; case 3: if( score.getGraduate()) { if(YSOK==png4.Decode("ClickButton.png")) { png4.Flip(); int winWid,winHei; FsGetWindowSize(winWid,winHei); glRasterPos2d(400,300); glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba); // changes by Chun Fan //printf("%d %d",png4.wid,png4.hei); } MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my); switch(MouseEvent) { case FSMOUSEEVENT_LBUTTONDOWN: if(mx>=400 && mx<=600 && my>=200 && my<=300) { state3=1; } } } if(state3==1 ) { shuttle.action(); glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); score.DrawScoreCard(); FsSwapBuffers(); FsPollDevice(); int key1 = FsInkey(); while(key1!=FSKEY_ENTER) { FsPollDevice(); key1 = FsInkey(); FsSleep(20); } glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); awardStage.SetDept("Mechanical Engineering"); awardStage.DrawStage(); awardStage.PrintCert(); FsSwapBuffers(); FsPollDevice(); key1 = FsInkey(); while(key1!=FSKEY_ENTER) { FsPollDevice(); key1 = FsInkey(); FsSleep(20); } key=FSKEY_ESC; } state3=0; //if (checkscore()==1) FsClearEventQueue(); break; case 4: // stayawake if(YSOK==png4.Decode("ClickButton.png")) { png4.Flip(); int winWid,winHei; FsGetWindowSize(winWid,winHei); glRasterPos2d(400,300); glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba); // changes by Chun Fan //printf("%d %d",png4.wid,png4.hei); } MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my); switch(MouseEvent) { case FSMOUSEEVENT_LBUTTONDOWN: if(mx>=400 && mx<=600 && my>=200 && my<=300) { state4=1; } } if(state4==1) { stayawake.StartGame(); score.setResult(3, stayawake.GetScore()); // changes by Chun Fan //printf("Game 4: %d trials, %s\n", score.getCount(3), score.getResult(3)?"Passed":"Failed"); FsClearEventQueue(); } state4=0; //FsClearEventQueue(); break; } } } FsSwapBuffers(); FsSleep(50); } }
int Menu(void) { int r=0,key; const double angleInc = PI/180.; while(r!=eStart && r!= eStop) { FsPollDevice(); key=FsInkey(); switch(key) { case FSKEY_S: r=eStart; break; case FSKEY_ESC: r=eStop; break; case FSKEY_UP: iSpeed++; break; case FSKEY_DOWN: iSpeed = max(2., iSpeed-1); break; case FSKEY_LEFT: iAngle = max(0., iAngle-angleInc); break; case FSKEY_RIGHT: iAngle = min(90.0, iAngle+angleInc); break; } initPhysics(radius, iSpeed, iAngle); if (r == eStop) return r; int wid,hei; FsGetWindowSize(wid,hei); glViewport(0,0,wid,hei); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-0.5,(GLdouble)wid-0.5,(GLdouble)hei-0.5,-0.5,-1,1); glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3ub(127,127,127); char sSpeed[128]; sprintf(sSpeed, "Initial ball speed is %f m/s. Use Up/Down keys to change it!\n", iSpeed); char sAngle[128]; sprintf(sAngle, "Initial horizon Angle is %f degrees. Use Left/Right keys to change it!\n", iAngle*180./PI); glColor3ub(255,255,255); glRasterPos2i(32,32); glCallLists(strlen(sSpeed),GL_UNSIGNED_BYTE,sSpeed); glRasterPos2i(32,64); glCallLists(strlen(sAngle),GL_UNSIGNED_BYTE,sAngle); const char *msg1="S.....Start Game"; const char *msg2="ESC...Exit"; glRasterPos2i(32,96); glCallLists(strlen(msg1),GL_UNSIGNED_BYTE,msg1); glRasterPos2i(32,128); glCallLists(strlen(msg2),GL_UNSIGNED_BYTE,msg2); FsSwapBuffers(); FsSleep(10); } return r; }
int main(void) { GLfloat vtx[3*3*2*8*16],texCoord[3*3*2*8*16],nom[3*3*2*8*16],col[3*4*2*8*16]; int nVtx=MakeSphere(vtx,texCoord,nom,col,16,8); YsBitmap bmp[6]; bmp[0].LoadPng("explosion01.png"); bmp[1].LoadPng("explosion02.png"); bmp[2].LoadPng("explosion03.png"); bmp[3].LoadPng("explosion04.png"); bmp[4].LoadPng("explosion05.png"); bmp[5].LoadPng("flash01.png"); FsOpenWindow(16,16,800,600,1); YsGLSL3DRenderer *variColorPerVtxShadingRenderer=YsGLSLCreateVariColorPerVtxShading3DRenderer(); YsGLSL3DRenderer *monoColorPerVtxShadingRenderer=YsGLSLCreateMonoColorPerVtxShading3DRenderer(); YsGLSL3DRenderer *monoColorPerPixShadingRenderer=YsGLSLCreateMonoColorPerPixShading3DRenderer(); YsGLSL3DRenderer *variColorPerPixShadingRenderer=YsGLSLCreateVariColorPerPixShading3DRenderer(); YsGLSL3DRenderer *monoColorPerVtxShadingWithTexRenderer=YsGLSLCreateMonoColorPerVtxShadingWithTexCoord3DRenderer(); YsGLSL3DRenderer *variColorPerVtxShadingWithTexRenderer=YsGLSLCreateVariColorPerVtxShadingWithTexCoord3DRenderer(); YsGLSL3DRenderer *monoColorPerPixShadingWithTexRenderer=YsGLSLCreateMonoColorPerPixShadingWithTexCoord3DRenderer(); YsGLSL3DRenderer *variColorPerPixShadingWithTexRenderer=YsGLSLCreateVariColorPerPixShadingWithTexCoord3DRenderer(); YsGLSL3DRenderer *renderer3d=monoColorPerVtxShadingRenderer; printf("SPACE Switch between Per Vertex and Per Pixel renderers.\n"); GLuint texId; glGenTextures(1,&texId); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,texId); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,bmp[0].GetWidth(),bmp[0].GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,bmp[0].GetRGBABitmapPointer()); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); double rot=0.0; int bmpId=0; for(int key=FSKEY_NULL; FSKEY_ESC!=key; FsSleep(10)) { FsPollDevice(); key=FsInkey(); switch(key) { case FSKEY_ENTER: bmpId=(bmpId+1)%6; glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,bmp[bmpId].GetWidth(),bmp[bmpId].GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,bmp[bmpId].GetRGBABitmapPointer()); break; case FSKEY_SPACE: if(renderer3d==monoColorPerVtxShadingRenderer) { renderer3d=monoColorPerPixShadingRenderer; } else if(renderer3d==monoColorPerPixShadingRenderer) { renderer3d=variColorPerVtxShadingRenderer; } else if(renderer3d==variColorPerVtxShadingRenderer) { renderer3d=variColorPerPixShadingRenderer; } else if(renderer3d==variColorPerPixShadingRenderer) { renderer3d=monoColorPerVtxShadingWithTexRenderer; } else if(renderer3d==monoColorPerVtxShadingWithTexRenderer) { renderer3d=variColorPerVtxShadingWithTexRenderer; } else if(renderer3d==variColorPerVtxShadingWithTexRenderer) { renderer3d=monoColorPerPixShadingWithTexRenderer; } else if(renderer3d==monoColorPerPixShadingWithTexRenderer) { renderer3d=variColorPerPixShadingWithTexRenderer; } else { renderer3d=monoColorPerVtxShadingRenderer; } break; } glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); int wid,hei; FsGetWindowSize(wid,hei); const double aspect=(double)wid/(double)hei; GLfloat modelview[16],projection[16],tfm[16]; YsGLMakePerspectivefv(projection,YSGLPI/6.0,aspect,1.0,50.0); YsGLMakeIdentityfv(modelview); YsGLMakeTranslationfv(tfm,0.0,0.0,-15.0); YsGLMultMatrixfv(modelview,modelview,tfm); YsGLMakeXZRotationfv(tfm,rot); YsGLMultMatrixfv(modelview,modelview,tfm); YsGLMakeScalingfv(tfm,3.0,3.0,3.0); YsGLMultMatrixfv(modelview,modelview,tfm); YsGLSLUse3DRenderer(monoColorPerVtxShadingRenderer); YsGLSLSet3DRendererProjectionfv(monoColorPerVtxShadingRenderer,projection); YsGLSLSet3DRendererModelViewfv(monoColorPerVtxShadingRenderer,modelview); YsGLSLEndUse3DRenderer(monoColorPerVtxShadingRenderer); YsGLSLUse3DRenderer(variColorPerVtxShadingRenderer); YsGLSLSet3DRendererProjectionfv(variColorPerVtxShadingRenderer,projection); YsGLSLSet3DRendererModelViewfv(variColorPerVtxShadingRenderer,modelview); YsGLSLEndUse3DRenderer(variColorPerVtxShadingRenderer); YsGLSLUse3DRenderer(monoColorPerPixShadingRenderer); YsGLSLSet3DRendererProjectionfv(monoColorPerPixShadingRenderer,projection); YsGLSLSet3DRendererModelViewfv(monoColorPerPixShadingRenderer,modelview); YsGLSLEndUse3DRenderer(monoColorPerPixShadingRenderer); YsGLSLUse3DRenderer(variColorPerPixShadingRenderer); YsGLSLSet3DRendererProjectionfv(variColorPerPixShadingRenderer,projection); YsGLSLSet3DRendererModelViewfv(variColorPerPixShadingRenderer,modelview); YsGLSLEndUse3DRenderer(variColorPerPixShadingRenderer); YsGLSLUse3DRenderer(monoColorPerVtxShadingWithTexRenderer); YsGLSLSet3DRendererProjectionfv(monoColorPerVtxShadingWithTexRenderer,projection); YsGLSLSet3DRendererModelViewfv(monoColorPerVtxShadingWithTexRenderer,modelview); YsGLSLEndUse3DRenderer(monoColorPerVtxShadingWithTexRenderer); YsGLSLUse3DRenderer(variColorPerVtxShadingWithTexRenderer); YsGLSLSet3DRendererProjectionfv(variColorPerVtxShadingWithTexRenderer,projection); YsGLSLSet3DRendererModelViewfv(variColorPerVtxShadingWithTexRenderer,modelview); YsGLSLEndUse3DRenderer(variColorPerVtxShadingWithTexRenderer); YsGLSLUse3DRenderer(monoColorPerPixShadingWithTexRenderer); YsGLSLSet3DRendererProjectionfv(monoColorPerPixShadingWithTexRenderer,projection); YsGLSLSet3DRendererModelViewfv(monoColorPerPixShadingWithTexRenderer,modelview); YsGLSLEndUse3DRenderer(monoColorPerPixShadingWithTexRenderer); YsGLSLUse3DRenderer(variColorPerPixShadingWithTexRenderer); YsGLSLSet3DRendererProjectionfv(variColorPerPixShadingWithTexRenderer,projection); YsGLSLSet3DRendererModelViewfv(variColorPerPixShadingWithTexRenderer,modelview); YsGLSLEndUse3DRenderer(variColorPerPixShadingWithTexRenderer); glEnable(GL_CULL_FACE); glFrontFace(GL_CW); YsGLSLUse3DRenderer(renderer3d); YsGLSLSet3DRendererTextureType(renderer3d,YSGLSL_TEX_TYPE_BILLBOARD); const GLfloat billBoardCenter[3]={0,0,0}; const GLfloat billBoardDimension[2]={3.0f,3.0f}; YsGLSLSet3DRendererBillBoardfv(renderer3d,billBoardCenter,billBoardDimension); GLfloat color[4]={0,0,1,1}; YsGLSLSet3DRendererUniformColorfv(renderer3d,color); if(renderer3d!=monoColorPerPixShadingWithTexRenderer && renderer3d!=variColorPerPixShadingWithTexRenderer && renderer3d!=monoColorPerVtxShadingWithTexRenderer && renderer3d!=variColorPerVtxShadingWithTexRenderer) { YsGLSLDrawPrimitiveVtxNomColfv(renderer3d,GL_TRIANGLES,nVtx,vtx,nom,col); } else if(renderer3d==monoColorPerPixShadingWithTexRenderer || renderer3d==monoColorPerVtxShadingWithTexRenderer) { YsGLSLDrawPrimitiveVtxTexCoordNomfv(renderer3d,GL_TRIANGLES,nVtx,vtx,texCoord,nom); } else if(renderer3d==variColorPerPixShadingWithTexRenderer || renderer3d==variColorPerVtxShadingWithTexRenderer) { YsGLSLDrawPrimitiveVtxTexCoordNomColfv(renderer3d,GL_TRIANGLES,nVtx,vtx,texCoord,nom,col); } YsGLSLEndUse3DRenderer(renderer3d); FsSwapBuffers(); rot+=YSGLPI/30.0; } YsGLSLDelete3DRenderer(monoColorPerVtxShadingRenderer); YsGLSLDelete3DRenderer(variColorPerVtxShadingRenderer); YsGLSLDelete3DRenderer(monoColorPerPixShadingRenderer); return 0; }
int main(){ Vector2 startPosition(300, 500); Vector2 startDirection(0, -1); /* This list is used to store all user emmitted active missiles */ MissileList enemy2Missiles; MissileList playerMissiles; /* Create the thunder */ Thunder thunder(startPosition, startDirection); thunder.setVelocity(5); thunder.SwitchWeapon(BULLET, playerMissiles); Plane *player; player = &thunder; /* Create the boss */ LazerEnemy enemy2(Vector2(300, 0), Vector2(0,1)); enemy2.Init(enemy2Missiles); enemy2.setVelocity(15); Plane *enemy; enemy = &enemy2; FsOpenWindow(0,0,WINDOW_WID,WINDOW_HEI,1); glClearColor(0.1, 0.1, 0.1, 1); bool running = true; int i = 0; int cntDown = 0; while(running) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); FsPollDevice(); int key=FsInkey(); int lb, mb, rb, mx, my; int mouse = FsGetMouseEvent(lb, mb, rb, mx, my); if(FSKEY_ESC==key) { running=false; break; } else if (FSKEY_UP == key) { /* UP for power up */ ((Thunder *)player)->PowerUp(playerMissiles); } if (FSMOUSEEVENT_RBUTTONDOWN == mouse) { /* Right click for switch between 3 types of weapons */ i = (i+1) % 3; ((Thunder *)player)->SwitchWeapon((MissileType)i, playerMissiles); } /* Thunder: shoot and cool down weapon. */ player->Shoot(mouse, playerMissiles); player->CoolDown(); /* Thunder: move and draw. */ player->Move(1.0); player->Draw(); /* Draw the enemy */ enemy->Aim(player); printf("before move\n"); enemy->Move(0.4); printf("after move\n"); enemy->Draw(); /* Enemy fire */ ((LazerEnemy *)enemy)->Shoot(enemy2Missiles); enemy->CoolDown(); if (enemy->CheckHit(playerMissiles) == 1) { ((LazerEnemy *)enemy)->Disappear(enemy2Missiles); cntDown = 100; } /* Stay for a while after boss die */ if (cntDown > 0) { cntDown--; if (cntDown == 0) running = false; } /* traverse the missiles list, move missile */ MissileNode *node; node = enemy2Missiles.getFront(); while(node) { node->dat->Move(1.0); if (!node->dat->CheckInWindow()) { node = enemy2Missiles.Delete(node); } else { node = node->next; } } node = playerMissiles.getFront(); while(node) { node->dat->Move(1.0); if (!node->dat->CheckInWindow()) { node = playerMissiles.Delete(node); } else { node = node->next; } } FOR_EACH(node, enemy2Missiles) { node->dat->Draw(); } FOR_EACH(node, playerMissiles) { node->dat->Draw(); } PrintPower(((LazerEnemy *)enemy)->getLife()); FsSwapBuffers(); FsSleep(25); } return 0; }
int main(int argc,char **argv) { Options opt; if(!parse_args(&opt,argc,argv)){ return 1; } char strk[256],strmu[256],strsigma[256],striso[256]; int terminate=0; CameraObject camera; OrbitingViewer orbit; orbit.focusY=4.0; camera.z=10.0; FsOpenWindow(16,16,800,600,1); Cylinder cylinder; cylinder.setRadius(9.0); YsVec3 min(-10.0,0.0,-10.0); YsVec3 max(10.0,20.0,10.0); Box box; box.setMinMax(min,max); std::vector <YsVec3> iniPos; const double interval=0.9; CreateUniformInitialParticleLocation(iniPos,10,40,10,YsVec3(10.0,20.0,0.0),interval); std::vector <YsVec3> drip; CreateUniformInitialParticleLocation(drip,5,5,5,YsVec3(0.0,20.0,0.0),interval); ParticleSimulation sim; if(opt.infile){ sim.read(opt.infile); } else{ //sim.init(iniPos); } sim.setObstacle(box); //sim.calculate_force(); //sim.calculate_force(); sim.mode=sim.MODE_NORMAL; glClearColor(0,0,0,0); YSBOOL pause=YSFALSE; YSBOOL cube=YSFALSE; YSBOOL savestl=YSFALSE; while(0==terminate) { FsPollDevice(); int wid,hei; FsGetWindowSize(wid,hei); int key=FsInkey(); switch(key) { case FSKEY_K: { printf("Enter k:\n"); fscanf(stdin,"%lf",strk); double k=atof(strk); sim.setK(k); break; } case FSKEY_M: { printf("Enter mu:\n"); fscanf(stdin,"%lf",strmu); double mu=atof(strmu); sim.setMu(mu); break; } case FSKEY_S: { printf("Enter Sigma:\n"); fscanf(stdin,"%lf",strmu); double sigma=atof(strsigma); sim.setSigma(sigma); break; } case FSKEY_Q: if(cube){ cube=YSFALSE; } else{ cube=YSTRUE; } break; case FSKEY_I: { printf("Enter isolevel:\n"); fscanf(stdin,"%lf",striso); double iso=atof(striso); sim.setIso(iso); break; } case FSKEY_L: if(savestl){ savestl=YSFALSE; } else{ savestl=YSTRUE; } break; case FSKEY_D: sim.placeParticles(drip); break; case FSKEY_P: YsFlip(pause); break; case FSKEY_ESC: terminate=1; break; } if(FSKEY_SPACE==key || YSTRUE!=pause) { sim.update(); } if(0!=FsGetKeyState(FSKEY_LEFT)) { orbit.h+=YsPi/180.0; } if(0!=FsGetKeyState(FSKEY_RIGHT)) { orbit.h-=YsPi/180.0; } if(0!=FsGetKeyState(FSKEY_UP)) { orbit.p+=YsPi/180.0; } if(0!=FsGetKeyState(FSKEY_DOWN)) { orbit.p-=YsPi/180.0; } if(0!=FsGetKeyState(FSKEY_F) && orbit.dist>1.0) { orbit.dist/=1.05; } if(0!=FsGetKeyState(FSKEY_B) && orbit.dist<200.0) { orbit.dist*=1.05; } orbit.SetUpCamera(camera); glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glViewport(0,0,wid,hei); // Set up 3D drawing camera.SetUpCameraProjection(); camera.SetUpCameraTransformation(); glEnable(GL_DEPTH_TEST); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1,1); // 3D drawing from here glPushMatrix(); glPointSize(3); if(cube){ sim.drawMesh(); if(savestl){ sim.shl.SaveBinStl("test.stl"); printf("stl saved\n"); savestl=YSFALSE; } } else{ sim.drawParticles(); } //sim.drawColorFieldGrid(); glPopMatrix(); // Set up 2D drawing glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,(float)wid-1,(float)hei-1,0,-1,1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_DEPTH_TEST); FsSwapBuffers(); FsSleep(25); } //sim.write(opt.outfile); return 0; }
int main(void) { Vector2 bulletV(0, -10); Vector2 cannonV(0, -20); Vector2 laserV(0, -1); Vector2 bulletPosition(300, 400); Vector2 laserPosition(100, 400); Vector2 cannonPosition(200, 400); Vector2 velocity(1, 1); MissileList missiles; Missile *missile; MissileNode *laser = NULL; int laserReload = 0; int cannonReload = 0; int bulletReload = 0; int firing = 0; srand(time(NULL)); FsOpenWindow(0,0,600, 800,1); glClearColor(0, 0, 0, 1); bool running = true; while(running) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); FsPollDevice(); int key=FsInkey(); int lb, mb, rb, mx, my; int mouse = FsGetMouseEvent(lb, mb, rb, mx, my); if(FSKEY_ESC==key) { running=false; } if(FsGetKeyState(FSKEY_UP)) { bulletV.rotate(0.05); cannonV.rotate(0.05); laserV.rotate(0.05); } if(FsGetKeyState(FSKEY_DOWN)) { bulletV.rotate(-0.05); cannonV.rotate(-0.05); laserV.rotate(-0.05); } if(FSMOUSEEVENT_LBUTTONDOWN == mouse) { firing = 1; } else if (FSMOUSEEVENT_LBUTTONUP == mouse) { firing = 0; } if (firing == 1) { if (laserReload <= 0) { laserReload = 100; missile = new Laser(gBlue, 100, laserPosition, laserV, 1); laser = missiles.InsertFront(missile); } if (bulletReload <= 0) { bulletReload = 100; missile = new Bullet(gRed, 100, bulletPosition, bulletV, 1); missiles.InsertFront(missile); } if (cannonReload <= 0) { cannonReload = 100; missile = new Cannon(gGreen, 100, cannonPosition, cannonV, 1); missiles.InsertFront(missile); } } else if (firing == 0 && laser) { missiles.Delete(laser); laser = NULL; laserReload = 0; } MissileNode *node; node = missiles.getFront(); while(node) { node->dat->Move(1.0); node->dat->Draw(); if (!node->dat->CheckInWindow()) { node = missiles.Delete(node); } else { node = node->next; } } if (bulletReload > 0) bulletReload -= 10; if (cannonReload > 0) cannonReload -= 10; /* if(key == FSKEY_UP) printf("UP!!!!\n"); if(key == FSKEY_SPACE) printf("SPACE!!!\n"); if (FsCheckKeyHeldDown()) printf("KEY DOWN!!!\n"); */ FsSwapBuffers(); FsSleep(25); } return 0; }
int main(void) { printf("Enter Dimension>"); char str[256]; fgets(str,255,stdin); int wid=0,hei=0; { // Either cut & paste Parse function, or write parsing algorithm here. int state=0,n=0; for(int i=0; 0!=str[i]; ++i) { if(0==state) { if(' '!=str[i]) { if(0==n) { wid=atoi(str+i); } else if(1==n) { hei=atoi(str+i); } ++n; state=1; } } else { if(' '==str[i]) { state=0; } } } if(2>n || 0>wid || 0>hei) { return 0; } } CharBitmap bmp; bmp.Create(wid,hei); CharBitmap undo(bmp); FsOpenWindow(0,0,wid*20,hei*20,1); for(;;) { FsPollDevice(); auto key=FsInkey(); int lb,mb,rb,mx,my; FsGetMouseEvent(lb,mb,rb,mx,my); if(FSKEY_ESC==key) { break; } if(FSKEY_0<=key && key<=FSKEY_7) { undo=bmp; int px=mx/20; int py=my/20; int colorCode=key-FSKEY_0; bmp.SetPixel(px,py,colorCode); //why can int colorcode call the function setpixel which takes unsigned char? } if(FSKEY_U==key) { bmp=undo; } glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); bmp.Draw(); FsSwapBuffers(); FsSleep(25); } }