int main(void){ TExaS_Init(SSI0_Real_Nokia5110_Scope); // set system clock to 80 MHz Random_Init(1); Nokia5110_Init(); Nokia5110_ClearBuffer(); Nokia5110_DisplayBuffer(); // draw buffer Nokia5110_PrintBMP(32, 47, PlayerShip0, 0); // player ship middle bottom Nokia5110_PrintBMP(33, 47 - PLAYERH, Bunker0, 0); Nokia5110_PrintBMP(0, ENEMY10H - 1, SmallEnemy10PointA, 0); Nokia5110_PrintBMP(16, ENEMY10H - 1, SmallEnemy20PointA, 0); Nokia5110_PrintBMP(32, ENEMY10H - 1, SmallEnemy20PointA, 0); Nokia5110_PrintBMP(48, ENEMY10H - 1, SmallEnemy30PointA, 0); Nokia5110_PrintBMP(64, ENEMY10H - 1, SmallEnemy30PointA, 0); Nokia5110_DisplayBuffer(); // draw buffer Delay100ms(50); // delay 5 sec at 50 MHz Nokia5110_Clear(); Nokia5110_SetCursor(1, 1); Nokia5110_OutString("GAME OVER"); Nokia5110_SetCursor(1, 2); Nokia5110_OutString("Nice try,"); Nokia5110_SetCursor(1, 3); Nokia5110_OutString("Earthling!"); Nokia5110_SetCursor(2, 4); Nokia5110_OutUDec(1234); while(1){ } }
void GPIOPortF_Handler(void){ SW1 = GPIO_PORTF_DATA_R&0x10; // read PF4 into SW1 SW2 = GPIO_PORTF_DATA_R&0x01; // read PF0 into SW2 if(SW1==0 ){ // both pressed z=0; if((LFish.y+4)>=47) LFish.y=47; else LFish.y+=4; Nokia5110_ClearBuffer(); for(p=0;p<30;p++){ if(vector[p].fl==1){ z++; Nokia5110_PrintBMP(vector[p].x, vector[p].y,vector[p].image[0], 0); } if(z>=o) break; } Nokia5110_PrintBMP(LFish.x,LFish.y, LFish.image[0], 0); Nokia5110_DisplayBuffer(); GPIO_PORTF_ICR_R = 0x10; } else if(SW2==0 ){ // neither switch z=0; if ((LFish.y-4)<=16) LFish.y=16; else LFish.y-=4; Nokia5110_ClearBuffer(); for(p=0;p<30;p++){ if(vector[p].fl==1){ z++; Nokia5110_PrintBMP(vector[p].x, vector[p].y,vector[p].image[0], 0); } if(z>=o) break; } Nokia5110_PrintBMP(LFish.x, LFish.y,LFish.image[0], 0); Nokia5110_DisplayBuffer(); GPIO_PORTF_ICR_R = 0x01; } // acknowledge flag4 }
int main(void){ DisableInterrupts(); TExaS_Init(SSI0_Real_Nokia5110_Scope); // set system clock to 80 MHz Random_Init(1); Nokia5110_Init(); PF1Init(); //SysTick_Init(2666666); //Initialize SysTick with 30 Hz interrupts SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed Nokia5110_ClearBuffer(); Nokia5110_DisplayBuffer(); // draw buffer ADC0_Init(); Game_Init(); SwitchLed_Init(); Sound_Init(); Timer2_Init(&Sound_Play,7256); //11.025 kHz. 80,000,000/11,025 cycles, which is about 7256 GameOverFlag = 0; EnableInterrupts(); while(1){ while(Semaphore==0){}; Semaphore = 0; if(GameOverFlag){ State_GameOver(); } else{ Draw_GameFrame(); // update the LCD } if((GameOverFlag == 0) && (Check_GameOver())){ //just detected game over Delay100ms(2);//Delay 200ms GameOverFlag = Check_GameOver(); //SysTick_Init(2666666);//Re-initialize with 30 Hz interrupt SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed } } }
int main(void){ int AnyLife = 1; int i; TExaS_Init(NoLCD_NoScope); // set system clock to 80 MHz // you cannot use both the Scope and the virtual Nokia (both need UART0) Random_Init(1); Nokia5110_Init(); EnableInterrupts(); // virtual Nokia uses UART0 interrupts Nokia5110_ClearBuffer(); Nokia5110_DisplayBuffer(); // draw buffer Nokia5110_PrintBMP(32, 47, PlayerShip0, 0); // player ship middle bottom Nokia5110_PrintBMP(33, 47 - PLAYERH, Bunker0, 0); Nokia5110_PrintBMP(0, ENEMY10H - 1, SmallEnemy10PointA, 0); Nokia5110_PrintBMP(16, ENEMY10H - 1, SmallEnemy20PointA, 0); Nokia5110_PrintBMP(32, ENEMY10H - 1, SmallEnemy20PointA, 0); Nokia5110_PrintBMP(48, ENEMY10H - 1, SmallEnemy30PointA, 0); Nokia5110_PrintBMP(64, ENEMY10H - 1, SmallEnemy30PointA, 0); Nokia5110_DisplayBuffer(); // draw buffer Delay100ms(50); // delay 5 sec at 80 MHz Init(); Timer2_Init(80000000/30); // 30 Hz while(AnyLife){ while(Semaphore == 0){}; Semaphore = 0; // runs at 30 Hz AnyLife = 0; for(i=0; i<4 ; i++){ AnyLife |= Enemy[i].life; } Draw(); } Nokia5110_Clear(); Nokia5110_SetCursor(1, 1); Nokia5110_OutString("GAME OVER"); Nokia5110_SetCursor(1, 2); Nokia5110_OutString("Nice try,"); Nokia5110_SetCursor(1, 3); Nokia5110_OutString("Earthling!"); Nokia5110_SetCursor(2, 4); Nokia5110_OutUDec(1234); Nokia5110_SetCursor(0, 0); // renders screen while(1){ } }
void Draw(void){ int i; Nokia5110_ClearBuffer(); for(i=0;i<4;i++){ if(Enemy[i].life > 0){ Nokia5110_PrintBMP(Enemy[i].x, Enemy[i].y, Enemy[i].image, 0); } } Nokia5110_DisplayBuffer(); // draw buffer }
void Draw(void){ int i; Nokia5110_ClearBuffer(); for(i=0;i<4;i++){ if(Enemy[i].life > 0){ Nokia5110_PrintBMP(Enemy[i].x, Enemy[i].y, Enemy[i].image[FrameCount], 0); } } Nokia5110_DisplayBuffer(); // draw buffer FrameCount = (FrameCount+1)&0x01; // 0,1,0,1,... }
int main(void){ PLL_Init(); // set system clock to 80 MHz Random_Init(1); Nokia5110_Init(); Nokia5110_ClearBuffer(); Nokia5110_DisplayBuffer(); // draw buffer Init(); Draw(); while(1){ Move(); Draw(); Delay100ms(2); } }
int main(void){ TExaS_Init(SSI0_Real_Nokia5110_Scope); // set system clock to 80 MHz DisableInterrupts(); Random_Init(1); Nokia5110_Init(); Nokia5110_ClearBuffer(); Nokia5110_DisplayBuffer(); SysTick_Init(); // initialize Timer2 after Nokia5110_Init because of // error-prone registers operations (old and new registers // are not working good together) // 80MHz/11,025 cycles, which is about 7256 Timer2_Init(7256); Ports_Init(); InitSprites(NumberOfEnemies); RestartGame(); // Countdown, after which all interrupts are enabled! // print 3 Nokia5110_ClearBuffer(); Nokia5110_PrintBMP(28, 41, _my_Countdown_03, 0); Nokia5110_DisplayBuffer(); Delay100ms(3); // print 2 Nokia5110_ClearBuffer(); Nokia5110_PrintBMP(28, 41, _my_Countdown_02, 0); Nokia5110_DisplayBuffer(); Delay100ms(3); // print 1 Nokia5110_ClearBuffer(); Nokia5110_PrintBMP(28, 41, _my_Countdown_01, 0); Nokia5110_DisplayBuffer(); Delay100ms(3); // print GO Nokia5110_ClearBuffer(); Nokia5110_PrintBMP(28, 41, _my_Countdown_GO, 0); Nokia5110_DisplayBuffer(); Delay100ms(3); EnableInterrupts(); while(1){ if (Flag == 1) { Nokia5110_DisplayBuffer(); Flag = 0; } } }
void Timer2A_Handler(void){ ST enemy; TIMER2_ICR_R = 0x00000001; // acknowledge timer2A timeout q++; d=(Random())%4; k=(Random())%4; s=(d+k)%4; if(q<10){ enemy.x=Enemy[s].x; enemy.y=Enemy[s].y; enemy.life=1; enemy.b=0; enemy.image[0]=Black; enemy.image[1]=Dead; } else { enemy.x=Enemy[s].x; enemy.y=Enemy[s].y; enemy.life=1; enemy.image[0]=bomp; enemy.image[1]=bomp; enemy.b=1; q=0; } for(i=0;i<30;i++) { if(vector[i].fl==0) { vector[i]=enemy; vector[i].fl=1; vector[i].life=1; o++; break; } } Nokia5110_ClearBuffer(); Nokia5110_PrintBMP(LFish.x, LFish.y, LFish.image[0], 0); for(p=0;p<30;p++){ if(vector[p].fl==1 && vector[p].life==1){ if(vector[p].x >0){ vector[p].x -= 10; if(((((LFish.y-16)<vector[p].y) && (vector[p].y<=(LFish.y)))||((vector[p].y-16)<LFish.y && (vector[p].y-16)<LFish.y))&& (vector[p].x<=17) && (vector[p].b==0 )) { Score+=10; vector[p].life=0; Nokia5110_PrintBMP(vector[p].x, vector[p].y,vector[p].image[1], 0); o--; } else if((((LFish.y-16)<vector[p].y)&& (vector[p].y<=(LFish.y+4))) &&(vector[p].x<=17) && vector[p].b==1){ Nokia5110_ClearBuffer(); Nokia5110_DisplayBuffer(); Nokia5110_SetCursor(1, 1); Nokia5110_OutString("GAME OVER"); Nokia5110_SetCursor(1, 2); Nokia5110_OutString("Nice try,"); Nokia5110_SetCursor(1, 4); Nokia5110_OutString("Score: "); Nokia5110_SetCursor(6, 4); Nokia5110_OutUDec(Score); Delay100ms(50); exit(0); } else Nokia5110_PrintBMP(vector[p].x, vector[p].y,vector[p].image[0], 0); } else if (vector[p].x==0){ vector[p].fl=0; vector[p].life=0; o--; } } if(p>=o)break; } Nokia5110_DisplayBuffer(); }