コード例 #1
0
ファイル: Logic.cpp プロジェクト: RoastedBard/Pacman
void Logic::processMovement(Pacman &pacman, Maze &maze)
{
	Vector2<int> coords(0,0);

	switch(pacman.getDirection())	
	{
		case Direction::UP:
			coords.x = pacman.getPosition().x;
			coords.y = pacman.getPosition().y - 1;
			break;

		case Direction::DOWN:
			coords.x = pacman.getPosition().x;
			coords.y = pacman.getPosition().y + 1;
			break;

		case Direction::LEFT:
			coords.x = pacman.getPosition().x - 1;
			coords.y = pacman.getPosition().y;
			break;

		case Direction::RIGHT:
			coords.x = pacman.getPosition().x + 1;
			coords.y = pacman.getPosition().y;
			break;

		case Direction::STOP:
			coords.x = pacman.getPosition().x;
			coords.y = pacman.getPosition().y;
			break;
	}

	if(maze.getMaze()[coords.x][coords.y].getType() != Type::NOTHING)
	{
		if(Physics::isIntersects(&pacman, &maze.getMaze()[coords.x][coords.y], pacman.getDirection()))
		{
			switch(maze.getMaze()[coords.x][coords.y].getType())
			{
			case Type::PILL:
					pacman.setScore(pacman.getScore() + 2);
					maze.getMaze()[coords.x][coords.y].setType(Type::NOTHING);
					cellsToChange.setXY(coords.x, coords.y);
					break;

				case Type::BONUS:
					break;

				case Type::WALL:
					pacman.setDirection(Direction::STOP);
					break;
			}
		}
	}

	pacman.setMovingVector();
}
コード例 #2
0
bool GestionnaireCollision::collisionPacgomme(const Pacman& pacman, const Case& uneCase, char direction)
{
    switch(direction)
    {
        case 'z':
        {
            if(uneCase.getType() == 4 && uneCase.pacGommePresente() &&
               uneCase.getRectangle().getGlobalBounds().contains(pacman.getPosition().x,pacman.getPosition().y + 23))
            {
                return true;
            }
            else if(uneCase.getType() == 5 && uneCase.pacGommePresente() &&
                    uneCase.getRectangle().getGlobalBounds().contains(pacman.getPosition().x, pacman.getPosition().y + 23))
            {
                return true;
            }
            
            return false;
            
            break;
        }
        case 's':
        {
            if(uneCase.getType() == 4 && uneCase.pacGommePresente() &&
               uneCase.getRectangle().getGlobalBounds().contains(pacman.getPosition().x, pacman.getPosition().y + 5))
            {
                return true;
            }
            else if(uneCase.getType() == 5 && uneCase.pacGommePresente() &&
                    uneCase.getRectangle().getGlobalBounds().contains(pacman.getPosition().x, pacman.getPosition().y + 5))
            {
                return true;
            }
            
            return false;
            
                        break;
        }
        case 'q':
        {
            if(uneCase.getType() == 4 && uneCase.pacGommePresente() &&
               uneCase.getRectangle().getGlobalBounds().contains(pacman.getPosition().x + 23, pacman.getPosition().y))
            {
                return true;
            }
            else if(uneCase.getType() == 5 && uneCase.pacGommePresente() &&
                    uneCase.getRectangle().getGlobalBounds().contains(pacman.getPosition().x+23, pacman.getPosition().y))
            {
                return true;
            }
            
            return false;
            
                       break;
        }
        case 'd':
        {
            if(uneCase.getType() == 4 && uneCase.pacGommePresente() &&
               uneCase.getRectangle().getGlobalBounds().contains(pacman.getPosition().x + 5, pacman.getPosition().y))
            {
                return true;
            }
            else if(uneCase.getType() == 5 && uneCase.pacGommePresente() &&
                    uneCase.getRectangle().getGlobalBounds().contains(pacman.getPosition().x +5, pacman.getPosition().y))
            {
                return true;
            }
            
            return false;
            
                        break;
        }
    }
}