Example #1
0
/*
* Returns true if the game is still going or false if over
*
*/
uint8_t Game::play() {
  if (playerTurn) {
    uint8_t outcome = checkPlayerMove();
    switch (outcome) {
      case 0:
        return true;
      case 1:
        lightButton(*nextMove, 1000);
        nextMove = nextMove + sizeof(uint8_t);
        if (*nextMove == 0) {
          playerTurn = false;
          rnd++;
          b.rainbow(1);
          b.playSong("E5,8,G6,8");
          //TODO Fanfare!
          b.allLedsOff();
          delay(1000);
        }
        return true;
      case 2:
        started = false;
        showGameOver(2000);
        //TODO: sad trombone
        return false;
    }
  } else {
    nextMove = getCPUMoves();
    playerTurn = true;
  }
  return true;
}
Example #2
0
	void SnakeScene::switchToMainMenu(float)
	{
		dead = true;
		over = true;
		
		showGameOver();
	}
Example #3
0
int main() {
  init();

  while (true) {
    setGameInput();
    game->update();
    if (!game->isActive()) {
      showGameOver();
      wait(.1f);
      getch();
      nodelay(stdscr, FALSE);
      int ch = getch();
      if (ch == 'q' || ch == 'Q') {
        break;
      } else {
        game->newGame({gameWidth / 3, gameHeight / 3}, direction::RIGHT, STARTLENGTH);
        nodelay(stdscr, TRUE);
      }
    }
    drawGame();
    refresh();
    wait(0.1f);
  }

  endwin();
  return 0;
}
Example #4
0
// Leben verloren
void playerDead(Game *g)
{
    freeShotList(g->enemyShots);
    g->enemyShots = NULL;
    if (g->player.shot != NULL) {
        free(g->player.shot);
        g->player.shot = NULL;
    }
    
    g->player.lives -= 2; // startNewLevel erhöht um 1
    g->level--;
    g->enemyContainer.ufo.alive = false;
    g->enemyContainer.ufo.lastufo = ms_time();
    
    // Spielerposition
    g->player.rect.x = WIDTH/2 - PLAYER_WIDTH/2;
    g->player.rect.y = PLAYER_Y_POS;
    g->player.rect.w = PLAYER_WIDTH;
    g->player.rect.h = PLAYER_HEIGHT;
    
    SDL_Rect area = {0, BORDER_TOP, WIDTH, HEIGHT - BORDER_TOP};
    SDL_FillRect(g->screen, &area, SDL_MapRGB(g->screen->format, 0, 0, 0));
    
    if (g->player.lives+2 == 0) {
        free(g->blocks);
        
        showGameOver(g);
        saveHighscore(g->score);
        showHighscore(g);
        
        SDL_Flip(g->screen);
        
        // Warten auf Tastendruck
        SDL_Event e;
        SDL_WaitEvent(&e);
        
        SDL_FillRect(g->screen, &area, SDL_MapRGB(g->screen->format, 0, 0, 0));
        
        initGame(g);
        startNewLevel(g);
        
        return;
    }
    
    SDL_Flip(g->screen);
    usleep(100000);
    
    // Nur zeichen, daher None
    movePlayer(g, None);
    
    startNewLevel(g);
}
Example #5
0
	void MatryoshkaScene::switchToMainMenu(float)
	{
		showGameOver();
	}
