Advertisement
xerpi

randum

Feb 13th, 2012
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1. void Enemies::respawnRandomEnemy(){
  2.                 byte direction = 0, type= 0, color= 0;
  3.                 int w= 0, h= 0;
  4.                 float x= 0, y= 0, scale= 0, speed= 0;
  5.                 //Random type
  6.                     type = RandomInt(1, 2);
  7.                 //Depending on the type, the scale and the speed changes and calculate the w and h
  8.                     switch( type ){
  9.                         case T_CIRCLE:
  10.                             scale = RandomFloat(0.4 , 0.6);
  11.                             speed = RandomFloat(1, 2);
  12.                             break;
  13.                         case T_SQUARE:
  14.                             scale = RandomFloat(0.2 , 0.4);
  15.                             speed = RandomFloat(0.5, 1.5);
  16.                             break;
  17.                     }
  18.                     w = (int)(64 * scale);
  19.                     h = (int)(64 * scale);
  20.                 //Random color
  21.                     color = RandomInt(1, 2);
  22.                 switch( direction ){
  23.                     case D_UP:
  24.                         x = RandomFloat(w, limitX - w);
  25.                         y = limitY-1;
  26.                         break;
  27.                     case D_DOWN:
  28.                         x = RandomFloat(w, limitX - w);
  29.                         y = -h+1;
  30.                         break;                 
  31.                     case D_RIGHT:
  32.                         x = -w+1;
  33.                         y = RandomFloat(h, limitY - h);
  34.                         break;
  35.                     case D_LEFT:
  36.                         x = limitX-1;
  37.                         y = RandomFloat(h, limitY - h);
  38.                         break;
  39.                 }
  40.             //Add the enemy to the list!
  41.                 enemyList.push_back( Enemy(x, y, scale, speed, type, color, direction));
  42.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement