示例#1
0
void Board::checkEvents(sf::Event *event) { 
    if(match != -1) {
        if(event->Type == sf::Event::KeyPressed) {
            if(event->Key.Code == sf::Key::Y) {
                gameReset();
            } else if(event->Key.Code == sf::Key::N) {
                window->Close();
            }
        }
    } else {
        if((event->Type == sf::Event::MouseButtonPressed) &&
            (event->MouseButton.Button == sf::Mouse::Left)) {
              short xy = getXRegion(event->MouseButton.X) + BOARD_HEIGHT * 
                 getYRegion(event->MouseButton.Y);
               
            if(board[xy] == B) {
                board[xy] = player;
                if(checkWinCondition() == 0) {
                    switchPlayer();
                } else {
                    gameMatch();
                }
            }
        }
    }
}
示例#2
0
void Board::switchPlayer() { 
    (player == O) ? (player = X) : (player = O); 
    
    // Run AI.
    if(player == ai->getPiece()) {
        ai->run(board);
        if(checkWinCondition() == 0) {
            switchPlayer();
        } else {
            gameMatch();
        }
    }
    
}
示例#3
0
bool MiniGolf::Update(){
	ball.position = ball.position->add(ball.velocity);
	camManager->setCamTarg(ball.position->getX(), ball.position->getZ(), ball.position->getY());
	//golfball.setVelocity(0, 0, 0);	
	ball.aim = arrowAngle;
	//Find the current tile we are on
	Tile* currTile = getTile(ball.position, physMan, currLevel - 1);
	ball.position->setY(physMan->getHeightOfBall(currTile, &ball));
	//std::cout <<"Height of ball is " << height <<std::endl;
	
	//Check to see if we need to bounce off a wall
	physMan->checkForCollision(currTile, &ball);

	//Check to see if we're in the cup
	if(checkWinCondition()){
		playNextLevel();
		return false;
	}

	//Apply physicsManager forces
	Vector3* normal = currTile->tileNorm;
	ball.velocity = physMan->applyForces(ball.velocity, currTile->slope, currTile->downVec);
	
	//std::cout << "Down vector is (" << curr.down->getX() << ", " << curr.down->getY() << ", " <<curr.down->getZ() << ")" <<std::endl;
	modelViews[0] = glm::translate(defaultView, glm::vec3(ball.position->getX(), ball.position->getZ(), ball.position->getY()));
	modelViews[1] = modelViews[0];
	modelViews[1] = glm::rotate(modelViews[1], 0 - 90.0f, glm::vec3(0.0f, 0.0f, 1.0f));
		
	if ((ball.velocity->getLength() < MIN_BALL_SPEED) && currTile->slope == 0) { 
		ballMoving = false;
		ball.velocity = new Vector3(0.0, 0.0, 0.0);
	} else ballMoving = true;
	//draw_string(0.0, 0.0, 0.0, "scojfadofj");	

	//If the ball is not moving, we need to aim the ball
	//Calculate the angle between the mouse point and the ball position
	if(!ballMoving){
		isVisible[1] = true;
		modelViews[1] = modelViews[0];
		modelViews[1] = glm::rotate(modelViews[1], arrowAngle - 90.0f, glm::vec3(0.0f, 0.0f, 1.0f));
	} else {
		isVisible[1] = false;
	}

	return true;
}