コード例 #1
0
int main(void)
{
	int menu;
	FsOpenWindow(32, 32, winWidth, winHeight, 1); // 800x600 pixels, useDoubleBuffer=1

	int listBase;
	listBase=glGenLists(256);
	YsGlUseFontBitmap8x12(listBase);
	glListBase(listBase);

	glDisable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);
	glDepthFunc(GL_ALWAYS);

	while(1)
	{
		menu=Menu();
		if(menu==1)
		{
			int score;
			score=Game();
			GameOver(score);
		}
		else if(menu==eStop)
		{
			break;
		}
	}

	return 0;
}
コード例 #2
0
int main(void)
{
    int x[20]={17,10,13,14,15,6,3,2,9,8,18,7,12,11,16,4,1,20,5,19};
    FsOpenWindow(16,16,400,400,1);
    BubbleSort(20, x);
    return 0;
}
コード例 #3
0
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;
}
コード例 #4
0
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;
}
コード例 #5
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;
}
コード例 #6
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;
}
コード例 #7
0
ファイル: main.cpp プロジェクト: fionaguoguolu/cmuadvanture
int main(void)
{
    FsOpenWindow(16,16,800,600,1);
    
	Map map;
    map.RunMap();
    /*
	int x=map.GetPlayersPositionX();
    int y=map.GetPlayersPositionY();
    
    printf("x=%d,y=%d",x,y);
    */
	//KeepAwake stayawake;
	//stayawake.StartGame();
	return 0;
}
コード例 #8
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;
}
コード例 #9
0
ファイル: prize.cpp プロジェクト: migorain/ThunderBolt
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;
}
コード例 #10
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;
}
コード例 #11
0
ファイル: main.cpp プロジェクト: Jenny19880324/MCG03
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;
}
コード例 #12
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;
}
コード例 #13
0
ファイル: missile.cpp プロジェクト: migorain/ThunderBolt
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;
}
コード例 #14
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;
}
コード例 #15
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;
}
コード例 #16
0
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;
}
コード例 #17
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;
	
}
コード例 #18
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);
    }
}