~vesto/uxn-shenanigans

b133c6e54e0eb34e396de2b602db897b59303e86 — Steve Gattuso 1 year, 7 months ago d51d584
we've got a hex grid!
1 files changed, 25 insertions(+), 11 deletions(-)

M hex-grid.tal
M hex-grid.tal => hex-grid.tal +25 -11
@@ 16,21 16,35 @@
  #01c0 .System/g DEO2
  #2ce5 .System/b DEO2

  .Screen/width DEI2 #0000
  &loop-x
    DUP2 #0000 #c5 ;draw-hex JSR2  ( push y and color onto the stack, draw it )
    #000c ADD2  ( increment our x counter )
    GTH2k  ( check to see if the width is greater than our x, jump if not )
  #0000 #0000
  ( ws: xpos ypos / rs: )
  &loop-y
    DEBUG
    &loop-x
      STH2 STH2                       ( ws: / rs: ypos xpos )
      STH2rk SWP2r STH2rk SWP2r       ( ws: xpos ypos / rs: ypos xpos )
      #c5 ;draw-hex JSR2              ( ws: / rs: ypos xpos )
      .Screen/width DEI2              ( ws: width / rs: ypos xpos )
      STH2r               ( ws: width xpos / rs: ypos )
      #000c ADD2          ( ws: width new-xpos / rs: ypos )
      STH2k               ( ws: width new-xpos / rs: ypos new-xpos )
      GTH2 #00            ( ws: cond / rs: ypos new-xpos )
      STH2r STH2r         ( ws: cond new-xpos ypos / rs: )
      ROT2 POP
    ,&loop-x JCN
  POP2 POP2

  ( #0000 #0000 #c5 ;draw-hex JSR2 )
    ( ws: xpos ypos / rs: )
    NIP2 #0000 SWP2 ( 0000 ypos / rs: )
    #000c ADD2 DUP2 ( ws: xpos new-ypos new-ypos / rs: )
    .Screen/height DEI2 ( ws: xpos new-ypos new-ypos height / rs: )
    SWP2 ( ws: xpos new-ypos height new-ypos / rs: )
    GTH2 ( ws: xpos new-ypos cond / rs: )
    ,&loop-y JCN
BRK

@draw-hex ( x^ y^ color -- )
  STH
  ( set x/y coords and stash the color )
  .Screen/y DEO2 .Screen/x DEO2
@draw-hex ( x y color -- )
  ( stash the color, set x/y coords )
  STH .Screen/y DEO2 .Screen/x DEO2

  ;hex-sprite/tl .Screen/addr DEO2
  STHrk .Screen/sprite DEO