Difference between revisions of "Talk:Roguelike Tutorial, using python3+tdl"

From RogueBasin
Jump to navigation Jump to search
(Easier/Cleaner movement delta handling.)
 
 
(One intermediate revision by the same user not shown)
Line 9: Line 9:
you can change your player handling movement to
you can change your player handling movement to


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


instead of the giant block it currently is.
instead of the giant block it currently is.

Latest revision as of 04:38, 24 June 2017

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
       player_attack_or_move(dx, dy)

instead of the giant block it currently is.