Example #1
0
//game screen graphics
void displayMe(void)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
  /*BACKGROUND COLOR
  glBegin(GL_QUADS);
  glColor4f(0.5f, 0.0f, 1.0f, 0.7); // (0.5, 0, 1) is half red and full blue, giving dark purple.
  //menu rectangle
  glVertex2f(-1, -1);
  glVertex2f(-1, 1);
  glVertex2f(1, 1);
  glVertex2f(1, -1);
  glEnd();
  */

  glColor4f(1,1,1,0.5);

  displayScore(lives);  
  p.drawPaddle();
  b.drawBall();
  m.drawMap();

  //if paused aka main menu is displayed
  switch(state){
    case GAME_ACTIVE: //main mode
		      p.movePaddle(mouseX,0);
		      b.moveBall(p, &m, lives);
		      break;
    case GAME_PAUSED: //main menu state	      
		      mainMenu(); 
                      break; 
    case GAME_ABOUT:  //about screen		       
                      showAboutScreen();
		      break;
    default: // cannot be here 
             cout << "Fatal error" << endl;
	     exit(0);
             break; 
  }

  glutSwapBuffers();
}
Example #2
0
//the main game loop
void gameLoop() {
	hasMoved = false;

	//draw screen
	theMap.drawMap();
	cout << "Level: " << level << " - 'h' for help " << endl;
	
	if (thePlayer.getItem() != "NONE") {
		cout << "Type 'f' to use '" << thePlayer.getItem() << "'." << endl;
	}


	//player turn
	while (!hasMoved) {
		moveInput = _getch();
		//player move
		if (moveInput == 'w' || moveInput == 'a' || moveInput == 's' || moveInput == 'd') {
			hasMoved = thePlayer.playerMove(pTheMap, pTheEnemies, pTheItems, moveInput);
		}
		else if (moveInput == 'h') {
			help();
			//redraw screen
			theMap.drawMap();
			cout << "Level: " << level << endl;
		}
		else if (moveInput == 'f') {
			//use item
			theItems.useItem(pTheMap, thePlayer.getPlayerLocation(), thePlayer.getItem());
			thePlayer.removeItem();
			//redraw screen without the 'type f to use' etc
			theMap.drawMap();
			cout << "Level: " << level << " - 'h' for help " << endl;
		}
	}
	//death check
	if (thePlayer.isDead()) {
		isPlaying = false;
	}
	// victory check
	if (victoryCheck()) {
		newRoom();
		return;
	}

	//enemies act
	for (int x = 0; x < theMap.getMax(); x++) {
		for (int y = 0; y != theMap.getMax(); y++) {
			if (theEnemies.isEnemy(pTheMap, x, y)) {
				if (theMap.getElement(x, y) == 'm') {
					theEnemies.moveEnemy(pTheMap, thePlayer.getPlayerLocation(), "GRUNT", x, y);
				}
				else if (theMap.getElement(x, y) == 'M') {
					theEnemies.moveEnemy(pTheMap, thePlayer.getPlayerLocation(), "STALKER", x, y);
				}
			}
		}
	}

	//Change new enemy placements to valid enemy placements
	for (int i = 0; i < theMap.getMax(); i++) {
		for (int a = 0; a < theMap.getMax(); a++) {
			if (theMap.getElement(i, a) == 'n') {
				theMap.insertElement('m', i, a);
			}
			if (theMap.getElement(i, a) == 'N') {
				theMap.insertElement('M', i, a);
			}
		}
	}

		// - victory check
}