-
I got the rotational code written for my game, I can now rotate my units on a map with the right click of a mouse... Now to implement the unit points usage!
There's 8 possible directions - N (1), NE (2), E (3), SE (4), S (5), SW (6), W (7), NW (8). The numbers in brackets are the value of SoldierDirectionValue, an integer.
I have two variables, Soldiers(SelectedSoldier).Direction and Soldiers(SelectedSoldier).UnitPointsAvailible - .Direction is one of the 8 numbers above. Each time you rotate one direction it will cost 1 unit point, eg. if you rotate East to West it will cost 4 unit points, East to South East will cost 1, East to South will cost 2, etc..
However you can only rotate if you have more than 0 points.
Here raises a question.
How do I figure out the best way to turn (anti-clockwise or clockwise), and if I have enough movement points (if I don't I want it to stop and rotate as much as possible with the availible points)?
I want there to be a loop when it rotates, so I can put the graphics code in and also end the loop if it runs out of unit points.
If anyone can help me write this I'd be very happy. =) I've been working on this code for ages but it's just getting more complicated and I don't think it's gunna work anyway... =/
Thanks.
-Git
-
Why don't you first change the indexing from 0 to 7 and starting from W and going clockwise, that will ease further math problems.
If CurrentDirection>TargetDirection then TargetDirection=TargetDirection+8
will make sure target direction is larger than current direction
Clockwise = TargetDirection-CurrentDirection>4
makes sure you rotate in the correct direction
Movepointsneeded = 4-abs(TargetDirection-CurrentDirection-4)
How many movement points you need to move, you can now compare this to the amount of movement points you have.
Code:
For X=1 to movementpoints
CurrentDirection=CurrentDirection-sgn(Clockwise+0.5)
'Draw the soldier and have your dealy
next X