Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI-Nspire => Topic started by: linuxgeek96 on April 08, 2012, 05:37:51 pm

Title: Minicraft / Terraria clone
Post by: linuxgeek96 on April 08, 2012, 05:37:51 pm
Hi guys,

I recently began work on a minicraft like game in Lua, but I realized it was missing something (I'll give you a hint -- another dimension). I decided to make a minicraft with TERRARIA view! What do y'all think?

EDIT: here are some planning notes.
Blocks
stage1
0/nil → air (maybe vaccum?), rgb(254,254,255)
1 → dirt, rgb(150,100,50)
stage2
2 → stone, rgb(200,200,200)
3 → cobble, rgb(150,150,150)
4 → wood, rgb(150,100,50)
5 → leaf/air, rgb(100,200,100)
stage3
6 → coal (ore)
7 → coal (drop)
8 → iron (ore)
9 → iron (ingot)
10 → crafting table
11 → furnace

Ideas
store last key (instabreak to start)
sparse matrix of fixed size (to start)
UPDATE 2:
Check daily for Updates!!!
Code: [Select]
function create(mode)
t=1/2
timer.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=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()>(y-4)/ylen then
color[x][y][z].type=1
elseif math.random()>1-y/ylen then
if math.random()>1-(y*0.25-8)/ylen then
color[x][y][z].type=4
else
color[x][y][z].type=2
end
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 pickColor(top,d)
local t = {255,0,0}
if top==0 then
t = {255*d,255*d,255*d}
elseif top==1 then
t = {150*d,100*d,50*d}
elseif top==2 then
t = {150*d,150*d,150*d}
elseif top==3 then
t = {200*d,200*d,200*d}
elseif top==4 then
t ={175*d,100*d,0}
end
return t
end
function calcFog(x,y,z,position)
local d
if not color[x][y][z].visited then
d = 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 then
d=0
elseif d>1 then
d=1
end
else
d=1
end
return d
end
function on.charIn(ch)
c=ch
end
function on.timer()
platform.window:invalidate()
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 and inventory[inventory.select].number>0 then
color[coords[1]][coords[2]][coords[3]].type=inventory[inventory.select].type
inventory[inventory.select].number=inventory[inventory.select].number-1
end
end
function on.paint(gc)
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()
elseif c=="a" then
inventory.select=1
elseif c=="b" then
inventory.select=2
elseif c=="c" then
inventory.select=3
elseif c=="d" then
inventory.select=4
elseif c=="e" then
inventory.select=5
elseif c=="f" then
inventory.select=6
elseif c=="g" then
inventory.select=7
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=inventory.current+1
for i=1,inventory.current do
if inventory[i].type==color[position[1]][position[2]][position[3]].type then
slot=i
end
end
if not inventory[slot].type or
inventory[slot].type==0 then
inventory.current=inventory.current+1
inventory[slot].type=color[position[1]][position[2]][position[3]].type
inventory[slot].number=1
else inventory[slot].number=inventory[slot].number+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
local top=1
for y=position[2],xlen do
if top==1 and color[x][y][z].type~=0 then
top=y
end
end
local type=color[x][top][z].type
if type>0 then
local 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 then
gc:drawImage(sprites[2],x*j-j*0.5,z*j-j*0.5)
end
if x==position[1] and z==position[3] then
gc:drawImage(sprites[1],x*j-j*0.5,z*j-j*0.5)
end
end
end
elseif view==1 then
for y=1,xlen do
for z=1,ylen do
local type=color[position[1]][y][z].type
if type>0 then
local 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 then
gc:drawImage(sprites[2],y*j-j*0.5,z*j-j*0.5)
end
if y==position[2] and z==position[3] then
gc:drawImage(sprites[1],y*j-j*0.5,z*j-j*0.5)
end
end
end
elseif view==2 then
for x=1,xlen do
for y=1,ylen do
local type=color[x][y][position[3]].type
if type>0 then
local 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 then
gc:drawImage(sprites[2],x*j-j*0.5,y*j-j*0.5)
end
if x==position[1] and y==position[2] then
gc:drawImage(sprites[1],x*j-j*0.5,y*j-j*0.5)
end
end
end
end
--Inventory overlay
for x=1,7 do
local 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")
end
gc:setColorRGB(255,255,255)
gc:drawString("("..position[1]..","..position[2]..","..position[3]..")",0,0,"top")
end
Title: Re: Minicraft / Terraria clone
Post by: aeTIos on April 08, 2012, 05:42:01 pm
This sounds promising. Have screenshots/photos?
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 08, 2012, 05:44:59 pm
currently, no sprites, just colored blocks, but ill upload some when i get a chance to use ti nspire connect at school. How have you guys been doing w/ the TI.IMAGE format?
Title: Re: Minicraft / Terraria clone
Post by: DJ Omnimaga on April 08, 2012, 06:06:09 pm
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. :)
Title: Re: Minicraft / Terraria clone
Post by: AzNg0d1030 on April 08, 2012, 07:14:08 pm
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. :)
And it's in Lua too.  It might be faster and better in C, but then again, that would be much harder O_o
Good luck! Is it possible to add the other dimension to make it a bird's eye view?
Title: Re: Minicraft / Terraria clone
Post by: DJ Omnimaga on April 08, 2012, 08:13:53 pm
Well for such game, I think Lua might be just fine enough, and if Lua is fast enough for that type of game, I guess it's a good idea to make it in that language so whenever Ndless gets blocked by TI, people can still play the game.
Title: Re: Minicraft / Terraria clone
Post by: Jonius7 on April 08, 2012, 08:15:56 pm
Nice job linuxgeek96! I've been thinking of a Terraria clone in Lua too for a while (check my signature) but I was planning to learn and release some more easier games first before I tackle this more ambitious project myself. Have you created any other projects? Cuz attempting this as one of your first projects will be difficult.
Anyway good luck!
Title: Re: Minicraft / Terraria clone
Post by: Spyro543 on April 08, 2012, 08:18:02 pm
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.
Title: Re: Minicraft / Terraria clone
Post by: Jonius7 on April 08, 2012, 08:19:01 pm
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.
Lol yes, looks like we might have several clones of Terraria or Minecraft. :P Minecraft 3D would be very hard to do though.
Title: Re: Minicraft / Terraria clone
Post by: DJ Omnimaga on April 08, 2012, 08:26:00 pm
Most usually die, though, so I guess that's good there are other clones being worked on, in case the rest die and yours becomes finished. :P
Title: Re: Minicraft / Terraria clone
Post by: Jonius7 on April 08, 2012, 08:26:56 pm
Many die due to the sheer difficulty and mass scale of these types of projects. It could probably take years for a project like this to near completion.
Side view is much simpler than 3D viewing.
Title: Re: Minicraft / Terraria clone
Post by: hellninjas on April 08, 2012, 08:30:01 pm
*cough*tinycraft*cough*
Title: Re: Minicraft / Terraria clone
Post by: AzNg0d1030 on April 08, 2012, 08:43:58 pm
*cough*tinycraft*cough*
^^^
Title: Re: Minicraft / Terraria clone
Post by: DJ Omnimaga on April 08, 2012, 10:05:45 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.
Title: Re: Minicraft / Terraria clone
Post by: Jonius7 on April 09, 2012, 01:47:39 am
*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.
I'd prefer the Terraria style any day. Allows fall damage and other things.
Title: Re: Minicraft / Terraria clone
Post by: Builderboy on April 09, 2012, 02:01:28 am
I too prefer the side-view style for a game such as this.  Do you plan to have some sort of field of view code, or something equivalent such that people can only see area's they have been in before?  I think that would be cool and useful, and it would make exploring caves and stuff more interesting because you don't necessarily know what is coming up, and you would have to dig and explore to find minerals and stuff.

Can't wait for some screenies!
Title: Re: Minicraft / Terraria clone
Post by: Chockosta on April 09, 2012, 04:34:57 am
This looks like a nice project !
I think I prefer side-view.

Good luck !
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 09, 2012, 07:27:38 am
Wow! Lots of intrest! I'm excoted that you guys care. This is one of my first projects for the CX, but I've been programming with my 84+ for over 4 years now, starting with BASIC, but I dabbled in assembly (Hex codes only tho, I really don't use computers for programming), and when Axe came out I used that. Currently, I've written a small 3d cube renderer in Lua, a classic bouncing ball (DVD screensaver), and a GOL simulator. If anyone wants the source code, I can post them on Tuesday or Thursday. This project grew out of the GOL sim, as I finally got the hang of Lua tables. I currently don't have any gravity or physics implemented (Builderboy, please forgive me :P), and have a fixed world size. However, I do have world slices implemented (ie Terraria mode). Basically, the world is a (sparse) 3-d table. The -1 element (w
Title: Re: Minicraft / Terraria clone
Post by: aeTIos on April 09, 2012, 07:31:49 am
game of life, post it!
Also is the 3d cube renderer perspective or orthographic?
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 09, 2012, 07:34:30 am
Sorry for the double post, but I see that some people were already working on this. Oops. I did see Tiny craft, was excited for a while and thought about getting involved, but I couldn't put in the time (EXAMS, scourge of the student coder). I believe it has stalled AND it was  for the 84+ series. With the extra memory of the nSpires, this could become much bigger. Right now, this is basically minecraft creative w/o mobs (for now) and w/very few blocks and no redstone, till I have some idea of how redstone works in actual minecraft. BTW, does anyone know the ComputerCraft mod? I think it might be easier to incorporate (at least the computers) then you think. Also, my projected timeline is that I'll post alpha by Sunday. Crossing fingers :-)
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 09, 2012, 07:35:23 am
perspective,
the GOL uses a fixed matrix, but I'll post it anyways soon.
game of life, post it!
Also is the 3d cube renderer perspective or orthographic?
Title: Re: Minicraft / Terraria clone
Post by: aeTIos on April 09, 2012, 07:36:29 am
Luckily, it's not a doublepost. (thats what you get for using so much tux avatars XD)
Also this is for the CX not? Then it's all right, tinycraft is for the 84+ series.

edit: woah huh? :confused:
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 09, 2012, 07:44:02 am
Yup CX to start, back-compatibility as soon as I have time.
Title: Re: Minicraft / Terraria clone
Post by: spud2451 on April 09, 2012, 11:36:38 am
I made something like this for the  TI-83+/84+/SE. I did it using XLib. You can find it in the Cemetech archives
Title: Re: Minicraft / Terraria clone
Post by: DJ Omnimaga on April 09, 2012, 01:30:25 pm
@Linux Tinycraft died. The authors decided to cancel it completely. I hope your Minecraft game doesn't know the same fate as most others.
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 09, 2012, 01:31:27 pm
I hope not... I do have support from a group at school who might help me plan some.
Title: Re: Minicraft / Terraria clone
Post by: DJ Omnimaga on April 09, 2012, 01:33:17 pm
That's good, and also feel free to ask help in the Lua programming section if you ever run into troubles with some coding. :)
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 09, 2012, 01:34:04 pm
Thanks, I appreciate having community support. It gives me a warm fuzzy feeling!
Title: Re: Minicraft / Terraria clone
Post by: Nick on April 09, 2012, 01:40:19 pm
This would be great, don't hesitate to ask questions for the coding too if you have some, we can help :) i hope the alpha comes out soon
Title: Re: Minicraft / Terraria clone
Post by: Yeong on April 09, 2012, 06:07:59 pm
It'll be awesome to see terraria in nspire. :)
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 09, 2012, 06:25:25 pm
FOV, seems possible...maybe with a distance formula with onchange(x,y,z) events and viewed property in table each cell. No lighting for now though.

I too prefer the side-view style for a game such as this.  Do you plan to have some sort of field of view code, or something equivalent such that people can only see area's they have been in before?  I think that would be cool and useful, and it would make exploring caves and stuff more interesting because you don't necessarily know what is coming up, and you would have to dig and explore to find minerals and stuff.

Can't wait for some screenies!
Title: Re: Minicraft / Terraria clone
Post by: aeTIos on April 10, 2012, 10:24:31 pm
side-view seems perfect indeed.
Title: Re: Minicraft / Terraria clone
Post by: DJ Omnimaga on April 10, 2012, 10:35:34 pm
By field of view, do you mean like fog of war in Joltima for the 83+? That would be interesting, although would it cause lag?
Title: Re: Minicraft / Terraria clone
Post by: leafy on April 10, 2012, 10:51:50 pm
I don't think field of view should present too much of a problem - it may even help reduce the number of sprites to be drawn if you do it right.
Title: Re: Minicraft / Terraria clone
Post by: DJ Omnimaga on April 10, 2012, 10:54:47 pm
Oh, right, I didn't think about that part. Draw black tiles instead of actual sprites. But I'm a bit concerned about the complex algorithm. Is that complicated to implement such thing in any language? I remember Michael_Lee tried something similar last year in his game Light and it was extremely slow. Joltima, on the other hand, manages to do it fine and the Nspire is 120 MHz.
Title: Re: Minicraft / Terraria clone
Post by: Builderboy on April 10, 2012, 11:19:09 pm
I think with this game it could be implemented in a much different way that would actually be better and faster.  The way I would do it is to have all tiles in the world either hidden or visible.  The tiles above ground would all be visible, and all the tiles below ground (including caves) would be hidden.  Whenever you are able to see a hidden tile, it would become visible permanently, that way if you explore a cave you would be able to see all the areas you had already explored, and the areas you haven't would still be dark.
Title: Re: Minicraft / Terraria clone
Post by: leafy on April 10, 2012, 11:49:33 pm
I know in Terraria it's more like any tiles around you or a light source show up, and those that don't fade to black.
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 11, 2012, 12:13:31 am
builderboy, that seems like a good idea. I'll try that. BTW, the other method didn't cause all that much lag, but this is better (and easier to code).
Title: Re: Minicraft / Terraria clone
Post by: DJ Omnimaga on April 11, 2012, 12:43:28 am
Leafy do you mean some kind of circle like if you had a flash light?
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 12, 2012, 01:15:40 pm
UPDATE:
Hi guys,
It appears I promised an unrealistic release schedule. I'll work like mad to keep it today, but chances are I'll upload on Saturday or even Sunday.  :-(. But on the upside, I have lighting working, mining partially working and inventoruy partially working. If anyone has a 7x7 iron ore sprite, it would be appreciated (writing sprites by hand on the calc is hard!).

If you don't get an upload by 2:30, you know what to expect now.
Title: Re: Minicraft / Terraria clone
Post by: Nick on April 12, 2012, 01:41:22 pm
something lik ethis?

(http://img.removedfromgame.com/imgs/iron%20ore.jpg)
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 12, 2012, 08:10:36 pm
Slightly functional Pre-alpha available on first post. Docs coming soon. ("." to switch views, there is a menu, please comment)
Title: Re: Minicraft / Terraria clone
Post by: Jim Bauwens on April 12, 2012, 08:32:12 pm
Linuxgeek, I have a little request.
Could you please please use indentation for your code?
I almost get a hard attack looking through it :P

I've been indenting it manually until a point where there are syntax errors (I think).
Code: [Select]
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

Title: Re: Minicraft / Terraria clone
Post by: someone on April 13, 2012, 12:07:16 am
The function on.paint misses an END (you can see this fairly easy with notepad++). I added it, but all I can see is a blue screen...

I would also recommend (apart of indenting the code) is that since I saw several pieces of code that repeats, it should be good to identify them & create a function for them, like for example, the color picker.

Something like this could do:
Code: [Select]
function color_picker(gc, top)
    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
end
^This can be optimized, but I think is ok for now...

This will make the code more legible
Title: Re: Minicraft / Terraria clone
Post by: Jim Bauwens on April 13, 2012, 12:12:25 am
There are many things that can be changed, but the most important thing right now is identation.
Getting used to it will be a very great help. Do not under estimate it ;)
You will also see your bugs much clearer.
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 13, 2012, 01:25:30 am
Hi all,

I thoughtlessly uploaded a version where I was still working on the inventory. Fixed. Hopefully, I'll be able to use LuaCS to help prettify this code. Update available tomorrow (maybe docs, maybe trees, I'm still deciding). Oh, and the code prettying is last priority: First I want to have something with crafting, then it will start to be more like minecraft then the current version.
Title: Re: Minicraft / Terraria clone
Post by: Jim Bauwens on April 13, 2012, 11:02:36 am
The prettying is not a last priority. It is a coding style that will help you a great deal.
Trust me, your code will be a lot more clear and easy to work with.
Normally you use indentation while programming ;)

Another thing you should know is that LuaCS is still a bit buggy, and might not be suitable for development.

Anyway, good luck!
Title: Re: Minicraft / Terraria clone
Post by: Chockosta on April 13, 2012, 02:45:05 pm
I agree with jim, identation is really useful.
It's a good habit, because it doesn't just make your code prettier, but it makes it much clearer (especially for other people if you need help)

Anyway, it's nice to see progress on this :)

EDIT :
I modified one line in your code and got it to work... The results are quite strange (maybe my modification is wrong).
It displays a black grid on a white background, and sometimes, randomly, it displays a gray gradient. (see attachment)
Title: Re: Minicraft / Terraria clone
Post by: Jim Bauwens on April 13, 2012, 03:34:33 pm
Yeah, I get the same result in PCspire.
But I guess he is still busy on it, so I'm patient :)
Title: Re: Minicraft / Terraria clone
Post by: someone on April 13, 2012, 05:33:12 pm
I got a crash when using the click button, it throws an error on the function on.mouseDown(x,y) on the last conditional (IF)
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 13, 2012, 06:55:10 pm
Indenting is hard on the calculator, as tab moves to the next line :-(. LuaCS is definitely beta, it is slower then using notes. To use theis project (no name yet, post names if you want one), use d-pad or number keys to move around, "." to switch views, and the world is initially clear. press menu, then reset to build a new one. view 0 (default) is top down, views 2 and 3 are different sides. letters a-g switch inventory slot. CODE IS UPDATED AS OF 04/15/2012 09:14 EST
Title: Re: Minicraft / Terraria clone
Post by: DJ Omnimaga on April 17, 2012, 09:17:57 pm
I agree indenting helps, but not on-calc IMHO. It makes the code even harder to read because the screen is too small (especially on a 83+ where only 16 chars fit in one line). Even on the computer it can be annoying on some editors, because tab doesn't produce the same indentation lenght every line.

Anyway any progress, since what matters the most is what the code do (assuming it does it well)? I'm curious how well this project will go, since I have been waiting for a Minecraft-style clone for a long while.
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on April 18, 2012, 07:20:02 am
Trees work, as do dirt and stone. I'm working on crafting today (as I've been for a while) and expect to upload an update today.
Title: Re: Minicraft / Terraria clone
Post by: Jonius7 on April 19, 2012, 07:29:04 pm
Indenting is hard on the calculator, as tab moves to the next line :-(.
I think I just put in two spaces as an indent. Works well enough!
Then Notepad++ should do indenting very nicely on the PC
Nice progress you have here so far linuxgeek.
Title: Re: Minicraft / Terraria clone
Post by: hellninjas on May 03, 2012, 11:44:27 pm
May I ask about your progress so far?
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on May 14, 2012, 12:16:27 pm
Hi guys, sorry I haven't posted in a while (finals cramming :P). Right now, I am working on crafting. If I can get crafting working, I will release another version. My current version doesn't work, as you can move around, but no blocks can be broken (pickax code is broken). Is it worth it to try and 3dify it? I am having trouble finding a good tutorial (mostly, they let an engine do the math).
Title: Re: Minicraft / Terraria clone
Post by: MasterGeek on May 14, 2012, 09:15:49 pm
Could you post a TNS file?
i have tried compiling this but as soon as I copy the machine code into the student software it instantly crashes.
Title: Re: Minicraft / Terraria clone
Post by: DJ Omnimaga on May 14, 2012, 09:18:50 pm
By the way, will it be possible to cycle through your various equipped items like how you can cycle through guns in a FPS? I noticed many Minecraft clones lacks this and it can be annoying to have to use the number keys everytime. Also in the original game, when you ran out of slots to equip items on, you had to open your inventory everytime.
Title: Re: Minicraft / Terraria clone
Post by: AzNg0d1030 on July 17, 2012, 10:37:48 pm
Is this project still continued or has it been terminated?
Title: Re: Minicraft / Terraria clone
Post by: Jonius7 on July 17, 2012, 11:42:09 pm
Probably been inactive for a while. It's an ambitious project. Besides there are several similar projects also going on.
PS: Haven't posted much in a few months
Title: Re: Minicraft / Terraria clone
Post by: DJ Omnimaga on July 19, 2012, 01:49:45 pm
Yeah Minecraft is really ambitious. Notice how every other project like this died. X.x

Also welcome back Jonius7
Title: Re: Minicraft / Terraria clone
Post by: linuxgeek96 on July 19, 2012, 03:25:34 pm
Its been a little slow to develop lately, with the contest and summer work. However, I am starting to make le crafting table! Coming soon to a calculator near you! Also, to answer DJ_O's question, you should be able to cycle tools: I hooked that functionality to -/+
Title: Re: Minicraft / Terraria clone
Post by: DJ Omnimaga on July 20, 2012, 03:19:34 am
Nice to hear :)
Title: Re: Minicraft / Terraria clone
Post by: AzNg0d1030 on August 16, 2012, 09:36:15 pm
Any updates?
Title: Re: Minicraft / Terraria clone
Post by: DWLooney on August 18, 2012, 12:20:48 pm
Looks completely awesome to me! However, there might be some *lag* issues. You'll have to make it pretty lightweight for it to run on such low hardware specs.
Title: Re: Minicraft / Terraria clone
Post by: AzNg0d1030 on August 18, 2012, 08:28:05 pm
Looks completely awesome to me! However, there might be some *lag* issues. You'll have to make it pretty lightweight for it to run on such low hardware specs.
It's in Lua so it shouldn't have a problem supposedly.  If it did I'd guess it would have been mentioned, so for right now I think its  a ok :)
Title: Re: Minicraft / Terraria clone
Post by: AzNg0d1030 on September 21, 2012, 08:45:26 pm
Oh, the creator has been gone for 2 months now... (double post since last one was a month ago)