-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path2D map editor to code - v2.bb
185 lines (168 loc) · 3.29 KB
/
2D map editor to code - v2.bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
; This tool is a map editor that turns the data into a
; piece of copyable code. Its in the form of an
; multidimensional array.
;
;
;
Global win = CreateWindow("Make Monkey array (tilemap) Example",100,100,800,600,0,1)
Global txt = CreateTextArea(0,20,800,600,win)
Global tab = CreateTabber(0,0,800,20,win)
Global can = CreateCanvas(0,20,800,600,win)
Global mw = 20
Global mh = 15
Global tw = 32
Global th = 32
Dim map(mw,mh)
Global canim = CreateImage(800,600)
Global brushindex=0
Global cmx
Global cmy
Global tileim = CreateImage(32,32,11)
For i = 0 To 10
SetBuffer ImageBuffer(tileim,i)
Color 200+i*3,10+i*20,10
Rect 0,0,33,33,True
For x=-1 To 1
For y=-1 To 1
Color 4,4,4
Text 16+x,16+y,i,1,1
Next
Next
Color 255,255,255
Text 16,16,i,1,1
Next
InsertGadgetItem tab,0,"TextArea",0
InsertGadgetItem tab,1,"Canvas",1
Global mytxt$
makemonkeycode
Global timer = CreateTimer(60)
updateinterface
Repeat
we = WaitEvent()
If we=$201
If EventSource() = can
If EventData() = 1
End If
End If
End If
If we=$202
If EventSource() = can
If EventData() = 1
If RectsOverlap(cmx,cmy,1,1,680,0,32,11*th)
brushindex=cmy/th
updateinterface
End If
End If
End If
End If
If we=$203
If EventSource()=can
cmx = EventX()
cmy = EventY()
If MouseDown(1) = True
If RectsOverlap(cmx,cmy,1,1,0,0,(mw+1)*tw,(mh+1)*th)
map(cmx/tw,cmy/th) = brushindex
updateinterface
End If
End If
If MouseDown(2) = True
If RectsOverlap(cmx,cmy,1,1,0,0,(mw+1)*tw,(mh+1)*th)
map(cmx/tw,cmy/th) = 0
updateinterface
End If
End If
End If
End If
If we=$401
If EventSource() = tab
sg = SelectedGadgetItem(tab)
If sg = 0
makemonkeycode
HideGadget can
ShowGadget txt
End If
If sg = 1
readmonkeycode
HideGadget txt
ShowGadget can
updateinterface
FlipCanvas can
End If
End If
End If
If we=$4001
End If
If we=$803 Then Exit
Forever
End
Function updateinterface()
SetBuffer ImageBuffer(canim)
Cls
Color 255,255,255
For y=0 To mh-1
For x=0 To mw-1
DrawImage tileim,x*tw,y*th,map(x,y)
Next
Next
For y=0 To 10
DrawImage tileim,680,y*th,y
If brushindex = y
Rect 681,y*th,31,31,False
End If
Next
SetBuffer CanvasBuffer(can)
Cls
DrawImage canim,0,0
FlipCanvas can
End Function
Function makemonkeycode()
mytxt$="Global map:Int[][] = ["+Chr(13)+Chr(10)
For y=0 To mh-1
mytxt$=mytxt$+"["
For x=0 To mw-1
mytxt$=mytxt$+map(x,y)
mytxt$=mytxt$+","
Next
mytxt$=Left(mytxt$,Len(mytxt$)-1)
mytxt$=mytxt$+"]"
mytxt$=mytxt$+","
mytxt$=mytxt$+Chr(13)+Chr(10)
Next
mytxt$=Left(mytxt$,Len(mytxt$)-3)
mytxt$=mytxt$+"]"
SetTextAreaText txt,mytxt$
End Function
Function readmonkeycode()
mytxt$ = TextAreaText(txt)
Local cnt=0
Local stp=1
Local exitloop=False
While exitloop=False
stp=Instr(mytxt$,",",stp)
If stp=0 Then exitloop=True
stp=stp+1
cnt=cnt+1
Wend
If cnt <> ((mw)*(mh)) Then Notify "Not valid map data"
Local mytxt2$
Local a$=""
Local b$=""
Local c$=""
For i = 1 To Len(mytxt$)
a$=Mid(mytxt$,i,1)
If a$="," Then b$=b$+a$
If Asc(a$) >= 48 And Asc(a$)<= 57 Then b$=b$+a$
Next
For i=1 To Len(b$)
a$=Mid(b$,i,1)
If Asc(a$)>=48 And Asc(a$)<=57
c$=c$+a$
End If
If a$="," Then
map(x,y) = Int(c)
c$=""
x=x+1
If x>=mw Then x=0:y=y+1
End If
Next
End Function