...

View Full Version : 32 increment isometric rotation + 16 increment movement



Mortecha
03-04-2009, 01:07 PM
I'm building a cannon fodder inspired shootemup but need some help with these 2 key bits of code.

The first piece of code is the turret rotation. The rotation is dependant upon the mouse/cursor to define its direction/facing. There are 32 directions which means they change in 11.25 degree increments. At present the first couple of angles to the left of 360 work but the rest don't. Also the registration points seem to offset by 120 degrees.

[CODE]
onClipEvent(load){
turretOrientation = 0;
}

onClipEvent(enterFrame){
myRadians = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x);
myDegrees = Math.round((myRadians*180/Math.PI));
//_root.yChange = Math.round(_root._ymouse-this._y);
//_root.xChange = Math.round(_root._xmouse-this._x);
//this._rotation = myDegrees+90;


switch (turretOrientation){
case 0:
if (myDegrees > 5.625 && myDegrees < 17.25){
turretOrientation = 1;
this.gotoAndPlay(2);
}
break;

case 1:
if (myDegrees > 17.25 && myDegrees < 28.5){
turretOrientation = 2;
this.gotoAndPlay(3);
}
break;

case 2:
if (myDegrees > 28.5 && myDegrees < 39.75){
turretOrientation = 3;
this.gotoAndPlay(4);
}
break;

case 3:
if (myDegrees > 39.75 && myDegrees < 51){
turretOrientation = 4;
this.gotoAndPlay(5);
}
break;

case 4:
if (myDegrees > 51 && myDegrees < 62.25){
turretOrientation = 5;
this.gotoAndPlay(6);
}
break;

case 5:
if (myDegrees > 62.25 && myDegrees < 73.5){
turretOrientation = 6;
this.gotoAndPlay(7);
}
break;

case 6:
if (myDegrees > 73.5 && myDegrees < 84.75){
turretOrientation = 7;
this.gotoAndPlay(8);
}
break;

case 7:
if (myDegrees > 84.75 && myDegrees < 96){
turretOrientation = 8;
this.gotoAndPlay(9);
}
break;

case 8:
if (myDegrees > 96 && myDegrees < 107.25){
turretOrientation = 9;
this.gotoAndPlay(10);
}
break;

case 9:
if (myDegrees > 107.25 && myDegrees < 118.5){
turretOrientation = 10;
this.gotoAndPlay(11);
}
break;

case 10:
if (myDegrees > 118.5 && myDegrees < 129.75){
turretOrientation = 11;
this.gotoAndPlay(12);
}
break;

case 11:
if (myDegrees > 129.75 && myDegrees < 141){
turretOrientation = 12;
this.gotoAndPlay(13);
}
break;

case 12:
if (myDegrees > 141 && myDegrees < 152.25){
turretOrientation = 13;
this.gotoAndPlay(14);
}
break;

case 13:
if (myDegrees > 152.25 && myDegrees < 163.5){
turretOrientation = 14;
this.gotoAndPlay(15);
}
break;

case 14:
if (myDegrees > 163.5 && myDegrees < 174.75){
turretOrientation = 15;
this.gotoAndPlay(16);
}
break;

case 15:
if (myDegrees > 174.75 && myDegrees < 186){
turretOrientation = 16;
this.gotoAndPlay(17);
}
break;

case 16:
if (myDegrees > 186 && myDegrees < 197.25){
turretOrientation = 17;
this.gotoAndPlay(18);
}
break;

case 17:
if (myDegrees > 197.25 && myDegrees < 208.5){
turretOrientation = 18;
this.gotoAndPlay(19);
}
break;

case 18:
if (myDegrees > 208.5 && myDegrees < 219.75){
turretOrientation = 19;
this.gotoAndPlay(20);
}
break;

case 19:
if (myDegrees > 219.75 && myDegrees < 231){
turretOrientation = 20;
this.gotoAndPlay(21);
}
break;

case 20:
if (myDegrees > 231 && myDegrees < 242.25){
turretOrientation = 21;
this.gotoAndPlay(22);
}
break;

case 21:
if (myDegrees > 242.25 && myDegrees < 253.5){
turretOrientation = 22;
this.gotoAndPlay(23);
}
break;

case 22:
if (myDegrees > 253.5 && myDegrees < 264.75){
turretOrientation = 23;
this.gotoAndPlay(24);
}
break;

case 23:
if (myDegrees > 264.75 && myDegrees < 276){
turretOrientation = 24;
this.gotoAndPlay(25);
}
break;


case 24:
if (myDegrees > 276 && myDegrees < 287.25){
turretOrientation = 25;
this.gotoAndPlay(26);
}
break;

case 25:
if (myDegrees > 287.25 && myDegrees < 298.5){
turretOrientation = 26;
this.gotoAndPlay(27);
}
break;

case 26:
if (myDegrees > 298.5 && myDegrees < 309.75){
turretOrientation = 27;
this.gotoAndPlay(28);
}
break;

case 27:
if (myDegrees > 309.75 && myDegrees < 321){
turretOrientation = 28;
this.gotoAndPlay(29);
}
break;

case 28:
if (myDegrees > 321 && myDegrees < 332.25){
turretOrientation = 29;
this.gotoAndPlay(30);
}
break;

case 29:
if (myDegrees > 332.25 && myDegrees < 343.5){
turretOrientation = 30;
this.gotoAndPlay(31);
}
break;

case 30:
if (myDegrees > 343.5 && myDegrees < 354.75){
turretOrientation = 31;
this.gotoAndPlay(32);
}
break;

default:
turretOrientation = 0;
this.gotoAndPlay(1);

}

}
[ICODE]

I'll get onto the next problem after this one is done:P.

Do you know of any resources or tutorials that can help with this level of programming problems?

Mortecha
03-05-2009, 11:44 PM
Disregard my last post, I am working on ways to calculate and simplify this mess into a group of functions and formule. That may fix it:)

gnomeontherun
03-06-2009, 09:43 AM
Thank you, I looked at your post and was overwhelmed by it all, calculations would be a better way and easier to manage in the long run.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum