2019-03-09 23:49:45 +00:00
|
|
|
( M A P )
|
|
|
|
var tileselect
|
2019-03-10 23:51:24 +00:00
|
|
|
: invalidate-map mapsize mapsize! ;
|
2019-03-09 23:49:45 +00:00
|
|
|
: mouseworldpos mousepos scrollpos +pos ;
|
|
|
|
: mousetile mouseworldpos world>tile ;
|
|
|
|
: tile ( x y -- ptr ) mapsize drop * + map + ;
|
|
|
|
|
|
|
|
1 const WALKABLE
|
|
|
|
2 const DRIVABLE
|
|
|
|
|
|
|
|
array tileflags
|
2019-03-10 23:51:24 +00:00
|
|
|
( grass ) WALKABLE b,
|
2019-03-14 00:43:38 +00:00
|
|
|
( dirt ) WALKABLE DRIVABLE | b,
|
2019-03-10 23:51:24 +00:00
|
|
|
( water ) 0 b,
|
|
|
|
( pavement ) WALKABLE DRIVABLE | b,
|
|
|
|
( brick ) 0 b,
|
|
|
|
( forest ) 0 b,
|
|
|
|
( roof ) 0 b,
|
|
|
|
( brick ) 0 b,
|
|
|
|
( window ) 0 b,
|
|
|
|
( carpet ) WALKABLE b,
|
|
|
|
( wallpaper ) 0 b,
|
|
|
|
( tile ) WALKABLE b,
|
|
|
|
( door ) 0 b,
|
|
|
|
( cabinet ) 0 b,
|
|
|
|
( fridge ) 0 b,
|
|
|
|
( countertop ) 0 b,
|
|
|
|
( sink ) 0 b,
|
2019-03-14 00:43:38 +00:00
|
|
|
( house ) 0 b,
|
2019-03-15 02:18:20 +00:00
|
|
|
( fence ) 0 b,
|
|
|
|
( storefront ) 0 b,
|
2019-03-10 23:51:24 +00:00
|
|
|
|
|
|
|
here tileflags - 1 - const MAXTILE
|
2019-03-09 23:49:45 +00:00
|
|
|
|
|
|
|
: mapflag? ( x y flag -- b ) >rot tile b@ tileflags + b@ & ;
|
|
|
|
: walkable? ( x y -- b ) WALKABLE mapflag? ;
|
|
|
|
: drivable? ( x y -- b ) DRIVABLE mapflag? ;
|
|
|
|
|
|
|
|
: tick-mapedit
|
|
|
|
tileselect @
|
|
|
|
^< key-pressed if 1 - then
|
|
|
|
^> key-pressed if 1 + then
|
|
|
|
dup 0 < if drop MAXTILE then
|
|
|
|
dup MAXTILE > if drop 0 then
|
|
|
|
tileselect !
|
|
|
|
|
2019-03-10 23:51:24 +00:00
|
|
|
MOUSEL mousedown if tileselect @ mousetile tile b! invalidate-map then
|
|
|
|
MOUSER clicked if
|
|
|
|
mouseworldpos world>tile
|
2019-03-14 00:43:38 +00:00
|
|
|
2dup tile b@ tileselect !
|
2019-03-10 23:51:24 +00:00
|
|
|
swap . . cr then ;
|
2019-03-09 23:49:45 +00:00
|
|
|
|
|
|
|
: copy-mapseg ( neww oldw y -- )
|
2019-05-17 01:05:40 +00:00
|
|
|
>r ( oldw neww r: y )
|
2019-03-09 23:49:45 +00:00
|
|
|
2dup min >rot ( copyw neww oldw )
|
|
|
|
r@ * map + ( copyw neww src )
|
2019-05-17 01:05:40 +00:00
|
|
|
swap <r * map + ( copyw src dst )
|
2019-03-09 23:49:45 +00:00
|
|
|
swap <rot memmove ;
|
|
|
|
|
|
|
|
: resize-map ( neww newh -- )
|
2019-05-17 01:05:40 +00:00
|
|
|
swap mapsize >r ( newh neww oldw r: oldh )
|
|
|
|
2dup < if 1 <r else <r 1 - 0 then ( newh neww copyw ystart ylim )
|
2019-03-09 23:49:45 +00:00
|
|
|
for 2dup i copy-mapseg next
|
|
|
|
drop swap mapsize! ;
|
|
|
|
|
2019-03-26 02:05:23 +00:00
|
|
|
: mapw mapsize drop ;
|
|
|
|
: maph mapsize nip ;
|
|
|
|
|
|
|
|
: offset-map ( p d -- p ) dup 0 < if drop else + then ;
|
|
|
|
|
|
|
|
: shift-map ( dx dy -- )
|
2019-05-17 01:05:40 +00:00
|
|
|
maph over abs - >r ( dx dy r: h )
|
2019-03-26 02:05:23 +00:00
|
|
|
swap mapw over abs - >rot ( w dy dx r: h )
|
|
|
|
2dup map swap offset-map
|
|
|
|
swap mapw * offset-map >rot ( w end dy dx r: h )
|
|
|
|
map swap negate offset-map
|
|
|
|
swap mapw * negate offset-map ( w end start r: h )
|
|
|
|
2dup > if r@ mapw * + swap r@ mapw * + swap then
|
2019-05-17 01:05:40 +00:00
|
|
|
<r 0 for
|
2019-03-26 02:05:23 +00:00
|
|
|
3dup <rot memmove
|
|
|
|
2dup < if mapw + swap mapw + swap
|
|
|
|
else mapw - swap mapw - swap then
|
|
|
|
next drop drop drop invalidate-map ;
|
|
|
|
|
2019-03-09 23:49:45 +00:00
|
|
|
: save-map ( filename -- )
|
|
|
|
fdeactivate swap overwrite
|
|
|
|
mapsize swap fput fput
|
|
|
|
mapsize * map fwrite
|
|
|
|
factivate ;
|
|
|
|
|
|
|
|
: load-map ( filename -- )
|
|
|
|
fdeactivate swap open
|
|
|
|
fget fget
|
|
|
|
2dup * map fread
|
|
|
|
mapsize!
|
|
|
|
factivate ;
|
2019-03-10 23:51:24 +00:00
|
|
|
|
|
|
|
: fill-map ( tile -- )
|
|
|
|
0 mapsize * for dup map i + b! next drop invalidate-map ;
|