for(Rectangle tile: tiles) {
if(koalaRect.overlaps(tile)) {
// we actually reset the koala y-position here
// so it is just near the tile we collided with
// this removes bouncing :)
if(koala.velocity.y > 0) {
koala.position.y = tile.y - Koala.HEIGHT;
// we hit a block jumping upwards, let's destroy it!
TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get(1);
layer.setCell((int)tile.x, (int)tile.y, null);
} else {
koala.position.y = tile.y + tile.height;
// if we hit the ground, mark us as grounded so we can jump
koala.grounded = true;
}
koala.velocity.y = 0;
break;
}
}
这段代码来自 superkoala。
我想要的是当考拉/英雄与墙壁/瓷砖碰撞时,它会检查瓷砖。然后我想将瓷砖更改为 3 种形式。坚固的瓷砖,轻微破裂的瓷砖,非常脆弱的瓷砖,最后摧毁它。
例子
switch(layer){
"SolidLayer": TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get(3);
//get cracked tile
layer.setCell((int)tile.x, (int)tile.y, null);
"CrackLayer": TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get(2);
//get fragile tile
layer.setCell((int)tile.x, (int)tile.y, null);
"FragileLayer": TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get(1);
//get destroyed layer
layer.setCell((int)tile.x, (int)tile.y, null);}
这是可能的吗?