Talk:Roguelike Tutorial, using python3+tdl

From RogueBasin
Revision as of 04:37, 24 June 2017 by Cerepol (talk | contribs)
Jump to navigation Jump to search

Worthwhile considering is a better condensed movement code using pythons dict.

using a simple constant


DIR = dict([('KP8', (0, -1)), ('KP2', (0, 1)), ('KP4', (-1, 0)), ('KP6', (1, 0)), ('KP7', (-1, -1)), ('KP9', (1, -1)), ('KP1', (-1, 1)), ('KP3', (1, 1)), ('KP5', (0, 0))])

you can change your player handling movement to

   if key in DIR:
       (dx, dy) = DIR.get(key)
       #Do something with deltas

instead of the giant block it currently is.