Exemplo n.º 1
0
Arquivo: main.cpp Projeto: HLH15/24783
/* 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;
}
Exemplo n.º 2
0
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);
	}
}
Exemplo n.º 3
0
Arquivo: main.cpp Projeto: HLH15/24783
/* 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;
}
Exemplo n.º 4
0
Arquivo: main.cpp Projeto: HLH15/24783
/* 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;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
void MouseChaser::Move(void)
{
	int lb,mb,rb,mx,my;
	FsGetMouseEvent(lb,mb,rb,mx,my);
	if(x<mx-3)
	{
		x+=3;
	}
	else if(mx+3<x)
	{
		x-=3;
	}
	if(y<my-3)
	{
		y+=3;
	}
	else if(my+3<y)
	{
		y-=3;
	}
}
Exemplo n.º 7
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;
	
}
Exemplo n.º 8
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);
    }
}
Exemplo n.º 9
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;
}
void FsSimpleWindowIntervalCallBack(void)
{
	int winWid,winHei;
	FsGetWindowSize(winWid,winHei);

	int lb,mb,rb,mx,my;
	FsGetMouseEvent(lb,mb,rb,mx,my);

	float r=1.0,g=0.0,b=0.0,a=1.0;


    glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	

	GLfloat spriteVtx[]=
	{
		1,1,1,
		-1,1,1,
		1,-1,1,
		-1,-1,1,
		1,1,-1,
		-1,1,-1,
		1,-1,-1,
		-1,-1,-1,
	};
	GLfloat spriteColor[]=
	{
		0,0,1, 1,
		0,1,0, 1,
		1,0,0, 1,
		1,0,1, 1,
		1,1,0, 1,
		1,1,1, 1,
		0,0,1, 1,
		0,1,0, 1,
	};

	GLfloat monoColorVtx[]=
	{
		 1, 0, 0,
		-1, 0, 0,
		 0, 1, 0,
		 0,-1, 0,
		 0, 0, 1,
		 0, 0,-1,
	};


	const int nVtx=(sizeof(spriteVtx)/(3*sizeof(GLfloat)));



	glDisable(GL_DEPTH_TEST);

	glEnable(GL_PROGRAM_POINT_SIZE);  // Needed for enabling gl_PointSize in the vertex shader.
	glEnable(GL_POINT_SPRITE);        // Needed for enabling gl_PointCoord in the fragment shader.

	YsGLSLUsePlain2DRenderer(YsGLSLSharedPlain2DRenderer());
	YsGLSLUseWindowCoordinateInPlain2DDrawing(YsGLSLSharedPlain2DRenderer(),1);
	YsGLSLDrawPlain2DLinef(YsGLSLSharedPlain2DRenderer(),mx-10,my-10,mx+10,my+10,r,g,b,a);
	YsGLSLDrawPlain2DLinef(YsGLSLSharedPlain2DRenderer(),mx+10,my-10,mx-10,my+10,r,g,b,a);
	
	YsGLSLEndUsePlain2DRenderer(YsGLSLSharedPlain2DRenderer());

	
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	
	
	glEnable(GL_DEPTH_TEST);

	static double hdg=0.0;

	GLfloat modelview[16],projection[16],tfm[16];
	YsGLMakeIdentityfv(modelview);
	YsGLMakeTranslationfv(tfm,0.0f,0.0f,-5.0f);
	YsGLMultMatrixfv(modelview,modelview,tfm);
	YsGLMakeXZRotationfv(tfm,(float)hdg);
	YsGLMultMatrixfv(modelview,modelview,tfm);

	YsGLMakePerspectivefv(projection,YSGLPI/6.0,(float)winWid/(float)winHei,1.0,50.0);


	YsGLSLUse3DRenderer(variColorRenderer);

	YsGLSLSet3DRendererModelViewfv(variColorRenderer,modelview);
	YsGLSLSet3DRendererProjectionfv(variColorRenderer,projection);

	YsGLSLDrawPrimitiveVtxColfv(variColorRenderer,GL_POINTS,nVtx,spriteVtx,spriteColor);

	YsGLSLEndUse3DRenderer(variColorRenderer);


	YsGLSLUse3DRenderer(monoColorRenderer);

	YsGLSLSet3DRendererModelViewfv(monoColorRenderer,modelview);
	YsGLSLSet3DRendererProjectionfv(monoColorRenderer,projection);

	YsGLSLDrawPrimitiveVtxfv(monoColorRenderer,GL_POINTS,6,monoColorVtx);

	YsGLSLEndUse3DRenderer(monoColorRenderer);

	
	hdg+=0.01;

	FsSwapBuffers();
}
Exemplo n.º 11
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);
    }
}
Exemplo n.º 12
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;
}