Author Topic: Minicraft / Terraria clone  (Read 27541 times)

0 Members and 2 Guests are viewing this topic.

Offline linuxgeek96

  • LV3 Member (Next: 100)
  • ***
  • Posts: 99
  • Rating: +4/-0
  • ( ͡° ͜ʖ ͡°)
    • View Profile
    • Personal Site
Re: Minicraft / Terraria clone
« Reply #30 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!

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Minicraft / Terraria clone
« Reply #31 on: April 10, 2012, 10:24:31 pm »
side-view seems perfect indeed.
I'm not a nerd but I pretend:

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Minicraft / Terraria clone
« Reply #32 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?

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Minicraft / Terraria clone
« Reply #33 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.
In-progress: Graviter (...)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Minicraft / Terraria clone
« Reply #34 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.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Minicraft / Terraria clone
« Reply #35 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.

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: Minicraft / Terraria clone
« Reply #36 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.
In-progress: Graviter (...)

Offline linuxgeek96

  • LV3 Member (Next: 100)
  • ***
  • Posts: 99
  • Rating: +4/-0
  • ( ͡° ͜ʖ ͡°)
    • View Profile
    • Personal Site
Re: Minicraft / Terraria clone
« Reply #37 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).

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Minicraft / Terraria clone
« Reply #38 on: April 11, 2012, 12:43:28 am »
Leafy do you mean some kind of circle like if you had a flash light?

Offline linuxgeek96

  • LV3 Member (Next: 100)
  • ***
  • Posts: 99
  • Rating: +4/-0
  • ( ͡° ͜ʖ ͡°)
    • View Profile
    • Personal Site
Re: Minicraft / Terraria clone
« Reply #39 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.

Offline Nick

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1166
  • Rating: +161/-3
  • You just got omnom'd
    • View Profile
    • Nick Steen
Re: Minicraft / Terraria clone
« Reply #40 on: April 12, 2012, 01:41:22 pm »
something lik ethis?


Offline linuxgeek96

  • LV3 Member (Next: 100)
  • ***
  • Posts: 99
  • Rating: +4/-0
  • ( ͡° ͜ʖ ͡°)
    • View Profile
    • Personal Site
Re: Minicraft / Terraria clone
« Reply #41 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)

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Minicraft / Terraria clone
« Reply #42 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


Offline someone

  • LV3 Member (Next: 100)
  • ***
  • Posts: 49
  • Rating: +9/-0
    • View Profile
Re: Minicraft / Terraria clone
« Reply #43 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

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Minicraft / Terraria clone
« Reply #44 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.