Example #6
0
void moveBot()
{
	uint16_t bot_x = 0;
	uint16_t bot_y = 0;

	uint8_t direction;

	time_t t;
	srand((unsigned) time(&t));

	SDL_Surface* bot = NULL;
	bot = SDL_LoadBMP("resources/bot.bmp");

	Uint32 colorkey1 = SDL_MapRGB(bot->format, 255, 255, 255);
	SDL_SetColorKey(bot, SDL_SRCCOLORKEY, colorkey1);

	direction = rand() % 4;

	uint8_t i, j;

	while (quit)
	{
		i = 0;
		j = 0;

		if (bot_y == y)
		{
			if ((bot_x + BOT_WIDTH) > x && (bot_x + BOT_WIDTH) < x + PACMAN_WIDTH)
			{
				quit = 0;
				showGameOver();
				
			}
		}

		if (bot_x == x)
		{
			if ((bot_y + BOT_HEIGHT) > y && (bot_y + BOT_HEIGHT) < y + PACMAN_HEIGHT)
			{
				quit = 0;
				showGameOver();
				
			}
		}

		clear(bot_x, bot_y);

		if (bot_x == 0 || bot_x == 250 || bot_x == 500 || bot_x == SCREEN_WIDTH - BOT_WIDTH)
		i = 1;

		if (bot_y == 0 || bot_y == 280 || bot_y == 370 || bot_y == SCREEN_HEIGHT - BOT_HEIGHT)
		j = 1;

		if (i && j)
		{
			direction = rand() % 4;
		}
		
		switch (direction)
                {
                   	case 0:
			moveUp(&bot_x, &bot_y);
			break;

			case 1:
			moveDown(&bot_x, &bot_y);
			break;

			case 2:
			moveLeft(&bot_x, &bot_y);
			break;

			case 3:
			moveRight(&bot_x, &bot_y);
			break;
		}

		apply_surface(bot_x, bot_y, bot);

		SDL_Delay(5);
		SDL_Flip(screen);
	}
}
Example #7
0
int start_campaign()
{
  int i, j;
  int gameresult = 0, endcampaign = 0;
  char roundmessage[10];
  char endtext[2][MAX_LINEWIDTH] = {N_("Congratulations! You win!"), " "};
  fprintf(stderr, "Entering start_campaign()\n");
  
  
  for (i = 0; i < NUM_STAGES; ++i)
  {
      fprintf(stderr, "Stage %s\n", stagenames[i]);
      briefPlayer(i);
      for (j = 1; j <= NUM_ROUNDS; ++j)
      {
	  fprintf(stderr, "Round %d\n", j);

	  //read in settings 
	  read_named_config_file(local_game, "campaign/campaign");    
	  readStageSettings(i);
	  readRoundSettings(i, j);
	  Opts_SetKeepScore(0);

	  snprintf(roundmessage, 10, "%s %d", N_("Round"), j);
	  game_set_start_message(roundmessage, "", "", "");

	  DEBUGCODE(debug_setup)
	  {
	      MC_PrintMathOptions(local_game, stdout, 0);
	  }

	  //play!
	  fprintf(stderr, "Starting game...\n");
          gameresult = comets_game(local_game);

	  //move on if we've won, game over if not
	  if (gameresult == GAME_OVER_WON)
	      ;
	  else if (gameresult == GAME_OVER_LOST)
	  {
	      showGameOver();
	      endcampaign = 1;
	  }
	  else if (gameresult == GAME_OVER_ERROR)
	  {
	      DEBUGMSG(debug_game, "Error!\n");
	      endcampaign = 1;
	  }
#ifndef TESTING_CAMPAIGN
	  else if (gameresult == GAME_OVER_ESCAPE)
	  {
	      DEBUGMSG(debug_game, "hit escape\n");
	      endcampaign = 1;
	  }
#endif      
	  else
	  {
	      fprintf(stderr, "gameresult = %d\n", gameresult);
	      endcampaign = 0;
	  }

	  if (endcampaign)
	      return 0;
      }

      //if we've beaten the last stage, there is no bonus, skip to win sequence
      if (i == NUM_STAGES - 1)
      {
	  showGameWon();
	  break;
      }
      /*    //bonus round
	    readStageSettings(i);
	    readRoundSettings(i, -1);
	    game_set_start_message("Bonus", "", "", "");
	    game();
	    */
  }
  scroll_text(endtext, screen->clip_rect, 3);
  return 0;
}
void GameScene::update(float dt) {
    CCSprite* bird = (CCSprite*)getChildByTag(TAG_BIRD);
    
    if (bird->getPositionY() >= screenSize.height) {
        bird->setPositionY(screenSize.height);
    }
    
    CCRect birdRect = CCRectMake(bird->getPositionX() - bird->getContentSize().width * 0.45f, bird->getPositionY() - bird->getContentSize().height * 0.45f,
                                 bird->getContentSize().width * 0.9f, bird->getContentSize().height * 0.9f);
    
    
    if (isGameOver) {
        CCSprite* land = (CCSprite*)getChildByTag(TAG_LAND);
        CCRect landRect = CCRectMake(land->getPositionX(), land->getPositionY(),
                                     land->getContentSize().width * 0.9f, land->getContentSize().height * 0.97f);
        if (landRect.intersectsRect(birdRect)) {
            bird->stopAllActions();
            unscheduleUpdate();
            showGameOver();
        }
        return;
    }
    
    CCSprite* land = (CCSprite*)getChildByTag(TAG_LAND);
    CCRect landRect = CCRectMake(land->getPositionX(), land->getPositionY(),
                                 land->getContentSize().width * 0.9f, land->getContentSize().height * 0.97f);
    if (landRect.intersectsRect(birdRect)) {
        isGameOver = true;
        bird->stopAllActions();
        unscheduleAllSelectors();
        
        CCShake* shake = CCShake::create(0.6f, 15);
        runAction(shake);
        M3AudioManager::shareInstance()->playSound(SOUND_HIT);
        
        for (int i = 0; i < hitCheckArray->count(); i++) {
            CCSprite* pipe = (CCSprite*)hitCheckArray->objectAtIndex(i);
            pipe->stopAllActions();
        }
        CCSprite* land = (CCSprite*)getChildByTag(TAG_LAND);
        land->stopAllActions();
        
        showGameOver();
        return;
    }
    

    
    for (int i = 0; i < hitCheckArray->count(); i++) {
        CCSprite* pipe = (CCSprite*)(hitCheckArray->objectAtIndex(i));
        CCRect pipeRect = CCRectMake(pipe->getPositionX() - pipe->getContentSize().width * 0.45f, pipe->getPositionY() + screenSize.height * 0.03f,
                                     pipe->getContentSize().width * 0.9f, pipe->getContentSize().height * 0.925f);
        if (pipeRect.intersectsRect(birdRect)) {
            CCShake* shake = CCShake::create(0.6f, 15);
            runAction(shake);
            M3AudioManager::shareInstance()->playSound(SOUND_HIT);
            gameOver();
            return;
        }
    }
    
    
    for (int i = 0; i < pipeArray->count(); i++) {
        CCSprite* pipe = (CCSprite*)(pipeArray->objectAtIndex(i));
        int uData = (int)pipe->getUserData();
        if (uData == 0 && pipe->getPositionX() <= screenSize.width * 0.25f) {
            pipe->setUserData((void*)1);
            
            gameScore += 1;
            CCLabelAtlas* score = (CCLabelAtlas*)getChildByTag(999);
            score->setString(CCString::createWithFormat("%d", gameScore)->getCString());
            
            M3AudioManager::shareInstance()->playSound(SOUND_MUSIC);
            
            if (gameScore == 15) {
                CCSprite* glass = CCSprite::createWithSpriteFrameName("glass.png");
                glass->setPosition(ccp(screenSize.width * 0.5f, screenSize.height * 0.5f));
                addChild(glass, 100);
                
                CCDelayTime* delay = CCDelayTime::create(2.0f);
                CCCallFuncN* c = CCCallFuncN::create(this, callfuncN_selector(GameScene::removeGlass));
                CCSequence* seq = CCSequence::create(delay, c, NULL);
                glass->runAction(seq);
                
                M3AudioManager::shareInstance()->playSound(SOUND_HIT);
            }
            break;
        }
    }
}