Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int time;
- int state;
- bool side;
- float self[12];
- float debris[10][3];
- float laser[3];
- float comet[6];
- float v;
- float ar;
- float _ZERO[3];
- void init(){
- time = 0;
- state = 0;
- memset(_ZERO,0,3*sizeof(float));
- }
- void loop(){
- time ++;
- api.getMySphState(self);
- if(time == 1) {
- side = self[0]>0;
- for(int i = 0; i < 10; i ++) {
- game.getDebrisLocation(i,debris[i]);
- }
- game.getDebrisLocation(10,laser);
- laser[0] *= side?1:-1;
- }
- game.getCometState(0,comet);
- v = mathVecMagnitude(&self[3],3);
- ar = mathVecMagnitude(&self[9],3);
- switch(state) {
- case 0: {
- api.setPositionTarget(laser);
- float attrate[3] = {0,0,0};
- api.setAttRateTarget(attrate);
- if(distanceTo(laser) < 0.05f && v < 0.02f && ar < 0.04f) state = 1;
- break;
- }
- case 1: {
- //if(distanceTo(laser) > 0.05f || v > 0.02f) state = 0;
- //float attrate[3] = {0,0,1};
- //api.setAttRateTarget(attrate);
- //api.setPositionTarget(laser);
- //api.setVelocityTarget(_ZERO);
- if(game.haveItem(0,!side)) state = 2;
- }
- case 2: {
- face(comet);
- float target[3] = {0.55f*side?1:-1,0.35f,0};
- api.setPositionTarget(target);
- if(time >= 90) state = 3;
- }
- case 3: {
- float predictedComet[3];
- game.predictCometState(10,predictedComet,comet);
- face(predictedComet);
- game.shootLaser();
- }
- }
- DEBUG(("State=%d\n",state));
- }
- void drift(float target[3]) {
- float diff[3];
- mathVecSubtract(diff,target,self,3);
- api.setVelocityTarget(diff);
- }
- void face(float target[3]) {
- float diff[3];
- mathVecSubtract(diff,target,self,3);
- mathVecNormalize(diff,3);
- api.setAttitudeTarget(diff);
- }
- float distanceTo(float target[3]) {
- float diff[3];
- mathVecSubtract(diff,target,self,3);
- return mathVecMagnitude(diff,3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement