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;
}
}
このコードはスーパーコアラのものです。
私が欲しいのは、コアラ/ヒーローが壁/タイルに衝突したときにタイルをチェックすることです。次に、タイルを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);}
これは可能ですか?