[NXC] 彈跳球 – 可計分版本

大家新年快樂,這是阿邦老師教學生寫的彈跳球程式,除了畫面最下方有板子可以彈回球之外,還多了一個計分功能,當玩家接到一顆球分數就會加一分,當然如果沒接到,就是GAMEOVER囉!

過年期間,大家一起玩玩看看誰分數最高唷~~~

==============================

task main()
{
 int A = 0 ;
 int P = 0 ;
 int X = Random(95);
 int Y = 50;
 int XZ = 1 ;
 int YZ = 1 ;
 int X1 = Random(50);
 int Y1 = 40;
 int XZ1 = 1 ;
 int YZ1 = 1 ;
 TextOut(20,25,"Press Orange");
 until(ButtonPressed(BTNCENTER,false));
 PlayTone(150,100);
 while(true)
 {
 RectOut(A,4,100,2) ;
 CircleOut(X,Y,2);
 CircleOut(X1,Y1,2);
  X = X + XZ ;
  Y = Y + YZ ;
 if(X > 95 || X < 5)
 {
  XZ = XZ * (-1);
 }
 if(Y > 63)
 {
  YZ = YZ * (-1);
 }

 

 if(Y < 7 )
 {
 if( X > A&&X < A + 100)
 {
 YZ = YZ * (-1);
 PlayTone(200,100);
 NumOut(80,60,P);
 P = P + 1 ;
 }
 }

 if(Y < 5 )
 {
 ClearScreen();
 while(true)
 {
 TextOut(20,30,"GAMEOVER");
 PlayTone(300,100);
 }
 }

 

 if(ButtonPressed(BTNRIGHT,false))
 {
 A = A + 3 ;
 RectOut(A,4,100,2) ;
 if( A > 71 )
 {
 ClearScreen();
 A = A – 3 ;
 PlayTone(500,100);
 }
 }

 if(ButtonPressed(BTNLEFT,false))
 {
 A = A – 3 ;
 RectOut(A,4,100,2);
 if( A < -1 )
 {
 ClearScreen();
 A = A + 3 ;
 PlayTone(500,100);
 }
 }

 X1 = X1 + XZ1 ;
 Y1 = Y1 + YZ1 ;

 if(X1 > 95 || X1 < 5)
 {
  XZ1 = XZ1 * (-1);
 }

 if(Y1 > 63)
 {
  YZ1 = YZ1 * (-1);
 }

 if(Y1 < 7)
 {
 if( X1 > A&&X1 < A + 100)
 {
 YZ1 = YZ1 * (-1);
 PlayTone(200,100);
 NumOut(80,60,P);
 P = P + 1 ;
 }
 }
 
 
 if(Y1 < 5 )
 {
 TextOut(20,30,"GAMEOVER");
 PlayTone(300,100);
 }
 Wait(5);
 ClearScreen();
 NumOut(80,60,P);

}//while

}//tm

About CAVEDU 阿吉 - 雜工 (2521 Articles)

CAVEDU 教育團隊 打雜

Contact: Website

Leave a comment

Your email address will not be published.


*