Example #1
0
int updateWorld(char keyPressed) {	// run this method every frame
	if (!paused) {
		if (!gameover) {
			switch (keyPressed) {
				case 27:				// puase the game
					gamePause();
					break;
				case 32:				// jump the bird
				case 10:
					updateBird(1);
					updatePipe(PIPE);
					break;
				default:				// falling bird
					updateBird(0);
					updatePipe(PIPE);
					break;
			}
		} else {
				switch (keyPressed) {
					case 'r':
					case 'R':
					case 27:
						initializeWorld();
						break;
					case 'c':
					case 'C':
						QUIT = 1;
					default:			// do nothing
						break;
				}
		}
	}	else {
			if (keyPressed == 27)
				gamePause();
	}
	return paused;	
}
Example #2
0
int startGame(Pipe* lead, Pipe* trail, int scrWidth, int scrHeight) {

	int loop = 1; 
    int score = 0;
    double birdX = 150, birdY = 275, birdR = 12, birdV = 0, t = .05;
    int flap = 0;
   //#1 - to see game over screen make this while (loop < 5) and uncomment #2
	while (loop) {
        //if bird touches the drawpipe loop = 2

		gfx_clear();
        
        
        //draw background
        drawBackground(scrWidth, scrHeight);
        
        //check for loss
        if ((lead->leadingX-3 <= birdX+16 && lead->trailingX+3 >= birdX-16) &&
            (lead->topHeight >= birdY-16 || lead->bottomHeight <= birdY-16+24)) 
            break;
        if (birdY-16+24 >= scrHeight)
            break;
        
        flap = drawBird(birdX, birdY, birdR, flap);
        updateBird(&birdY, &birdV, &t, birdY, birdV, t);

        if(gfx_event_waiting()){
            char c = gfx_wait();
            if(c == ' ') birdV = -40;
        }
		
        //draw leading pipe
		drawPipe(lead, scrWidth, scrHeight);
        updatePipe(lead);

        //increase the score upon passing through a pair of pipes
        if(lead->trailingX == birdX){
            score++;
        }

        if (lead->trailingX < scrWidth/2) {
            drawPipe(trail, scrWidth, scrHeight);
            updatePipe(trail);
        }
        if (lead->trailingX <= 0) {
            //swap the leader
            Pipe *temp = lead;
            lead = trail;
            trail = temp;
            initializePipe(trail, scrWidth, scrHeight);
        }
   
        //print the score on the top of the screen
        printScore(score, scrWidth);

		gfx_flush(); 
        usleep(10000);
        t+=.001;
		//loop++ #2  -- to see end screen uncomment this and above
	}

    return score;

}