gpt4 book ai didi

Java/Libgdx 自动磁贴

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:19:00 25 4
gpt4 key购买 nike

我目前正在开发一个小游戏,因为我只有一些方 block 作为墙,所以我真的很想实现自动平铺。但是怎么做呢?我还没有找到任何关于它的教程,只有一个是针对游戏制作者的,但是在 java 上不起作用:/

我已经尝试找到一个街区的邻居,而不是改变它的风格,但我想我还需要寻找角落的邻居?是这样吗?

有人知道如何实现这样的机制吗? :)

------------编辑------------

所以,我看了维基和 Ze Rubeus 的一些教程,以为可以解决,但还有一个问题:

Wall problem

它可以工作,当一个 block 接触另一个时,但一旦有四个 block ,它就不再工作了。通常,当一个 block 被左邻居、右邻居和下邻居包围时,右下角和左下角也有一个角,而不是它应该绘制另一个图像,你可以在左右部分看到它。通过顺便说一下,值 2 是一堵墙。这是我所做的:

//------------------------------------------------------------------
//--------------------Checking for all sides------------------------
//------------------------------------------------------------------

// got an under neighbour
directions[2] = copyOfMap[((int) y)-1][(int) x] == 2;

// got an upper neighbour
directions[0] = copyOfMap[((int) y)+1][(int) x] == 2;

// got an left neighbour
directions[1] = copyOfMap[((int) y)][(int) x-1] == 2;

// got an right neighbour
directions[3] = copyOfMap[((int) y)][(int) x+1] == 2;

//------------------------------------------------------------------
//--------------------Checking for corners--------------------------
//------------------------------------------------------------------


corners[0] = copyOfMap[y-1][x+1] == 2 ;

corners[2] = copyOfMap[y-1][x-1] == 2;

corners[3] = copyOfMap[y+1][x-1] == 2;

corners[1] = copyOfMap[y+1][x+1] == 2;





// Right
if(directions[3]){

if(directions[2]){

if(directions[1] && corners[1] && corners[3]){

region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(32, 0, 32, 32);

wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);


}
else{
region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(0, 0, 32, 32);

wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
}

}
else if(directions[0]){

region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(0, 64, 32, 32);

wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);

}
else{

region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(32, 0, 32, 32);

wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);

}
}





// Left
else if(directions[1]){

if(directions[2]){

if(directions[3] && corners[1] && corners[3]){

region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(32, 0, 32, 32);

wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);


}
else{
region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(128, 0, 32, 32);

wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
}

}
else if(directions[0]){

region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(128, 32, 32, 32);

wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);

}
else{
region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(32, 0, 32, 32);

wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
}

}





// Up
else if(directions[0]){

if(corners[2]){

region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(0, 32, 32, 32);

wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);

}
else if(corners[3]){

region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(0, 32, 32, 32);

wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);

}
else{
region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(0, 32, 32, 32);

wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
}

}





// Down
else if(directions[2]){


region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(0, 32, 32, 32);

wallLayer.add(region, (x*100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);


}

写的很清楚,如果你能看一下就好了:)忽略wallLayer.add和纹理的东西。

祝你有美好的一天^^

最佳答案

Libgdx 没有为您自动生成图 block 的功能,相反您必须实现自己的算法来执行此类操作。

我建议你阅读this官方 WIKI 中的部分,这里还有一个提供 programmatically generates tilemap 的示例, 和 here 关于如何创建可在 LIBGDX 中实现的程序生成地牢洞穴系统的教程。

关于Java/Libgdx 自动磁贴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36571509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com