示例#1
0
void display(void){



	adjustCamera();
	glClear(GL_COLOR_BUFFER_BIT);
	giveTexture();
	glPushMatrix();
	glTranslatef(demonX,demonY,0);
	giveTextureDemon();
	glPopMatrix();


	glPushMatrix();
	{
		//translating to the left-bottom corner of our boundary
		if(jumped){
			moveCannon();
		}
		glTranslatef(cannonBaseX ,cannonBaseY,0);
		glColor3f(BLACK);
		drawObstacles();
		//tranlating to the cannon's bottom
		glRotatef(rot_angle , 0 , 0 , 1);
		drawCannon();
		drawPiston();
		//draw Cannon Ball
		curBall->drawUnreleased();
	}
	glPopMatrix();
	displayScoreboard();
	updateDemon();
	//drawDemon();
	manageTurtles();

	//for every released ball...
	for(int i=0;i<balls.size();i++){
		balls[i]->drawReleased();
		//cout << balls[i]->ballX << " " << balls[i]->ballY << " " << balls[i]->ballVelX << " " << balls[i]->ballVelY << endl;
		if(balls[i]->stoped()){
			removeBall(i);
		}
	}
	ballTurtle();
	ballDemon();
	turtleCannon();
	glFlush();
	glutSwapBuffers();
}
示例#2
0
int main(int ac, char *av[])
{
	int	       	i, c, quitFlag, twoPlayer;		
	pthread_t	collisionThread;
	pthread_t	destCollisionThread;
	pthread_t	gameMonitor;
	void	      	*animate();	
	
	quitFlag = 0;

	setup();
	
	/*
	 * Display start screen, have the user press 'S' to start
	 * the game.
	 */
	printStartMessage();
	while (1) {
		c = getch();
		if (c == '1') {
			twoPlayer = 0;
			clear();
			refresh();
			break;
		} else if (c == '2') {
			twoPlayer = 1;
			clear();
			refresh();
			break;
		} else if (c == 'Q') {
			quitFlag = 1;
			break;
		}
	}	
		

	if (twoPlayer) {
		setupCannon(2);	
		displayCannon(2);
	} else {
		setupCannon(1);
	}
	
	setRocketsToDead(rockets);
	displayCannon(1);
	displayInfo();

	if (pthread_create(&saucerSetup, NULL, setupSaucer, NULL)) {
		endwin();
		exit(0);
	} 	
	pthread_create(&destroyerThread, NULL, sendDestroyer, &destShip); 
	pthread_create(&collisionThread, NULL, collisionDetection, NULL);
	pthread_create(&destCollisionThread, NULL, checkDestRocketCollision, NULL);
	pthread_create(&gameMonitor, NULL, checkEndConditions, NULL);

	/* process user input */
	while(!quitFlag) {
		c = getch();

		if ( c == 'Q' || quitFlag){
			 quitFlag = 1;
			 break;
		} else if (c == 'j' && !endGame) {
			moveCannon(-1, 1);
		} else if (c == 'l' && !endGame) {
			moveCannon(1, 1);
		} else if (c == 'a' && !endGame) {
			moveCannon(-1, 2);
		} else if (c == 'd' && !endGame) {
			moveCannon(1, 2);
		} else if (c == 'w' && !endGame) {
			shootRocket(2);
		} else if (c == 'i' && !endGame) {
			shootRocket(1);	
		}	
	}

	/* cancel all the threads */
	pthread_mutex_lock(&mx);
	for (i=0; i < MAX_ROCKETS; i++) {
		pthread_cancel(rocketThreads[i]);
	}
	pthread_cancel(collisionThread);
	pthread_cancel(destCollisionThread);
	pthread_cancel(gameMonitor);
	endwin();
	return 0;
}