Movement with arrow keys.

Thoughts on the further development of Haven & Hearth? Feel free to opine!

Re: Movement with arrow keys.

Postby boshaw » Thu Aug 25, 2011 3:43 am

dra6o0n wrote:stuff



Wrong, a good implementation of key movement does not go through the mousedown,mouseup,etc functions like normal events do which is where it handles calls to the various widgets. If you actually looked at the source code for hnh you would know that the only server calls that actually affect movement are wdgmsg calls of type "click", there's NO need to actually make your mouse click in the spot you wish to move since all you really need is the tile you wish to move to in the form of it's Coord obj. Once again there's NO need to actually make a mouse click at the spot you wish to move, the server doesn't even care about where you clicked on the screen. it completely ignores those coordinates as long as they are not (0,0).

A good implementation would look something like this:
Code: Select all
ui.mapview.wdgmsg("click",new Coord(1,1),COORDINATE_OF_TILE,LEFT_BUTTON(1),ui.modflags());   


Obviously knowing the players location you can make it move north,south,east,west easily (remember coordinates are randomized so north might be (-) one session and (+) the next so you'll also need to determine what's true north and east which aren't hard tasks to be on the safe side)

Never does this code conflict with any actual mouse clicks to any other widgets (or the MapView itself which means if you click on your map while W is held it's going to first jerk your char towards that spot then back north assuming you still have W held in a short span of time) nor will it interfere with key clicks considering ones that are already in use in other widgets will be performed first, meaning if W is used for say the Wig button in the menu grid it'll perform the Wig button hotkey RATHER than the W for movement. With that being said you have to plan around these obviously which requires you to either change up the menu grids hot keys or use different keys for movement ie: arrow keys, i,j,k,l maybe,etc

Also when going around other objects in the game that stop your movement you can easily use your movement keys multiple times so it goes around it because it's not like you're required to finish walking to the tile you wanted before changing direction ie: going north with W then jerking east real fast with E then back north with W to go around something

To get at what Patchouli Knowledge said you can make all movement conform to tile via the tilify method within MapView which makes any Coordinate input conform to the actual grid(center of the tile) with the returned Coord

Believe it or not you can even do Auto Run in the sense of clicking "I" which starts your char going north automatically without any more key clicks then the user can adjust his direction via changing the angle of the wanted tile(tile to move to). This can Obviously be done via another two keys one subtracting from angle and other adding or even going as far as making mouse drags change the angle(worked best) via subtracting/adding based on delta movement from last known position on screen and then factoring it down a bit so it doesn't spin you super fast (nice smooth rotation around 360 degrees). Also the ender update which added in movement lines made this one pretty nice to debug :D Note: the farther you make your radius of the circle in this auto run the better imo from playing with it and this would obviously take on a different approach as how to make this work vs the one liner for simple key movement(more like 5 lines if you count the checking of the key + error handling if MapView isn't created which is simple stuff)


Trust me though, a proper key movement implementation works perfect I personally loved it for when i was mining which brings me to yet another point which is that you can go even further with your key movement stuff and actually make it a auto miner(if your requested tile is a null block(black)) or auto farmer if a crop lies on the requested tile. auto miner actually requires no further changes to the above simple code, but you'll want to implement some way to change how far your request tile is obviously since you'd need it to be 1 tile in said direction for mining and maybe 5 tiles in said direction for nice easy movement. Auto farming would require you to actually look and check if any Gob objects are at said tile (remember to center it) and send in the additional hit gob info if so thus letting you farm with arrow keys as long as you have your harvest cursor on.
User avatar
boshaw
 
Posts: 1590
Joined: Tue Jun 01, 2010 10:22 pm

Previous

Return to Critique & Ideas

Who is online

Users browsing this forum: Google [Bot] and 58 guests