Skip to content

Instantly share code, notes, and snippets.

@veeneck
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save veeneck/e6d881884efdc7077c8b to your computer and use it in GitHub Desktop.

Select an option

Save veeneck/e6d881884efdc7077c8b to your computer and use it in GitHub Desktop.
Rotate our formation.
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