Esempio n. 1
0
// Process SDL events
void processEvents() {
	SDL_Event event;
	while(SDL_PollEvent(&event)) {
		switch(event.type) {
			case SDL_KEYDOWN:	handleKeys(&event.key.keysym, true );	break;
			case SDL_KEYUP  :	handleKeys(&event.key.keysym, false);	break;
			case SDL_QUIT   :	endProgram(0);	break;
		}
	}
}
Esempio n. 2
0
int main(int argc, char* args[])
{
    if (!init(SCREEN_WIDTH, SCREEN_HEIGHT, "Lab 01", &gContext)) {
        fprintf(stderr, "Failed to initialize\n");
        return 1;
    }

    gProgram = gl_compileShaderProgram(VERTEX_SHADER, FRAGMENT_SHADER);
    // gShape = shapes_makeTriangleStrip();
    gShape = shapes_makeCircle(100, 0.4);

    glUseProgram(gProgram);

    SDL_Event e;
    SDL_StartTextInput();

    while (!gContext.quit) {
        while(SDL_PollEvent(&e) != 0) {
            if (e.type == SDL_QUIT) {
                gContext.quit = true;
            } else if(e.type == SDL_TEXTINPUT) {
                int x = 0, y = 0;
                SDL_GetMouseState(&x, &y);
                handleKeys(e.text.text[0], x, y);
            }
        }
        render();
        SDL_GL_SwapWindow(gContext.window);
    }
    
    SDL_StopTextInput();
    shutdown(&gContext);

    return 0;
}
Esempio n. 3
0
void update(){
  handleKeys();
  GLfloat oldX = ball.x;
  GLfloat oldY = ball.y;
  GLfloat oldZ = ball.z;
  if(oldZ + ball.radius >= 15 && !keep){
    scored = false;
  }
  ball.update();
  if(distance(oldX, 0, oldZ, 0, 0, 14.65) < ball.radius + 0.35){
    if(oldY > 3.05 && ball.y<= 3.05){
      scored = true;
    }
  }
  if(ball.z + ball.radius > 15){
    if(ball.y + ball.radius >= 4.4f){
      GLfloat _x = random(-7.5, 7.5);
      GLfloat _z = random(0, 13);
      ball.move(0,0,0);
      ball.y = ball.radius;
      changePosition(_x,_z);
    }
  }
  if(distance(mainCamera.x, 0, mainCamera.z, ball.x, 0, ball.z) < 1.0f && !ball.locked){
    mode = TURNING_MODE;
  }
}
int main( int argc, char* args[] )
{
	//Start up SDL and create window
	if (!init())
	{
		printf("Failed to initalize!\n");
	}//end if
	else
	{
		//Load Media
		if (!loadMedia())
		{
			printf("Failed to load media!\n");
		}//end if
		else
		{
			// Main Loop Flag
			bool quit = false;

			//Event Handler
			SDL_Event e;

			//enable text input
			SDL_StartTextInput();

			//While application is running
			while (!quit)
			{
				//Handle events on queue
				while (SDL_PollEvent(&e) != 0)
				{
					//User request quite
					if (e.type == SDL_QUIT)
					{
						quit = true;
					}//end if
					else if (e.type == SDL_TEXTINPUT)
					{
						int x = 0, y = 0;
						SDL_GetMouseState(&x, &y);
						handleKeys(e.text.text[0], x, y);
					}
				}//end while
				
				//Render quad
				render();

				//Update screen
				SDL_GL_SwapWindow(gWindow);
			}//end main loop

			SDL_StopTextInput();
		}//end else
	}//end if

	//Free resources and close SDL
	close();
	system("pause");
	return 0;
}// end main func
Esempio n. 5
0
void SPlayer::renderScene(SDL_Event *event) {
    player_types::key key;
    Status gameStatus;
	
    if (menu) {
	if (menu->handleEvent(event)) {

	    handlePauseEvent(menu->getSelected());
	}

    } else {
	//All Logic hapens here
	Uint8 *keystate = SDL_GetKeyState(NULL);
	if (event && event->type == SDL_KEYDOWN) {
	    for (int i = 0; i < 6; i++) {
		//cast sdl key to own virtual key mapping
		if (keystate[keys[i]]) {
		    key = static_cast<player_types::key> (i);
		    handleKeys(key);
		    break;
		}
	    }
	}
    }

    if (menu)
	game->renderScene(NULL);
    else
	game->renderScene(event);
    gameStatus = game->getStatus();

    if (menu)
	menu->render();
    else
	switch (gameStatus){

	case WIN:
	    Mix_HaltMusic();
	    menu = new MenuWindow(width, height, "You Win!!", NULL);
	    menu->addOption("New Game");
	    menu->addOption("Main Menu");
	    break;

	case LOSS:
	    game->setPaused(true);
	    Mix_HaltMusic();
	    menu  = new MenuWindow(width,height,"GAME OVER",NULL);
	    menu->addOption("New Game");
	    menu->addOption("Main Menu");
	    break;

	default:
	    break;


	}

}
Esempio n. 6
0
void MoSyncStub::processEvents() {
	MAEvent e;
	while(maGetEvent(&e) != 0) {
		switch(e.type) {
			case EVENT_TYPE_SCREEN_CHANGED: {
				FrameBuffer_close();
				FrameBuffer_init(SCREEN_W, SCREEN_H, currentOrientation, FLAG_4BPP|FLAG_RGB666);
			}
			break;
			case EVENT_TYPE_KEY_PRESSED: handleKeys(e.key, 1); break;
			case EVENT_TYPE_KEY_RELEASED: handleKeys(e.key, 0); break;
			case EVENT_TYPE_CLOSE: _pi.quit = true; break;
			case EVENT_TYPE_POINTER_PRESSED: handleKeys(MAK_FIRE, 1); break;
			case EVENT_TYPE_POINTER_RELEASED: handleKeys(MAK_FIRE, 0); break;
			case EVENT_TYPE_AUDIOBUFFER_FILL:
				uint8 *b = buffer;
				int i = 0;

				while(i<BUFFERSIZE) {
					int numSamplesToNextTick = samplesAtNextTick-(i+curSample);
					int numSamplesToEndOfBuffer = BUFFERSIZE-i;
					if(timerActive&&numSamplesToNextTick<=numSamplesToEndOfBuffer) {
						callback(param, b, numSamplesToNextTick);
						i+=numSamplesToNextTick;
						b+=numSamplesToNextTick;
						timer.delay = timer.callback(timer.delay, timer.param);
						numSamplesToNextTick = (timer.delay*getOutputSampleRate()/1000);
						samplesAtNextTick+=numSamplesToNextTick;
					} else {
						callback(param, b, numSamplesToEndOfBuffer);
						break;
					}
				}

				curSample += BUFFERSIZE;
				maAudioBufferReady();

				break;
		}
	}

	_pi.lastChar = '1';
}
Esempio n. 7
0
int main( int argc, char* args[] )
{
	//Start up SDL and create window
	if( !init() )
	{
		printf( "Failed to initialize!\n" );
	}
	else
	{
		//Main loop flag
		bool quit = false;

		//Event handler
		SDL_Event e;
		
		//Enable text input
		SDL_StartTextInput();

		//While application is running
		while( !quit )
		{
			//Handle events on queue
			while( SDL_PollEvent( &e ) != 0 )
			{
				//User requests quit
				if( e.type == SDL_QUIT )
				{
					quit = true;
				}
				//Handle keypress with current mouse position
				else if( e.type == SDL_TEXTINPUT )
				{
					int x = 0, y = 0;
					SDL_GetMouseState( &x, &y );
					handleKeys( e.text.text[ 0 ], x, y );
				}
			}

			//Render quad
			render();
			
			//Update screen
			SDL_GL_SwapWindow( gWindow );
      SDL_Delay(20);
		}
		
		//Disable text input
		SDL_StopTextInput();
	}

	//Free resources and close SDL
	Quit();

	return 0;
}
Esempio n. 8
0
int main( int argc, char *argv[] )
{
    //Quit flag
    bool quit = false;

    //Initialize
    if( init() == false )
    {
        return 1;
    }

    //The frame rate regulator
    Timer fps;

	//Wait for user exit
	while( quit == false )
	{
        //Start the frame timer
        fps.start();

        //While there are events to handle
		while( SDL_PollEvent( &event ) )
		{
			if( event.type == SDL_QUIT )
			{
                quit = true;
            }
            else if( event.type == SDL_KEYDOWN )
            {
                //Handle keypress with current mouse position
                int x = 0, y = 0;
                SDL_GetMouseState( &x, &y );
                handleKeys( event.key.keysym.unicode, x, y );
            }
		}

        //Run frame update
        update();

        //Render frame
        render();

        //Cap the frame rate
        if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
        {
            SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
        }
	}

	//Clean up
	clean_up();

	return 0;
}
Esempio n. 9
0
// ****************************************************************************
// main
//
int main(void)
{
    InitializeSystem();

    USBDeviceAttach();
    
    while (1) {
        updateState();
        handleKeys();
        CLRWDT();  // tickle watchdog
    }

} //end main
Esempio n. 10
0
/* @fn      LoacationApp_ProcessEvent
 * @brief   Generic Application Task event processor.
 * @param   task_id  - The OSAL assigned task ID.
 * @param   events - Bit map of events to process.
 * @return  none*/
