MapEditor

Do you have something to share with us? A tip for newbies, perhaps? Post it here.
Post Reply
peter
Active Member
Posts: 123
Joined: Mon Oct 22, 2007 2:31 pm

MapEditor

Post by peter » Sat Jan 24, 2009 5:19 pm

Hi,

i wanted to write a Layer Editor with 8 Layer.
But now i have to program another thing, which is very important .
i do not know when i am ready therewith.
It can need a long time. And i will not to begin again with the Editor.
if you want, then you can to proceed with my Editor work.
have a look into the source code and you will understand everything.
in the moment, you cannot load/save a Map.
but you can load a tileset by clicking the "LoadTile Button".
you have to write then "tiles.png" and then press the return key.
on the right side is the tile raster. on left side is the main raster.
by clicking on the tileraster, you will select a tile.
if you are clicking on the main raster, you will put a tile on the main raster.
you can pick a tile from the main raster by clicking with the right mouse button on a tile.
you choose a layer by clicking on a layer1 - 8 with the left mouse button.
below the main raster, right side, you will see a yellow square.
you can move this square if you are pressing "Lcontrol" and hold down the left mouse button.
this is a check mark for an area if you want to make a smaller map.
But this will not in use now ! you can meditate over this idea, only
if you want.

do not forget to load the graphics !
best regards.

Code: Select all

SCREEN 1024,576,16,1
DefaultMask ON,$FF,$FF,$FF

Global ax,bx,cx,dx,xPos,yPos,char,iRas,mRas,mBox,curs
Global b1_1,b2_1,b3_1,b4_1,b5_1,b6_1,b7_1,b8_1
Global b1_2,b2_2,b3_2,b4_2,b5_2,b6_2,b7_2,b8_2
Global bFlag,mark,xMark,yMark,High,Wide,Tile,til1,til2,rasb
Global bRas,rFlag,aKey,xKey,yKey,zKey,vKey,xName$,Tiles
Global Message$,Raster,outs,save,load,zx,sFlag,TileFlag

Dim Map1(1504)
Dim Map2(1504)
Dim Map3(1504)
Dim Map4(1504)
Dim Map5(1504)
Dim Map6(1504)
Dim Map7(1504)
Dim Map8(1504)

char = LoadAnimImage("Media/CharStrip.png",16,16,0,65)
curs = LoadAnimImage("Media/Cursor.png",16,16,0,32)
mBox = LoadImage("Media/Box.png")
mark = LoadImage("Media/Marker.png")
outs = LoadImage("Media/ExitButton.png") 
mRas = LoadImage("Media/MainRaster.png")
load = LoadImage("Media/LoadButton.png")
save = LoadImage("Media/SaveButton.png")
iRas = LoadImage("Media/ImageRaster.png")
til1 = LoadImage("Media/TileButton1.png")
til2 = LoadImage("Media/TileButton2.png")
rasb = LoadImage("Media/RasterButton.png")
b1_1 = LoadImage("Media/Button1_1.png")
b2_1 = LoadImage("Media/Button2_1.png")
b3_1 = LoadImage("Media/Button3_1.png")
b4_1 = LoadImage("Media/Button4_1.png")
b5_1 = LoadImage("Media/Button5_1.png")
b6_1 = LoadImage("Media/Button6_1.png")
b7_1 = LoadImage("Media/Button7_1.png")
b8_1 = LoadImage("Media/Button8_1.png")
b1_2 = LoadImage("Media/Button1_2.png")
b2_2 = LoadImage("Media/Button2_2.png")
b3_2 = LoadImage("Media/Button3_2.png")
b4_2 = LoadImage("Media/Button4_2.png")
b5_2 = LoadImage("Media/Button5_2.png")
b6_2 = LoadImage("Media/Button6_2.png")
b7_2 = LoadImage("Media/Button7_2.png")
b8_2 = LoadImage("Media/Button8_2.png")

bFlag =1:Raster =1
xMark =736:yMark =496
High  = 31:Wide  =46
rFlag =1:TileFlag =0

Repeat
DrawImage til1,448,528  
DrawImage rasb,384,528
DrawImage Outs,384,544
DrawImage load,448,544
DrawImage save,448,560
MouseCoordinate()
GetButton()
SetButton()
LoadTiles()
SetTiles()
GetTile()
DropTile()
PickTile()
ShowMaps()
SetRaster()
SetMarker()
SetMessage()
'SetBox()
ExitNow()
TextOut("X:" + xPos, 0,560) 
TextOut("Y:" + yPos,80,560) 
DrawScreen
Until EscapeKey()
End

