Esempio n. 1
0
int main() {

	int width = 400; 
	int height = 550;
    int gameLoop = 1;
    int highScore = 0;
    
    gfx_open(width, height, "Flappy Bird");
    
    //create two pipes to be recycled
    Pipe* leadPipe = (Pipe*)malloc(sizeof(Pipe));
    Pipe* trailPipe = (Pipe*)malloc(sizeof(Pipe));
    
    while (gameLoop) {
    
        //initialize each pipe
        initializePipe(leadPipe, width, height);
        initializePipe(trailPipe, width, height);
    
        //set background color
        gfx_clear_color(85, 203, 217);
        gfx_clear();
        
        //present game home screen
    
        char c;
        int flap = 0;
        double birdX = 150, birdY = 275, birdR = 12, degrees = 0;
        while (1) {
            gfx_clear();
            if(gfx_event_waiting()){
                if(gfx_wait()==' ') break;
            }
            presentHomeScreen(width, height);
            stationaryBird(&birdY,degrees);
            flap = drawBird(birdX, birdY, birdR, flap);
            gfx_flush();
            usleep(50000);
            degrees+=(2*M_PI)/20;
        }
    
        //begin animation
        int score = startGame(leadPipe, trailPipe, width, height);
        highScore = endGame(score, highScore, width, height);
        char d;
	
    }
 
	return 0; 
}
Esempio n. 2
0
TCPPipe::TCPPipe(std::string hostname,int portId,TCPPipe::Endianness sEndianness)
	:TCPSocket(hostname,portId),
	 readMustSwapEndianness(false),writeMustSwapEndianness(false),
	 readBuffer(0),writeBuffer(0)
	{
	/* Set up the socket, endianness conversion, and read/write buffers: */
	initializePipe(sEndianness);
	}
Esempio n. 3
0
TCPPipe::TCPPipe(const TCPSocket& socket,TCPPipe::Endianness sEndianness)
	:TCPSocket(socket),
	 readMustSwapEndianness(false),
	 writeMustSwapEndianness(false),
	 readBuffer(0),writeBuffer(0)
	{
	/* Set up the socket, endianness conversion, and read/write buffers: */
	initializePipe(sEndianness);
	}
Esempio n. 4
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;

}