示例#1
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;

}
示例#2
0
int play()
{
	int score = 0;
	int speed = 1;
	int life = 1;
	int timer = 10;
	int pT = 0;
	char lifes[15];
	char scores[15];

	BIRD bird;
	bird.r = 70;
	bird.c = BIRD_C;

	// loadPalette(pics_palette, PICS_PALETTE_SIZE, 0);
	drawImage4(0, 0, 240, 160, (u16*)background);
	FlipPage();
	drawImage4(0, 0, 240, 160, (u16*)background);

	PIPE pp[4];
	for(int i = 0; i < 4; i++)
	{
		pp[i].r = 10;
		pp[i].c = 219 - i*60;
		pp[i].hole = 25 + rand() / (RAND_MAX / (145 - HOLE_L - 25 + 1) + 1);
		pp[i].on = 0;

		if(i == 0)
		{
			pp[i].on = 1;
		}
	}

	int frame = 0;
	while(1)
	{
		if(KEY_DOWN_NOW(BUTTON_SELECT))
		{
			return 0;
		}

		if(KEY_DOWN_NOW(BUTTON_A))
		{
			speed = -5;
		}

		if(timer == 0)
		{
			bird.r += speed;
			speed++;
			timer = 3;
		}
		timer--;
		if(pT == 0)
		{
			pp[0].on = 1;
		}
		else
		{
			pT--;
		}
		if(bird.r < 10)
		{
			bird.r = 10;
		}
		if(bird.r > 149)
		{			
			life--;
			if (life < 0) 
			{
				return LOSE;
			}
			bird.r = 70;
			speed = 1;
			timer = 2;
		}

		for(int i = 1; i < 4; i++)
		{
			if(pp[0].c < 220 - i*60 && !pp[i].on)
			{
				pp[i].c = 219;
				pp[i].on = 1;
			}
		}

		for(int i = 0; i < 4; i++)
		{
			if(pp[i].on)
			{
				pp[i].c -= 1;
				if(bird.c == (pp[i].c + PIPE_W / 2) && pp[i].on)
				{
					score++;
					if(score == 5)
					{
						return WIN;
					}
				}
				if(pp[i].c < 0)
				{
					pp[i].c = 219;
					pp[i].hole = 25 + rand() / (RAND_MAX / (145 - HOLE_L - 25 + 1) + 1);
					pT = 20;
					pp[i].on = 0;
				}
				//collision
				if(bird.c + 14 > pp[i].c && bird.c < pp[i].c + 20 && ((bird.r < pp[i].hole) | (bird.r + 10 > pp[i].hole + HOLE_L)) && pp[i].on)
				{
					life--;
					if (life < 0)
					{
						return LOSE;		
					}
					bird.r = pp[i].hole + 2;
					speed = 1;
					timer = 2;
				}
			}
		}

		drawImage4(0, 0, 240, 160, (u16*)background);
		delay(3);


		//draw pipe
		for(int i = 0; i < 4; i++)
		{
			if(pp[i].on)
			{
				drawPipe(pp[i].r, pp[i].c, pp[i].hole, (u16*)pipes);
			}
		}

		//draw bird
		if(frame % 9 == 0)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy0);
		}
		else if(frame % 9 == 1)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy1);
		}
		else if(frame % 9 == 2)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy2);
		}
		else if(frame % 9 == 3)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy3);
		}
		else if(frame % 9 == 4)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy4);
		}
		else if(frame % 9 == 5)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy5);
		}
		else if(frame % 9 == 6)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy6);
		}
		else if(frame % 9 == 7)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy7);
		}
		else
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy8);
		}
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy0);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy1);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy2);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy3);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy4);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy5);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy6);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy7);
		sprintf(lifes, "Life: %d", life);
		drawString4(0, 10, lifes, PALETTE[0]);
		sprintf(scores, "Score: %d", score);
		drawString4(0, 170, scores, PALETTE[0]);
		waitForVblank();
		frame++;
		FlipPage();
	}
	return 1;
}
示例#3
0
void display(){

	//clear the display
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glClearColor(0,0,0,0);	//color black
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	/********************
	/ set-up camera here
	********************/
	//load the correct matrix -- MODEL-VIEW matrix
//	glMatrixMode(GL_MODELVIEW);

	//initialize the matrix
//	glLoadIdentity();

	//now give three info
	//1. where is the camera (viewer)?
	//2. where is the camera looking?
	//3. Which direction is the camera's UP direction?

	//gluLookAt(100,100,100,	0,0,0,	0,0,1);
//	gluLookAt(ex,ey,ez,	cx,cy,cz, upx,upy,upz);
	//gluLookAt(0,-1,150,	0,0,0,	0,0,1);

//	positionCamera();


	//again select MODEL-VIEW
//	glMatrixMode(GL_MODELVIEW);

    setDiffuseLight();


	/****************************
	/ Add your objects from here
	****************************/




	drawAxes();
	drawGrid();
	glColor3f(1,1,1);



    drawBaseLevel0();

    glPushMatrix();

        glTranslatef(0,0,3.71);
        drawBaseLevel1();

    glPopMatrix();

    drawBaseLevel2();





    drawPartBaseRoof();
    glPushMatrix();
        glRotatef(120,0,0,1);
        drawPartBaseRoof();
        glRotatef(120,0,0,1);
        drawPartBaseRoof();

    glPopMatrix();




    glPushMatrix();

        glRotatef(60,0,0,1);
        drawAnglePillars();
        drawAnglePillarsUpper();
        glRotatef(120,0,0,1);
        drawAnglePillars();
        drawAnglePillarsUpper();
        glRotatef(120,0,0,1);
        drawAnglePillars();
        drawAnglePillarsUpper();
     glPopMatrix();



     glPushMatrix();

        glTranslatef(0,0,25.07);

        drawPartFloatingChamber();
        glRotatef(120,0,0,1);

        drawPartFloatingChamber();
        glRotatef(120,0,0,1);

        drawPartFloatingChamber();


     glPopMatrix();


     glPushMatrix();

        glTranslatef(0,0,57.82);

        drawPartFloatingBeams();
        glRotatef(120,0,0,1);

        drawPartFloatingBeams();
        glRotatef(120,0,0,1);

        drawPartFloatingBeams();


     glPopMatrix();


     // The crown

     glPushMatrix();

        glTranslatef(0,0,144.95);

        for(double angle = 0; angle < 360; angle += 7.5){

            drawPartCrown();
            glRotatef(7.5,0,0,1);

        }


     glPopMatrix();



     drawPipe(230 - 47.8);



    glFlush();
	//ADD this line in the end --- if you use double buffer (i.e. GL_DOUBLE)
	glutSwapBuffers();
}