Пример #1
0
void LEDupdate(){
	unsigned int index = (LEDdigit*6 + 4-LEDcolumn + (LEDscrollCount>>2));
	char x, slen = strlen(pString);

	if(LEDupdateFLAG){
		x = *(&videoBuf[0][0] + index);
		PGOUT = x & 0x7F;
		PEOUT = 0x1F & ~(1 << LEDcolumn);
		clockLed(LEDdigit);

		if(++LEDdigit == 4) {
			LEDdigit = 0;
			if(++LEDcolumn == 5) {
				LEDcolumn = 0;
				if(slen > 4){
					if(++LEDscrollCount == (6<<2)){
						LEDscrollCount = 0;
						if(++LEDcharNum == slen){
							LEDcharNum = 0;
						}
						LEDsetString(pString, LEDcharNum);
					}
				}
			}
		}
	}
	LEDupdateFLAG = 0;
}
Пример #2
0
void main() 
{
	init_uart(_UART0,_DEFFREQ,_DEFBAUD); // set-up UART0 to 57600, 8n1
	
	timer2000();	//Starts the internal timer 
	LEDinit();		//Activates the LED displays
	LEDsetString("//Reflex Ball\\\\");	

	//Initialization of variables used during the game
	gamedata.ballspeed = 100;
	gamedata.strikerspeed = 20;
	gamedata.wigglecount = 0;
	gamedata.ballcount = 0;
	gamedata.strikercount = 0;
	gamedata.randAngle = 64;
	gamedata.ball2 = 0;
	
	//This loop resets game data and starts a new game
	while(1){
		//Menu 1 evaluates to true when player hits 'play' and selects no. of balls
		if(menu1()){ 
		
			//Ball, striker and block declarations
			Ball_t ball1;
			Ball_t ball2;
			Striker_t striker;
			Block_t block;

			//Ball, striker and block initializations
			ball1.angle = 64;
			gamedata.score = 0;
			gamedata.blocksleft = 0;
			if(gamedata.ball2) ball2.angle = 32;	//Only sets 2nd ball angle if user selects 2 balls
			striker.lives = 3;
			initBall(&ball1,ball1.angle,20,20); 
			if(gamedata.ball2) initBall(&ball2,ball2.angle,30,20);	//Only initializes 2nd ball if user selects it
			initStriker(&striker,62,77,38);

			clrscr();
			initBlocks(&block);		//Creates and draws the blocks on the map
			drawBox();				//Draws the borders of the map

			//Draws striker and various game data
			gotoxy(62,39);
			printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",219,219,219,219,219,219,219,219,219,219,219,219,219,219,219);
			gotoxy(160,10);
			printf("Lives remaining: %d",striker.lives);
			gotoxy(160,12);
			printf("Score: %d",gamedata.score);
			gotoxy(160, 14);
			printf("Blocks left: %d",gamedata.blocksleft);
			window(158,8,180,16,"Stats",2);
			LEDsetString("Lives: 3");

			//This loop starts the actual game
			while(1) {

				//Quits current game and goes to menu if user hits all three buttons
				if(readkey() == 7){
					break;
				}

				//If all blocks are gone: celebrate with a lady and go back to menu
				if(gamedata.blocksleft == 0)
				{
					clrscr();
					lady();
					wiggleLady();
					break;
				}
				
				if(striker.lives > 0)
				{
					
					if(gamedata.strikerUpdate)  //Only runs when flag is high (controlled by timer)
					{ 
						updateStriker(&striker);
						gamedata.strikerUpdate = 0;

						
						if(striker.drawEnable)	//Only draws striker if it has moved and the flag is high
						{ 
							gotoxy((striker.x1_prev >> FIX14_SHIFT),39);
							printf("               ");			//Deletes 'old' striker
							gotoxy((striker.x1 >> FIX14_SHIFT),39);
							printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",219,219,219,219,219,219,219,219,219,219,219,219,219,219,219); //Draws 'new' striker
						}
					}

					if(gamedata.ballUpdate) //Only runs when flag is high (controlled by timer)
					{ 
						gotoxy((ball1.xpos >> FIX14_SHIFT),(ball1.ypos >> FIX14_SHIFT));
						printf(" ");		//Deletes 'old' ball
						checkBallpos(&ball1,&striker);	//Checks if ball hits borders of map or striker and changes direction accordingly
						checkBlock(&block,&ball1);		//Checks if ball hits a block and takes actions accordingly
						if(ball1.xspeed == 0 && ball1.yspeed == 0) ball1.xpos = striker.x1 + (striker.x2 - striker.x1)/3;  //Places ball on top of striker if it just died
						updateBall(&ball1, &striker);	//Moves ball according to its vector
						gotoxy((ball1.xpos >> FIX14_SHIFT),(ball1.ypos >> FIX14_SHIFT));
						printf("%c",223);	//Draws 'new' ball

						if(gamedata.ball2) //If 2nd ball is in use, do the same to it as to the first ball above
						{
							gotoxy((ball2.xpos >> FIX14_SHIFT),(ball2.ypos >> FIX14_SHIFT));
							printf(" ");
							checkBallpos(&ball2,&striker);
							checkBlock(&block,&ball2);
							if(ball2.xspeed == 0 && ball2.yspeed == 0) ball2.xpos = striker.x1 + (striker.x2 - striker.x1)/3 + (striker.x2 - striker.x1)/2 ;
							updateBall(&ball2, &striker);
							gotoxy((ball2.xpos >> FIX14_SHIFT),(ball2.ypos >> FIX14_SHIFT));
							printf("%c",223);
						}
						gamedata.ballUpdate = 0;
					}
				}