Page 1 of 1

move 5 tiles up, while locking controls?

PostPosted: Sat Mar 09, 2013 2:35 am
by Hblade
I want to work on a tactical battle system style thing just for fun soon, and I was wondering the best way to go about moving 5 tiles up? (The movement will be based on 32x32 tiles). I want to know if theres a short code that will let me control the character and have him move 5 tiles up when I press the up arrow, and -not- let me press down left or right during the movement?

I know how to do this but I code incredibly sloppy. I'd end up with like, who knows how many if statements lol

Re: move 5 tiles up, while locking controls?

PostPosted: Sat Mar 09, 2013 3:19 am
by skydereign
A simple and clean way would be to use states. Essentially lock the player's state to moving, while they move to the their destination. You can then only change direction/position while not already moving. You could also just disable keydown events while moving, though you might not want that if you have other keydown events. Remember ifs aren't bad, your code will at some level need to make choices. So if it makes sense to use an if, use one.