Exemplo n.º 1
0
void print_hsync(int hsync)
{
	static int	peak_hsync = 0;
	static int	peak_count;

	if (hsync > peak_hsync) {
		peak_hsync = hsync;
		peak_count = 60;
	}
	else if (peak_count > 0) {
		if (--peak_count == 0) {
			peak_hsync = hsync;
		}
	}
	FntPrint("\nH-SYNC: %d\n", hsync);
	FntPrint("  PEAK: %d\n", peak_hsync);
}
Exemplo n.º 2
0
bool playGame()
{
	int pic_idx; // id for drunkard image
	int beer_idx; // id for beer image
	static int barman_frame_idx;// idx for barman frame idling
	static int beer_frame_idx; 	// idx for beer frame filling
	static short barman_table_pos_idx;

	if (gameDelays.drunk_gen_wait == 0)
	{
		// listDrunkards(d_array);
		pic_idx = rand() % NUM_AVAIL_DRUNKARDS;	// one of the available avatars
// # warning DRUNKARDS DISABLED
#if 1 
		if (addDrunkard(pic_idx, d_array) == false)
			fail(ERR, "Could not add a new drunkard!");
		gameDelays.drunk_gen_wait = gameSetups[currGameSetupIdx].drunkard_gen_time;
#endif
	}

	// if moveBeers returns false, a beer has crashed
	if (moveBeers(b_array, barman_table_pos_idx) == false)
	{
		remLife();
		setGameStatus(GAME_LOCKED);

		// trigger barman failing sprite
		Sprite_SetPosition(&barmanFailSprt,
			barmanPosition[barman_table_pos_idx].x,
			barmanPosition[barman_table_pos_idx].y);

		// Init timer for beer falling
		gameDelays.falling_lag = FALLING_LAG;

		return false;
	}

	// listDrunkards(d_array);
	// if moveDrunkards return false, someone reached
	// the end of the table
	if (moveDrunkards(d_array) == false)
	{
		remLife();
		setGameStatus(GAME_LOCKED);

		// XXX hide the current barman (?) sprite
		// item->b_sprt.w = 0;
		// item->b_sprt.h = 0;

		// TODO trigger drunkard rage animation
		// trigger barman sprite being dragged
		// position him completely on the table
		Sprite_SetPosition(&barmanDragged,
			barmanPosition[barman_table_pos_idx].x -
							barmanDragged.w,
			barmanPosition[barman_table_pos_idx].y);

		return false;
	}

	// check for beers filling in this iteration
	beer_idx = haveBeersFilling(b_array);
	// printf("beers filling? %d\n", beer_idx);

	/***** Barman movement between tables *****/
	// barman can only move if the timer is over
	if (gameDelays.input_wait == 0)
	{
		// ... and he's not filling a mug
		if (beer_idx == -1)
		{
			if (IsPadPress(Pad1Down))
			{
				gameDelays.input_wait = INPUT_LAG;
				if (barman_table_pos_idx < 3)
				{
					barman_table_pos_idx++;
				}
			}

			if (IsPadPress(Pad1Up))
			{
				gameDelays.input_wait = INPUT_LAG;
				if (barman_table_pos_idx > 0)
				{
					barman_table_pos_idx--;
				}
			}

			// idle barman sprite positioning on screen
			Sprite_SetPosition(&barmanIdleSprt,
				barmanPosition[barman_table_pos_idx].x,
				barmanPosition[barman_table_pos_idx].y);

			// busy barman torso sprite positioning on screen
			Sprite_SetPosition(&barmanTapTorsoSprt,
				barmanPosition[barman_table_pos_idx].x,
				barmanPosition[barman_table_pos_idx].y);

			// busy barman legs sprite positioning on screen
			Sprite_SetPosition(&barmanTapLegsSprt,
				barmanPosition[barman_table_pos_idx].x,
				barmanPosition[barman_table_pos_idx].y + BARMAN_SPRT_BEER_TORSO_H);

			if (IsPadPress(Pad1Cross))
			{
				// generate a new beer and add to the list of active beers
				if (gameDelays.filling_lag <= 0)
				{
					// initialize filling animation
					gameDelays.filling_lag = FILLING_LAG;
					barman_frame_idx = 0;

					addBeer(
						barman_table_pos_idx, // table idx
						b_array);
					// listBeers(b_array);
				}
			}
		} // end of beer being filled

#if DEBUG
		if (IsPadPress(Pad1Triangle))
		{
			listBeers(b_array);
			listDrunkards(d_array);
		}
#endif

	} // end barman movevent between tables

	/**** BARMAN IS FILLING A BEER ****/
	// calculate the right barman frame
	if (beer_idx != -1)
	{
		// advance frame while the player is pressing Cross
		// (and I can count down the filling_lag)
		// otherwise stick to the last frame FILLING_OPERATING_4
		// even if the player keeps pressing Cross
		float fill_time = 0.0;
		if (IsPadPress(Pad1Cross))
		{
			barman_is_active = true;

			fill_time = (100 * gameDelays.filling_lag) / FILLING_LAG;
			if (fill_time <= 5.0)
			{
				barman_frame_idx = FILLING_OPERATING;
				beer_frame_idx = BEERTAP_FRO;
			}
			else if (fill_time <= 25.0)
			{
				barman_frame_idx = FILLING_OPERATING;
				beer_frame_idx = BEERTAP_100;
			}
			else if (fill_time <= 50.0)
			{
				barman_frame_idx = FILLING_OPERATING;
				beer_frame_idx = BEERTAP_050;
			}
			else if (fill_time <= 75.0)
			{	
				barman_frame_idx = FILLING_OPERATING;
				beer_frame_idx = BEERTAP_025;
			}
			else if (fill_time <= 100.0)
			{
				barman_frame_idx = FILLING_OPERATING;
				beer_frame_idx = BEERTAP_EMPTY;
			}
		}
		else
		{
			barman_is_active = false;

			if (fill_time <= 25.0)
			{
				barman_frame_idx = FILLING_IDLE;
				beer_frame_idx = BEERTAP_100;
			}
			else if (fill_time <= 50.0)
			{
				barman_frame_idx = FILLING_IDLE;
				beer_frame_idx = BEERTAP_050;
			}
			else if (fill_time <= 75.0)
			{
				barman_frame_idx = FILLING_IDLE;
				beer_frame_idx = BEERTAP_025;
			}
			else if (fill_time <= 100.0)
			{
				barman_frame_idx = FILLING_IDLE;
				beer_frame_idx = BEERTAP_EMPTY;
			}
		}

		// set barman frame
		Sprite_Change(&barmanTapTorsoSprt, &barmanImg,
			barman_frames[barman_frame_idx].x,
			barman_frames[barman_frame_idx].y);

		// set filling beer sprite
		Sprite_Init(&beerTapSprt, &barmanImg,
			SPRITE_NORMAL,
			beerTap_frames[beer_frame_idx].x,
			beerTap_frames[beer_frame_idx].y,
			BEER_TAP_SPRT_W, BEER_TAP_SPRT_W);

		Sprite_SetPosition(&beerTapSprt,
			tapSprt[barman_table_pos_idx].x,
			tapSprt[barman_table_pos_idx].y + BEER_TAP_SPRT_H);
	}
	else
	{
		/**** BARMAN IS IDLE ****/
		if (gameDelays.barman_breath_wait == 0)
		{
			gameDelays.barman_breath_wait = BARMAN_BREATH_WAIT;
			if ((barman_frame_idx % 2) == 0)
			{
				barman_frame_idx = IDLE_0;
				Sprite_Change(&barmanIdleSprt, &barmanImg,
					barman_frames[IDLE_0].x,
					barman_frames[IDLE_0].y);
			}
			else
			{
				barman_frame_idx = IDLE_1;
				Sprite_Change(&barmanIdleSprt, &barmanImg,
					barman_frames[IDLE_1].x,
					barman_frames[IDLE_1].y);
			}
		}
	}

	// where is the barman and what is he doing?
	// draw the tap sprites accordingly!
	{
		int i;
		for (i = 0; i < 4; ++i)
		{
			// this tap is the one next to the barman
			if (i == barman_table_pos_idx)
			{
				if (beer_idx != -1 && barman_is_active == true)
				{
					// barman is filling a beer
					Sprite_Change(&tapSprt[i], &barmanImg,
						tap_frames[TAP_BARMAN_1].x,
						tap_frames[TAP_BARMAN_1].y);
				}
				else if (beer_idx != -1 && barman_is_active == false)
				{
					// barman is idle at the tap
					Sprite_Change(&tapSprt[i], &barmanImg,
						tap_frames[TAP_BARMAN_0].x,
						tap_frames[TAP_BARMAN_0].y);
				}
				else
				{
					// barman is doing nothing
					Sprite_Change(&tapSprt[i], &barmanImg,
						tap_frames[TAP_NORMAL].x,
						tap_frames[TAP_NORMAL].y);
				}
			}
			else
			{
				// tap is not where the barman stands
				Sprite_Change(&tapSprt[i], &barmanImg,
					tap_frames[TAP_NORMAL].x,
					tap_frames[TAP_NORMAL].y);
			}
		}
	}

	// listBeers(b_array);

	// Finished filling a beer? Position the beer
	// on the table and launch it!
	// NOTE: there must be at most one beer in B_BEINGFILLED status.
	// NOTE1: when the wait is over, the beer can be launched.
	// NOTE2: "filling_lag" can be global, because we only have one barman
	// 			and he can fill one beer mug at a time!
	if (
		(beer_idx != -1)  &&
		(gameDelays.filling_lag <= 0) &&
		(!IsPadPress(Pad1Cross))
	)
	{
		setBeerStatus(b_array[beer_idx], B_MOVING);
	}

#if 0 // DEBUG
		for (i = 0; i < MAX_BEERS; ++i)
		{
			if (b_array[i]->dbgstats != 0)
			{
				FntPrint(b_array[i]->dbgstats, "%p", b_array[i]);
				FntFlush(b_array[i]->dbgstats);
			}
		}
#endif

	err_cond->err_table = -1;
	err_cond->err_code = ERR_NONE;
	return true;
}
Exemplo n.º 3
0
main()
{
	DB		db[2];		/* packet double buffer */
	DB		*cdb;		/* current db */
	MATRIX		rottrans;	/* rot-trans matrix */
	int		i;		/* work */
	int		dmy, flg;	/* dummy */
	CVECTOR		col[12];	/* cube color */
	u_long		cnt;

	etc.near_clip=500;
	etc.far_clip=5000;
	etc.clip_off=0;
	
	PadInit(0);             /* initialize PAD */
	ResetGraph(0);		/* reset graphic subsystem (0:cold,1:warm) */
	SetGraphDebug(0);	/* set debug mode (0:off, 1:monitor, 2:dump) */
	
	InitGeom();			/* initialize geometry subsystem */
	SetGeomOffset(320, 240);	/* set geometry origin as (160, 120) */
	SetGeomScreen(SCR_Z);		/* distance to viewing-screen */

	SetLightMatrix(&LLM);
	SetColorMatrix(&LCM);
	SetBackColor(BK.vx,BK.vy,BK.vz);
	SetFarColor(FC.vx,FC.vy,FC.vz);
	SetFogNear(1*SCR_Z,SCR_Z);
	
	/* initialize environment for double buffer (interlace)
	 *	buffer ID	VRAM address 
	 *-------------------------------------------------------
	 *	buffer #0	(0,  0)-(640,480)
	 *	buffer #1	(0,  0)-(640,480)
	 */
	SetDefDrawEnv(&db[0].draw, 0, 0, 640, 480);	
	SetDefDrawEnv(&db[1].draw, 0, 0, 640, 480);	
	SetDefDispEnv(&db[0].disp, 0, 0, 640, 480);	
	SetDefDispEnv(&db[1].disp, 0, 0, 640, 480);
	
	FntLoad(960,256);
	SetDumpFnt(FntOpen(64,64,256,200,0,512));
	SetRCnt(RCntCNT2,0xffff,RCntMdNOINTR|RCntMdFR);
	StartRCnt(RCntCNT2);

	/* set surface colors */
	for (i = 0; i < 12; i+=2) {
		col[i].r = col[i+1].r = 0xff/*rand()*/;	/* R */
		col[i].g = col[i+1].g = 0xff/*rand()*/;	/* G */
		col[i].b = col[i+1].b = 0xff/*rand()*/;	/* B */
		col[i].cd = col[i+1].cd = CODE_G3;	/* cd */
	}
	
	init_prim(&db[0]);	/* set primitive parameters on buffer #0 */
	init_prim(&db[1]);	/* set primitive parameters on buffer #1 */
	
	SetDispMask(1);		/* enable to display (0:inhibit, 1:enable) */
	
	while (pad_read(&rottrans) == 0) {
		cdb = (cdb==db)? db+1: db;	/* swap double buffer ID */
		ClearOTagR(cdb->ot, OTSIZE);	/* clear ordering table */

		/* add cube */
		ResetRCnt(RCntCNT2);

		add_cube(cdb->ot, cdb->s, v, n, col);

		cnt= GetRCnt(RCntCNT2);
		FntPrint("cnt=%d\n",cnt);
		
		/* swap buffer */
		DrawSync(0);	/* wait for end of drawing */
		VSync(0);	/* wait for the next V-BLNK */
	
		PutDrawEnv(&cdb->draw); /* update drawing environment */
		PutDispEnv(&cdb->disp); /* update display environment */

		DrawOTag(cdb->ot+OTSIZE-1);	/* draw */
		FntFlush(-1);
	}
        PadStop();
        exit();
}
Exemplo n.º 4
0
main()
{
	int		i;
	int		hsync;
	int		ret;
	int		tmp_v;

	ResetCallback();
	// initialize CD subsystem
	CdInit();
	CdSetDebug(0);
	// initialize graphics
	ResetGraph(0);

	// initialize debug display
	FntLoad(960, 256);
	SetDumpFnt(FntOpen(64, 64, 128, 128, 0, 512));

	// initialize display double buffer
	SetDefDrawEnv(&db[0].draw, 0,   0, 320, 240);
	SetDefDrawEnv(&db[1].draw, 0, 240, 320, 240);
	SetDefDispEnv(&db[0].disp, 0, 240, 320, 240);
	SetDefDispEnv(&db[1].disp, 0,   0, 320, 240);
	db[0].draw.isbg = 1;
	setRGB0(&db[0].draw, 0, 0, 0);
	db[1].draw.isbg = 1;
	setRGB0(&db[1].draw, 0, 0, 0);

	setPolyF4(&db[0].prim);
	setRGB0(&db[0].prim, 255, 255, 0);
	setPolyF4(&db[1].prim);
	setRGB0(&db[1].prim, 255, 255, 0);

	for (i = 0; i < READ_FILES; i++) {
		set_read_file(i, filename[file_order[i]], (void *)0x80100000);
	}
	file_num = 0;

	// set CD subsystem mode
	param[0] = CdlModeSpeed;		// x2 speed
	while (CdControl(CdlSetmode, param, 0) == 0)
		;

	SetDispMask(1);		// enable display

	// main loop
	while(1) {
		cdb  = (cdb==db)? db+1: db;		// swap double buffer ID
		ClearOTag(cdb->ot, OTSIZE);	

		moving_object();

		FntPrint("CD READ TEST 2\n----------------\n");
		FntPrint("FILE: %d\n", file_num);
		FntPrint("POS: %02x:%02x:%02x\n", fp[file_num].pos.minute,
				fp[file_num].pos.second,
				fp[file_num].pos.sector);
		FntPrint("SECTORS: %d\n", read_remain_sector);
		FntPrint("READ V: %d\n", read_v);

		if ((ret = check_read_file()) == CD_READ_COMPLETE) {
			if (++file_num > READ_FILES-1) {
				file_num = 0;
				tmp_v = VSync(-1);
				read_v = tmp_v - start_v;
				start_v = tmp_v;
			}
			read_remain_sector = READ_SECTORS;	// for display
			start_read_file(file_num);
		}
		else if (ret != CD_READ_BUSY) {
				start_read_file(0);
				start_v = VSync(-1);
		}

		read_manage();

		hsync = VSync(0);
		PutDispEnv(&cdb->disp); // update display environment
		PutDrawEnv(&cdb->draw); // update drawing environment
		DrawOTag(cdb->ot);

		print_hsync(hsync);
		FntPrint("\nERROR: %d\n", errcnt);

		// flush debug strings
		FntFlush(-1);
	}
}