|
|
|
|
|
by to3m
3863 days ago
|
|
If you really insist on having an enum for your directions, what you could do is something like this: (assuming 2s complement and TRUE being ~0) : DIREQ DIRECTION @ = ;
: DELTA DIREQ SWAP DIREQ NEGATE + ;
: MOVE-SNAKE-HEAD
LEFT RIGHT DELTA SNAKE-X-HEAD +!
UP DOWN DELTA SNAKE-Y-HEAD +! ;
It's an open question whether this approach is any better but I think it looks a bit more Forthlike, insofar as I have any grasp of what that is.I think having offsets would make more sense - e.g., suppose your playfield is 80 units wide, then you'd have left and right as -1 and +1, and up and down as -80 and +80 (which I assume is what you mean). |
|