Exemplo n.º 1
0
int main(void) {
  uint8_t opt = 0;

  /* Reset of all peripherals, Initializes the Flash interface and the SysTick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();

  /* Enable USART2 interrupt */
  HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(USART2_IRQn);

printMessage:

  printWelcomeMessage();

  while (1)  {
    opt = readUserInput();
    if(opt > 0) {
      processUserInput(opt);
      if(opt == 3)
        goto printMessage;
    }
    performCriticalTasks();
  }
}
Exemplo n.º 2
0
/*
	This is the update function
	double dt - This is the amount of time in seconds since the previous call was made

	Game logic should be done here.
	Such as collision checks, determining the position of your game characters, status updates, etc
	If there are any calls to write to the console here, then you are doing it wrong.

    If your game has multiple states, you should determine the current state, and call the relevant function here.
*/
void update(double dt)
{
    // get the delta time
    elapsedTime += dt;
    deltaTime = dt;

    processUserInput(); // checks if you should change states or do something else with the game, e.g. pause, exit
    moveCharacter();    // moves the character, collision detection, physics, etc
    // sound can be played here too.
}
Exemplo n.º 3
0
void Game::playGame() {
	gameActive = true;

	string userInput;
	cout << describeRoom(current_room) << endl;

	//----------- GAME LOOP -----------------
	do{
		cout << ">";
		getline(cin, userInput);
		processUserInput(userInput);
		doAction(current_action);
	} while (gameActive);
	//------------------------------------

	system("pause");
}
Exemplo n.º 4
0
void gameplay(){
    processUserInput();     // checks if you should change states or do something else with the game, e.g. pause, exit
    // Cobwebbed
    if (cobwebToken == 0){
        moveCharacter();    // moves the character, collision detection, physics, etc
    }
    invincibility();
    
    if (Monster == STARTGAME){
        monsterDamage();    // check ghost damage
    }

    traps();                // check traps
    monsterSpawn();         // check for monster spawn
    guardMovement(); 
    monstersMoveChecker();  // Moving trap function

    // sound can be played here too.
    // When the player dies and the gamestate switches to the game over screen
	if (player.health <= 0){
		g_eGameState = GAMEOVER;
		PlaySound(L"sounds/dietheme.wav", NULL, SND_ASYNC | SND_LOOP);
	}
    // When the boss dies and the gamestate switches to the victory screen
    if (Bhealth <= 0){
        g_eGameState = VICTORY;
        PlaySound(L"sounds/victorytheme.wav", NULL, SND_ASYNC | SND_LOOP);
    }
    // When player not in boss room
	if (gamesoundToken == 0){
		if (level != BOSSROOM){
			PlaySound(L"sounds/gametheme.wav", NULL, SND_ASYNC | SND_LOOP);
			gamesoundToken++;
		}
	}
    // When player in boss room
	if (level == BOSSROOM){
		if (bossSoundToken == 0){
			PlaySound(L"sounds/bosstheme.wav", NULL, SND_ASYNC | SND_LOOP);
			bossSoundToken++;
		}
	}
}
int main(int /*argc*/, char** /*argv*/)
{
    sf::Vector2i screenSize{800, 600};
    sf::RenderWindow mainWindow(sf::VideoMode(screenSize.x, screenSize.y),
                                "myproject");
    mainWindow.setVerticalSyncEnabled(true);
    // std::stringstream s;
    common::StreamLog slog{std::cout};
    lmg03::World w{slog};

    sf::Clock frameClock;

    constexpr float baseSpeed = 50.f;
    constexpr float frameDuration = 1.f / 60.f;

    while (mainWindow.isOpen())
    {
        sf::Event event;
        while (mainWindow.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                mainWindow.close();
            }
        }

        const auto duration = frameClock.getElapsedTime();
        if (duration.asSeconds() < frameDuration)
            continue;

        frameClock.restart();

        sf::Vector2f movement{processUserInput(baseSpeed, mainWindow)};
        w.advance(duration, movement);

        w.display_on(mainWindow);
        mainWindow.display();
    }
}
Exemplo n.º 6
0
/*This is the update function
double dt - This is the amount of time in seconds since the previous call was made

Game logic should be done here.
Such as collision checks, determining the position of your game characters, status updates, etc
If there are any calls to write to the console here, then you are doing it wrong.
If your game has multiple states, you should determine the current state, and call the relevant function here.*/
void update(double dt)
{
    //Gets the delta time
    elapsedTime += dt;
    deltaTime = dt;
	
	//Updates the world grid. Only do it once per level. Set bupdateWorldGrid to true whenever you load a new level.
	//It will turn itself off after it update once.
	if (bupdateWorldGrid == true) {
		updateWorldGrid(g_levelNumber);
		bupdateWorldGrid = false;
	}

	//Updates the position of the camera.
	moveCameraTo();

	//Checks if you should change states or do something else with the game, e.g. pause, exit.
    processUserInput(); 
    
	//Sets the position of the teleporters in the level and check if the player can teleport through them in this frame.
	setItemsInLevel();

	//Updates the position of the monsters and if the player is killed by them.
	monsterUpdate();

	//Moves the character, collision detection, physics, etc
	moveCharacter();

	//Updates the position of the box. Ensure that this is called AFTER moveCharacter to prevent glitches.
	boxesUpdate();

	//Checks if the player has walked over an item.
	detectItemsCollision();
	
	//Update the bullet(?)
	bulletUpdate();

}
Exemplo n.º 7
0
int main(void) {
	uint8_t opt = 0;

	/* Reset of all peripherals, Initializes the Flash interface and the SysTick. */
	HAL_Init();

	/* Configure the system clock */
	SystemClock_Config();

	/* Initialize all configured peripherals */
	MX_GPIO_Init();
	MX_USART2_UART_Init();

printMessage:

	printWelcomeMessage();

	while (1)  {
		opt = readUserInput();
		processUserInput(opt);
		if(opt == 3)
			goto printMessage;
	}
}
Exemplo n.º 8
0
/* Grab commands from clients and process commands
 * Remove clients if the connection is lost of the client want to quit
 * 
 * clientManager : ClientManager* - the client manager
 * readSet : fd_set* - the set of file descriptors that has information to be read 
 * return : void
 */
