0 Members and 3 Guests are viewing this topic.
function create(mode)t=1/2timer.start(t)sprites={image.new("\008\000\000\000\008\000\000\000\000\000\000\000\016\000\000\000\016\000\001\000\000\000\000\000\000\000)\165)\165\000\000\000\000\000\000\000\000\000\000)\165\000\000\000\000)\165\000\000\000\000)\165\000\000\000\000)\165)\165\000\000\000\000)\165\000\000)\165\000\000\000\000\000\000\000\000)\165\000\000\000\000\000\000)\165)\165)\165)\165\000\000\000\000\000\000\000\000\000\000)\165)\165\000\000\000\000\000\000\000\000\000\000)\165\000\000\000\000)\165\000\000\000\000\000\000\000\000)\165\000\000\000\000)\165\000\000\000\000"),image.new("\008\000\000\000\008\000\000\000\000\000\000\000\016\000\000\000\016\000\001\000\000\128\140\177\000\128\140\177\000\128\140\177\000\128\140\177\140\177\000\128\140\177\000\128\140\177\000\128\140\177\000\128\000\128\140\177\000\128\140\177\000\128\140\177\000\128\140\177\140\177\000\128\140\177\000\128\140\177\000\128\140\177\000\128\000\128\140\177\000\128\140\177\000\128\140\177\000\128\140\177\140\177\000\128\140\177\000\128\140\177\000\128\140\177\000\128\000\128\140\177\000\128\140\177\000\128\140\177\000\128\140\177\140\177\000\128\140\177\000\128\140\177\000\128\140\177\000\128")}inventory={current=0,select=1,{type=0,number=0},{type=0,number=0},{type=0,number=0},{type=0,number=0},{type=0,number=0},{type=0,number=0},{type=0,number=0},{type=0,number=0}}i=0view=0position={1,1,1}pause=0w=316h=210xlen=math.floor(w/j)ylen=math.floor(h/j)color={}for x=1,xlen docolor[x]={}for y=1,xlen docolor[x][y]={}for z=1,xlen docolor[x][y][z]={visited=false,type=0}if y==xlen thencolor[x][y][z].type=-1elseif y<=8 thencolor[x][y][z].visited=trueelseif mode=="clear" thenelseif math.random()>(y-4)/ylen thencolor[x][y][z].type=1elseif math.random()>1-y/ylen thenif math.random()>1-(y*0.25-8)/ylen thencolor[x][y][z].type=4elsecolor[x][y][z].type=2endendendendendreloadMenu()endfunction reloadMenu()menu={{"Functions",{"Reset",reset},{"Clear",clear}}}toolpalette.register(menu)endfunction clear()create("clear")endfunction reset()create("reset")endfunction on.arrowLeft()c="4"endfunction left()if (position[1]~=1 and view~=1) thenposition[1]=position[1]-1elseif (position[2]~=1 and view==1) thenposition[2]=position[2]-1endendfunction on.arrowRight()c="6"endfunction right()if (position[1]~=xlen and view~=1) thenposition[1]=position[1]+1elseif (position[2]~=xlen and view==1) thenposition[2]=position[2]+1endendfunction on.arrowDown()c="2"endfunction down()if (position[3]~=ylen and view~=2) thenposition[3]=position[3]+1elseif (position[2]~=ylen and view==2) thenposition[2]=position[2]+1endendfunction on.arrowUp()c="8"endfunction up()if (position[3]~=1 and view~=2) thenposition[3]=position[3]-1elseif (position[2]~=1 and view==2) thenposition[2]=position[2]-1endendfunction pickColor(top,d)local t = {255,0,0}if top==0 thent = {255*d,255*d,255*d}elseif top==1 thent = {150*d,100*d,50*d}elseif top==2 thent = {150*d,150*d,150*d}elseif top==3 thent = {200*d,200*d,200*d}elseif top==4 thent ={175*d,100*d,0}endreturn tendfunction calcFog(x,y,z,position)local dif not color[x][y][z].visited thend = math.sqrt((x-position[1])*(x-position[1])+(y-position[2])*(y-position[2])*4+(z-position[3])*(z-position[3]))d=1-(d/xlen*4)if d<0 thend=0elseif d>1 thend=1endelsed=1endreturn dendfunction on.charIn(ch)c=chendfunction on.timer()platform.window:invalidate()endfunction on.mouseDown(x,y)local coords={position[1],position[2],position[3]}if view==0 thencoords[1]=math.ceil(x/j)coords[3]=math.ceil(y/j)elseif view==1 thencoords[2]=math.ceil(x/j)coords[3]=math.ceil(y/j)elseif view==2 thencoords[1]=math.ceil(x/j)coords[2]=math.ceil(y/j)endif color[coords[1]][coords[2]][coords[3]].type==0 and inventory[inventory.select].number>0 thencolor[coords[1]][coords[2]][coords[3]].type=inventory[inventory.select].typeinventory[inventory.select].number=inventory[inventory.select].number-1endendfunction on.paint(gc)gc:setColorRGB(0,0,64)gc:fillRect(0,0,316,210)if j==nil thenj=8create("clear")end--Keypresses and d-padif c=="." thenif view==2 thenview = 0elseview=view+1endelseif c=="1" thendown()left()elseif c=="2" thendown()elseif c=="3" thendown()right()elseif c=="4" thenleft()elseif c=="6" thenright()elseif c=="7" thenup()left()elseif c=="8" thenup()elseif c=="9" thenup()right()elseif c=="a" theninventory.select=1elseif c=="b" theninventory.select=2elseif c=="c" theninventory.select=3elseif c=="d" theninventory.select=4elseif c=="e" theninventory.select=5elseif c=="f" theninventory.select=6elseif c=="g" theninventory.select=7endif c thenc=""end--Gravityi=1-iif i==1 and color[position[1]][position[2]+1][position[3]] .type==0 thenposition[2]=position[2]+1end--Lighting / shroudfor x=-1,1 dofor y=-1,1 dofor z=-1,1 doif 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)) thencolor[position[1]+x][position[2]+y][position[3]+z].visited=trueendendendend--Inventory/miningif color[position[1]][position[2]][position[3]].type>0 thenlocal slot=inventory.current+1for i=1,inventory.current doif inventory[i].type==color[position[1]][position[2]][position[3]].type thenslot=iendendif not inventory[slot].type orinventory[slot].type==0 theninventory.current=inventory.current+1inventory[slot].type=color[position[1]][position[2]][position[3]].typeinventory[slot].number=1else inventory[slot].number=inventory[slot].number+1endcolor[position[1]][position[2]][position[3]].type=0end--Draw tilesif view==0 thenfor x=1,xlen dofor z=1,ylen dolocal top=1for y=position[2],xlen doif top==1 and color[x][y][z].type~=0 thentop=yendendlocal type=color[x][top][z].typeif type>0 thenlocal triple=pickColor(type,calcFog(x,top,z,position))gc:setColorRGB(triple[1],triple[2],triple[3])gc:fillRect(x*j-j*0.5,z*j-j*0.5,j,j)elseif type==-1 thengc:drawImage(sprites[2],x*j-j*0.5,z*j-j*0.5)endif x==position[1] and z==position[3] thengc:drawImage(sprites[1],x*j-j*0.5,z*j-j*0.5)endendendelseif view==1 thenfor y=1,xlen dofor z=1,ylen dolocal type=color[position[1]][y][z].typeif type>0 thenlocal triple = pickColor( color[position[1]][y][z].type, calcFog(position[1],y,z,position))gc:setColorRGB(triple[1],triple[2],triple[3])gc:fillRect(y*j-j*0.5,z*j-j*0.5,j,j)elseif type==-1 thengc:drawImage(sprites[2],y*j-j*0.5,z*j-j*0.5)endif y==position[2] and z==position[3] thengc:drawImage(sprites[1],y*j-j*0.5,z*j-j*0.5)endendendelseif view==2 thenfor x=1,xlen dofor y=1,ylen dolocal type=color[x][y][position[3]].typeif type>0 thenlocal triple=pickColor(type,calcFog(x,y,position[3],position))gc:setColorRGB(triple[1],triple[2],triple[3])gc:fillRect(x*j-0.5*j,y*j-0.5*j,j,j)elseif type==-1 thengc:drawImage(sprites[2],x*j-j*0.5,y*j-j*0.5)endif x==position[1] and y==position[2] thengc:drawImage(sprites[1],x*j-j*0.5,y*j-j*0.5)endendendend--Inventory overlayfor x=1,7 dolocal triple=pickColor(inventory[x].type,1)gc:setColorRGB(triple[1],triple[2],triple[3])gc:fillRect(118+x*10,195,10,10)gc:setColorRGB(0,0,0)gc:drawString(inventory[x].number,120+x*10,189,"top")endgc:setColorRGB(255,255,255)gc:drawString("("..position[1]..","..position[2]..","..position[3]..")",0,0,"top")end
Basically Minecraft, but instead of Tinycraft,s flat, top-down view, you want to make it like Mario? It would be a great idea I think, because Minecraft relies a lot on digging, so a flat world doesn't sound as fun to me. Is it your first project by the way? As this might be kinda challenging if you go for large maps and keep every Minecraft option, if it's your first ever venture into programming. Good luck regardless, though.
Oh wow! I was just working on a game like this! I swear, as soon as I start working on a project, someone else makes a topic about them making the exact same thing.
*cough*tinycraft*cough*
Quote from: hellninjas on April 08, 2012, 08:30:01 pm*cough*tinycraft*cough*Yeah I mentionned it above, but he wants a more side-scrolling approach with pits and cliffs rather than the flat lands in Tinycraft.