-- MindCraft
-- Programming By Perli55

local temp = pge.texture.load("pix/load.png")
pge.gfx.startdrawing()
pge.texture.activate(temp)
pge.texture.draweasy(temp,0,0)
pge.gfx.enddrawing()
pge.gfx.swapbuffers()

math.randomseed(os.clock())
pge.math.srand(os.clock())
black = pge.gfx.createcolor(0,0,0)
red = pge.gfx.createcolor(255,0,0)
orange = pge.gfx.createcolor(255,100,0)
yellow = pge.gfx.createcolor(255,255,0)
white = pge.gfx.createcolor(255,255,255)

function b(f_num) 
	local array={}
	for t=1,f_num do
		table.insert(array,black)
	end
	return array
end

function copy(a, b)
	for k,v in pairs(a) do
		if type(v)~="table" then
			b[k]=v
		else
			local x={}
			copy(v,x)
			b[k]=x
		end 
	end
end

function sign(f_num)
	if f_num>0 then 
		return 1
	elseif f_num<0 then
		return -1
	else
		return 0
	end
end

function char(f_s,f_num)
	return string.sub(f_s,f_num,f_num)
end

function at_pos(f_x,f_y)
	return char(game_data[math.floor(f_x/48)],math.floor(f_y/48))
end

function at_pos_r(f_x,f_y)
	return char(game_data[f_x],f_y)
end

function place(f_x,f_y,f_s)
	local temp=game_data[f_x]
	game_data[f_x]=string.sub(temp,1,f_y-1)..f_s..string.sub(temp,f_y+string.len(f_s))
end

function place_d(f_x,f_y,f_s)
	local temp=game_data[f_x]
	game_data[f_x]=string.sub(temp,1,f_y-string.len(f_s))..f_s..string.sub(temp,f_y+1)
end

function place_b(f_x,f_y,f_s,f_w,f_h)
	local half=f_w*0.5
	f_x=f_x-pge.math.round(half)
	for t=1,f_w do
		local temp=pge.math.round((1-(math.abs(half+0.5-t)/half))*f_h)
		place(f_x+t,f_y-pge.math.round(temp*0.5),string.rep(f_s,temp))
	end
end

function is_update(f_x,f_y)
	if funq_update[at_pos_r(f_x,f_y)] then
		funq_update[at_pos_r(f_x,f_y)](f_x,f_y)
	end
end

function update_at(f_x,f_y)
	is_update(f_x,f_y)
	is_update(f_x,f_y+1)
	is_update(f_x,f_y-1)
	is_update(f_x+1,f_y)
	is_update(f_x-1,f_y)
end

function is_none(f_s)
	return f_s==" " or f_s=="W" or f_s=="V"
end

function flag_set(f_ob,f_x,f_y,f_val)
	if f_val~=nil then
		if not f_ob[f_x] then
			f_ob[f_x]={}
		end
		f_ob[f_x][f_y]=f_val
	end
end

function flag_get(f_ob,f_x,f_y)
	if f_ob[f_x] then
		return f_ob[f_x][f_y]
	else
		return nil
	end
end

function flag_kill(f_ob,f_x,f_y)
	if f_ob[f_x] then
		f_ob[f_x][f_y]=nil
		local temp=true
		for i,v in pairs(f_ob[f_x]) do
			temp=nil
			break
		end
		if temp then
			f_ob[f_x]=nil
		end
	end
end

ore_types=""
local temp={"c","i","a","e","A","r","G","D"}
local temp2={30,22,15,5,14,6,6,2}
for t=1,#temp do
	ore_types=ore_types..string.rep(temp[t],temp2[t])
end

