Last active
August 29, 2015 14:06
-
-
Save veeneck/e6d881884efdc7077c8b to your computer and use it in GitHub Desktop.
Rotate our formation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func moveIntoFormation() { | |
| // Loop over each unit in our Squad. | |
| for (i, unit) in enumerate(self.units) { | |
| // Get the vector from the formation class for that position. | |
| // Just a simple accessor to the array. | |
| let vector = self.formation!.getVectorAtPosition(i) | |
| // Hard coded rotation by radian of 0.4. | |
| var newX = vector.dx * cos(0.4) - vector.dy * sin(0.4); | |
| var newY = vector.dx * sin(0.4) + vector.dy * cos(0.4); | |
| // Make a CGPoint from the new X & Y, and tell the unit to walk to it. | |
| let position = CGPoint(x:newX, y:newY) | |
| unit.moveToPoint(position, callback: { | |
| // clean up post animation | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment