From 1d6c6523b25305beb68001084fe96f4284003838 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 20 Jan 2020 13:43:36 -0500 Subject: [PATCH] v0.8.0: made diamond painter patterns generic --- .../levels/painters/Painter.java | 23 +++++++++++++++++++ .../rooms/sewerboss/DiamondGooRoom.java | 11 +-------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/Painter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/Painter.java index e886f857b..dc338ff54 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/Painter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/Painter.java @@ -137,6 +137,29 @@ public abstract class Painter { } } + + public static void fillDiamond(Level level, Rect rect, int value ) { + fillDiamond( level, rect.left, rect.top, rect.width(), rect.height(), value ); + } + + public static void fillDiamond(Level level, Rect rect, int m, int value ) { + fillDiamond( level, rect.left + m, rect.top + m, rect.width() - m*2, rect.height() - m*2, value ); + } + + public static void fillDiamond(Level level, int x, int y, int w, int h, int value){ + + //we want the end width to be w, and the width will grow by a total of (h-2 - h%2) + int diamondWidth = w - (h-2 - h%2); + //but starting width cannot be smaller than 2 on even width, 3 on odd width. + diamondWidth = Math.max(diamondWidth, w%2 == 0 ? 2 : 3); + + for (int i = 0; i <= h; i++){ + Painter.fill( level, x + (w - diamondWidth)/2, y+i, diamondWidth, h-2*i, value); + diamondWidth += 2; + if (diamondWidth > w) break; + } + + } public static Point drawInside( Level level, Room room, Point from, int n, int value ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/sewerboss/DiamondGooRoom.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/sewerboss/DiamondGooRoom.java index ab46ff01c..dd4877518 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/sewerboss/DiamondGooRoom.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/sewerboss/DiamondGooRoom.java @@ -33,16 +33,7 @@ public class DiamondGooRoom extends GooBossRoom { public void paint(Level level) { Painter.fill( level, this, Terrain.WALL ); - //we want the end width to be width()-2, and the width will grow by a total of (height()-4 - height()%2) - int diamondWidth = width()-2 - (height()-4 - height()%2); - //but starting width cannot be smaller than 2 on even width, 3 on odd width. - diamondWidth = Math.max(diamondWidth, width()%2 == 0 ? 2 : 3); - - for (int i = 1; i < height(); i++){ - Painter.fill( level, left + (width() - diamondWidth)/2, top+i, diamondWidth, height()-2*i, Terrain.EMPTY); - diamondWidth += 2; - if (diamondWidth >= width()) break; - } + Painter.fillDiamond( level, this, 1, Terrain.EMPTY); for (Door door : connected.values()) { door.set( Door.Type.REGULAR );