Results 1 to 2 of 2

Thread: Logic problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    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

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width