Example #1
1
void Pacman::replacing(int value){
	Pacman * p = reinterpret_cast<Pacman *> (value);
	p->_xcoord = 0;
	p->_ycoord = 2;
	p->setDirection(DOWN);
	p->_isDead=false;
}
Example #2
0
// Location for the code to play pacMan.
void pacManFunction()
    {

    bool Playing=true;
    splashscreen();
    initialization();
    Maze* maze = new Maze();
    maze->showMaze();
    Pacman* pac = new Pacman(20,20,maze->maze1);
    pac->moveShow(36,13,'O');
    Ghost* ghost1 = new Ghost(9,36,'R','@' | COLOR_PAIR(2), '@' | COLOR_PAIR(3), '@' | COLOR_PAIR(6), ':' | COLOR_PAIR(6), maze->maze1);
    Ghost* ghost2 = new Ghost(11,35,'U','@' | COLOR_PAIR(4), '@' | COLOR_PAIR(3), '@' | COLOR_PAIR(6), ':' | COLOR_PAIR(6), maze->maze1);
    Ghost* ghost3 = new Ghost(11,36,'U','@' | COLOR_PAIR(9), '@' | COLOR_PAIR(3), '@' | COLOR_PAIR(6),  ':' | COLOR_PAIR(6), maze->maze1);
    Ghost* ghost4 = new Ghost(11,37,'U','@' | COLOR_PAIR(1), '@' | COLOR_PAIR(3), '@' | COLOR_PAIR(6),  ':' | COLOR_PAIR(6), maze->maze1);
    while (Playing){
        Playing = pac->movep();
        ghost1->moveG(pac -> bonus, pac -> bonusEnding, pac -> pacY, pac -> pacX );
        ghost2->moveG(pac -> bonus, pac -> bonusEnding, pac -> pacY, pac -> pacX );
        ghost3->moveG(pac -> bonus, pac -> bonusEnding, pac -> pacY, pac -> pacX );
        ghost4->moveG(pac -> bonus, pac -> bonusEnding, pac -> pacY, pac -> pacX );

        if(!(ghost1 -> playing && ghost2 -> playing && ghost3 -> playing && ghost4 -> playing))
        {
            Playing = false;
        }

        if( pac -> score >= 400 )
            {

            Playing = false;

            }//if( pac -> score >= 466 )

    }

    if( pac -> score >= 400 )
        {

        gameOverWin();

        }// if( pac -> score )

    else
        {

        gameOverLose();

        }// else of if( pac -> score == 466 )

    }// void pacManFunction()