Function PickTile()
If MouseDown(2) = True And xPos >=0 And xPos <=46 And yPos >=0 And yPos <=31 Then
bx = yPos *47 + xPos
If bFlag =1 Then zx = Map1(bx)
If bFlag =2 Then zx = Map2(bx)
If bFlag =3 Then zx = Map3(bx)
If bFlag =4 Then zx = Map4(bx)
If bFlag =5 Then zx = Map5(bx)
If bFlag =6 Then zx = Map6(bx)
If bFlag =7 Then zx = Map7(bx)
If bFlag =8 Then zx = Map8(bx)
End If
End Function


Function DropTile()
If MouseDown(1) = True And xPos >=0 And xPos <=46 And yPos >=0 And yPos <=31 Then
bx = yPos *47 + xPos
Select bFlag
Case 1 
Map1(bx) = zx
Case 2 
Map2(bx) = zx
Case 3 
Map3(bx) = zx
Case 4 
Map4(bx) = zx
Case 5 
Map5(bx) = zx
Case 6 
Map6(bx) = zx
Case 7 
Map7(bx) = zx
Case 8 
Map8(bx) = zx
End Select
End If
End Function

Function ShowMaps()
For cx =0 To 31
For dx =0 To 46
bx = cx *47 + dx
If Tiles >0 Then
If Map1(bx) >0 Then DrawImage Tiles,dx *16,cx *16,Map1(bx)
If Map2(bx) >0 Then DrawImage Tiles,dx *16,cx *16,Map2(bx)
If Map3(bx) >0 Then DrawImage Tiles,dx *16,cx *16,Map3(bx)
If Map4(bx) >0 Then DrawImage Tiles,dx *16,cx *16,Map4(bx)
If Map5(bx) >0 Then DrawImage Tiles,dx *16,cx *16,Map5(bx)
If Map6(bx) >0 Then DrawImage Tiles,dx *16,cx *16,Map6(bx)
If Map7(bx) >0 Then DrawImage Tiles,dx *16,cx *16,Map7(bx)
If Map8(bx) >0 Then DrawImage Tiles,dx *16,cx *16,Map8(bx)
End If
Next dx
Next cx
End Function

Function GetTile()
TextOut("TILE " + zx,832,512)
If Tiles > 0 Then DrawImage Tiles,896,528,zx
If MouseDown(1) =True And xPos >=48 And xPos <=63 And yPos >=0 And yPos <=31 Then
zx = (yPos *16 + xPos) -48
End If
End Function
 
Function ExitNow()
If MouseDown(1) = True And xPos >=24 And xPos <=27 And yPos =34 Then
End
End If
End Function

Function SetMessage()
If Message <> "" Then
TextOut(Message,33 *16,33 *16)
If EscapeKey() = True Then Message = ""
End If
End Function

Function SetCursor()
DrawImage curs,xKey,yKey,zKey
vKey = vKey +1
If vKey =4 Then 
vKey =0
zKey = zKey +1
If zKey =32 Then zKey =0
End If
End Function

Function SetTiles()
If TileFlag =1 Then 
For cx =0 To 31
For dx =0 To 15
bx = cx *16 + dx 
DrawImage Tiles,dx*16 +768,cx *16,bx
Next dx: Next cx
End If
End Function

Function LoadTiles()
If MouseDown(1) = True And xPos >=28 And xPos <=31 And yPos =33 Then
xKey =33 *16:yKey =33 *16
xName =""
GetTiles()
End If
End Function

Function GetTiles()
Repeat
DrawImage til2,448,528,0
DrawImage til1,448,528  
DrawImage rasb,384,528
DrawImage Outs,384,544
DrawImage load,448,544
DrawImage save,448,560
MouseCoordinate()
SetButton()
SetRaster()
SetMarker()
SetCursor()
aKey = GetKey()
If aKey >=32 And aKey <=128 And Len(xName) <=20 Then  
xName = xName + Chr(aKey)
xKey = xKey +16
ElseIf KeyDown(28) = True Then
ax = FileExists(xName)
If ax = False Then 
Message = "NOT PRESENT!"
Return 0
End If 
Tiles = LoadAnimImage(xName,16,16,0,512)
TileFlag =1
Message =""
Return 0
ElseIf KeyDown(14) And xKey > 33*16 Then
xName =""
xKey = 33*16
End If
TextOut(Upper(xName),33*16,33*16)
TextOut("X:" + xPos, 0,35*16) 
TextOut("Y:" + yPos,80,35*16) 
DrawScreen
Until EscapeKey()
End Function

Function SetRaster()
DrawImage iRas,768,0
If Raster =1 Then DrawImage mRas,0,0
If MouseDown(1) = True And xPos >=24 And xPos <=27 And yPos =33 And Raster =0 Then Raster =1
If MouseDown(2) = True And xPos >=24 And xPos <=27 And yPos =33 And Raster =1 Then Raster =0
End Function