void processClientsRequests(ClientManager* clientManager, fd_set* readSet){
	char* userInput;
	Client* clients = clientManager->clients;
	int i, connectingStatus;
	int maxCount = clientManager->maxI + 1; 
	for ( i = 0 ; i < maxCount ; i++){
		if (clients[i].soc > 0){
			if (FD_ISSET(clients[i].soc, readSet)){				
				connectingStatus = readfromclient(&(clients[i]), &userInput);
				if (connectingStatus == 0){
					printf("Got full command from client %d\n", i);
					processUserInput(clientManager, userInput, i);
					removeClient(clientManager, i);
				}
				else if (connectingStatus == 1){
					// readfromclient returns 1 when client lost connection 
					removeClient(clientManager, i);
				}
				// readfromclient returns 2 when a full command is not
				free(userInput);
			}
		}
	}
}
Exemplo n.º 9
0
int main(int argc, const char **argv)
{
  // Instantiate a ModelManager:
  ModelManager manager("Test wiimote");

  nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
  manager.addSubComponent(ofs);

  nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
  manager.addSubComponent(ifs);

  // Parse command-line:
  if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);

  manager.start();



  //Init camara params
        itsIntrinsicMatrix = cvCreateMat( 3, 3, CV_32FC1);
        itsDistortionCoeffs = cvCreateMat( 4, 1, CV_32FC1);
  itsCameraRotation = cvCreateMat( 1, 3, CV_64FC1);
  itsCameraTranslation = cvCreateMat( 1, 3, CV_64FC1);

  //cvmSet(itsDistortionCoeffs, 0, 0, -0.2403274);
  //cvmSet(itsDistortionCoeffs, 1, 0, 2.5312502);
  //cvmSet(itsDistortionCoeffs, 2, 0, -0.0439848);
  //cvmSet(itsDistortionCoeffs, 3, 0, -0.0106820);
  cvmSet(itsDistortionCoeffs, 0, 0, 0);
  cvmSet(itsDistortionCoeffs, 1, 0, 0);
  cvmSet(itsDistortionCoeffs, 2, 0, 0);
  cvmSet(itsDistortionCoeffs, 3, 0, 0);

  cvmSet(itsCameraRotation, 0, 0, 2.391102);
  cvmSet(itsCameraRotation, 0, 1, 0);
  cvmSet(itsCameraRotation, 0, 2, 0);

  cvmSet(itsCameraTranslation, 0, 0, 0);
  cvmSet(itsCameraTranslation, 0, 1, 0);
  cvmSet(itsCameraTranslation, 0, 2, 840.954432);


  //cvmSet(itsIntrinsicMatrix, 0, 0, 290.85342); cvmSet(itsIntrinsicMatrix, 0, 1, 0); cvmSet(itsIntrinsicMatrix, 0, 2, 320/2); //159.50000);
  //cvmSet(itsIntrinsicMatrix, 1, 0, 0); cvmSet(itsIntrinsicMatrix, 1, 1, 290.85342 ); cvmSet(itsIntrinsicMatrix, 1, 2, 240/2); // 119.5);
  //cvmSet(itsIntrinsicMatrix, 2, 0, 0); cvmSet(itsIntrinsicMatrix, 2, 1, 0); cvmSet(itsIntrinsicMatrix, 2, 2, 1);

  cvmSet(itsIntrinsicMatrix, 0, 0, 415.5); cvmSet(itsIntrinsicMatrix, 0, 1, 0); cvmSet(itsIntrinsicMatrix, 0, 2, 320/2); //159.50000);
  cvmSet(itsIntrinsicMatrix, 1, 0, 0); cvmSet(itsIntrinsicMatrix, 1, 1, 436 ); cvmSet(itsIntrinsicMatrix, 1, 2, 240/2); // 119.5);
  cvmSet(itsIntrinsicMatrix, 2, 0, 0); cvmSet(itsIntrinsicMatrix, 2, 1, 0); cvmSet(itsIntrinsicMatrix, 2, 2, 1);

  bool drawGrid = true;
  bool saveCorners = false;
  bool calibrate = false;

  std::vector<CvPoint2D32f> allCorners;

  while(1)
  {

    GenericFrame input = ifs->readFrame();
    Image<PixRGB<byte> > img = input.asRgb();


    int rows = 4, cols = 3;

    std::vector<CvPoint2D32f> corners = findCorners(img, rows, cols);

    if (corners.size() == (uint)(rows*cols))
    {
      if (saveCorners)
        for(uint i=0; i<corners.size(); i++)
          allCorners.push_back(corners[i]);
      saveCorners = false;

      cvDrawChessboardCorners(img2ipl(img), cvSize(rows,cols), &corners[0], corners.size(), 1);
    }

    if (calibrate)
    {
      calibrateViews(allCorners, rows, cols);
      if (corners.size() == (uint)(rows*cols))
        findExtrinsic(corners, rows, cols);
      calibrate = false;
    }

    if (drawGrid)
      projectGrid(img);

    projectRect(img, 216.5, 279.5);


    processUserInput(ofs, drawGrid, saveCorners, calibrate);

    ofs->writeRGB(img, "Output", FrameInfo("Output", SRC_POS));

    ofs->updateNext();
  }

  // stop all our ModelComponents
  manager.stop();

  // all done!
  return 0;
}
Exemplo n.º 10
0
int main(int argc, char **argv) { 

  int windX=10;
  int windY=30;
  int windWidth=320;
  int windHeight=200;
  int c;
  opterr = 0;

  openSound(configUseCD); 
  catchSignals();


  while ((c = getopt(argc, argv, "b:h:w:")) != -1){
    switch (c)
      {

      case '?':
	fprintf(stderr, "%s: unknown option \"%s\"\n", 
		argv[0], argv[optind-1]);
	usage(argv[0]);
	exit(1);	
      case 'b':
	bright = (double) atoi(optarg);
	bright = bright/10;
	break;
      case 'w':
	windWidth = atoi(optarg);
	break;
      case 'h':
	windHeight = atoi(optarg);
	break;
      }
  }

 
  if (bright > 1.0)
    bright = 1.0;
  else if (bright < 0.0)
    bright = 0.0;


  if (windWidth < 1)
    windWidth = 320;
  if (windHeight < 1)
    windHeight = 200;

  setBrightness(bright);

  screenInit(windX,windY,windWidth,windHeight);
  output = new unsigned char[outWidth*outHeight*2];

  coreInit();

  time_t timer = time(NULL);
  
  int frames = 0;
  do {
    screenShow();
    coreGo();
    frames++;
  } while(!processUserInput());

  timer = time(NULL) - timer;
  delete output;
  closeSound();

  if (timer > 10)
    fprintf(stderr,"Frames per second: %f\n", double(frames)/timer);
  
  return 0;
}
Exemplo n.º 11
0
Arquivo: idbug.cpp Projeto: bpow/irods
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

    int status;
    int continueAllFlag = 0;
    int sleepSec = 1;
    int rNum = 1;
    int stdinflags;
    int verbose = 0;
    int opt;
    getXmsgTicketInp_t getXmsgTicketInp;
    xmsgTicketInfo_t xmsgTicketInfo;
    xmsgTicketInfo_t *outXmsgTicketInfo;
    sendXmsgInp_t sendXmsgInp;
    rcvXmsgInp_t rcvXmsgInp;
    rcvXmsgOut_t *rcvXmsgOut = NULL;
    char  ubuf[4000];

    /* set up signals */

