move 5 tiles up, while locking controls?

Non-platform specific questions.

move 5 tiles up, while locking controls?

Postby Hblade » Sat Mar 09, 2013 2:35 am

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: move 5 tiles up, while locking controls?

Postby skydereign » Sat Mar 09, 2013 3:19 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron