Esempio n. 1
0
void changeGhostDir(int index) {
  int dir[4];
  int i;
  int flag = 0;
  if ((int)ghost[index].screenX == mapToscreen(ghost[index].mapX) + UNIT / 2 && (int)ghost[index].screenY == mapToscreen(ghost[index].mapY) + UNIT / 2) {
    /* 判断前方是否是死路
    */
    switch (ghost[index].dir) {
      case UP:
          if (map[ghost[index].mapY - 1][ghost[index].mapX] == 0)
            flag++;
          break;
      case DOWN:
          if (map[ghost[index].mapY + 1][ghost[index].mapX] == 0)
            flag++;
          break;
      case LEFT:
          if (map[ghost[index].mapY][ghost[index].mapX - 1] == 0)
            flag++;
          break;
      case RIGHT:
          if (map[ghost[index].mapY][ghost[index].mapX + 1] == 0)
            flag++;
          break;
    }
    /* 判断是否是路口
    */

    if (map[ghost[index].mapY - 1][ghost[index].mapX] != 0)
      flag++;
    if (map[ghost[index].mapY + 1][ghost[index].mapX] != 0)
      flag++;
    if (map[ghost[index].mapY][ghost[index].mapX - 1] != 0)
      flag++;
    if (map[ghost[index].mapY][ghost[index].mapX + 1] != 0)
      flag++;

    if (flag) {
      coord ghostPos[4];
      for (i = 0; i < 4; i++)
      {
        ghostPos[i].x = ghost[i].mapX;
        ghostPos[i].y = ghost[i].mapY;
        dir[i] = ghost[i].dir;
      }
      ghost[index].dir = moveAI(&ghost[index].ai, map, ghostPos, dir, pacman.mapX, pacman.mapY, ghost[index].burst);
    } 
  }
}
Esempio n. 2
0
void GameEngine::onPlayerTurn(bool b, Point p) {
	if (b) {
		//Increment turn
		log.incTurn();

		//Restore some mana
		if (turns % 3 == 0)
			hero->changeMana(1);

		//Move Player
		Point d = p;
		p = p + screenOrientation;
		if (moveableCell(p)) {
			screenOrientation = p;
			hero->setLoc(hero->getLoc() + d);

			int mapCellType = map[p.x()][p.y()].getCellType();
			if (mapCellType == 5)
				log.registerEvent("Press enter to descend stairs");
			else if (mapCellType == 6)
				log.registerEvent("Press enter to use Shop");
			else if (mapCellType == 7)
				log.registerEvent("A mysterious cave...press enter to descend");
			else if (mapCellType == 8)
				log.registerEvent("Press enter to ascend up the stairs");

			if (map[p.x()][p.y()].getPickup() != NULL)
				addPickup(p);
		}
		else if (map[p.x()][p.y()].getActor() != NULL)
			doBattle(hero, map[p.x()][p.y()].getActor());

		//Move AI
		if (!inBossRoom) {
			for (unsigned int i = 0; i < monsters.size(); i++) {
				Point mLoc = monsters[i]->getLoc();
				Actor* m = map[mLoc.x()][mLoc.y()].getActor();
				if (moveAI(m))
					doBattle(m, hero);
			}
		}
		turns++;
	}
}
Esempio n. 3
0
void main()
{
	int choiceMM = 0, choicePM = 0, choiceOM = 0, choiceBM = 0, choicePPM = 0, choiceLoss = 0;
	float tempSpeed;
	bool first = true;
	bool mm = true;
	bool dPress = false, aPress = false, wPress = false, sPress = false, spacePress = false;
	bool playTennis = false, playSingle = false, playMulti = false;
	bool ballOffScreen = false;
	bool ballOp = false, playOp = false;

	curCX = 250;
	curCY = 250;

	/*cout << "Please choose game mode:\n\n" 
		 << "Tennis: 1\n" 
		 << "Single Player: 2\n" 
		 << "Multiplayer: 3\n";
	cin >> choice;*/

	initContext(SCREEN_X, SCREEN_Y, "Pong");

	while (stepContext())
	{
		// The main Menu
		if(mm)
		{
			cout << "Main; ";

			//This if chunk makes one key = one press on MM
			if (getKey('D') && !dPress)
			{
				choiceMM++;
				dPress = true;
			}
			else if (getKey('A') && !aPress)
			{
				choiceMM--;
				aPress = true;
			}

			if (choiceMM <= -1) { choiceMM = 2; }
			else if (choiceMM >= 3) { choiceMM = 0; }

			if (getKey(' ') && !spacePress) 
			{ 
				mm = false;
				spacePress = true;
			}

			cout << choiceMM << "(1); ";

			menuMain(choiceMM);
		}
		//All other menus
		else if (!mm && !playTennis && !playSingle && !playMulti)
		{
			cout << "Other menu; ";
			//Play menu
			if (choiceMM == 0)
			{
				cout << "Play Menu; ";
				cout << choicePM << "(1); ";

				if (getKey('D') && !dPress)
				{
					switch (choicePM)
					{
					case 0:
						choicePM = 1;
						break;
					case 1:
						choicePM = 0;
						break;
					case 2:
						choicePM = 3;
						break;
					case 3:
						choicePM = 2;
						break;
					}

					dPress = true;
				}
				else if (getKey('A') && !aPress)
				{
					switch (choicePM)
					{
					case 0:
						choicePM = 1;
						break;
					case 1:
						choicePM = 0;
						break;
					case 2:
						choicePM = 3;
						break;
					case 3:
						choicePM = 2;
						break;
					}

					aPress = true;
				}
				else if (getKey('W') && !wPress)
				{  
					switch (choicePM)
					{
					case 0:
						choicePM = 2;
						break;
					case 1:
						choicePM = 3;
						break;
					case 2:
						choicePM = 0;
						break;
					case 3:
						choicePM = 1;
						break;
					}

					wPress = true;
				}
				else if (getKey('S') && !sPress)
				{
					switch (choicePM)
					{
					case 0:
						choicePM = 2;
						break;
					case 1:
						choicePM = 3;
						break;
					case 2:
						choicePM = 0;
						break;
					case 3:
						choicePM = 1;
						break;
					}

					sPress = true;
				}

				if (choicePM == -1) { choicePM = 3; }
				else if (choicePM == 4) { choicePM = 0; }

				if (getKey(' ') && !spacePress)
				{
					if (choicePM == 0)
					{
						playSingle = true;
					}
					else if (choicePM == 1)
					{
						playMulti = true;
					}
					else if (choicePM == 2)
					{
						choicePM = 0;
						choiceMM = 0;
						mm = true;
					}
					else
					{
						playTennis = true;
					}

					spacePress = true;
				}

				menuPlay(choicePM);
			}
			//Options menu
			else if (choiceMM == 1)
			{
				cout << "Op Menu; ";
				
				if (getKey('W') && !wPress)
				{
					choiceOM--;
					wPress = true;
				}
				else if (getKey('S') && !sPress)
				{
					choiceOM++;
					sPress = true;
				}

				if (choiceOM == -1) { choiceOM = 2; }
				else if (choiceOM == 3) { choiceOM = 0; }

				if (ballOp)
				{
					cout << "Ball menu; ";

					if (getKey('A')) { choiceBM--; }
					else if (getKey('D')) { choiceBM++; }
					if (choiceBM < 0) { choiceBM = 0; }
					else if(choiceBM > 1) {choiceBM = 1; }

					menuBallOp(choiceBM);

					if (getKey(' ') && !spacePress)
					{
						if (!choiceBM)
						{
							ballOp = false;
							menuBallOp(3);
						}
						else
						{
							menuBallOp(3);
						}

						spacePress = true;
					}

					cout << choiceBM << "(4); ";
				}
				else if (playOp)
				{
					cout << "Play  mmenu; ";

					if (getKey('A')) { choicePPM--; }
					else if (getKey('D')) { choicePPM++; }
					if (choicePPM < 0) { choicePPM = 0; }
					else if (choicePPM > 1) { choicePPM = 1; }

					menuBallOp(choicePPM);

					if (getKey(' ') && !spacePress)
					{
						if (!choicePPM)
						{
							playOp = false;
							menuPlayOp(3);
						}
						else
						{
							menuPlayOp(3);
						}

						spacePress = true;
					}

					cout << choicePPM << "(4); ";
				}
				else if(getKey(' ') && !spacePress)
				{
					switch (choiceOM)
					{
					case 0:
						ballOp = true;
						break;
					case 1:
						playOp = true;
						break;
					case 2:
						choiceOM = 0;
						choiceMM = 0;
						mm = true;
						break;
					}

					spacePress = true;
				}
				else
				{
					menuOpt(choiceOM);
				}

				cout << choiceOM << "(1); ";
			}
			else if (choiceMM == 2) { termContext(); }
		}
		else if (playTennis)
		{
			if (first)
			{
				moveBall(true, true);
				first = false;
			}

			if (!ballOffScreen)
			{
				movePlayers();
				moveBall(false, true);
			}
			else
			{
				if (getKey('W') && !wPress) { choiceLoss--, wPress = true; }
				else if (getKey('S') && !sPress) { choiceLoss++, sPress = true;  }
				if (choiceLoss < 0) { choiceLoss = 2; }
				else if (choiceLoss > 2) { choiceLoss = 0; }

				menuLoss(choiceLoss);

				if (getKey(' ') && !spacePress)
				{
					switch (choiceLoss)
					{
					case 0:
						curCX = xSpace(1, 2);
						curCY = ySpace(1, 2);
						first = true;
						cSPEED_Y = 0;
						ballOffScreen = false;
						break;
					case 1:
						choicePM = 0;
						choiceMM = 0;
						choiceLoss = 0;
						mm = true;
						playTennis = false;
						curCX = xSpace(1, 2);
						curCY = ySpace(1, 2);
						first = true;
						cSPEED_Y = 0;
						ballOffScreen = false;
						break;
					case 2:
						termContext();
						break;
					}
				}

				spacePress = true;
			}

			cout << choiceLoss << "(4); ";

			drawPlayer(PLAYER1);
			drawCircle(curCX, curCY, R);
			drawWalls(true);

			if (curCX > SCREEN_X || curCX < 0)
			{
				ballOffScreen = true;
			}
		}
		else if (playSingle)
		{
			if (first)
			{
				moveBall(true, false);
				first = false;
			}

			if (!ballOffScreen)
			{
				movePlayers();
				moveBall(false, true);
				moveAI();
			}
			else
			{
				if (getKey('W') && !wPress) { choiceLoss--, wPress = true; }
				else if (getKey('S') && !sPress) { choiceLoss++, sPress = true; }
				if (choiceLoss < 0) { choiceLoss = 2; }
				else if (choiceLoss > 2) { choiceLoss = 0; }

				menuLoss(choiceLoss);

				if (getKey(' ') && !spacePress)
				{
					switch (choiceLoss)
					{
					case 0:
						curCX = xSpace(1, 2);
						curCY = ySpace(1, 2);
						first = true;
						cSPEED_Y = 0;
						ballOffScreen = false;
						break;
					case 1:
						choicePM = 0;
						choiceMM = 0;
						choiceLoss = 0;
						mm = true;
						playSingle = false;
						curCX = xSpace(1, 2);
						curCY = ySpace(1, 2);
						first = true;
						cSPEED_Y = 0;
						ballOffScreen = false;
						break;
					case 2:
						termContext();
						break;
					}
				}

				spacePress = true;
			}

			cout << choiceLoss << "(4); ";

			drawPlayer(PLAYER1);
			drawPlayer(AI);
			drawCircle(curCX, curCY, R);
			drawWalls(false);

			if (curCX > SCREEN_X || curCX < 0)
			{
				ballOffScreen = true;
			}
		}
		else if (playMulti)
		{
			if (first)
			{
				moveBall(true, false);
				first = false;
			}

			if (!ballOffScreen)
			{
				movePlayers();
				moveBall(false, true);
			}
			else
			{
				if (getKey('W') && !wPress) { choiceLoss--, wPress = true; }
				else if (getKey('S') && !sPress) { choiceLoss++, sPress = true; }
				if (choiceLoss < 0) { choiceLoss = 2; }
				else if (choiceLoss > 2) { choiceLoss = 0; }

				menuLoss(choiceLoss);

				if (getKey(' ') && !spacePress)
				{
					switch (choiceLoss)
					{
					case 0:
						curCX = xSpace(1, 2);
						curCY = ySpace(1, 2);
						first = true;
						cSPEED_Y = 0;
						ballOffScreen = false;
						break;
					case 1:
						choicePM = 0;
						choiceMM = 0;
						choiceLoss = 0;
						mm = true;
						playMulti = false;
						curCX = xSpace(1, 2);
						curCY = ySpace(1, 2);
						first = true;
						cSPEED_Y = 0;
						ballOffScreen = false;
						break;
					case 2:
						termContext();
						break;
					}
				}

				cout << choiceLoss << "(4); ";
				spacePress = true;
			}

			drawPlayer(PLAYER1);
			drawPlayer(PLAYER2);
			drawCircle(curCX, curCY, R);
			drawWalls(false);

			if (curCX > SCREEN_X || curCX < 0)
			{
				ballOffScreen = true;
			}
		}

		if (!getKey('W') && wPress) { wPress = false; }
		if (!getKey('A') && aPress) { aPress = false; }
		if (!getKey('S') && sPress) { sPress = false; }
		if (!getKey('D') && dPress) { dPress = false; }
		if (!getKey(' ') && spacePress) { spacePress = false; }

		cout << endl;
	}
}