#ifndef _WIN32
    signal( SIGINT, signalIdbugExit );
    signal( SIGHUP, signalIdbugExit );
    signal( SIGTERM, signalIdbugExit );
    signal( SIGUSR1, signalIdbugExit );
    /* XXXXX switched to SIG_DFL for embedded python. child process
     * went away. But probably have to call waitpid.
     * signal(SIGCHLD, SIG_IGN); */
    signal( SIGCHLD, SIG_DFL );
#endif


    while ( ( opt = getopt( argc, argv, "cChv:" ) ) != EOF ) {
        switch ( opt ) {
        case 'v':
            verbose = atoi( optarg );
            break;
        case 'c':
            continueAllFlag = 1;
            break;
        case 'C':
            continueAllFlag = 2;
            break;
        case 'h':
            printIdbugHelp( argv[0] );
            exit( 0 );
            break;
        default:
            fprintf( stderr, "Error: Unknown Option\n" );
            printIdbugHelp( argv[0] );
            exit( 1 );
            break;
        }
    }


    /* initialize and connect */
    snprintf( lastSent, HEADER_TYPE_LEN, "CMSG:BEGIN" );
    myHostName[0] = '\0';
    gethostname( myHostName, MAX_NAME_LEN );
    connectToX();

    memset( &xmsgTicketInfo, 0, sizeof( xmsgTicketInfo ) );
    memset( &getXmsgTicketInp, 0, sizeof( getXmsgTicketInp ) );

    /* get Ticket */
    getXmsgTicketInp.flag = 1;
    status = rcGetXmsgTicket( conn, &getXmsgTicketInp, &outXmsgTicketInfo );
    if ( status != 0 ) {
        fprintf( stderr, "Unable to get Xmsg Ticket. status = %d\n", status );
        exit( 8 );
    }
    fprintf( stdout, "Debug XMsg Stream= %i\n", outXmsgTicketInfo->sendTicket );
    streamId = outXmsgTicketInfo->sendTicket;


    /* Send STOP message on newly created Debug XMsg Stream */
    if ( continueAllFlag == 0 ) {
        status = sendIDebugCommand( "discontinue", "CMSG:BEGIN" );
    }
    else if ( continueAllFlag == 1 ) {
        status = sendIDebugCommand( "continue", "CMSG:BEGIN" );
    }
    else {
        status = sendIDebugCommand( "Continue", "CMSG:BEGIN" );
    }
    if ( status < 0 ) {
        fprintf( stderr, "Error sending Message to Debug Stream %i = %d\n",
                 streamId, status );
        exit( -1 );
    }


    /*
    memset (&sendXmsgInp, 0, sizeof (sendXmsgInp));
    xmsgTicketInfo.sendTicket = streamId;
    xmsgTicketInfo.rcvTicket = streamId;
    xmsgTicketInfo.flag = 1;
    sendXmsgInp.ticket = xmsgTicketInfo;
    snprintf(sendXmsgInp.sendAddr, NAME_LEN, "%s:%i", myHostName, getpid ());
    sendXmsgInp.sendXmsgInfo.numRcv = 100;
    sendXmsgInp.sendXmsgInfo.msgNumber = mNum;
    strcpy(sendXmsgInp.sendXmsgInfo.msgType, "idbug:client");
    snprintf(ubuf,3999, "stop");
    sendXmsgInp.sendXmsgInfo.msg = ubuf;
    status = sendIDebugCommand(&sendXmsgInp);
    mNum++;
    */

    /* Send Startup messages on Stream 4 */
    memset( &sendXmsgInp, 0, sizeof( sendXmsgInp ) );
    xmsgTicketInfo.sendTicket = 4;
    xmsgTicketInfo.rcvTicket = 4;
    xmsgTicketInfo.flag = 1;
    sendXmsgInp.ticket = xmsgTicketInfo;
    snprintf( sendXmsgInp.sendAddr, NAME_LEN, "%s:%i", myHostName, getpid() );
    sendXmsgInp.sendXmsgInfo.numRcv = 100;
    sendXmsgInp.sendXmsgInfo.msgNumber = 1;
    strcpy( sendXmsgInp.sendXmsgInfo.msgType, "STARTDEBUG" );
    snprintf( ubuf, 3999, "%i", outXmsgTicketInfo->sendTicket );
    sendXmsgInp.sendXmsgInfo.msg = ubuf;
    status = rcSendXmsg( conn, &sendXmsgInp );
    if ( status < 0 ) {
        fprintf( stderr, "Error sending Message to Stream 4 = %d\n", status );
        exit( -1 );
    }
    myMNum = status;

    /* switch off blocking for stdin */
    stdinflags = fcntl( 0, F_GETFL, 0 ); /* get current file status flags */
    stdinflags |= O_NONBLOCK;/* turn off blocking flag */
    if ( int status = fcntl( 0, F_SETFL, stdinflags ) ) { /* set up non-blocking read */
        fprintf( stderr, "fcntl failed with status: %d", status );
    }

    /* print to stdout */
    /*    printf("idbug> ");*/

    while ( 1 ) {
        /* check for user  input */
        ubuf[0] = '\0';
        if ( fgets( ubuf, 3999, stdin ) == NULL ) {
            if ( errno !=  EWOULDBLOCK ) {
                printf( "Exiting idbug\n" );
                cleanUpAndExit();
            }
        }
        else { /* got some user input */
            processUserInput( ubuf );
        }
        /* check for messages */
        ubuf[0] = '\0';
        memset( &rcvXmsgInp, 0, sizeof( rcvXmsgInp ) );
        rcvXmsgInp.rcvTicket = streamId;
        sprintf( rcvXmsgInp.msgCondition, "(*XSEQNUM >= %d) && (*XADDR != \"%s:%i\") ", rNum, myHostName, getpid() );

        status = getIDebugReply( &rcvXmsgInp, &rcvXmsgOut, 0 );
        if ( status == 0 ) {
            if ( verbose == 3 ) {
                printf( "%s:%s#%i::%s: %s",
                        rcvXmsgOut->sendUserName, rcvXmsgOut->sendAddr,
                        rcvXmsgOut->seqNumber, rcvXmsgOut->msgType, rcvXmsgOut->msg );
            }
            else if ( verbose == 2 ) {
                printf( "%s#%i::%s: %s",
                        rcvXmsgOut->sendAddr,
                        rcvXmsgOut->seqNumber, rcvXmsgOut->msgType, rcvXmsgOut->msg );
            }
            else if ( verbose == 1 ) {
                printf( "%i::%s: %s", rcvXmsgOut->seqNumber, rcvXmsgOut->msgType, rcvXmsgOut->msg );
            }
            else {
                printf( "%s: %s", rcvXmsgOut->msgType, rcvXmsgOut->msg );
            }
            if ( strstr( rcvXmsgOut->msg, "PROCESS BEGIN" ) != NULL ) {
                /*  printf(" FROM %s ", rcvXmsgOut->sendAddr); */
                storeSendAddr( rcvXmsgOut->sendAddr );
            }
            if ( strstr( rcvXmsgOut->msg, "PROCESS END" ) != NULL ) {
                printf( " FROM %s ", rcvXmsgOut->sendAddr );
                unstoreSendAddr( rcvXmsgOut->sendAddr );
            }
            if ( rcvXmsgOut->msg[strlen( rcvXmsgOut->msg ) - 1] != '\n' ) {
                printf( "\n" );
            }
            rNum  = rcvXmsgOut->seqNumber + 1;
            sleepSec = 1;
            free( rcvXmsgOut->msg );
            free( rcvXmsgOut );
            rcvXmsgOut = NULL;
            localStatus = 2;
        }
        else {
            sleep( sleepSec );
            sleepSec = 2 * sleepSec;
            /* if (sleepSec > 10) sleepSec = 10; */
            if ( sleepSec > 1 ) {
                sleepSec = 1;
            }
        }
    }
}
Exemplo n.º 12
0
void gameplay()            // gameplay logic
{
    processUserInput(); // checks if you should change states or do something else with the game, e.g. pause, exit
    moveCharacter();    // moves the character, collision detection, physics, etc
                        // sound can be played here too.
}
Exemplo n.º 13
0
int 
main(int argc, char **argv) 
{
  int windX=10;
  int windY=30;
  int windWidth=uiWidth;
  int windHeight=uiHeight;
  int c;
  int xx, xy;
  opterr = 0;

  /*
  KAboutData aboutData( "kscdmagic", I18N_NOOP("kscdmagic"),
			KSCDMAGICVERSION, I18N_NOOP("sound visualisation"), 
			KAboutData::License_GPL,
			"(c) 2000, Dirk Försterling");
  aboutData.addAuthor("Paul Harrison",0, "*****@*****.**");
  aboutData.addAuthor("Dirk Försterling",0, "*****@*****.**");

  KCmdLineArgs::init( argc, argv, &aboutData );

  KApplication magicApp;
  */


  openSound(SourceCD, 44100, "/dev/dsp", NULL);

  catchSignals();

  while ((c = getopt(argc, argv, "b:h:w:")) != -1){
    switch (c)
      {
      case '?':
	fprintf(stderr, "%s: unknown option \"%s\"\n", 
		argv[0], argv[optind-1]);
	usage(argv[0]);
	exit(1);	
      case 'b':
	bright = (double) atoi(optarg);
	bright = bright/10;
	break;
      case 'w':
	windWidth = atoi(optarg);
	break;
      case 'h':
	windHeight = atoi(optarg);
	break;
      }
  }
  
  if (bright > 1.0)
    bright = 1.0;
  else if (bright < 0.0)
    bright = 0.0;
  
  if (windWidth < 1)
    windWidth = uiWidth;
  if (windHeight < 1)
    windHeight = uiHeight;

  screenInit(windX,windY,windWidth,windHeight);

  allocOutput(outWidth,outHeight);

  coreInit();
  

  setStarSize(starSize);
  setBrightness(bright);

  time_t timer = time(NULL);
  
  int frames = 0;

  for(;;) {
    fade();
    if (-1 == coreGo())
      break;

    polygonEngine.clear();

    for( xy = 0; xy < 48; xy++)
      {
	for( xx = 0; xx < 48; xx++)
	  {
	    if ( logo[xy][xx] != 0)
	      {
		polygonEngine.add(32769, xx+10, xy+3);
	      }
	  }
      }
    polygonEngine.apply(outputBmp.data);
    screenShow(); 



    frames++;
    if(processUserInput() == -1)
      break;
  } 

  
  timer = time(NULL) - timer;
  delete ucoutput;
  closeSound();
  
  if (timer > 10)
    fprintf(stderr,"Frames per second: %f\n", double(frames)/timer);
  
  return 0;
} // main() /* linux */