Function SetMarker()
DrawImage mark,xMark,yMark
Color 255,255,0 
Box 0,0,xMark +16,yMark +16,0
If KeyDown(29) And MouseDown(1) = True And xPos >=1 And xPos <=46 And Ypos >=1 And yPos <=31 Then
Wide = xPos:High = yPos
xMark = xPos *16:yMark =yPos *16
End If
End Function

Function GetButton()
If MouseDown(1) =True And xPos >= 0 And xPos <= 3 And yPos =32 Then bFlag =1
If MouseDown(1) =True And xPos >= 4 And xPos <= 7 And yPos =32 Then bFlag =2
If MouseDown(1) =True And xPos >= 8 And xPos <=11 And yPos =32 Then bFlag =3
If MouseDown(1) =True And xPos >=12 And xPos <=15 And yPos =32 Then bFlag =4
If MouseDown(1) =True And xPos >=16 And xPos <=19 And yPos =32 Then bFlag =5
If MouseDown(1) =True And xPos >=20 And xPos <=23 And yPos =32 Then bFlag =6
If MouseDown(1) =True And xPos >=24 And xPos <=27 And yPos =32 Then bFlag =7
If MouseDown(1) =True And xPos >=28 And xPos <=31 And yPos =32 Then bFlag =8
End Function

Function SetButton()
Select bFlag 
Case 1
DrawImage b1_1,0*16,32*16
DrawImage b2_2,4*16,32*16
DrawImage b3_2,8*16,32*16
DrawImage b4_2,12*16,32*16
DrawImage b5_2,16*16,32*16
DrawImage b6_2,20*16,32*16
DrawImage b7_2,24*16,32*16
DrawImage b8_2,28*16,32*16
Case 2 
DrawImage b1_2,0*16,32*16
DrawImage b2_1,4*16,32*16
DrawImage b3_2,8*16,32*16
DrawImage b4_2,12*16,32*16
DrawImage b5_2,16*16,32*16
DrawImage b6_2,20*16,32*16
DrawImage b7_2,24*16,32*16
DrawImage b8_2,28*16,32*16
Case 3 
DrawImage b1_2,0*16,32*16
DrawImage b2_2,4*16,32*16
DrawImage b3_1,8*16,32*16
DrawImage b4_2,12*16,32*16
DrawImage b5_2,16*16,32*16
DrawImage b6_2,20*16,32*16
DrawImage b7_2,24*16,32*16
DrawImage b8_2,28*16,32*16
Case 4 
DrawImage b1_2,0*16,32*16
DrawImage b2_2,4*16,32*16
DrawImage b3_2,8*16,32*16
DrawImage b4_1,12*16,32*16
DrawImage b5_2,16*16,32*16
DrawImage b6_2,20*16,32*16
DrawImage b7_2,24*16,32*16
DrawImage b8_2,28*16,32*16
Case 5 
DrawImage b1_2,0*16,32*16
DrawImage b2_2,4*16,32*16
DrawImage b3_2,8*16,32*16
DrawImage b4_2,12*16,32*16
DrawImage b5_1,16*16,32*16
DrawImage b6_2,20*16,32*16
DrawImage b7_2,24*16,32*16
DrawImage b8_2,28*16,32*16
Case 6 
DrawImage b1_2,0*16,32*16
DrawImage b2_2,4*16,32*16
DrawImage b3_2,8*16,32*16
DrawImage b4_2,12*16,32*16
DrawImage b5_2,16*16,32*16
DrawImage b6_1,20*16,32*16
DrawImage b7_2,24*16,32*16
DrawImage b8_2,28*16,32*16
Case 7 
DrawImage b1_2,0*16,32*16
DrawImage b2_2,4*16,32*16
DrawImage b3_2,8*16,32*16
DrawImage b4_2,12*16,32*16
DrawImage b5_2,16*16,32*16
DrawImage b6_2,20*16,32*16
DrawImage b7_1,24*16,32*16
DrawImage b8_2,28*16,32*16
Case 8 
DrawImage b1_2,0*16,32*16
DrawImage b2_2,4*16,32*16
DrawImage b3_2,8*16,32*16
DrawImage b4_2,12*16,32*16
DrawImage b5_2,16*16,32*16
DrawImage b6_2,20*16,32*16
DrawImage b7_2,24*16,32*16
DrawImage b8_1,28*16,32*16
End Select 
End Function

Function TextOut(Txt$,x1,y1)
Dim lx,sx,rx
lx = Len(Txt)
For sx = 1 To lx
rx = Asc(Mid(Txt,sx,1))
If rx >= 32 And rx <= 90 Then
rx = rx -32
DrawImage Char,x1,y1,rx
x1 = x1 + 16
End If
Next sx
End Function

Function MouseCoordinate()
xPos = Int(MouseX() /16) 
yPos = Int(MouseY() /16)
End Function
Attachments
Graphics.rar
(118.38 KiB) Downloaded 282 times

Post Reply