function gen(f_begin,f_end)
	local ores={}
	local temp
	if f_end>0 then
		temp=height[f_begin-1]-4
	else
		temp=height[f_end+1]-4
	end
	local temp2
	local temp3
	local temp4
	local temp5
	local water={}
	local w_x
	if math.random(10)<7 then
		w_x=math.random(f_begin,f_end-34)
	end
	local w_x2
	if math.random(1)==1 then
		w_x2=math.random(f_begin,f_end-34)
	else
		w_x2=nil
	end
	local t=f_begin
	while t<=f_end do
		if w_x==t or w_x2==t then
			
			local w_sel=true
			if w_x2==t then
				w_sel=nil
			end
			
			for t2=t,t+math.random(4) do
				temp=temp+math.random(0,1)
				if temp>56 then temp=56 end
				local temp2=math.random(-1,1)
				local sand_h=math.random(2,3)
				game_data[t2]=string.rep(" ",temp-1)..string.rep("S",sand_h)..string.rep("R",5-sand_h+temp2)..string.rep("s",128-(temp+5+temp2)+math.random(3))
				height[t2]=temp
				t=t+1
			end
			
			local w_l=math.random(8,26)
			local w_al=w_l*0.5
			local w_g=t
			local w_y=math.random(4,12)
			
			if w_sel then
				water[1]=t
				water[2]=t+w_l
				water[3]=temp
			else
				water[4]=t
				water[5]=t+w_l
				water[6]=temp
			end
			
			for t2=t,t+w_l do
				local length=math.ceil((1-math.abs(t2-w_g-w_al)/w_al)*w_y+0.1)
				local temp2=math.random(-1,1)
				local sand_h=math.random(2,3)
				game_data[t2]=string.rep(" ",temp-1+length)..string.rep("S",sand_h)..string.rep("R",5-sand_h+temp2)..string.rep("s",128-(temp+length+5+temp2)+math.random(3))
				height[t2]=temp+length
				t=t+1
			end
			
			for t2=t,t+math.random(4) do
				temp=temp+math.random(-1,0)
				if temp<16 then temp=16 end
				local temp2=math.random(-1,1)
				local sand_h=math.random(2,3)
				game_data[t2]=string.rep(" ",temp-1)..string.rep("S",sand_h)..string.rep("R",5-sand_h+temp2)..string.rep("s",128-(temp+5+temp2)+math.random(3))
				height[t2]=temp
				t=t+1
			end
		else
			temp=temp+math.random(-1,1)
			temp2=temp+4+math.random(-1,1)
			temp5=temp4
			temp4=temp3
			temp3=temp
			if temp5==temp and temp4~=temp then
				temp=temp+(temp4-temp5)*math.random(2)
				temp5=temp4
				temp4=temp3
				temp3=temp
			end
			if temp<16 then temp=16
			elseif temp>56 then temp=56
			end
			game_data[t]=string.rep(" ",temp-1).."g"..string.rep("d",temp2-temp)..string.rep("s",128-temp2+math.random(3))
			height[t]=temp
			t=t+1
		end
	end
	
	local t=f_begin+4
	while pge.running() do
		t=t+math.random(0,4)
		if t>f_end then
			break
		end
		local h=math.random(4,7)
		for t2=0,math.random(1,3) do
			place(t-t2,h,"@")
		end
	end
	
	for t=f_begin,f_end,2 do
		if t>f_begin and t<f_end then table.insert(ores,{t,math.random(height[t]+6,126)}) end
	end
	
	for t=1,#ores do
		temp=math.random(100)
		local ore=char(ore_types,temp)
		temp=ores[t]
		local ore_x=temp[1]
		local ore_y=temp[2]
		temp=""
		for t=1,9 do
			if math.random(2)==1 then
				temp=temp.."s"
			else
				temp=temp..ore
			end
		end
		place(ore_x,ore_y,string.sub(temp,1,3))
		place(ore_x-1,ore_y,string.sub(temp,4,6))
		place(ore_x+1,ore_y,string.sub(temp,7))
	end
	
	for t=1,math.random(35,50) do
		local c_x=math.random(f_begin+8,f_end-8)
		place_b(c_x,math.random(height[c_x]+11,123),"R",math.random(3,6),math.random(3,6))
	end
	
	for t=1,math.random(2) do
		local c_x=math.random(f_begin+15,f_end-15)
		local c_y=height[c_x]-4
		local c_dir=sign(math.random()-0.5)
		local c_max=pge.math.randfloat(0.85,1)
		local c_min=c_max-1
		local rand_t=0
		local rand_r=math.random(10,16)
		for t2=1,math.random(40,80) do
			c_x=c_x+c_dir
			if c_x<f_begin or c_x>f_end then
				break
			end
			c_y=c_y+pge.math.round(pge.math.randfloat(c_min,c_max))
			if c_y>124 then
				break
			end
			local c_size=math.random(0,1)
			place(c_x,c_y+c_size,string.rep(" ",math.random(4,5)-c_size))
			
			rand_t=rand_t+1
			if rand_t>rand_r then
				c_max=pge.math.randfloat(0.85,1)
				c_min=c_max-1
				rand_t=0
				rand_r=math.random(10,16)
			end
			
		end
	end
	
	for t=1,math.random(8,12) do
		local c_x=math.random(f_begin+15,f_end-15)
		local c_y=math.random(height[c_x]+10,115)
		local c_dir=sign(math.random()-0.5)
		local c_max=math.random()
		local c_min=c_max-1
		local rand_t=0
		local rand_r=math.random(10,16)
		for t2=1,math.random(40,80) do
			c_x=c_x+c_dir
			if c_x<f_begin or c_x>f_end then
				break
			end
			c_y=c_y+pge.math.round(pge.math.randfloat(c_min,c_max))
			if c_y<(height[c_x]+5) or c_y>124 then
				break
			end
			local c_size=math.random(0,1)
			place(c_x,c_y+c_size,string.rep(" ",math.random(4,5)-c_size))
			
			rand_t=rand_t+1
			if rand_t>rand_r then
				rand_t=0
				rand_r=math.random(10,16)
				c_max=math.random()
				c_min=c_max-1
			end
			
		end
	end
	
	if water[1] then
		for t=water[1],water[2] do
			place(t,water[3],string.rep("W",height[t]-water[3]))
		end
	end
	if water[4] then
		for t=water[4],water[5] do
			place(t,water[6],string.rep("W",height[t]-water[6]))
		end
	end
	
	local plants=""
	while string.len(plants)<130 do
		plants=plants..string.rep(char("11223345",math.random(9)),math.random(5,10))
	end
	local t=f_begin
	local space=t
	while pge.running() do
		while game_data[t] do
			if string.find(game_data[t],"g") then
				break
			else
				t=t+1
				if t>f_end then break end
			end
		end
		if t>f_end then break end
		if t-3<space or t+3>f_end then
			temp=43
		else
			if temp~=1 then temp=1 end
		end
		local rand=math.random(temp,100)
		if rand<=24 then
			local trunk=char("uvw",math.random(3))
			local tree_len=math.random(4,6)
			local leaves=""
			for t2=1,21 do
				leaves=leaves..char("lL",math.random(2))
			end
			tree_y=height[t]-1-tree_len
			place(t,tree_y,char(leaves,1))
			place(t-1,tree_y,string.sub(leaves,5,7))
			place(t+1,tree_y,string.sub(leaves,2,4))
			place(t,tree_y-1,char(leaves,math.random(0,1)*11))
			place(t-1,tree_y-1,char(leaves,math.random(0,1)*12))
			place(t+1,tree_y-1,char(leaves,math.random(0,1)*13))
			place(t-1,tree_y+3,char(leaves,math.random(0,1)*14))
			place(t+1,tree_y+3,char(leaves,math.random(0,1)*15))
			place(t-2,tree_y,char(leaves,math.random(0,1)*16))
			place(t-2,tree_y+1,char(leaves,math.random(0,1)*17))
			place(t-2,tree_y+2,char(leaves,math.random(0,1)*18))
			place(t+2,tree_y,char(leaves,math.random(0,1)*19))
			place(t+2,tree_y+1,char(leaves,math.random(0,1)*20))
			place(t+2,tree_y+2,char(leaves,math.random(0,1)*21))
			if char(game_data[t+2],tree_y+1)~=" " then
				place(t+2,tree_y+1,char(leaves,math.random(0,1)*8))
			end
			if char(game_data[t-2],tree_y+1)~=" " then
				place(t-2,tree_y+1,char(leaves,math.random(0,1)*9))
			end
			if char(game_data[t],tree_y-1)~=" " then
				place(t,tree_y-2,char(leaves,math.random(0,1)*10))
			end
			place_d(t,height[t]-1,string.rep(trunk,tree_len))
			space=t
		elseif rand<=42 then
			if math.random(2)==1 then
				local h=math.min(height[t],height[t+1])-1
				place(t,h,string.rep("b",height[t]-h))
				place(t+1,h,string.rep("b",height[t+1]-h))
				place(t,height[t]-2,char("b",math.random(0,1)))
				place(t+1,height[t+1]-2,char("b",math.random(0,1)))
				t=t+1
			else
				local h=math.min(height[t],height[t+1],height[t+2])-1
				place(t,h,string.rep("b",height[t]-h))
				place(t+1,h-1,string.rep("b",height[t+1]-h+1))
				place(t+2,h,string.rep("b",height[t+2]-h))
				place(t,height[t]-2,char("b",math.random(0,1)))
				place(t+2,height[t+2]-2,char("b",math.random(0,1)))
				t=t+2
			end
			space=t-1
		elseif rand<=64 then
			place(t,height[t]-1,char(plants,math.abs(t-f_begin)+1))
		end
		t=t+1
	end
	
	for t=f_begin,f_end do
		height[t]=height[t]+4
	end
	
	if f_end<0 then
		local mid=f_begin+64
		local temp={}
		local temp2={}
		for t=1,64 do
			temp[mid+t-1]=game_data[mid-t]
			temp2[mid+t-1]=height[mid-t]
		end
		for t=1,64 do
			game_data[mid-t]=game_data[mid+t-1]
			height[mid-t]=height[mid+t-1]
		end
		for i,v in pairs(temp) do
			game_data[i]=v
		end
		for i,v in pairs(temp2) do
			height[i]=v
		end
	end
