Lua   发布时间:2019-10-08  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了简单的游戏地图生成器大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
-- 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",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()
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)
end

function 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 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(R_692_11845@apTable[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,255)
    fill(0,255)
    rect(x,y,scaleX,scaleY)
end

function drawTree(position,plant)
    local x,scaleY * position.y
    
    sprite(itemTable[plant],x,scaleX*4/10,scaleY)
    
    fill(100,200,255)
    --text(plant,y)

end

function 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

大佬总结

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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: