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); } }
/* virtual */ void FsLazyWindowApplication::Interval(void) { int lb,mb,rb,mx,my; FsGetMouseEvent(lb,mb,rb,mx,my); mouseOn=PickedNode(mx,my); auto key=FsInkey(); if(FSKEY_ESC==key) { SetMustTerminate(true); } if(FSKEY_D==key && nullptr!=mouseOn) { btree.Delete(mouseOn); VerifyTree(); } if(FSKEY_L==key && nullptr!=mouseOn) { btree.RotateLeft(mouseOn); VerifyTree(); } if(FSKEY_B==key) { BreadthFirstTraversal(btree.GetRoot()); } needRedraw=true; }
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); } }
/* virtual */ void FsLazyWindowApplication::Interval(void) { auto key=FsInkey(); if(FSKEY_ESC==key) { SetMustTerminate(true); } needRedraw=true; }
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 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 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); } }
/* virtual */ void FsLazyWindowApplication::Interval(void) { int wid,hei; FsGetWindowSize(wid,hei); int lb,mb,rb,mx,my; auto evt=FsGetMouseEvent(lb,mb,rb,mx,my); if(0!=lb && (mx!=prevMx || my!=prevMy)) { double denom=(double)YsGreater(wid,hei); double dx=2.0*(double)(prevMx-mx)/denom; double dy=2.0*(double)(prevMy-my)/denom; drawEnv.RotateView(dx,dy); } if(evt==FSMOUSEEVENT_LBUTTONDOWN) { drawEnv.SetWindowSize(wid,hei); drawEnv.SetViewportByTwoCorner(0,0,wid,hei); drawEnv.TransformScreenCoordTo3DLine(lastClick[0],lastClick[1],mx,my); lastClick[1]*=80.0; lastClick[1]+=lastClick[0]; cellVtx.clear(); auto itscIdx=ltc.GetIntersectingBlock(lastClick[0],lastClick[1]-lastClick[0]); for(auto i : itscIdx) { YsVec3 min,max; ltc.GetBlockRange(min,max,i); auto cen=(min+max)/2.0; cellVtx.push_back(cen.xf()); cellVtx.push_back(cen.yf()); cellVtx.push_back(cen.zf()); } if(true!=ltc.ClipLine(lastClick[0],lastClick[1],lastClick[0],lastClick[1]-lastClick[0])) { printf("No intersection.\n"); } } prevMx=mx; prevMy=my; auto key=FsInkey(); if(FSKEY_ESC==key) { SetMustTerminate(true); } needRedraw=true; }
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 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; }
/* virtual */ void FsLazyWindowApplication::Interval(void) { int wid,hei; FsGetWindowSize(wid,hei); int lb,mb,rb,mx,my; auto evt=FsGetMouseEvent(lb,mb,rb,mx,my); if(0!=lb && (mx!=prevMx || my!=prevMy)) { double denom=(double)YsGreater(wid,hei); double dx=2.0*(double)(prevMx-mx)/denom; double dy=2.0*(double)(prevMy-my)/denom; drawEnv.RotateView(dx,dy); } if(evt==FSMOUSEEVENT_LBUTTONDOWN) { double x=(double)mx/(double)wid; double y=(double)(hei-my)/(double)hei; x=x*2.0-1.0; y=y*2.0-1.0; lastClick[0].Set(x,y,-1.0); lastClick[1].Set(x,y, 1.0); for(auto &p : lastClick) { drawEnv.GetProjectionMatrix().MulInverse(p,p,1.0); drawEnv.GetViewMatrix().MulInverse(p,p,1.0); } } prevMx=mx; prevMy=my; auto key=FsInkey(); if(FSKEY_ESC==key) { SetMustTerminate(true); } needRedraw=true; }
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; }
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::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 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; }
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 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) { 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); } }
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(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; }