uint16 LoacationApp_ProcessEvent( uint8 task_id, uint16 events ) {
  if ( events & SYS_EVENT_MSG ) {
    afIncomingMSGPacket_t *MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive(
                                                             LoacationApp_TaskID );
    while ( MSGpkt != NULL ) {
      switch ( MSGpkt->hdr.event ) {
      case KEY_CHANGE:
        handleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
        break;
      case AF_DATA_CONFIRM_CMD:
#if !defined( RTR_NWK )
        {
        // This message is received as a confirmation of a data packet sent.
        // The status is of ZStatus_t type [defined in ZComDef.h]
        afDataConfirm_t *afDataConfirm = (afDataConfirm_t *)MSGpkt;
        /* No ACK from the MAC layer implies that mobile device is out of
         * range of most recent parent. Therefore, begin an orphan scan
         * to try to find a former parent.
         * NOTE: To get the fastest action in the process of finding a new
         * parent, set the MAX_JOIN_ATTEMPTS in ZDApp.c to 1.*/
        if(afDataConfirm->hdr.status == ZMacNoACK) LoacationApp_NoACK();
        else{}// Some other error -- Do something.
        }
#endif
        break;
      case AF_INCOMING_MSG_CMD:
        processMSGCmd( MSGpkt );
        break;
      case ZDO_STATE_CHANGE:
#if defined( POWER_SAVING )
        if(rejoinPending) {
          rejoinPending = FALSE;
          LoacationApp_Sleep(TRUE); //Ok to resume power saving ops.
        }
#endif
        break;
      default:
        break;
      }
      osal_msg_deallocate( (uint8 *)MSGpkt );
      MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive(LoacationApp_TaskID);
    }
    return (events ^ SYS_EVENT_MSG);  // Return unprocessed events.
  }
  return 0;  // Discard unknown events
}
Esempio n. 11
0
void startLoop() {
	glfwSetTime(0);
	float a = 0.0;
	while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0) {
		a = sin(glfwGetTime() * 3) + 1;
		float color[] = { 1.0f, 1.0f, 0.0f, a };
		handleKeys();
		draw(color);
		glfwSwapBuffers(window);
		glfwPollEvents();
		fps++;
		if (glfwGetTime() > nextTime) {
			std::cout << "FPS: " << fps << std::endl;
			nextTime += 1;
			fps = 0;
		}

	}
}
Esempio n. 12
0
bool ArcController::listen()
{
  // While there are events to handle
  while (SDL_PollEvent(&mEvent))
  {
    if (mEvent.type == SDL_QUIT)
    {
      return true;
    }
    else if (mEvent.type == SDL_KEYDOWN)
    {
      // Handle keypress with current mouse position
      int x = 0;
      int y = 0;
      SDL_GetMouseState(&x, &y);
      handleKeys(mEvent.key.keysym.unicode, x, y);
    }
  }
  return false;
}
Esempio n. 13
0
// global update method
void update(float dt)
{
	handleKeys(dt);
	handleMouse(dt);
	
	// check for shader file refresh
	FILETIME create, access, write;
	HANDLE fhandle = CreateFile(SHADER_SRC, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
	GetFileTime(fhandle, &create, &access, &write);
	ULONGLONG time = (((ULONGLONG) write.dwHighDateTime) << 32) + write.dwLowDateTime;
	if  (time > g_shader_modified) {
		// detach old stuff
		for(int i = 0; i < g_shader.progs.size(); i++) {
			glDetachShader(g_shader.id, g_shader.progs.at(i));
		}
		g_shader.progs.clear();
		refreshShaderProgram(SHADER_SRC);
		g_shader_modified = time;
	}
	CloseHandle(fhandle);
}
Esempio n. 14
0
int main(int argc, char* args[])
{
	std::string pacmanFilename = "pacman.png";
	std::string ghostFilename = "monster.png";
	std::string blendiFilename = "Arial.bmp";

	int spacemanMovement = 0;
	int spacemanVelocity = 0;

	//Start up SDL and create window
	if (!init())
	{
		printf("Failed to initialize!\n");
	}
	else
	{
		//Load media
		if (!loadMedia("DefaultBackground.jpg", &gHelloWorld))
		{
			printf("Failed to load media!\n");
		}
		else{

			loadMedia(pacmanFilename, &pacman);
			loadMedia(pacmanFilename, &ghost);
			loadMedia(ghostFilename, &ghost2);
			loadMedia(ghostFilename, &ghost3);
			loadMedia(blendiFilename, &b);
			loadMedia(blendiFilename, &l);
			loadMedia(blendiFilename, &e);
			loadMedia(blendiFilename, &n);
			loadMedia(blendiFilename, &d);
			loadMedia(blendiFilename, &i);
			loadMedia(blendiFilename, &Colon);
			loadMedia(blendiFilename, &Points);
			loadMedia(blendiFilename, &DecPoints);

			//Apply the image
			SDL_BlitSurface(gHelloWorld, NULL, gScreenSurface, NULL);
			//Update the surface
			SDL_UpdateWindowSurface(gWindow);
		}



		SDL_Event event;
		SDL_Rect sourceRect, gsourceRect, g2sourceRect, g3sourceRect, sB, sL, sE, sN, sD, sI, sourceColon, sourcePoint, sourceDec;
		SDL_Rect destRect, gdestRect, g2destRect , g3destRect, dB, dL, dE, dN, dD, dI, destColon, destPoint, destDec;

		int quit = 0;
		int rnd = 1;
		int count = 1;
		int countPoints = 0;

		//pacman position
		destRect.x = 30;
		destRect.y = 30;
		destRect.h = 70;
		destRect.w = 70;

		sourceRect.x = 10;
		sourceRect.y = 10;
		sourceRect.h = 70;
		sourceRect.w = 70;

		// ghost 1 position
		gdestRect.x = 100;
		gdestRect.y = 100;
		gdestRect.h = 70;
		gdestRect.w = 70;

		gsourceRect.x = 300;
		gsourceRect.y = 100;
		gsourceRect.h = 70;
		gsourceRect.w = 70;

		//ghost 2 position
		g2destRect.x = 150;
		g2destRect.y = 200;
		g2destRect.h = 63;
		g2destRect.w = 65;

		g2sourceRect.x = 187;
		g2sourceRect.y = 0;
		g2sourceRect.h = 63;
		g2sourceRect.w = 65;

		//ghost 3 position
		g3destRect.x = 550;
		g3destRect.y = 300;
		g3destRect.h = 63;
		g3destRect.w = 64;

		g3sourceRect.x = 0;
		g3sourceRect.y = 0;
		g3sourceRect.h = 63;
		g3sourceRect.w = 64;

		//Position for "Blendi:d s n" text from Arial.bmp where "d s" are points
		dB.x = 0;
		dest(dB);

		sB.x = 273;
		sB.y = 25;
		sB.h = 25;
		sB.w = 21;

		dL.x = 21;
		dest(dL);

		sL.x = 315;
		sL.y = 75;
		sL.h = 25;
		sL.w = 21;

		dE.x = (42);
		dest(dE);

		sE.x = 168;
		sE.y = 75;
		sE.h = 25;
		sE.w = 21;

		dN.x = (63);
		dest(dN);

		sN.x = 357;
		sN.y = 75;
		sN.h = 25;
		sN.w = 21;

		dD.x = (84);
		dest(dD);

		sD.x = 147;
		sD.y = 75;
		sD.h = 25;
		sD.w = 21;

		dI.x = (105);
		dest(dI);

		sI.x = 252;
		sI.y = 75;
		sI.h = 25;
		sI.w = 21;

		destColon.x = 126;
		dest(destColon);

		sourceColon.x = 105;
		sourceColon.y = 25;
		sourceColon.h = 25;
		sourceColon.w = 21;

		destPoint.x = 168;
		dest(destPoint);

		sourcePoint.x = 315;
		sourcePoint.y = 0;
		sourcePoint.h = 25;
		sourcePoint.w = 21;

		destDec.x = 147;
		dest(destDec);

		sourceDec.x = 315;
		sourceDec.y = 0;
		sourceDec.h = 25;
		sourceDec.w = 21;


		while (!quit)
		{
			//whenever count reaches 20 give me a random number from 1 to 4
			count++;
			if (count >= 20)
			{
				rnd = rand() % 4 + 1;
				count = 0;
			}
			SDL_BlitSurface(gHelloWorld, NULL, gScreenSurface, NULL);

			while (SDL_PollEvent(&event))
			{
				if (event.type == SDL_QUIT){
					quit = 1;
				}
				if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP){
					handleKeys(&event, &spacemanMovement, &spacemanVelocity);
				}
			}
			// this should only be done when moving.
			sourceRect.x += 70;//move pacman
			gsourceRect.x += 70;//move ghost 1
			g2sourceRect.x += 61;//move ghost 2
			g3sourceRect.x += 61;//move ghost 3

			//if it is the last icon back to first
			if (sourceRect.x >= 240)
			{
				sourceRect.x = 0;
			}
			if (gsourceRect.x >= 430)
			{
				gsourceRect.x = 300;
			}
			if (g2sourceRect.x >= 310)
			{
				g2sourceRect.x = 186;
			}
			if (g3sourceRect.x >= 126)
			{
				g3sourceRect.x = 0;
			}


			if (spacemanVelocity > 0)
			{
				switch (spacemanMovement){
				case 7://go right(d)
					if (destRect.x <= 720)//to prevent pacman to go out from right side of screen
					{
						sourceRect.y = 220;
						destRect.x += spacemanVelocity;
					}
					else
						destRect.x = 720;
					break;
				case 8://go up(w)
					sourceRect.y = 80;
					destRect.y -= spacemanVelocity;

					break;
				case 6://go down(s)
					if (destRect.y <= 540)//to prevent pacman to go out from bottom side of screen
					{
						sourceRect.y = 10;
						destRect.y += spacemanVelocity;
					}
					else
						destRect.y = 540;
					break;
				case 9://go left(a)
					sourceRect.y = 150;
					destRect.x -= spacemanVelocity;
				}
			}

			//ghost 1
			switch (rnd)//move first ghost depending from random number
			{
			case 1://go down 
				if (gdestRect.y <= 540)//to prevent ghost to go out from right side of screen
				{
					gsourceRect.y = 10;
					gdestRect.y += GHOST_SPEED;
				}
				else gdestRect.y = 540;
				break;
			case 2://go up
				gsourceRect.y = 80;
				gdestRect.y -= GHOST_SPEED; break;
			case 3://go left
				gsourceRect.y = 150;
				gdestRect.x -= GHOST_SPEED; break;
			case 4://go right
				if (gdestRect.x <= 720)//to prevent ghost to go out from bottom side of screen
				{
					gsourceRect.y = 220;
					gdestRect.x += GHOST_SPEED;
				}
				else  gdestRect.x = 720;
				break;

			}

			//ghost 2
			switch (rnd)
			{
			case 1://go up
				g2sourceRect.y = 189;
				g2destRect.y -= GHOST_SPEED; break;
			case 2://go down
				if (g2destRect.x <= 720)//to prevent pacman to go out from bottom side of screen
				{
					g2sourceRect.y = 125;
					g2destRect.x += GHOST_SPEED;
				}
				else  g2destRect.x = 720;
				break;
			case 3://go right
				if (g2destRect.y <= 540)//to prevent pacman to go out from bottom side of screen
				{
					g2sourceRect.y = 0;
					g2destRect.y += GHOST_SPEED;
				}
				else g2destRect.y = 540;
				break;
			case 4://go left
				g2sourceRect.y = 63;
				g2destRect.x -= GHOST_SPEED; break;

			}
			//ghost 3
			switch (rnd)
			{
			case 1://go up
				g3sourceRect.y = 189;
				g3destRect.y -= GHOST_SPEED; break;
			case 2://go left
				g3sourceRect.y = 63;
				g3destRect.x -= GHOST_SPEED; break;
			case 3://go right
				g3sourceRect.y = 0;
				if (g3destRect.y <= 540)//to prevent pacman to go out from bottom side of screen
				{					
					g3destRect.y += GHOST_SPEED;
				}
				else g3destRect.y = 540;
				break;			
			case 4://go down
				g3sourceRect.y = 125;
				if (g3destRect.x <= 720)//to prevent pacman to go out from bottom side of screen
				{					
					g3destRect.x += GHOST_SPEED;
				}
				else  g3destRect.x = 720;
				break;
			}

			//check Collosion between pacman and first ghost
			if (checkCollision(destRect, gdestRect))
			{
				countPoints++;//count collisions
				sourcePoint.x += 21;//get numbers from Arial.bmp
				switch (countPoints)
				{
				case 5: sourcePoint.x = 0;
					sourcePoint.y = 25; break;
				case 10: sourcePoint.x = 315;
					sourcePoint.y = 0;
					countPoints = 0;
					sourceDec.x += 21;
					if (sourceDec.x == 420)
					{
						sourceDec.x = 315;
					}
					break;
				}
				//spawn ghost 1 into a new random location on screen
				gdestRect.x = rand() % 400;
				gdestRect.y = rand() % 400;;

			}
			if (checkCollision(destRect, g2destRect))
			{

				countPoints++;
				sourcePoint.x += 21;
				switch (countPoints)
				{
				case 5: sourcePoint.x = 0;
					sourcePoint.y = 25; break;
				case 10: sourcePoint.x = 315;
					sourcePoint.y = 0;
					countPoints = 0;
					sourceDec.x += 21;
					if (sourceDec.x == 420)
					{
						sourceDec.x = 315;
					}break;
				}

				//spawn ghost 2 into a new random location on screen
				g2destRect.x = rand() % 400;
				g2destRect.y = rand() % 400;;
			}

			//check Collosion between pacman and third ghost
			if (checkCollision(destRect, g3destRect))
			{
				countPoints++;//count collisions
				sourcePoint.x += 21;//get numbers from Arial.bmp
				switch (countPoints)
				{
				case 5: sourcePoint.x = 0;
					sourcePoint.y = 25; break;
				case 10: sourcePoint.x = 315;
					sourcePoint.y = 0;
					countPoints = 0;
					sourceDec.x += 21;
					if (sourceDec.x == 420)
					{
						sourceDec.x = 315;
					}
					break;
				}
				//spawn ghost 1 into a new random location on screen
				g3destRect.x = rand() % 400;
				g3destRect.y = rand() % 400;;

			}
	
			SDL_BlitSurface(pacman, &sourceRect, gScreenSurface, &destRect);
			SDL_BlitSurface(ghost, &gsourceRect, gScreenSurface, &gdestRect);
			SDL_BlitSurface(ghost2, &g2sourceRect, gScreenSurface, &g2destRect);
			SDL_BlitSurface(ghost3, &g3sourceRect, gScreenSurface, &g3destRect);
			SDL_BlitSurface(b, &sB, gScreenSurface, &dB);
			SDL_BlitSurface(l, &sL, gScreenSurface, &dL);
			SDL_BlitSurface(e, &sE, gScreenSurface, &dE);
			SDL_BlitSurface(n, &sN, gScreenSurface, &dN);
			SDL_BlitSurface(d, &sD, gScreenSurface, &dD);
			SDL_BlitSurface(i, &sI, gScreenSurface, &dI);
			SDL_BlitSurface(Colon, &sourceColon, gScreenSurface, &destColon);
			SDL_BlitSurface(Points, &sourcePoint, gScreenSurface, &destPoint);
			SDL_BlitSurface(DecPoints, &sourceDec, gScreenSurface, &destDec);
			SDL_Delay(50);
			SDL_UpdateWindowSurface(gWindow);

		}

	}

	//Free resources and close SDL
	close();
	
	return 0;

	}
