parent
7d3695d0a9
commit
ecbb2c8615
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 9.7 KiB |
Binary file not shown.
@ -0,0 +1,7 @@ |
||||
package mightypork.rogue.world.gen; |
||||
|
||||
|
||||
public enum TileProtectLevel |
||||
{ |
||||
NONE, WEAK, STRONG; |
||||
} |
@ -0,0 +1,99 @@ |
||||
package mightypork.rogue.world.gen.rooms; |
||||
|
||||
|
||||
import java.util.Random; |
||||
|
||||
import mightypork.gamecore.util.annot.DefaultImpl; |
||||
import mightypork.gamecore.util.math.algo.Coord; |
||||
import mightypork.gamecore.util.math.algo.Sides; |
||||
import mightypork.rogue.world.gen.MapTheme; |
||||
import mightypork.rogue.world.gen.RoomBuilder; |
||||
import mightypork.rogue.world.gen.RoomDesc; |
||||
import mightypork.rogue.world.gen.ScratchMap; |
||||
import mightypork.rogue.world.gen.TileProtectLevel; |
||||
import mightypork.rogue.world.tile.TileModel; |
||||
|
||||
|
||||
public abstract class AbstractRectRoom implements RoomBuilder { |
||||
|
||||
@Override |
||||
public RoomDesc buildToFit(ScratchMap map, MapTheme theme, Random rand, Coord center) |
||||
{ |
||||
// half width, half height actually
|
||||
final Coord innerSize = getInnerSize(rand); |
||||
final int width = 2 + innerSize.x; |
||||
final int height = 2 + innerSize.y; |
||||
|
||||
final int wLow = width / 2; |
||||
final int wHigh = width - wLow; |
||||
final int hLow = height / 2; |
||||
final int hHigh = height - hLow; |
||||
|
||||
final Coord min = new Coord(center.x - wLow, center.y - hLow); |
||||
final Coord max = new Coord(center.x + wHigh, center.y + hHigh); |
||||
|
||||
if (!map.isClear(min.add(-1, -1), max)) return null; |
||||
|
||||
map.fill(min, max, theme.floor()); |
||||
map.border(min, max, theme.wall()); |
||||
map.protect(min, max, getWallProtectionLevel()); |
||||
|
||||
placeDoors(map, theme, rand, min, max); |
||||
|
||||
buildExtras(map, theme, rand, min, max); |
||||
|
||||
return new RoomDesc(min.add(-1, -1), max); |
||||
} |
||||
|
||||
|
||||
protected void placeDoors(ScratchMap map, MapTheme theme, Random rand, Coord min, Coord max) |
||||
{ |
||||
final int width = max.x - min.x; |
||||
final int height = max.y - min.y; |
||||
|
||||
for (int i = 0, j = 0; i <= getDoorCount(rand) && j < 100; j++) { // j is to prevent inf loop
|
||||
final Coord door = min.copy(); |
||||
switch (rand.nextInt(4)) { |
||||
case 0: |
||||
door.y = min.y; |
||||
door.x += 1 + rand.nextInt(width - 1); |
||||
break; |
||||
case 1: |
||||
door.y = max.y; |
||||
door.x += 1 + rand.nextInt(width - 1); |
||||
break; |
||||
case 2: |
||||
door.x = min.x; |
||||
door.y += 1 + rand.nextInt(height - 1); |
||||
break; |
||||
case 3: |
||||
door.x = max.x; |
||||
door.y += 1 + rand.nextInt(height - 1); |
||||
break; |
||||
} |
||||
|
||||
if ((map.findDoors(door) & Sides.CARDINAL) == 0) { |
||||
map.set(door, getDoorType(theme, rand)); |
||||
i++; // increment pointer
|
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
@DefaultImpl |
||||
protected void buildExtras(ScratchMap map, MapTheme theme, Random rand, Coord min, Coord max) |
||||
{ |
||||
} |
||||
|
||||
|
||||
protected abstract Coord getInnerSize(Random rand); |
||||
|
||||
|
||||
protected abstract TileProtectLevel getWallProtectionLevel(); |
||||
|
||||
|
||||
protected abstract TileModel getDoorType(MapTheme theme, Random rand); |
||||
|
||||
|
||||
protected abstract int getDoorCount(Random rand); |
||||
} |
@ -0,0 +1,41 @@ |
||||
package mightypork.rogue.world.gen.rooms; |
||||
|
||||
|
||||
import java.util.Random; |
||||
|
||||
import mightypork.gamecore.util.math.algo.Coord; |
||||
import mightypork.rogue.world.gen.MapTheme; |
||||
import mightypork.rogue.world.gen.TileProtectLevel; |
||||
import mightypork.rogue.world.tile.TileModel; |
||||
|
||||
|
||||
public class BasicRoom extends AbstractRectRoom { |
||||
|
||||
|
||||
@Override |
||||
protected TileModel getDoorType(MapTheme theme, Random rand) |
||||
{ |
||||
return rand.nextInt(4) == 0 ? theme.passage() : theme.door(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected int getDoorCount(Random rand) |
||||
{ |
||||
return 1 + rand.nextInt(5); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected TileProtectLevel getWallProtectionLevel() |
||||
{ |
||||
return TileProtectLevel.WEAK; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected Coord getInnerSize(Random rand) |
||||
{ |
||||
return Coord.make(3 + rand.nextInt(3), 3 + rand.nextInt(3)); |
||||
} |
||||
} |
@ -0,0 +1,12 @@ |
||||
package mightypork.rogue.world.gen.rooms; |
||||
|
||||
|
||||
import mightypork.rogue.world.gen.RoomBuilder; |
||||
|
||||
|
||||
public class Rooms { |
||||
|
||||
public static final RoomBuilder BASIC = new BasicRoom(); |
||||
public static final RoomBuilder SECRET = new SecretRoom(); |
||||
public static final RoomBuilder DEAD_END = new DeadEndRoom(); |
||||
} |
@ -0,0 +1,41 @@ |
||||
package mightypork.rogue.world.gen.rooms; |
||||
|
||||
|
||||
import java.util.Random; |
||||
|
||||
import mightypork.gamecore.util.math.algo.Coord; |
||||
import mightypork.rogue.world.gen.MapTheme; |
||||
import mightypork.rogue.world.gen.TileProtectLevel; |
||||
import mightypork.rogue.world.tile.TileModel; |
||||
|
||||
|
||||
public class SecretRoom extends AbstractRectRoom { |
||||
|
||||
|
||||
@Override |
||||
protected TileModel getDoorType(MapTheme theme, Random rand) |
||||
{ |
||||
return theme.secretDoor(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected int getDoorCount(Random rand) |
||||
{ |
||||
return 1 + rand.nextInt(2); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected TileProtectLevel getWallProtectionLevel() |
||||
{ |
||||
return TileProtectLevel.STRONG; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected Coord getInnerSize(Random rand) |
||||
{ |
||||
return Coord.make(3 + rand.nextInt(2), 3 + rand.nextInt(2)); |
||||
} |
||||
} |
@ -1,72 +0,0 @@ |
||||
package mightypork.rogue.world.gen.rooms; |
||||
|
||||
|
||||
import java.util.Random; |
||||
|
||||
import mightypork.gamecore.util.math.algo.Coord; |
||||
import mightypork.gamecore.util.math.algo.Sides; |
||||
import mightypork.rogue.world.gen.MapTheme; |
||||
import mightypork.rogue.world.gen.RoomBuilder; |
||||
import mightypork.rogue.world.gen.RoomDesc; |
||||
import mightypork.rogue.world.gen.ScratchMap; |
||||
import mightypork.rogue.world.tile.TileModel; |
||||
|
||||
|
||||
public class SimpleRectRoom implements RoomBuilder { |
||||
|
||||
@Override |
||||
public RoomDesc buildToFit(ScratchMap map, MapTheme theme, Random rand, Coord center) |
||||
{ |
||||
// half width, half height actually
|
||||
final int width = 2 + rand.nextInt(2); |
||||
final int height = 2 + rand.nextInt(2); |
||||
|
||||
final Coord min = new Coord(center.x - width, center.y - height); |
||||
final Coord max = new Coord(center.x + width, center.y + height); |
||||
|
||||
if (!map.isClear(min, max)) return null; |
||||
|
||||
map.fill(min, max, theme.floor()); |
||||
map.border(min, max, theme.wall()); |
||||
map.protect(min, max); |
||||
|
||||
final boolean holes = rand.nextInt(4) == 0; |
||||
|
||||
for (int i = 0; i <= 2 + rand.nextInt(6); i++) { |
||||
final Coord door = min.copy(); |
||||
switch (rand.nextInt(4)) { |
||||
case 0: |
||||
door.y = min.y; |
||||
door.x += 1 + rand.nextInt((width - 1) * 2); |
||||
break; |
||||
case 1: |
||||
door.y = max.y; |
||||
door.x += 1 + rand.nextInt((width - 1) * 2); |
||||
break; |
||||
case 2: |
||||
door.x = min.x; |
||||
door.y += 1 + rand.nextInt((height - 1) * 2); |
||||
break; |
||||
case 3: |
||||
door.x = max.x; |
||||
door.y += 1 + rand.nextInt((height - 1) * 2); |
||||
break; |
||||
} |
||||
|
||||
if ((map.findDoors(door) & Sides.CARDINAL) == 0) { |
||||
TileModel placed; |
||||
switch (rand.nextInt(8)) { |
||||
case 0: |
||||
case 1: |
||||
placed = theme.passage(); |
||||
break; |
||||
default: |
||||
placed = holes ? theme.floor() : theme.door(); |
||||
} |
||||
map.set(door, placed); |
||||
} |
||||
} |
||||
|
||||
return new RoomDesc(min.add(-1, -1), max); |
||||
} |
||||
} |
@ -0,0 +1,43 @@ |
||||
package mightypork.rogue.world.gui.interaction; |
||||
|
||||
|
||||
import mightypork.gamecore.util.math.algo.Coord; |
||||
import mightypork.gamecore.util.math.constraints.vect.Vect; |
||||
import mightypork.rogue.world.PlayerControl; |
||||
import mightypork.rogue.world.gui.MapView; |
||||
|
||||
|
||||
public class MIPTileClick implements MapInteractionPlugin { |
||||
|
||||
@Override |
||||
public boolean onStepEnd(MapView wv, PlayerControl player) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean onClick(MapView wv, PlayerControl player, Vect mouse, int button, boolean down) |
||||
{ |
||||
if (down && button == 1) { // right button
|
||||
final Coord pos = wv.toWorldPos(mouse); |
||||
player.clickTile(pos); |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean onKey(MapView wv, PlayerControl player, int key, boolean down) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void update(MapView mapView, PlayerControl pc, double delta) |
||||
{ |
||||
} |
||||
} |
@ -0,0 +1,37 @@ |
||||
package mightypork.rogue.world.tile.renderers; |
||||
|
||||
|
||||
import mightypork.gamecore.render.Render; |
||||
import mightypork.gamecore.resources.textures.TxSheet; |
||||
import mightypork.gamecore.util.math.constraints.rect.Rect; |
||||
import mightypork.rogue.Res; |
||||
import mightypork.rogue.world.level.render.TileRenderContext; |
||||
import mightypork.rogue.world.tile.Tile; |
||||
|
||||
|
||||
public class LockedDoorRenderer extends DoorRenderer { |
||||
|
||||
private final TxSheet locked; |
||||
|
||||
|
||||
public LockedDoorRenderer(String sheetLocked, String sheetClosed, String sheetOpen) |
||||
{ |
||||
super(sheetClosed, sheetOpen); |
||||
this.locked = Res.getTxSheet(sheetLocked); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void renderTile(TileRenderContext context) |
||||
{ |
||||
final Tile t = context.getTile(); |
||||
|
||||
if (!t.isWalkable()) { |
||||
final Rect rect = context.getRect(); |
||||
Render.quadTextured(rect, locked.getRandomQuad(context.getTileNoise())); |
||||
} else { |
||||
super.renderTile(context); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,35 @@ |
||||
package mightypork.rogue.world.tile.tiles; |
||||
|
||||
|
||||
import mightypork.gamecore.util.math.color.Color; |
||||
import mightypork.rogue.world.tile.TileModel; |
||||
import mightypork.rogue.world.tile.TileRenderer; |
||||
import mightypork.rogue.world.tile.TileType; |
||||
|
||||
|
||||
public class SecretDoorTile extends LockedDoorTile { |
||||
|
||||
public SecretDoorTile(TileModel model, TileRenderer renderer) |
||||
{ |
||||
super(model, renderer); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean onClick() |
||||
{ |
||||
if (!locked) return false; |
||||
|
||||
locked = false; |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Color getMapColor() |
||||
{ |
||||
if (locked) return TileType.WALL.getMapColor(); |
||||
return super.getMapColor(); |
||||
} |
||||
} |
Loading…
Reference in new issue