bool GestionnaireCollision::collisionMur(const Pacman& pacman, const Case& mur)
{
    // 0 et 4 représente les tile ou l'on peut passer
    if(mur.getType() != 0 && mur.getType() != 4 && mur.getType() != 5)
    {
        return pacman.getSprite().getGlobalBounds().intersects(mur.getRectangle().getGlobalBounds());
    }
    else
    {
        return false;
    }
}
Example #4
0
void onDisplay(void) {
    // cams.projection(winW, winH);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    cams.look();
    lights.display(&pacman);

    //draw stuff
    maze.draw();
    if (!maze.getPacmanDeathTime()) { //pacman is alive
        pacman.draw();
    }
    else particles.draw();
    mazeFloor.draw();
    ghosts.draw();
    hud.draw(winW, winH, &maze);
    glFlush();
}
Example #5
0
void onIdle() {
    int elapsedTime = glutGet(GLUT_ELAPSED_TIME) - lastUpdate;
    //elapsedTime = (int) (elapsedTime * 0.5f); //slow down
    //if (elapsedTime < 5) return;
    if (!paused) {
        // FPS COUNTER //
        fpsCounter[0] += elapsedTime;
        fpsCounter[1]++;
        if (fpsCounter[0] > 1000) {
            //system("cls");
            cout << "FPS: " << 1000 / (fpsCounter[0] / fpsCounter[1]) << endl;
            fpsCounter[0] = fpsCounter[1] = 0;
        }
        // FPS COUNTER //
        cams.update(elapsedTime, &pacman);
        int pacmanDeathTime = maze.getPacmanDeathTime();
        if (!pacmanDeathTime) { //pacman is alive
            pacmanIsAlive = 1;
            pacman.update(elapsedTime, &maze);
            maze.eatBallAt(pacman.getPosX(), pacman.getPosY());
            ghosts.update(elapsedTime, pacman.getPosX(), pacman.getPosY(), &maze);
        }
        else {
            if (pacmanDeathTime + 6000 <  glutGet(GLUT_ELAPSED_TIME)) {
                //pacman.onBirth();
                pacman = Pacman();
                ghosts = Ghosts();
                maze.onPacmanBirth();
            }
            else {
                if (pacmanIsAlive) {
                    pacmanIsAlive = 0;
                    particles.start(pacman.getPosX(), pacman.getPosY());
                }
                particles.update(elapsedTime);
            }
        }
        glutPostRedisplay();
    }
    lastUpdate = glutGet(GLUT_ELAPSED_TIME);
}
Example #6
0
///////////////
///////////////
//Main function
int main()
{
    //Enable depth test for background and pacman sprites
    //glEnable( GL_DEPTH_TEST );

    // Create the main window
    sf::RenderWindow App(sf::VideoMode(640, 480), "SFML Pacman",
                         sf::Style::Default,
                         sf::ContextSettings(32));
    App.setFramerateLimit(60);
    //Initialize glew
    if( glewInit() != GLEW_OK )
        return EXIT_FAILURE;


    //and allocate an array of vertices
    GLuint data;
    //Fill vertex buffer with data
    const GLfloat vertices[] = {
        -1.0f, 1.0f,
        -0.9f, 0.9f,
        -0.9f, 1.f,

        0.f, 0.f,
        0.f, 0.5f,
        -0.5f, 0.5f };
    //Fill up indices
    const GLubyte indices[] = {
        0, 1,  2, 3,
        4, 5,  6, 7  };

    //glGenBuffers(1, &data);
    //Load square verts into the buffer object, GL_ARRAY_BUFFER
    //glBindBuffer( GL_ARRAY_BUFFER, data );
    //glBufferData( GL_ARRAY_BUFFER, 4*3*sizeof( GLfloat ), vertices, GL_STATIC_DRAW );

    // Enable Z-buffer read and write
    //glEnable(GL_DEPTH_TEST);
    //glDepthMask(GL_TRUE);
    //glClearDepth(1.f);


    //Allocate a new dot grid
    dotarray dots;
    //Allocate a new Pacman
    Pacman pac;
    pac.load();

    //Create a graphical text to display
    sf::Font font;
    if (!font.loadFromFile("arial.ttf"))
        return EXIT_FAILURE;
    sf::Text text;
    text.setFont(font);

    //Load the bg sprite
    sf::Texture backgroundTex;
    if(!backgroundTex.loadFromFile("resources/background.png"))
        return EXIT_FAILURE;
    sf::Sprite backgroundSprite(backgroundTex);



	// Start the game loop

	sf::Sprite currentSprite;

    while (App.isOpen())
    {
        // Process events
        sf::Event event;
        while (App.pollEvent(event))
        {
            // Close window: exit
            if (event.type == sf::Event::Closed)
                App.close();

            if(event.type == sf::Event::KeyPressed) {
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                    pac.setOrientation(1);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                    pac.setOrientation(2);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                    pac.setOrientation(3);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                    pac.setOrientation(4);
            }
        }

        //pac.setOrientation( (int)(clock.getElapsedTime().asSeconds()) % 4 + 1);

        //Get the next animation of pacman, and draw it against the background
        pac.animate();
        pac.move();
        const sf::Texture currentTexture = pac.getCurrentTexture();
        currentSprite.setTexture(currentTexture);
        currentSprite.setOrigin(pac.currentX, pac.currentY);

        App.pushGLStates();
        App.draw(backgroundSprite);
        App.draw(currentSprite);
        App.popGLStates();





        /*
        //Draw the mouse position
        char mousestr[20];
        float mouseposX = sf::Mouse::getPosition(App).x * 200.f /
                            App.getSize().x - 100.f;
        sprintf(mousestr, "%10f", mouseposX);
        text.setString(std::string(mousestr));
        App.pushGLStates();
        App.draw(text);
        App.popGLStates();
        */


        //Clear the depth buffer
        glClear( GL_DEPTH_BUFFER_BIT );
        //Activate the window
        App.setActive();
        //Draw the square
        //Enable drawing from vertex arrays


        /************ DRAW SOME DOTS ***********
        glEnableClientState( GL_VERTEX_ARRAY );

        for(int i = 0; i < dots.rows; i++)
            for(int j = 0; j < dots.cols; j++) {

                if(dots.hasDot[i][j]) {
                    //DO OPENGL HERE
                }

            }

        glDrawArrays( GL_TRIANGLES, 0, 6 * dots.numDotsRemaining );

        glDisableClientState( GL_VERTEX_ARRAY );
        /************ DRAW SOME DOTS *************/



        // Update the window
        App.display();
    }

    return EXIT_SUCCESS;
}
Example #7
0
void onSpecialKeyUp(int key, int x, int y) {
    pacman.onSpecialKeyUp(key);
}
Example #8
0
void onSpecialKeyPress(int key, int x, int y) {
    pacman.onSpecialKeyPress(key);
}
Example #9
0
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();
}
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;
        }
    }
}
bool GestionnaireCollision::collisionFantome(const Fantome& fantome, const Pacman& pacman)
{
    return pacman.getSprite().getGlobalBounds().intersects(fantome.getSprite().getGlobalBounds());
}