Here's proof of concept of the VSGE Editor that creates a file containing data statements to include in the engine program.
The graphic:
http://dl.dropbox.com/u/10291175/RogueCraftExp1.bmpThe code:
REM
DEFINT A-Z
_TITLE "VSGE Editor" ' our window title
SCREEN _NEWIMAGE(800, 600, 32) ' screen the user sees
DIM Map%(40, 30) ' structure to hold the map data inmemory
DIM SHARED mx%, my%, mbl%, mbr% ' structure for mouse x y left and right buttons
DIM Tints&(8) ' structure for the 8 colors numbers
Tiles1& = _LOADIMAGE("RogueCraftExp1.bmp", 32) ' hidden window of our tiles 8 tiles@(16 x 16)
IF Tiles1& <> 0 THEN ' error trap for unfound file
PRINT "Graphic file loaded"; Tiles1&
ELSE
PRINT "Unable to locate graphic file RougeCraftExp1.bmp"
_DELAY 3
END
END IF
Grey& = _RGB32(192, 192, 192)
Pink& = _RGB32(255, 105, 180)
LWhite& = _RGB32(255, 250, 250)
GOSUB Box
GOSUB Grid
GOSUB ShowTiles
TileNum = 0: Savfilename$ = "VSGE-Data.txt": CanSave = 0
_MOUSESHOW
DO
_LIMIT 30
GOSUB MicePoll
GOSUB FindPlace
IF _KEYDOWN(115) THEN GOSUB PrepareSave 'S button to save
IF Region = 2 THEN GOSUB InRegion2
IF Region = 1 THEN GOSUB InRegion1
LOCATE 34, 1: PRINT "Tile", "Region="; Region, "TileNum="; TileNum, cellx, celly
LOCATE 35, 1: PRINT "MiceX="; mx%, "MiceY="; my%; " "
_DISPLAY
LOOP UNTIL _KEYDOWN(27)
SLEEP
SYSTEM
'------------------------------------- GOSUBS ------------------------------------
Box:
LINE (7, 7)-(649, 489), Grey&, BF ' main window
LINE (663, 7)-(680, 136), Grey&, BF ' tile selection window
LINE (698, 6)-(739, 39), Grey&, BF ' mini map
RETURN
Grid:
FOR x = 8 TO 647 STEP 16 ' main paste window grid
FOR y = 8 TO 487 STEP 16
LINE (x, y)-(x + 15, y + 15), Pink&, B
NEXT y
NEXT x
x = 664: y = 8
FOR Tile = 0 TO 7 ' tile selection window grid
LINE (x, y)-(x + 15, y + 15), Pink&, B
y = y + 16
NEXT Tile
RETURN
ShowTiles:
x1 = 664: y1 = 8: x2 = 0: y2 = 0 ' show tiles zero to seven = 8 tiles total
FOR Tile = 0 TO 7 '
LINE (x1, y1)-(x1 + 15, y1 + 15), Pink&, B
_PUTIMAGE (x1, y1)-(x1 + 15, y1 + 15), Tiles1&, 0, (x2, y2)-(x2 + 15, y2 + 15)
y1 = y1 + 16
x2 = x2 + 16
NEXT Tile
GOSUB MakeColors ' 'probe the color of the tiles + save to array
RETURN
FindPlace:
Region = 0
IF mx% >= 8 THEN
IF mx% <= 647 THEN
IF my% >= 8 THEN
IF my% <= 487 THEN
Region = 1 'main draw window
END IF
END IF
END IF
END IF
IF mx% >= 664 THEN
IF mx% <= 679 THEN
IF my% >= 8 THEN
IF my% <= 135 THEN
Region = 2 'main tile window
END IF
END IF
END IF
END IF
RETURN
MicePoll:
DO WHILE _MOUSEINPUT
mx% = _MOUSEX: my% = _MOUSEY: mbl% = _MOUSEBUTTON(1): mbr% = _MOUSEBUTTON(2)
LOOP
RETURN
InRegion1:
micex = mx% - 8: MiceY = my% - 8 ' correct the offset from the left of the screen
cellx = micex \ 16 ' divide by 16 to get cell
celly = MiceY \ 16 ' divide by 16 to get cell
pastex1 = (cellx * 16) + 8: pastex2 = pastex1 + 15: pastey1 = (celly * 16) + 8: pastey2 = pastey1 + 15 'paste refers to place to paste
IF mbl% = -1 THEN
_PUTIMAGE (pastex1, pastey1)-(pastex2, pastey2), Tiles1&, 0, (copyx1, copyy1)-(copyx2, copyy2)
Map%(cellx, celly) = TileNum ' assign tile number
GOSUB ShowMiniDim ' update mini window
END IF
RETURN
InRegion2:
IF mbl% = -1 THEN
SELECT CASE my%
CASE 8 TO 23
TileNum = 0
copyx1 = 0: copyy1 = 0: copyx2 = copyx1 + 15: copyy2 = copyy1 + 15 'the source image co-ordinates for putimage
CASE 24 TO 39
TileNum = 1
copyx1 = 16: copyy1 = 0: copyx2 = copyx1 + 15: copyy2 = copyy1 + 15
CASE 40 TO 55
TileNum = 2
copyx1 = 32: copyy1 = 0: copyx2 = copyx1 + 15: copyy2 = copyy1 + 15
CASE 56 TO 71
TileNum = 3
copyx1 = 48: copyy1 = 0: copyx2 = copyx1 + 15: copyy2 = copyy1 + 15
CASE 72 TO 87
TileNum = 4
copyx1 = 64: copyy1 = 0: copyx2 = copyx1 + 15: copyy2 = copyy1 + 15
CASE 88 TO 103
TileNum = 5
copyx1 = 80: copyy1 = 0: copyx2 = copyx1 + 15: copyy2 = copyy1 + 15
CASE 103 TO 119
TileNum = 6
copyx1 = 96: copyy1 = 0: copyx2 = copyx1 + 15: copyy2 = copyy1 + 15
CASE 120 TO 135
TileNum = 7
copyx1 = 112: copyy1 = 0: copyx2 = copyx1 + 15: copyy2 = copyy1 + 15
END SELECT
_PUTIMAGE (10, 500)-(26, 516), Tiles1&, 0, (copyx1, copyy1)-(copyx2, copyy2)
END IF
RETURN
ShowMiniDim:
x = 699: y = 7
FOR across = 0 TO 29 '39
FOR down = 0 TO 39 '29
z = Map%(down, across) ' ->across ,down
PSET (699 + down, 8 + across), Tints&(z) ' ->across ,down
'LOCATE across + 1, down + 1: PRINT LTRIM$(STR$(z)) ' ->across ,down
NEXT down
NEXT across
CanSave = 1
RETURN
MakeColors:
count = 0
FOR T = 16 TO 130 STEP 16
Hue& = POINT(675, T)
Tints&(count) = Hue&
count = count + 1
NEXT T
RETURN
PrepareSave:
'convert onscreen to DATA statements
temp$ = "": LOCATE 20, 20: PRINT "SAVING FILE": _DISPLAY: _DELAY 1
FOR across = 0 TO 29 '39
FOR down = 0 TO 39 '29
z = Map%(down, across)
z$ = STR$(z): z$ = LTRIM$(z$)
temp$ = temp$ + z$ + ","
NEXT down
GOSUB SavTxt
temp$ = ""
NEXT across
LOCATE 20, 10: PRINT "FILE HAS BEEN SAVED AS VSGE-Data.txt": _DISPLAY: _DELAY 1
SYSTEM
RETURN
SavTxt:
z = LEN(temp$)
temp$ = LEFT$(temp$, z - 1)
temp$ = "DATA " + temp$
OPEN Savfilename$ FOR APPEND AS #1
PRINT #1, temp$
CLOSE #1
RETURN