From 2f8d7515c25b7ad6bb38b38a7c0e604adf40d136 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 12 May 2017 20:13:59 -0400 Subject: [PATCH] v0.6.0: improved platform room logic for larger sizes --- .../levels/rooms/standard/PlatformRoom.java | 68 ++++++++++++++----- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/standard/PlatformRoom.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/standard/PlatformRoom.java index 4925475ea..19c9b0a35 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/standard/PlatformRoom.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/standard/PlatformRoom.java @@ -21,11 +21,13 @@ package com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard; -import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter; import com.watabou.utils.Random; +import com.watabou.utils.Rect; + +import java.util.ArrayList; public class PlatformRoom extends StandardRoom { @@ -39,30 +41,64 @@ public class PlatformRoom extends StandardRoom { return Math.max(super.minHeight(), 5); } + @Override + public float[] sizeCatProbs() { + return new float[]{6, 3, 1}; + } + @Override public void paint(Level level) { Painter.fill( level, this, Terrain.WALL ); - Painter.fill( level, this, 1, !Dungeon.bossLevel() && Random.Int( 2 ) == 0 ? Terrain.CHASM : Terrain.WATER ); - Painter.fill( level, this, 2, Terrain.EMPTY_SP); + Painter.fill( level, this, 1, Terrain.CHASM ); + + ArrayList platforms = new ArrayList<>(); + splitPlatforms( new Rect(left+2, top+2, right-2, bottom-2), platforms); + + for (Rect platform : platforms){ + Painter.fill( level, platform.left, platform.top, platform.width()+1, platform.height()+1, Terrain.EMPTY_SP); + } for (Door door : connected.values()) { door.set( Door.Type.REGULAR ); - if (door.x == left) { - Painter.set( level, door.x + 1, door.y, Terrain.EMPTY_SP ); - Painter.set( level, door.x + 2, door.y, Terrain.EMPTY_SP ); - } else if (door.x == right) { - Painter.set( level, door.x - 1, door.y, Terrain.EMPTY_SP ); - Painter.set( level, door.x - 2, door.y, Terrain.EMPTY_SP ); - } else if (door.y == top) { - Painter.set( level, door.x, door.y + 1, Terrain.EMPTY_SP ); - Painter.set( level, door.x, door.y + 2, Terrain.EMPTY_SP ); - } else if (door.y == bottom) { - Painter.set( level, door.x , door.y - 1, Terrain.EMPTY_SP ); - Painter.set( level, door.x , door.y - 2, Terrain.EMPTY_SP ); - } + Painter.drawInside(level, this, door, 2, Terrain.EMPTY_SP); } } + + private void splitPlatforms( Rect curPlatform, ArrayList allPlatforms ){ + int curArea = (curPlatform.width()+1) * (curPlatform.height()+1); + + //chance to split scales between 0% and 100% between areas of 25 and 36 + if (Random.Float() < (curArea-25)/11f){ + if (curPlatform.width() > curPlatform.height() || + (curPlatform.width() == curPlatform.height() && Random.Int(2) == 0)){ + + //split the platform + int splitX = Random.IntRange( curPlatform.left+2, curPlatform.right-2); + splitPlatforms( new Rect( curPlatform.left, curPlatform.top, splitX-1, curPlatform.bottom) , allPlatforms); + splitPlatforms( new Rect( splitX+1, curPlatform.top, curPlatform.right, curPlatform.bottom) , allPlatforms); + + //add a bridge between + int bridgeY = Random.NormalIntRange(curPlatform.top, curPlatform.bottom); + allPlatforms.add( new Rect( splitX - 1, bridgeY, splitX + 1, bridgeY)); + + } else { + + //split the platform + int splitY = Random.IntRange( curPlatform.top+2, curPlatform.bottom-2); + splitPlatforms( new Rect( curPlatform.left, curPlatform.top, curPlatform.right, splitY-1) , allPlatforms); + splitPlatforms( new Rect( curPlatform.left, splitY+1, curPlatform.right, curPlatform.bottom) , allPlatforms); + + //add a bridge between + int bridgeX = Random.NormalIntRange(curPlatform.left, curPlatform.right); + allPlatforms.add( new Rect( bridgeX, splitY-1, bridgeX, splitY+1)); + + } + } else { + allPlatforms.add(curPlatform); + } + } + }