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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
| function create(mode) t=1/2 timer.start(t) sprites={image.new("\007\000\000\000\007\000\000\000\000\000\000\000\014\000\000\000\016\000\001\000\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128\031\252\224\131\031\128")} inventory={current=1,{type=0,amount=0},{type=0,amount=0},{type=0,amount=0},{type=0,amount=0},{type=0,amount=0},{type=0,amount=0},{type=0,amount=0},{type=0,amount=0}} i=0 view=0 position={1,1,1} pause=0 w=316 h=210 xlen=math.floor(w/j) ylen=math.floor(h/j) color={} for x=1,xlen do color[x]={} for y=1,xlen do color[x][y]={} for z=1,xlen do color[x][y][z]={visited=false,type=0} if y==xlen then color[x][y][z].type=-1 elseif y<=8 then color[x][y][z].visited=true elseif mode=="clear" then elseif math.random()>0.3 then color[x][y][z].type=1 elseif math.random()>0.3 then color[x][y][z].type=2 end end end end reloadMenu() end
function reloadMenu() menu={{"Functions",{"Reset",reset},{"Clear",clear}}} toolpalette.register(menu) end
function clear() create("clear") end
function reset() create("reset") end
function on.arrowLeft() c="4" end
function left() if (position[1]~=1 and view~=1) then position[1]=position[1]-1 elseif (position[2]~=1 and view==1) then position[2]=position[2]-1 end end
function on.arrowRight() c="6" end
function right() if (position[1]~=xlen and view~=1) then position[1]=position[1]+1 elseif (position[2]~=xlen and view==1) then position[2]=position[2]+1 end end
function on.arrowDown() c="2" end
function down() if (position[3]~=ylen and view~=2) then position[3]=position[3]+1 elseif (position[2]~=ylen and view==2) then position[2]=position[2]+1 end end
function on.arrowUp() c="8" end
function up() if (position[3]~=1 and view~=2) then position[3]=position[3]-1 elseif (position[2]~=1 and view==2) then position[2]=position[2]-1 end end
function on.charIn(ch) c=ch end
function on.timer() platform.window:invalidate() end
function on.paint(gc) --BG gc:setColorRGB(0,0,64) gc:fillRect(0,0,316,210)
if j==nil then j=8 create("clear") end
--Keypresses and d-pad if c=="." then if view==2 then view = 0 else view=view+1 end elseif c=="1" then down() left() elseif c=="2" then down() elseif c=="3" then down() right() elseif c=="4" then left() elseif c=="6" then right() elseif c=="7" then up() left() elseif c=="8" then up() elseif c=="9" then up() right() end
if c then c="" end
--Gravity i=1-i if i==1 and color[position[1]][position[2]+1][position[3]].type==0 then position[2]=position[2]+1 end
--Lighting / shroud for x=-1,1 do for y=-1,1 do for z=-1,1 do if not ((x==-1 and position[1]==1) or (y==-1 and position[2]==1) or (z==-1 and position[3]==1) or (x==1 and position[1]==xlen) or (y==1 and position[2]==xlen) or (z==1 and position[3]==xlen)) then color[position[1]+x][position[2]+y][position[3]+z].visited=true end end end end
--Inventory/mining if color[position[1]][position[2]][position[3]].type>0 then local slot=-1 for i=1,8 do if inventory[1].type==color[position[1]][position[2]][position[3]].type then end if not inventory[color[position[1]][position[2]][position[3]].type] then inventory[color[position[1]][position[2]][position[3]].type]=1 else inventory[color[position[1]][position[2]][position[3]].type]=inventory[color[position[1]][position[2]][position[3]].type]+1 end color[position[1]][position[2]][position[3]].type=0 end
--Draw tiles if view==0 then for x=1,xlen do for z=1,ylen do top=1 for y=position[2]+1,ylen do if top==1 and color[x][y][z] then top=y end end if x==position[1] and z==position[3] then gc:drawImage(sprites[1],x*j-j*0.5-1,z*j-j*0.5-1) else --Lighting/fog if color[x][top][z].visited==false then d = (math.sqrt((x-position[1])*(x-position[1])+(top-position[2])*(top-position[2])+(z-position[3])*(z-position[3]))) d=1-(d/ylen) if d<0 then d=0 elseif d>1 then d=1 end else d=1 end --Color picker top=color[x][top][z].type if top==0 then gc:setColorRGB(255*d,255*d,255*d) elseif top==1 then gc:setColorRGB(150*d,100*d,50*d) elseif top==2 then gc:setColorRGB(150*d,150*d,150*d) elseif top==3 then gc:setColorRGB(200*d,200*d,200*d) end gc:fillRect(x*j-j*0.5-1,z*j-j*0.5-1,j-1,j-1) end end end elseif view==1 then for y=1,xlen do for z=1,ylen do top=position[1] --for x=position[1]+1,ylen do --if top==1 and color[x][y][z] then --top=x --end --end if y==position[2] and z==position[3] then gc:drawImage(sprites[1],y*j-j*0.5-1,z*j-j*0.5-1) else --Lighting/fog if not color[top][y][z].visited then d = (math.sqrt((top-position[1])*(top-position[1])+(y-position[2])*(y-position[2])+(z-position[3])*(z-position[3]))) d=1-(d/ylen*3) if d<0 then d=0 elseif d>1 then d=1 end else d=1 end --Color picker top=color[top][y][z].type if top==0 then gc:setColorRGB(255*d,255*d,255*d) elseif top==1 then gc:setColorRGB(150*d,100*d,50*d) elseif top==2 then gc:setColorRGB(150*d,150*d,150*d) elseif top==3 then gc:setColorRGB(200*d,200*d,200*d) end gc:fillRect(y*j-j*0.5-1,z*j-j*0.5-1,j-1,j-1) end end end elseif view==2 then for x=1,xlen do for y=1,ylen do top=position[3] --for z=position[1]+1,ylen do --if top==1 and color[x][y][z] then --top=z --end --end if x==position[1] and y==position[2] then gc:drawImage(sprites[1],x*j-j*0.5-1,y*j-j*0.5-1) else --Lighting/fog if color[x][y][top].visited==false then d = (math.sqrt((x-position[1])*(x-position[1])+(y-position[2])*(y-position[2])+(top-position[3])*(top-position[3]))) d=1-(d/ylen*3) if d<0 then d=0 elseif d>1 then d=1 end else d=1 end --Color picker top=color[x][y][top].type if top==0 then gc:setColorRGB(255*d,255*d,255*d) elseif top==1 then gc:setColorRGB(150*d,100*d,50*d) elseif top==2 then gc:setColorRGB(150*d,150*d,150*d) elseif top==3 then gc:setColorRGB(200*d,200*d,200*d) end gc:fillRect(x*j-j*0.5-1,y*j-j*0.5-1,j-1,j-1) end end end end end function on.mouseDown(x,y) local coords={position[1],position[2],position[3]} if view==0 then coords[1]=math.ceil(x/j) coords[3]=math.ceil(y/j) elseif view==1 then coords[2]=math.ceil(x/j) coords[3]=math.ceil(y/j) elseif view==2 then coords[1]=math.ceil(x/j) coords[2]=math.ceil(y/j) end if color[coords[1]][coords[2]][coords[3]].type==0 then color[coords[1]][coords[2]][coords[3]].type=1 end end
|