-- use this function to perform your initial setup function setup() print("simple map sample!!") textmode(corner) spritemode(corner) gridcount = 20 scalex = 50 scaley = 50 -- number > 4 plantseed = 20.0 -- number > 3 minerialseed = 20.0 --[[ parameter.integer("scalex",20,100,50) parameter.integer("scaley",20,100,50) parameter.number("plantseed",5.0,100.0,10.0) parameter.number("minerialseed",4.0,100.0,10.0,resetmaptable) --parameter.integer("gridcount",1,10,6) --]] imgmap = image((gridcount 1)*scalex,(gridcount 1)*scaley) mapt = {} tree1 = "松树" tree2 = "杨树" tree3 = "小草" mine1 = "铁矿" mine2 = "铜矿" imgtree1 = "planet cute:tree short" imgtree2 = "planet cute:tree tall" imgtree3 = "platformer art:grass" imgmine1 = "platformer art:mushroom" imgmine2 = "small world:treasure" itemtable = {[tree1]=imgtree1,[tree2]=imgtree2,[tree3]=imgtree3,[mine1]=imgmine1,[mine2]=imgmine2} -- 3*3 maptable = {{pos=vec2(1,1),plant=nil,mineral=mine1},{pos=vec2(1,2),plant=nil,mineral=nil},{pos=vec2(1,3),plant=tree3,mineral=nil}, {pos=vec2(2,1),plant=tree1,mineral=nil},{pos=vec2(2,2),plant=tree2,mineral=mine2},{pos=vec2(2,3),plant=nil,mineral=nil}, {pos=vec2(3,1),plant=nil,mineral=nil},{pos=vec2(3,2),plant=nil,mineral=mine2},{pos=vec2(3,3),plant=tree3,mineral=nil}} --print(randomplant()) --print(randomminerial()) --maptable = createmap() --maptable = {} maptable = createmap() end function resetmaptable() maptable = createmap() end -- this function gets called once every frame function draw() -- this sets a dark background color background(40, 40, 50) --if #maptable == 0 then maptable = createmap() end -- this sets the line thickness -- strokewidth(5) -- do your drawing here simgmap = drawmap() sprite(simgmap,0,0) end function createmap() for i=1,gridcount,1 do for j=1,gridcount,1 do mapitem = {pos=vec2(i,j),plant=randomplant(),mineral=randomminerial()} table.insert(mapt,mapitem) --print(unpack(mapitem)) --print(mapitem[plant],mapitem[mineral]) end end return mapt end function randomplant() local seed = math.random(1.0,plantseed) local result = nil if seed >= 1 and seed < 2 then result = tree1 end if seed >= 2 and seed < 3 then result = tree2 end if seed >= 3 and seed < 4 then result = tree3 end if seed >= 4 and seed <= plantseed then result = nil end return result end function randomminerial() local seed = math.random(1.0,minerialseed) local result = nil if seed >= 1 and seed < 2 then result = mine1 end if seed >= 2 and seed < 3 then result = mine2 end if seed >= 3 and seed <= minerialseed then result = nil end return result end function getimg(name) return itemtable[name] end function drawmap() setcontext(imgmap) for i = 1,gridcount*gridcount,1 do drawground(maptable[i].pos) if maptable[i].plant ~= nil then drawtree(maptable[i].pos,maptable[i].plant) end if maptable[i].mineral ~= nil then drawmineral(maptable[i].pos,maptable[i].mineral) end end setcontext() return imgmap end function drawground(position) local x,y = scalex * position.x, scaley * position.y strokewidth(1) fill(5,155,40,255) fill(0,100,40,255) rect(x,y,scalex,scaley) end function drawtree(position,plant) local x,y = scalex * position.x, scaley * position.y sprite(itemtable[plant],x,y,scalex*4/10,scaley) fill(100,100,200,255) --text(plant,x,y) end function drawmineral(position,mineral) local x,y = scalex * position.x, scaley * position.y sprite(itemtable[mineral],x scalex/2,y,scalex/2,scalex/2) fill(100,100,200,255) text(mineral,x scalex/2,y) end
用户登录
还没有账号?立即注册
用户注册
投稿取消
文章分类: |
|
还能输入300字

上传中....