Guest User

[FS] Arcanoid

a guest
Aug 22nd, 2011
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.65 KB | None | 0 0
  1. /*
  2. arc.pwn
  3. Textdraw Arcanoid by OFFREAL
  4. 22.08.2011
  5. NOT Commercial - OpenSource
  6.  
  7. // WARNING !!!
  8. Irrational use of server resources !
  9.  
  10. Textdraws: 67
  11. Timers: 1 ( 50 ms )
  12. */
  13.  
  14. #include <a_samp>
  15.  
  16. #define VERSION "1.0 beta"
  17. #define MAX_BLOCKS 60       // maximum blocks
  18. #define MAX_LVL 3           // maximum levels
  19.  
  20. forward UpdateBall();
  21.  
  22. // basic variables
  23. new
  24.     Arcanoid,   // basic timer
  25.    
  26.     Float: ball_a = 8.0,                            // vector step
  27.     Float: ball_vector[2],                          // ball vector
  28.     Float: ball_coord[2],                           // ball coordinates
  29.     Float: ball_td_offset[2] = { -6.00, -9.00 },    // offset of textdraw centre
  30.     Float: bar_Y = 440.00,                          // surface of the reflector
  31.     Float: bar_X,                                   // reflector coordinates
  32.     Float: BarSize = 80.00,                         // reflector size
  33.     Float: K,                                       // square factor
  34.    
  35.     Text: ball_td,              // textdraw ball
  36.     Text: bar_td,               // textdraw reflector
  37.     Text: ScoreTD,              // textdraw score
  38.     Text: BKG,                  // textdraw background
  39.     Text: InfoTD,               // textdraw info
  40.     Text: block_td[MAX_BLOCKS], // textdraws blocks
  41.    
  42.     Score,              // score
  43.     CurLVL,             // current level
  44.     WaitTime = -1,      // pause of basic timer
  45.     arc_player = -1,    // ID of player
  46.     ball_speed = 50,    // timer frequency
  47.  
  48.     killed, // var for count of "dead blocks"
  49.     time;   // unix_time
  50.  
  51. // structure
  52. enum b_info {
  53. Float:maxX, Float:maxY, Float:minX, Float:minY,
  54. Float:bc, stat, bool:active
  55. }
  56.  
  57. new block[MAX_BLOCKS][b_info];
  58.  
  59. // block colors
  60. new ColorBlock[] = { 0, 0xFF000044, 0xFF800044, 0xFFFF0044, 0x00FF0044, 0x00FFFF44 };
  61.  
  62. // levels config
  63. new block_stat[MAX_LVL][MAX_BLOCKS] = {
  64. {
  65. 1,2,3,3,4,5,5,4,3,3,2,1,
  66. 1,2,3,4,5,4,4,5,4,3,2,1,
  67. 1,2,3,4,5,5,5,5,4,3,2,1,
  68. 1,2,3,4,5,4,4,5,4,3,2,1,
  69. 1,2,3,4,3,4,4,3,4,3,2,1
  70. },
  71. {
  72. 4,3,4,0,0,1,1,0,0,4,3,4,
  73. 4,4,3,4,0,1,1,0,4,3,4,4,
  74. 4,2,4,3,4,1,1,4,3,4,2,4,
  75. 0,4,2,4,4,1,1,4,4,2,4,0,
  76. 4,0,4,2,0,4,4,0,2,4,0,4
  77. },
  78. {
  79. 3,2,1,0,0,5,5,0,0,1,2,3,
  80. 4,3,2,1,0,0,0,0,1,2,3,4,
  81. 0,4,3,2,1,0,0,1,2,3,4,0,
  82. 0,0,4,3,2,1,1,2,3,4,0,0,
  83. 0,0,0,4,3,2,2,3,4,0,0,0
  84. }
  85. };
  86.  
  87. stock minrand(min, max)
  88. {
  89.    return random(max - min) + min;
  90. }
  91.  
  92. stock Float:floatrand(Float:min, Float:max)
  93. {
  94.     new imin;
  95.     imin = floatround(min);
  96.     return float(random((floatround(max) - imin) * 100) + (imin * 100)) / 100.0;
  97. }
  98.  
  99. // ball draw func
  100. stock DrawBoll(Float: X, Float: Y)
  101. {
  102.     TextDrawDestroy( ball_td );
  103.     ball_td = TextDrawCreate(X + ball_td_offset[0], Y + ball_td_offset[1], "o");
  104.     TextDrawSetShadow(ball_td, 0);
  105.     TextDrawFont(ball_td, 1);
  106.     TextDrawLetterSize(ball_td,0.4, 1.3 );
  107.     ball_coord[0] = X; ball_coord[1] = Y;
  108.     TextDrawShowForPlayer(arc_player, ball_td);
  109. }
  110.  
  111. // background draw func
  112. stock DrawBKG()
  113. {
  114.     TextDrawDestroy( BKG );
  115.     BKG = TextDrawCreate( 0.00, 0.00, "_");
  116.     TextDrawUseBox(BKG ,1);
  117.     TextDrawBoxColor(BKG, 0x00000080 );
  118.     TextDrawTextSize(BKG, 640.00,0.00);
  119.     TextDrawLetterSize(BKG, 0.00, 480.00*0.135 );
  120.     TextDrawShowForPlayer(arc_player, BKG);
  121. }
  122.  
  123. // blocks draw func
  124. stock DrawBlock( bid, st )
  125. {
  126.     if( block[bid][active] )
  127.     {
  128.         TextDrawDestroy( block_td[ bid ] );
  129.     }
  130.     block_td[ bid ] = TextDrawCreate(block[bid][minX], block[bid][minY], "_");
  131.     TextDrawUseBox(block_td[ bid ],1);
  132.     TextDrawBoxColor(block_td[ bid ], ColorBlock[st] );
  133.     TextDrawTextSize(block_td[ bid ],block[bid][maxX],0.00);
  134.     TextDrawLetterSize(block_td[ bid ],0.00, (block[bid][maxY] - block[bid][minY])*0.102 );
  135.     TextDrawShowForPlayer(arc_player, block_td[ bid ]);
  136.     block[bid][active] = true;
  137.     block[bid][ stat ] = st;
  138.     block[bid][bc] = ( block[bid][maxY] - block[bid][minY] )/( block[bid][maxX] - block[bid][minX] );
  139. }
  140.  
  141. // reflector move func
  142. stock MoveBar( Float:step )
  143. {
  144.     bar_X += step;
  145.    
  146.     if(bar_X > 580.00){ bar_X = 580.00; }
  147.     else if( bar_X < -20.00 ){ bar_X = -20.00; }
  148.    
  149.     TextDrawDestroy( bar_td );
  150.     bar_td = TextDrawCreate( bar_X, bar_Y, "_");
  151.     TextDrawUseBox(bar_td, 1);
  152.     TextDrawBoxColor(bar_td, -1 );
  153.     TextDrawTextSize(bar_td, bar_X + BarSize, 0.00);
  154.     TextDrawLetterSize(bar_td, 0.00, 10.00 );
  155.     TextDrawShowForPlayer(arc_player, bar_td);
  156. }
  157.  
  158. // is ball in block ?
  159. stock IsBallInBlock( Float:X, Float:Y, Float:mxX, Float:mxY, Float:mnX, Float:mnY ) // 2D
  160. {
  161.     if( X > mxX ) {return false;}
  162.     if( Y > mxY ) {return false;}
  163.     if( X < mnX ) {return false;}
  164.     if( Y < mnY ) {return false;}
  165.     return true;
  166. }
  167.  
  168. // level load func
  169. stock LoadLevel( lvl )
  170. {
  171.         if( arc_player == -1 ) { return; }
  172.         new str[64]; format(str, 64, "~r~Level ~w~%d", lvl);
  173.         SendInfo( str );
  174.         WaitTime = 50;
  175.         CurLVL = lvl;
  176.         DrawBKG();
  177.         bar_X = 0.00;
  178.         MoveBar( 280.00 );
  179.         ball_coord[0] = bar_X + 40.00;
  180.         ball_coord[1] = bar_Y + ball_td_offset[1];
  181.         ball_vector[0] = 0.25 - float(random(50))/100; ball_vector[1] = -0.75;
  182.  
  183.         for(new i=0;i<MAX_BLOCKS;i++)
  184.         {
  185.             DrawBlock( i , block_stat[lvl][ i ]);
  186.         }
  187. }
  188.  
  189. // send info func
  190. stock SendInfo( text[] )
  191. {
  192.     TextDrawSetString(InfoTD, text);
  193.     TextDrawShowForPlayer(arc_player, InfoTD);
  194. }
  195.  
  196. // score draw func
  197. stock SetScore( toscore )
  198. {
  199.     Score += toscore;
  200.     new str[64];
  201.     if(Score < 0)
  202.     { format(str, sizeof(str),"~r~%d",Score); }
  203.     else if( Score < 3000 )
  204.     { format(str, sizeof(str),"~w~%d",Score); }
  205.     else if( Score < 6000 )
  206.     { format(str, sizeof(str),"~y~~h~%d",Score); }
  207.     else if( Score < 9000 )
  208.     { format(str, sizeof(str),"~g~~h~%d",Score); }
  209.     else if( Score < 12000 )
  210.     { format(str, sizeof(str),"~b~~h~%d",Score); }
  211.     else
  212.     { format(str, sizeof(str),"~p~~h~%d",Score); }
  213.  
  214.     TextDrawSetString(ScoreTD, str);
  215.     TextDrawShowForPlayer(arc_player, ScoreTD);
  216. }
  217.  
  218. // basic timer func
  219. public UpdateBall()
  220. {
  221.     if( WaitTime > 0)
  222.     {
  223.         WaitTime--;
  224.         return;
  225.     }
  226.     else if( WaitTime == 0 )
  227.     {
  228.         ball_coord[0] = bar_X + 40.00;
  229.         ball_coord[1] = bar_Y + ball_td_offset[1] ;
  230.         ball_vector[0] = 0.25 - float(random(50))/100; ball_vector[1] = -0.75;
  231.         TextDrawHideForPlayer(arc_player, InfoTD);
  232.         WaitTime = -1;
  233.     }
  234.    
  235.     if(arc_player != -1)
  236.     {
  237.         if( time && time < gettime() )
  238.         {
  239.             SetScore( -10 );
  240.         }
  241.         time = gettime();
  242.        
  243.         // get player keys
  244.         new lr;
  245.         GetPlayerKeys(arc_player, lr, lr, lr);
  246.  
  247.         // move reflector
  248.         if(lr > 0) { MoveBar( 10.00 ); }
  249.         else if(lr < 0) { MoveBar( -10.00 ); }
  250.    
  251.         // contacl left-right borders
  252.         if( ball_coord[0] > 640.00+ball_td_offset[0] || ball_coord[0] < - ball_td_offset[0] )
  253.         {
  254.            ball_vector[0] *= -1;
  255.            //ball_vector[0] += float(minrand( -150, 150 ))/1000;
  256.         }
  257.  
  258.         // contact up border
  259.         if( ball_coord[1] < - ball_td_offset[1] )
  260.         {
  261.            ball_vector[1] *= -1;
  262.            //ball_vector[1] += float(minrand( -150, 150 ))/1000;
  263.         }
  264.        
  265.         // contact down border - check reflector
  266.         if( ball_coord[1] > bar_Y + ball_td_offset[1] )
  267.         {
  268.             if( bar_X - 5.00 < ball_coord[0] < bar_X + BarSize + 5.00 )
  269.             {
  270.                 ball_vector[1] *= -1;
  271.  
  272.                 if(lr > 0)
  273.                 {
  274.                     ball_vector[0] += 0.20;
  275.                 }
  276.                 else if(lr < 0)
  277.                 {
  278.                     ball_vector[0] -= 0.20;
  279.                 }
  280.                
  281.                 if( ball_vector[0] > 1.00 ) { ball_vector[0] = 1.00; }
  282.                 else if( ball_vector[0] < -1.00 ) { ball_vector[0] = -1.00; }
  283.  
  284.             }
  285.             else
  286.             {
  287.                 SetScore( -5000 );
  288.                 SendInfo( "~r~LOOSER !!!" );
  289.                 WaitTime = 60;
  290.             }
  291.         }
  292.        
  293.         // auto increase speed
  294.         if( -0.75 < ball_vector[1] < 0.75 )
  295.         {
  296.             if(ball_vector[1] < 0) { ball_vector[1] -= 0.01; }
  297.             else {ball_vector[1] += 0.01;}
  298.         }
  299.  
  300.         // contact blocks
  301.         for(new i=0;i<MAX_BLOCKS;i++)
  302.         {
  303.             if( !block[i][stat] ) { killed++; continue; }
  304.            
  305.             if( IsBallInBlock(  ball_coord[0] + ball_vector[0]*ball_a, ball_coord[1] + ball_vector[1]*ball_a,
  306.                 block[i][maxX], block[i][maxY], block[i][minX], block[i][minY] ))
  307.             {
  308.  
  309.                 K = ( ball_coord[1] - (block[i][maxY]+block[i][minY])*0.5 ) /
  310.                     ( ball_coord[0] - (block[i][maxX]+block[i][minX])*0.5 );
  311.                    
  312.                 block[i][ stat ] --;
  313.                 DrawBlock(i, block[i][ stat ]);
  314.  
  315.                 PlayerPlaySound(arc_player,1056, 0.00, 0.00, 0.00);
  316.                 SetScore( 100 );
  317.                
  318.                 //printf("%f | %f", ball_vector[0], ball_vector[1]);
  319.                
  320.                 if( floatabs( K ) > block[i][ bc ] )
  321.                 {
  322.                     ball_vector[1] *= -1;
  323.                     ball_vector[0] += float(minrand( -150, 150 ))/1000;
  324.                     if( ball_vector[0] > 1.00 ) { ball_vector[0] = 1.00; }
  325.                     else if( ball_vector[0] < -1.00 ) { ball_vector[0] = -1.00; }
  326.                 }
  327.                 else
  328.                 {
  329.                     ball_vector[0] *= -1;
  330.                     ball_vector[1] += float(minrand( -150, 150 ))/1000;
  331.                     if( ball_vector[1] > 1.00 ) { ball_vector[1] = 1.00; }
  332.                     else if( ball_vector[1] < -1.00 ) { ball_vector[1] = -1.00; }
  333.                 }
  334.                 break;
  335.             }
  336.         }
  337.        
  338.         killed = 0;
  339.        
  340.         // "death blocks" count
  341.         for(new i=0;i<MAX_BLOCKS;i++)
  342.         {
  343.             if( !block[i][stat] ) { killed++; }
  344.             if( killed == MAX_BLOCKS ) { LoadLevel( ( CurLVL+1 )%MAX_LVL ); WaitTime = 60; }
  345.         }
  346.        
  347.         // redraw ball
  348.         DrawBoll( ball_coord[0] + ball_vector[0]*ball_a, ball_coord[1] + ball_vector[1]*ball_a );
  349.  
  350.     }
  351. }
  352.  
  353. public OnFilterScriptInit()
  354. {
  355.     TextDrawCreate(640.00, 480.00, "BuggedTD");
  356.    
  357.     for(new i =0; i<MAX_BLOCKS; i++)
  358.     {
  359.         block[i][minX] = 30.00 + ( i%12 )*50;
  360.         block[i][maxX] = block[i][minX] + 30.00;
  361.        
  362.         block[i][minY] = 20.00 + (i/12)*50;
  363.         block[i][maxY] = block[i][minY] + 30.00;
  364.     }
  365.  
  366.     ball_td = TextDrawCreate(0.00, 0.00, "o");
  367.     BKG = TextDrawCreate( 0.00, 0.00, "_");
  368.    
  369.     InfoTD = TextDrawCreate(320.00, 360.00, "_" );
  370.     TextDrawLetterSize(InfoTD, 1.25, 3.00 );
  371.     TextDrawAlignment(InfoTD, 0);
  372.    
  373.     ScoreTD = TextDrawCreate(85.00, 370.00, "_" );
  374.     TextDrawLetterSize(ScoreTD, 0.80, 2.00 );
  375.     TextDrawAlignment(ScoreTD, 2);
  376.  
  377.     DrawBoll( 40.00, 40.00 );
  378.     Arcanoid = SetTimer("UpdateBall",ball_speed, true);
  379.     return 1;
  380. }
  381.  
  382. public OnFilterScriptExit()
  383. {
  384.     KillTimer( Arcanoid );
  385.     TextDrawDestroy( ball_td );
  386.     for(new i=0;i<MAX_BLOCKS;i++)
  387.     {
  388.         TextDrawDestroy( block_td[ i ] );
  389.     }
  390.     TextDrawDestroy( bar_td );
  391.     TextDrawDestroy( BKG );
  392.     TextDrawDestroy( InfoTD );
  393.     TextDrawDestroy( ScoreTD );
  394.     TogglePlayerControllable(arc_player,1);
  395.     return 1;
  396. }
  397.  
  398. main()
  399. {
  400.     print("\n----------------------------------");
  401.     print("FS Arconoid by OFFREAL");
  402.     print("----------------------------------\n");
  403. }
  404.  
  405.  
  406. public OnPlayerConnect(playerid)
  407. {
  408.     return 1;
  409. }
  410.  
  411. public OnPlayerDisconnect(playerid, reason)
  412. {
  413.     return 1;
  414. }
  415.  
  416. public OnPlayerSpawn(playerid)
  417. {
  418.     return 1;
  419. }
  420.  
  421. public OnPlayerCommandText(playerid, cmdtext[])
  422. {
  423.     if (strcmp("/arc", cmdtext, true, 10) == 0)
  424.     {
  425.         if( arc_player != -1 )
  426.         {
  427.             SendClientMessage(playerid, -1, "Accanoid now in use =(");
  428.             return 1;
  429.         }
  430.        
  431.         Score = 0;
  432.         TogglePlayerControllable(playerid,0);
  433.         arc_player = playerid;
  434.         LoadLevel( 0 );
  435.        
  436.         return 1;
  437.     }
  438.     if (strcmp("/arc_stop", cmdtext, true, 10) == 0)
  439.     {
  440.         if( playerid != arc_player )
  441.         {
  442.             SendClientMessage(playerid, -1, "You do not play to Arcanoid");
  443.             return 1;
  444.         }
  445.        
  446.         TogglePlayerControllable(arc_player,1);
  447.        
  448.         TextDrawHideForPlayer(arc_player, bar_td);
  449.         TextDrawHideForPlayer(arc_player, BKG);
  450.         TextDrawHideForPlayer(arc_player, ball_td);
  451.         TextDrawHideForPlayer(arc_player, InfoTD);
  452.         TextDrawHideForPlayer(arc_player, ScoreTD);
  453.        
  454.         for(new i=0;i<MAX_BLOCKS;i++)
  455.         {
  456.             TextDrawHideForPlayer(arc_player, block_td[ i ]);
  457.         }
  458.        
  459.         arc_player = -1;
  460.     }
  461.     return 0;
  462. }
Advertisement
Add Comment
Please, Sign In to add comment