end

-- 1: Health (number)
-- 2: None-solid? (nil or true) (set to nil if it's not meant to be placed)
-- 3: Not precise crosshair? (nil or true)
-- 4: Made of (one of d=dirt,s=sand,w=wood,p=plant,r=rock,m=metal,g=glass)
-- 5: Item drop(s) (as a function that returns a string or nil if nothing and true if itself)

block_data={
	g={90,nil,nil,"d"},
	d={90,nil,nil,"d"},
	R={50,nil,nil,"s"},
	S={60,nil,nil,"s"},
	u={140,nil,nil,"w"},
	v={70,nil,nil,"w"},
	w={105,nil,nil,"w"},
	l={70,nil,nil,"p"},
	L={75,nil,nil,"p"},
	b={110,nil,nil,"p"},
	["1"]={10,true,true,"p"},
	["2"]={10,true,true,"p"},
	["3"]={10,true,true,"p"},
	["4"]={10,true,true,"p"},
	["5"]={20,true,true,"p"},
	["6"]={20,true,true,"p"},
	["6"]={30,nil,nil,"p"},
	["@"]={10,nil,nil,"p"},
	
	s={150,nil,nil,"r"},
	c={180,nil,nil,"r"},
	i={270,nil,nil,"r"},
	a={330,nil,nil,"r"},
	e={450,nil,nil,"r"},
	A={265,nil,nil,"r"},
	r={390,nil,nil,"r"},
	G={415,nil,nil,"r"},
	D={450,nil,nil,"r"},
	
	f={80,true,nil,"w"},
	C={80,nil,nil,"g"},
	U={100,nil,nil,"w"},
	t={130,nil,nil,"w"},
	k={195,nil,nil,"r"},
	J={300,nil,nil,"m"},
	z={360,nil,nil,"m"},
	E={480,nil,nil,"m"},
	H={295,nil,nil,"m"},
	p={420,nil,nil,"m"},
	B={445,nil,nil,"m"},
	P={480,nil,nil,"m"},
	["*"]={200,nil,nil,"w"},
	["/"]={200,true,nil,"w"},
	["+"]={200,nil,nil,"w"},
	["-"]={200,true,nil,"w"},
	T={70,nil,nil,"s"},
}
block_data["W"]={nil,true}
block_data["V"]={nil,true}
block_data[" "]={nil,true}
block_data[""]={nil,nil,nil,"r"}

funq_break={}
funq_touch={}
funq_place={}
funq_placed={}
funq_use={}
funq_update={}
funq_screen={}

function funq_use.T(f_x,f_y)
	if not funq_05.boom then
		tnt={}
		function funq_05.boom()
			local temp=true
			for i,v in pairs(tnt) do
				temp=nil
				for i2,v2 in pairs(v) do
					if v2==0 then
						flag_kill(tnt,i,i2)
						local boom={}
						local array={}
						flag_set(boom,i,i2,true)
						copy(boom,array)
						repeat
							local temp=true
							local temp2={}
							copy(array,temp2)
							array={}
							for i,v in pairs(temp2) do
								temp=nil
								for i2,v2 in pairs(v) do
									for t_x=-4,4 do
										for t_y=-4,4 do
											if "T"==at_pos_r(i+t_x,i2+t_y) and not flag_get(boom,i+t_x,i2+t_y) then
												flag_set(boom,i+t_x,i2+t_y,true)
												flag_set(array,i+t_x,i2+t_y,true)
											end
										end
									end
								end
							end
						until temp
						local large=10
						for i,v in pairs(boom) do
							for i2,v2 in pairs(v) do
								local b_w=math.random(math.floor(large-4),math.floor(large))
								local b_h=math.random(math.floor(large-4),math.floor(large))
								local temp=pge.math.round(b_w*0.5)
								local temp2=pge.math.round(b_h*0.5)
								local temp3=pge.math.round(b_w*0.25)
								local temp4=pge.math.round(b_h*0.25)
								if game_data["min"]>i-temp then
									local temp=game_data["min"]
									gen(temp-128,temp-1)
									game_data["min"]=temp-128
								elseif game_data["max"]<i+temp then
									local temp=game_data["max"]
									gen(temp+1,temp+128)
									game_data["max"]=temp+128
								end
								if flag_get(tnt,i,i2) then
									flag_kill(tnt,i,i2)
								end
								place_b(i,i2," ",b_w,b_h)
								is_update(i+temp,i2)
								is_update(i-temp,i2)
								is_update(i,i2+temp2)
								is_update(i,i2-temp2)
								is_update(i+temp3,i2+temp4)
								is_update(i+temp3,i2-temp4)
								is_update(i-temp3,i2+temp4)
								is_update(i-temp3,i2-temp4)
								is_update(i+temp+1,i2)
								is_update(i-temp-1,i2)
								is_update(i,i2+temp2+1)
								is_update(i,i2-temp2-1)
								is_update(i+temp3+1,i2+temp4+1)
								is_update(i+temp3+1,i2-temp4-1)
								is_update(i-temp3-1,i2+temp4+1)
								is_update(i-temp3-1,i2-temp4-1)
								large=large+0.8
							end
						end
						if large>23 then
							funq.clean=loadstring("collectgarbage('collect') ; funq.clean=nil")
						end
						tnt_flash_timer=30
						function funq.flash()
							pge.gfx.drawrect(0,0,480,272,pge.gfx.createcolor(255,255,255,tnt_flash_timer*8.5))
							tnt_flash_timer=tnt_flash_timer-1
							if tnt_flash_timer==0 then
								funq.flash=nil
								tnt_flash_timer=nil
							end
						end
						moved=true
					else
						tnt[i][i2]=v2-1
					end
				end
			end
			if temp then
				funq_05.boom=nil
				tnt=nil
			end
		end
	end
	if not flag_get(tnt,f_x,f_y) then
		flag_set(tnt,f_x,f_y,6)
	end
end

funq_placed["*"] = function (f_x,f_y)
	if is_none(at_pos_r(f_x,f_y-1)) then
		place(f_x,f_y-1,"*")
	else
		place(f_x,f_y," ")
	end
end

funq_break["*"] = function (f_x,f_y)
	if at_pos_r(f_x,f_y+1)=="*" then
		place(f_x,f_y+1," ")
	else
		place(f_x,f_y-1," ")
	end
end

funq_break["/"] = function (f_x,f_y)
	if at_pos_r(f_x,f_y+1)=="/" then
		place(f_x,f_y+1," ")
	else
		place(f_x,f_y-1," ")
	end
end

funq_use["*"] = function (f_x,f_y)
	if at_pos_r(f_x,f_y+1)=="*" then
		place(f_x,f_y,"//")
	else
		place(f_x,f_y-1,"//")
	end
	moved=true
end

funq_use["/"] = function (f_x,f_y)
	if at_pos_r(f_x,f_y+1)=="/" then
		place(f_x,f_y,"**")
	else
		place(f_x,f_y-1,"**")
	end
	moved=true
end

funq_use["+"] = function (f_x,f_y)
	place(f_x,f_y,"-")
	moved=true
end

funq_use["-"] = function (f_x,f_y)
	place(f_x,f_y,"+")
	moved=true
end

function funq_break.T(f_x,f_y)
	if tnt and flag_get(tnt,f_x,f_y) then
		flag_kill(tnt,f_x,f_y)
	end
end

function funq_screen.d(f_x,f_y)
	if at_pos_r(f_x,f_y-1)==" " then
		if not funq_10.grass_grow then
			grass={}
			function funq_10.grass_grow()
				local temp=true
				for i,v in pairs(grass) do
					temp=nil
					for i2,v2 in pairs(v) do
						if at_pos_r(i,i2)=="d" and at_pos_r(i,i2-1)==" " then
							place(i,i2,"g")
						end
					end
				end
				if temp then
					funq_10.grass_grow=nil
					grass=nil
				else
					grass={}
				end
			end
		end
		flag_set(grass,f_x,f_y,true)
	end
end

function funq_touch.W(f_x,f_y)
	if not funq.swin then
		function funq.swin()
			if at_pos(x+234,y+90)=="W" or at_pos(x+241,y+90)=="W" or at_pos(x+234,y+181)=="W" or at_pos(x+241,y+181)=="W" then
				if m_jump() then
					jump_speed=3
				end
				fall_speed=4
			else
				funq.swin=nil
			end
		end
	end
end

function funq_touch.f(f_x,f_y)
	if not funq.climb then
		function funq.climb()
			if at_pos(x+232,y+88)=="f" or at_pos(x+243,y+88)=="f" or at_pos(x+232,y+183)=="f" or at_pos(x+243,y+183)=="f" then
				if m_jump() then
					jump_speed=3
				end
				fall_speed=4
			else
				funq.climb=nil
			end
		end
	end
end

function funq_update.W(f_x,f_y)
	if not funq_05.w_flow then
		funq_05.w_flow=w_flow
		water_flow={}
	end
	flag_set(water_flow,f_x,f_y,true)
end

function w_flow()
	local temp=true
	local temp2=water_flow
	water_flow={}
	for i,v in pairs(temp2) do
		for i2,v2 in pairs(v) do
			temp=nil
			if game_data["min"]<i-1 and i+1<game_data["max"] then
				if at_pos_r(i+1,i2)==" " and (not is_none(at_pos_r(i+1,i2+1)) or not is_none(at_pos_r(i,i2+1))) then
					place(i+1,i2,"W")
					flag_set(flags,i+1,i2,2)
					flag_kill(water_flow,i,i2)
					update_at(i+1,i2)
				end
				if at_pos_r(i-1,i2)==" " and (not is_none(at_pos_r(i-1,i2+1)) or not is_none(at_pos_r(i,i2+1))) then
					place(i-1,i2,"W")
					flag_set(flags,i-1,i2,0)
					flag_kill(water_flow,i,i2)
					update_at(i-1,i2)
				end
			end
			if at_pos_r(i,i2+1)==" " then
				place(i,i2+1,"W")
				flag_set(flags,i,i2+1,1)
				flag_kill(water_flow,i,i2)
				update_at(i,i2+1)
			end
		end
	end
	if temp then
		funq_05.w_flow=nil
		water_flow=nil
	end
end

function funq_update.S(f_x,f_y)
	if is_none(at_pos_r(f_x,f_y+1)) then
		if not funq_05.block_drop then
			funq_05.block_drop=block_drop
			drop_block={}
		end
		flag_set(drop_block,f_x,f_y,true)
	end
end
funq_update.R=funq_update.S

function block_drop()
	local temp=true
	local temp2={}
	copy(drop_block,temp2)
	drop_block={}
	for i,v in pairs(temp2) do
		for i2,v2 in pairs(v) do
			temp=nil
			if at_pos_r(i,i2)=="S" or at_pos_r(i,i2)=="R" and is_none(at_pos_r(i,i2+1)) then
				place(i,i2+1,at_pos_r(i,i2))
				place(i,i2," ")
				flag_kill(drop_block,i,i2)
				update_at(i,i2)
				is_update(i,i2+2)
				is_update(i+1,i2+1)
				is_update(i-1,i2+1)
				moved=true
			end
		end
	end
	if temp then
		funq_05.block_drop=nil
		drop_block=nil
	end
end

local dir=pge.file.open("settings.cfg",PGE_FILE_RDONLY)
temp=pge.file.read(dir,pge.file.size(dir))
pge.file.close(dir)
theme=string.sub(temp,16)
cons_file=string.sub(temp,1,15)
pix={}
dofile("resources.lua")