Esempio n. 15
0
int main(int argc, char** argv){
  // Set interactive mode for debugging the program when started with arguments
  bool interactive = false;
  if(argc > 1) interactive = true;

  // Initialize GLFW
  if (!glfwInit()) fatalError("GLFW could not be initialized");
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

  // Create window
  GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, NAME, NULL, NULL);
  if (window == NULL) fatalError("Failed to create GLFW window");
  glfwMakeContextCurrent(window);

  // Controls
  glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
  glfwSetKeyCallback(window, keycallback);

  // Start GLEW
  glewExperimental = GL_TRUE;
  if (glewInit() != GLEW_OK) fatalError("Failed to initialize GLEW");
  glViewport(0, 0, WIDTH, HEIGHT);

  // Load shaders
  Shader shader1("shaders/basic.vertex", "shaders/basic.frag");
  shader1.use();
  glUniform1f(glGetUniformLocation(shader1.program, "first"), FIRST);
  glUniform1f(glGetUniformLocation(shader1.program, "second"), SECOND);
  glUniform1f(glGetUniformLocation(shader1.program, "third"), THIRD);

  Shader shader2("shaders/basic.vertex", "shaders/advanced.frag");

  // Raster scene settings
  Camera camera(glm::vec3(0.0f, 0.0f, 3.0f), -90.0f, 0.0f);
  GLfloat vertices[] = {
    -1.0f, -1.0f, 0.0f, -1.0f, -1.0f,
     1.0f, -1.0f, 0.0f,  1.0f, -1.0f,
    -1.0f,  1.0f, 0.0f, -1.0f,  1.0f,
     1.0f,  1.0f, 0.0f,  1.0f,  1.0f
  };
  GLuint indices[] = {
    0, 1, 2,
    2, 1, 3
  };

  GLuint VAO, VBO, EBO;
  glGenVertexArrays(1, &VAO);
  glBindVertexArray(VAO);

  glGenBuffers(1, &VBO);
  glBindBuffer(GL_ARRAY_BUFFER, VBO);
  glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0);
  glEnableVertexAttribArray(0);
  glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*) (3* sizeof(GLfloat)));
  glEnableVertexAttribArray(1);

  glGenBuffers(1, &EBO);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

  glBindVertexArray(0);

  // FPS counter
  bool isTicking = true;
  int fpscount = 0;
  GLfloat fpstime = 0.0f;

  // Frame timings
  GLfloat timeFromStart = START;
  GLfloat lastFrame = (GLfloat) glfwGetTime();
  GLfloat thisFrame = (GLfloat) glfwGetTime();
  GLfloat deltaTime = thisFrame - lastFrame;

  Shader shader = shader1;
  int shaderNum = 1;

  while(!glfwWindowShouldClose(window)){
    thisFrame = (GLfloat) glfwGetTime();
    deltaTime = thisFrame - lastFrame;
    if(isTicking){
      timeFromStart += deltaTime;
      fpscount++;
      fpstime += deltaTime;
      if(fpstime > 1.0f) {
        if(FPSlog){
          std::cout << "FPS: " << (GLfloat) fpscount /  fpstime << std::endl;
        }
        fpstime = 0.0f;
        fpscount = 0;
      }
    }

    // Handle Inputs if we are in interactive mode
    //if (interactive) {
    glfwPollEvents();
    handleKeys(window, timeFromStart, isTicking, shader);
    //}


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

    glm::mat4 model;
    model = glm::scale(model, glm::vec3(SCALE, SCALE, SCALE));
    glm::mat4 view;
    view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f));
    glm::mat4 proj = glm::perspective(glm::radians(45.0f), (GLfloat) WIDTH / (GLfloat) HEIGHT, 0.1f, 100.0f);
    glm::mat4 trans = proj * view * model;

    if(timeFromStart > 40.0f && shaderNum == 1) {
      shader = shader2;
      shaderNum++;
    }

    shader.use();

    glUniform1f(glGetUniformLocation(shader.program, "time"), timeFromStart);
    glUniformMatrix4fv(glGetUniformLocation(shader.program, "transform"), 1, GL_FALSE, glm::value_ptr(trans));
    glBindVertexArray(VAO);
    // Draw
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);

    glBindVertexArray(0);
    glfwSwapBuffers(window);
    lastFrame = thisFrame;
  }
  glfwTerminate();
  return 0;
}
Esempio n. 16
0
// If main_cycle returns false, don't process more events!
int AgiEngine::mainCycle() {
	unsigned int key, kascii;
	VtEntry *v = &_game.viewTable[0];

	pollTimer();
	updateTimer();

	key = doPollKeyboard();

	// In AGI Mouse emulation mode we must update the mouse-related
	// vars in every interpreter cycle.
	//
	// We run AGIMOUSE always as a side effect
	if (getFeatures() & GF_AGIMOUSE || true) {
		_game.vars[28] = _mouse.x / 2;
		_game.vars[29] = _mouse.y;
	}
	if (key == KEY_PRIORITY) {
		_sprites->eraseBoth();
		_debug.priority = !_debug.priority;
		_picture->showPic();
		_sprites->blitBoth();
		_sprites->commitBoth();
		key = 0;
	}

	if (key == KEY_STATUSLN) {
		_debug.statusline = !_debug.statusline;
		writeStatus();
		key = 0;
	}

	// Click-to-walk mouse interface
	if (_game.playerControl && v->flags & ADJ_EGO_XY) {
		int toX = v->parm1;
		int toY = v->parm2;

		// AGI Mouse games use ego's sprite's bottom left corner for mouse walking target.
		// Amiga games use ego's sprite's bottom center for mouse walking target.
		// TODO: Check what Atari ST AGI and Apple IIGS AGI use for mouse walking target.
		if (getPlatform() == Common::kPlatformAmiga)
			toX -= (v->xSize / 2); // Center ego's sprite horizontally

		// Adjust ego's sprite's mouse walking target position (These parameters are
		// controlled with the adj.ego.move.to.x.y-command). Note that these values rely
		// on the horizontal centering of the ego's sprite at least on the Amiga platform.
		toX += _game.adjMouseX;
		toY += _game.adjMouseY;

		v->direction = getDirection(v->xPos, v->yPos, toX, toY, v->stepSize);

		if (v->direction == 0)
			inDestination(v);
	}

	kascii = KEY_ASCII(key);

	if (kascii)
		setvar(vKey, kascii);

process_key:

	switch (_game.inputMode) {
	case INPUT_NORMAL:
		if (!handleController(key)) {
			if (key == 0 || !_game.inputEnabled)
				break;
			handleKeys(key);

			// if ESC pressed, activate menu before
			// accept.input from the interpreter cycle
			// sets the input mode to normal again
			// (closes: #540856)
			if (key == KEY_ESCAPE) {
				key = 0;
				goto process_key;
			}

			// commented out to close Sarien bug #438872
			//if (key)
			//	_game.keypress = key;
		}
		break;
	case INPUT_GETSTRING:
		handleController(key);
		handleGetstring(key);
		setvar(vKey, 0);	// clear ENTER key
		break;
	case INPUT_MENU:
		_menu->keyhandler(key);
		_gfx->doUpdate();
		return false;
	case INPUT_NONE:
		handleController(key);
		if (key)
			_game.keypress = key;
		break;
	}
	_gfx->doUpdate();

	if (_game.msgBoxTicks > 0)
		_game.msgBoxTicks--;

	return true;
}
Esempio n. 17
0
hkDemo::Result SlidingWorldDemo::stepDemo()
{
	makeFakeInput();

	hkBool doShift = false;
	hkVector4 newCenter;
	handleKeys(doShift, newCenter);



	m_world->lock();

 	if(doShift)
	{
		   // reset the box colors to a light grey
		for (int i = 0; i < m_boxes.getSize(); i++)
		{
			HK_SET_OBJECT_COLOR(hkUlong(m_boxes[i]->getCollidable()), hkColor::LIGHTGREY);
		}

		{
			//hkVector4 currentCenter = m_centers[((m_ticks / delay) + (numCenters-1)) % numCenters];
			//HK_DISPLAY_STAR(currentCenter, 2.5f, 0xFF00FF00);
			//HK_DISPLAY_LINE(nextCenter, m_currentCenter, 0xFF00FF00);
		}

		hkVector4 diff; 
		diff.setSub4(newCenter, m_currentCenter);
		
		hkArray<hkpBroadPhaseHandle*> objectsEnteringBroadphaseBorder;
		
		hkVector4 effectiveShift;
		if( g_variants[m_variantId].m_mode == SlidingWorldDemoVariant::RECENTER_BROAD_PHASE_ONLY )
		{
			recenterBroadPhaseVariant(diff, objectsEnteringBroadphaseBorder, effectiveShift);
			
		}
		else // SlidingWorldDemoVariant::SHIFT_COORDINATE_SPACE)
		{
			shiftCoordinateSystemVariant(diff, objectsEnteringBroadphaseBorder, effectiveShift);
			
		} 

		removeDuplicatesFromArray(objectsEnteringBroadphaseBorder);

		// Some bodies may have to be removed from simulation, some may need to be added.
		{		
			removeBodiesLeavingBroadphaseFromSimulation(objectsEnteringBroadphaseBorder);
			addBodiesNewlyInsideSimulationAreaToSimulation();
		}

		m_currentCenter = newCenter;
	
	}

	
	// draw the grid in cyan
	{
		hkVector4 minOffset; minOffset.set(-5, 1, -5);
		hkVector4 maxOffset; maxOffset.set(5,1,5);
		hkVector4 min, max;

		for (int i = -2; i <= 2; i++)
		for (int j = -2; j <= 2; j++)
		{
			min.set((hkReal)10*i, 0, (hkReal)10*j);
			max = min;
			min.add4(minOffset);
			max.add4(maxOffset);
			drawAabb(min, max, hkColor::CYAN );
		}
	}

	 // draw the broadphase extents in red
	displayCurrentBroadPhaseAabb(m_world, hkColor::RED );

	// draw locations of all 'unsimulated' bodies
	drawUnsimulatedBodies();

	if( m_currentMode == AUTOMATIC_SHIFT)
	{
		m_ticks++;
	}

	m_world->unlock();

	return hkDefaultPhysicsDemo::stepDemo();
}
Esempio n. 18
0
void drawScene(){
	handleKeys();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	glLoadIdentity(); //load identity matrix

	GLdouble r = 16.0;
	GLdouble x = r * cos(teta) * cos(fi);
	GLdouble y = r * sin(teta);
	GLdouble z = r * cos(teta) * sin(fi);

	gluLookAt( x , y, z, 0, 0, 0, r * cos(teta + 0.1) * cos(fi), r * sin(teta + 0.1), r * cos(teta + 0.1) * sin(fi));
	
	glScalef(1.0, 1.0, 1.0);
	//
	//
	glEnable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	glColor3f(1.0,1.0,1.0);
	GLfloat dd = 7.0f;
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-dd, dd, 0.1f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-dd, -dd, 0.1f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(dd, -dd, 0.1f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(dd, dd, 0.1f);
	glEnd();

	glDisable(GL_TEXTURE_2D);
	
	glEnable(GL_LIGHTING);
	
	if(location_t){			
		int sign = 1;
		if(location_x/640 > 0.25)
			sign *= -1;
		glTranslatef(location_x/640*i*0.1 * sign, location_y/480*i*0.1, 0);
		printf("location_x = %f, location_x*i*0.01 =  = %f\n", location_x/640, location_x/640*i*0.1);
		if((location_y/480*i*0.1) < 9* location_y/480)
			i++;
	}
	//Draw teapot
	glColor3f(0.4, 0.2, 0.1);
	glTranslatef(0,0,2.0f);
	glRotatef(-264.60,1,0,0);
	
	// Draw sphere

	glTranslatef(5.0f,3.0f + move_y, 3.0f);
	glutSolidSphere(1, 30, 30);
	glTranslatef(-6.0f,-3.0f - move_y , 1.0f);
	glRotatef(rotate,0,1,0);
	
	// Draw a Teapot.
    glutSolidTeapot(3);
	glutSwapBuffers();
	glutPostRedisplay();

	if(move && move_y > - 2.7 && timeB == 0){
		move_y -= 0.01;
	}
	if(move_y <= -2.7 && timeB == 0){
		timeB = 1;
	}
	if(timeB == 1){
		move_y += 0.01;
		if(move_y > -1.0)
			timeB = 2;
	}
	if(timeB == 2){
		move_y -= 0.01;
		if(move_y <= -2.7)
			timeB = 3;
	}
}
Esempio n. 19
0
int AgiEngine::handleController(int key) {
	VtEntry *v = &_game.viewTable[0];
	int i;

	// AGI 3.149 games, The Black Cauldron and King's Quest 4 need KEY_ESCAPE to use menus
	// Games with the GF_ESCPAUSE flag need KEY_ESCAPE to pause the game
	if (key == 0 ||
		(key == KEY_ESCAPE && getVersion() != 0x3149 && getGameID() != GID_BC && getGameID() != GID_KQ4 && !(getFeatures() & GF_ESCPAUSE)) )
		return false;

	if ((getGameID() == GID_MH1 || getGameID() == GID_MH2) && (key == KEY_ENTER) &&
			(_game.inputMode == INPUT_NONE)) {
		key = 0x20; // Set Enter key to Space in Manhunter when there's no text input
	}

	debugC(3, kDebugLevelInput, "key = %04x", key);

	for (i = 0; i < MAX_CONTROLLERS; i++) {
		if (_game.controllers[i].keycode == key) {
			debugC(3, kDebugLevelInput, "event %d: key press", _game.controllers[i].controller);
			_game.controllerOccured[_game.controllers[i].controller] = true;
			return true;
		}
	}

	if (key == BUTTON_LEFT) {
		if ((getflag(fMenusWork) || (getFeatures() & GF_MENUS)) && _mouse.y <= CHAR_LINES) {
			newInputMode(INPUT_MENU);
			return true;
		}
	}

	// Show predictive dialog if the user clicks on input area
	if (key == BUTTON_LEFT &&
			(int)_mouse.y >= _game.lineUserInput * CHAR_LINES &&
			(int)_mouse.y <= (_game.lineUserInput + 1) * CHAR_LINES) {
		GUI::PredictiveDialog _predictiveDialog;
		_predictiveDialog.runModal();
		strcpy(_predictiveResult, _predictiveDialog.getResult());
		if (strcmp(_predictiveResult, "")) {
			if (_game.inputMode == INPUT_NONE) {
				for (int n = 0; _predictiveResult[n]; n++)
					keyEnqueue(_predictiveResult[n]);
			} else {
				strcpy((char *)_game.inputBuffer, _predictiveResult);
				handleKeys(KEY_ENTER);
			}
		}
		/*
		if (predictiveDialog()) {
			if (_game.inputMode == INPUT_NONE) {
				for (int n = 0; _predictiveResult[n]; n++)
					keyEnqueue(_predictiveResult[n]);
			} else {
				strcpy((char *)_game.inputBuffer, _predictiveResult);
				handleKeys(KEY_ENTER);
			}
		}
		*/
		return true;
	}

	if (_game.playerControl) {
		int d = 0;

		if (!KEY_ASCII(key)) {
			switch (key) {
			case KEY_UP:
				d = 1;
				break;
			case KEY_DOWN:
				d = 5;
				break;
			case KEY_LEFT:
				d = 7;
				break;
			case KEY_RIGHT:
				d = 3;
				break;
			case KEY_UP_RIGHT:
				d = 2;
				break;
			case KEY_DOWN_RIGHT:
				d = 4;
				break;
			case KEY_UP_LEFT:
				d = 8;
				break;
			case KEY_DOWN_LEFT:
				d = 6;
				break;
			}
		}

		if (!(getFeatures() & GF_AGIMOUSE)) {
			// Handle mouse button events
			if (key == BUTTON_LEFT) {
				if (getGameID() == GID_PQ1 && _game.vars[vCurRoom] == 116) {
					// WORKAROUND: Special handling for mouse clicks in the newspaper
					// screen of PQ1. Fixes bug #3018770.
					d = 3;	// fake a right arrow key (next page)
				} else {
					// Click-to-walk mouse interface
					v->flags |= fAdjEgoXY;
					v->parm1 = WIN_TO_PIC_X(_mouse.x);
					v->parm2 = WIN_TO_PIC_Y(_mouse.y);
					return true;
				}
			}
		}

		if (d || key == KEY_STATIONARY) {
			v->flags &= ~fAdjEgoXY;
			v->direction = v->direction == d ? 0 : d;
			return true;
		}
	}

	return false;
}
Esempio n. 20
0
void drawScene()
{

    handleKeys();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    //glEnable(GL_FOG);

    float FogCol[3]={0.8f,0.8f,0.8f}; // Define a nice light grey
    glFogfv(GL_FOG_COLOR,FogCol);
    glFogi(GL_FOG_MODE, GL_LINEAR); // Note the 'i' after glFog - the GL_LINEAR constant is an integer.
    glFogf(GL_FOG_START, 2.0*player_z);
    glFogf(GL_FOG_END, 3.0*player_z);



    gluLookAt(player_x, player_y, player_z,
            player_x+80.0*cos(camera_theta)*cos(camera_fi), player_y+80.0*cos(camera_theta)*sin(camera_fi),player_z-80.0+80.0*sin(camera_theta),
            0.0, 0.0, 1.0);
    drawFlor();

    GLfloat mShininess[] = {50};

    GLfloat DiffuseMaterial[3]={1.0, 0.0, 0.0};
    if(water)
    {
        DiffuseMaterial[0]=0.0;
        DiffuseMaterial[1]=1.0;
    }

    GLfloat AmbientMaterial[] = {0.0, 0.0, 0.0};
    GLfloat SpecularMaterial[] = {1.0, 1.0, 1.0};


    if(water)glUseProgram(p);
    else glUseProgram(w);

    glEnable(GL_TEXTURE_2D);
    for (int i = 0; i<map_width; i++)
    {

        if(world_map[i][3] < 3.3 || world_map[i][2] < 1.66)glBindTexture(GL_TEXTURE_2D, buildingSmall);
        else if(world_map[i][3] < 6.3 || world_map[i][2] < 3.33)glBindTexture(GL_TEXTURE_2D, buildingLow);
        else glBindTexture(GL_TEXTURE_2D, buldingHgh);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glPushMatrix();
        glTranslatef((GLfloat)world_map[i][0]*block_size, (GLfloat)world_map[i][1]*block_size, 0.0);
        //printf("%f %f\n",world_map[i][0],world_map[i][1]);
        drawCube(water?world_map[i][2]:world_map[i][3]);

    
       
        

        glPopMatrix();
        

    }






    glDisable(GL_TEXTURE_2D);




    glutSwapBuffers();
    glutPostRedisplay();
    glUseProgram(0);
}
Esempio n. 21
0
void run(SDL_Surface* screen, int fd){
  int currRoom, numSprites, i;
  SDL_Event event;

  Sprite components[NUMTYPES*NUMSPRITES];

  //Writing Variables
  struct Message message;
  int keyState[NUMKEYS];
  
  //Room Caption Variables
  char room_caption[7];
  strcpy(room_caption, "Room 0");


  //Local Chat Variables
  int typing = FALSE;  

  TTF_Font *font = TTF_OpenFont("src/Teen.ttf", 16);
  SDL_Color textColor = {0,0,0};

  char chatmsg[256];
  memset(chatmsg, '\0', 256); 

  SDL_Surface *chatsurface = NULL;
  SDL_Rect typePosition;
  typePosition.x = 30;
  typePosition.y = 550;


  //Server-wide chat log display positions
  SDL_Rect position[MAXCHATMESSAGES];

  for(i = 0; i < MAXCHATMESSAGES; i++){
    position[i].x = MSGLEFT;
    position[i].y = MSGTOP + ( MSGHEIGHT * (5 - i) );
  }


  currRoom = 0;
  
  long unsigned lastTick;
  lastTick = SDL_GetTicks();
  
  /*---------------------------------------

             END OF VARIABLE SEA

    ---------------------------------------*/



    while(1){
    //Considering how slow it's going, the FPS cap is probably useless now...
    lastTick = FPScap(lastTick);
    
    //Get the number of sprites to be read
    read(fd, &numSprites, sizeof(int));

    //The room has changed and the new room number has been read instead
    if(numSprites >= 40){
      
      currRoom = numSprites - 40;
      
      //Change room caption
      room_caption[5] = (char)(currRoom + 48);
      SDL_WM_SetCaption(room_caption, NULL);
      printf("Now in %s\n", room_caption);

      //Read number of sprites to be read, for real this time.
      read(fd, &numSprites, sizeof(int));
    
    }

    //Read all sprites
    for(i=0;i<numSprites;i++){
      read(fd, &(components[i]), sizeof(components[i]));
    }    

    //Draw components and blit the current chatsurface if player is typing
    draw(components, numSprites, screen);

    //Draw the chat message in progress
    if(chatsurface && strlen(chatmsg) > 0)
      SDL_BlitSurface(chatsurface, NULL, screen, &typePosition);

    //Draw the chat messages stored in text[]
    SDL_SemWait(textSem);

    for(i = 0; i<numMessages; i++){
      SDL_BlitSurface(text[i], NULL, (SDL_Surface*)screen, &position[i]); 
    }

    SDL_SemPost(textSem);
    
    //Flip the screen
    SDL_Flip(screen);    


    /*---------------
      EVENT HANDLING
      ---------------*/

    SDL_EnableUNICODE( SDL_ENABLE );
    SDL_PollEvent(&event);
    SDL_EnableUNICODE( SDL_DISABLE );


    if(event.type == SDL_QUIT)
      break;
    

    /*-----------------
      ENTER KEY PRESSED
      -----------------*/
    if(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN){
      
      //Started typing a message
      if(!typing){ 
	typing = TRUE;
	strcpy(chatmsg, clientname);
	chatsurface = TTF_RenderText_Solid(font, chatmsg, textColor);
      }
      
      //Finished typing a message
      else{
	typing = FALSE;
	
	if(strlen(chatmsg) > namelen){

	  //Write the chat message to the shared msgbuf
	  SDL_SemWait(msgbuf_sem);
	  strcpy(msgbuf, chatmsg);
	  SDL_SemPost(msgbuf_sem);
	  
	  //Reset the chat message
	  memset(chatmsg, '\0', 256);
	}
	
	//Free the chatsurface
	if(chatsurface != NULL){
	  SDL_FreeSurface(chatsurface);
	  chatsurface = NULL;
	}

      }
      
    }

  

    /*----------------
      CONTINUE TYPING
      ----------------*/
    else if(typing){

      //Handle chat if key pressed
      if(event.type == SDL_KEYDOWN)
	chatsurface = handleChat(event, namelen, chatmsg, chatsurface, font, textColor);      

    }
    

    /*--------------
      Message Setup
    ----------------*/
    message.clientid = getpid();
    message.roomid = currRoom;
	     
    for(i=0; i<NUMTYPES; i++)
      keyState[i] = FALSE;

    /*-------------------------
      Check event and keystates
    ---------------------------*/
    if(!typing)
      handleKeys(keyState);

    //Write the clientid and roomid
    write(fd, &message, sizeof(message));

    //Write the keystates
    for(i=0;i<NUMKEYS;i++){
      write(fd, &(keyState[i]), sizeof(int));
    }
   
  }

  if(chatsurface != NULL)
    SDL_FreeSurface(chatsurface);
}
Esempio n. 22
0
void NetworkRoleMenu::handleInput() {
    handleKeys();
}