Advertisement
iAndr0idOs

Untitled

Sep 27th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. int time;
  2. int state;
  3.  
  4. bool side;
  5.  
  6. float self[12];
  7.  
  8. float debris[10][3];
  9. float laser[3];
  10.  
  11. float comet[6];
  12.  
  13. float v;
  14. float ar;
  15.  
  16. float _ZERO[3];
  17.  
  18. void init(){
  19.     time = 0;
  20.     state = 0;
  21.    
  22.     memset(_ZERO,0,3*sizeof(float));
  23. }
  24.  
  25. void loop(){
  26.    
  27.     time ++;
  28.     api.getMySphState(self);
  29.    
  30.     if(time == 1) {
  31.         side = self[0]>0;
  32.         for(int i = 0; i < 10; i ++) {
  33.             game.getDebrisLocation(i,debris[i]);
  34.         }
  35.         game.getDebrisLocation(10,laser);
  36.         laser[0] *= side?1:-1;
  37.     }
  38.    
  39.     game.getCometState(0,comet);
  40.    
  41.     v = mathVecMagnitude(&self[3],3);
  42.     ar = mathVecMagnitude(&self[9],3);
  43.    
  44.     switch(state) {
  45.         case 0: {
  46.             api.setPositionTarget(laser);
  47.             float attrate[3] = {0,0,0};
  48.             api.setAttRateTarget(attrate);
  49.             if(distanceTo(laser) < 0.05f && v < 0.02f && ar < 0.04f) state = 1;
  50.             break;
  51.         }
  52.         case 1: {
  53.             //if(distanceTo(laser) > 0.05f || v > 0.02f) state = 0;
  54.             //float attrate[3] = {0,0,1};
  55.             //api.setAttRateTarget(attrate);
  56.             //api.setPositionTarget(laser);
  57.             //api.setVelocityTarget(_ZERO);
  58.             if(game.haveItem(0,!side)) state = 2;
  59.         }
  60.         case 2: {
  61.             face(comet);
  62.             float target[3] = {0.55f*side?1:-1,0.35f,0};
  63.             api.setPositionTarget(target);
  64.             if(time >= 90) state = 3;
  65.         }
  66.         case 3: {
  67.             float predictedComet[3];
  68.             game.predictCometState(10,predictedComet,comet);
  69.             face(predictedComet);
  70.             game.shootLaser();
  71.         }
  72.     }
  73.    
  74.     DEBUG(("State=%d\n",state));
  75. }
  76.  
  77. void drift(float target[3]) {
  78.     float diff[3];
  79.     mathVecSubtract(diff,target,self,3);
  80.     api.setVelocityTarget(diff);
  81. }
  82.  
  83. void face(float target[3]) {
  84.     float diff[3];
  85.     mathVecSubtract(diff,target,self,3);
  86.     mathVecNormalize(diff,3);
  87.     api.setAttitudeTarget(diff);
  88. }
  89.  
  90. float distanceTo(float target[3]) {
  91.     float diff[3];
  92.     mathVecSubtract(diff,target,self,3);
  93.     return mathVecMagnitude(diff,3);
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement