简单的游戏地图生成器

简单的游戏地图生成器,第1张

概述简单的游戏地图生成器

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

@H_404_4@-- Use this function to perform your initial setupfunction 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",50) parameter.number("plantSeed",5.0,100.0,10.0) parameter.number("minerialSeed",4.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),mineral=nil},3),plant=tree3,{pos=vec2(2,plant=tree1,plant=tree2,mineral=mine2},{pos=vec2(3,mineral=nil}} --print(randomPlant()) --print(randomminerial()) --maptable = createMap() --maptable = {} maptable = createMap()endfunction resetMaptable() maptable = createMap()end-- This function gets called once every framefunction 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)endfunction createMap() for i=1,grIDCount,1 do for j=1,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 mapTendfunction 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 resultendfunction 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 resultendfunction getimg(name) return itemtable[name]endfunction 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 imgMapendfunction drawGround(position) local x,y = scaleX * position.x,scaleY * position.y strokeWIDth(1) fill(5,155,255) fill(0,255) rect(x,y,scaleX,scaleY)endfunction drawTree(position,plant) local x,scaleY * position.y sprite(itemtable[plant],x,scaleX*4/10,scaleY) fill(100,200,255) --text(plant,y)endfunction drawmineral(position,mineral) local x,scaleY * position.y sprite(itemtable[mineral],x+scaleX/2,scaleX/2,scaleX/2) fill(100,255) text(mineral,y) end

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的简单的游戏地图生成器全部内容,希望文章能够帮你解决简单的游戏地图生成器所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1278309.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存