int main()
{
	char key;
	IplImage *base, *fr, *fr0;
	float dt;
	struct timeval past;
	
	inform();
	preprocessing(windowname, &base, &fr, &fr0);
	
	while(1)
	{
		initialize(&past);
		while(explosr<criticr && !restartflag && !escflag)
		{
			cvCopy(base, fr, NULL);
			easyplot(fr, fr0);
			dt = time_interval(&past);
			pausestate(&past, fr);
			user_update();
			com_update();
			ball_update(dt);
			cvShowImage(windowname, fr);
		}
		// exit
		if(escflag) break;
		// update score
		if(bpc.y<0) score[1]++;
		else score[0]++;
		// restart
		if(restartflag) {
			restartflag = 0;
			score[0] = 0;
			score[1] = 0;
		}
	}
	
	// free memory
	cvDestroyWindow(windowname);
	cvReleaseImage(&base);
	cvReleaseImage(&fr);
	cvReleaseImage(&fr0);
	cvReleaseImage(&scoretext1);
	cvReleaseImage(&scoretext2);
	cvReleaseImage(&pausetext);
	cvReleaseImage(&pausefr);
	return 0;
}
예제 #2
0
static void update()
{
	/* updating opponent AI first */
	if (g_ball->dim.y + 20 < g_opponent->dim.y) {
		g_opponent->up = 1;
		g_opponent->down = 0;
	} else if (g_ball->dim.y > g_opponent->dim.y + g_opponent->dim.h) {
		g_opponent->up = 0;
		g_opponent->down = 1;
	}
	/* updating game state */
	stick_update(g_player);
	stick_update(g_opponent);
	ball_update(g_ball);
	/* process score changes */
	if (g_score->player_event) {
		g_score->player_score++;
		if (g_score->player_score == 10) {
			printf("score: %d - %d\n", g_score->player_score,
						   g_score->opponent_score);
			printf("player wins!\n");
			run = 0;
		}
		g_ball->dim.x = SCREEN_WIDTH / 2;
		g_ball->dim.y = SCREEN_HEIGHT / 2;
		g_ball->x_direction = 1;
		g_ball->y_direction = -1;
		g_score->player_event = 0;
	} else if (g_score->opponent_event) {
		g_score->opponent_score++;
		if (g_score->opponent_score == 10) {
			printf("score: %d - %d\n", g_score->player_score,
						   g_score->opponent_score);
			printf("opponent wins!\n");
			run = 0;
		}
		g_ball->dim.x = SCREEN_WIDTH / 2;
		g_ball->dim.y = SCREEN_HEIGHT / 2;
		g_ball->x_direction = -1;
		g_ball->y_direction = 1;
		g_score->opponent_event = 0;
	}
	/* update client state */
	
}