python - How to implement smooth tile based movement -


the player in game centered in screen, , 'scroll' background move around.

i list of keys pressed pygame.key.get_pressed(), if player's move cooldown over, call move function. function scrolls map in direction of movement 1 tile.

however movement not smooth. 'jumps' next tile.

how implement movement system player moves in small steps (speed * dt) still moves distance of 1 tile every time move function called? game needs rendered in between each small step think.

full source here: https://github.com/hcollings/rpg-game/blob/alternate_movement/game.py

animations , movement perceive rather what's happening. in grid system, can abstract visual movement of player away actual mechanics taking drawing part of code , updating draw position independently of gameplay position.

the problem experiencing jumping commonly handled kind of interpolation technique. lerp() common function provides linear interpolation, in below example use different technique.

here resource interpolation techniques: http://paulbourke.net/miscellaneous/interpolation/

you implement movement destination, direction, , "unspent" increments of movement. if wanted move new square, set direction , add standard number of increments (representing 1 square) "unspent increment counter". draw graphic @ new location offset number of increments still have. if want move more 1 square @ time, increase number of unspent increments.

movement take place long have unspent increments (think movement points). technique lends visual collision detection; if remaining number of increments fraction of total increments (~25%?) between number of squares moving, graphic "practically" in square according player sees.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -