Commits

Anonymous committed b88a9e9

start of FOV stuff

Comments (0)

Files changed (8)

src/main/java/net/fishbulb/jcod/demo/Fov.java

+package net.fishbulb.jcod.demo;
+
+import com.badlogic.gdx.graphics.Color;
+import net.fishbulb.jcod.Console;
+
+public class Fov extends DemoApplet {
+    String[] map = new String[]{
+            "##############################################",
+            "#######################      #################",
+            "#####################    #     ###############",
+            "######################  ###        ###########",
+            "##################      #####             ####",
+            "################       ########    ###### ####",
+            "###############      #################### ####",
+            "################    ######                  ##",
+            "########   #######  ######   #     #     #  ##",
+            "########   ######      ###                  ##",
+            "########                                    ##",
+            "####       ######      ###   #     #     #  ##",
+            "#### ###   ########## ####                  ##",
+            "#### ###   ##########   ###########=##########",
+            "#### ##################   #####          #####",
+            "#### ###             #### #####          #####",
+            "####           #     ####                #####",
+            "########       #     #### #####          #####",
+            "########       #####      ####################",
+            "##############################################",
+    };
+
+    int torchRadius = 10;
+    boolean flicker = false;
+    boolean recompute = true;
+    boolean lightWalls = true;
+
+    Color darkWall = new Color(0,0, 0.35f,1f);
+    Color lightWall = new Color(0.5f, 0.4f, 0.2f,1f);
+    Color darkGround = new Color(0.2f, 0.2f, 0.6f,1);
+    Color lightGround = new Color(0.8f, 0.7f, 0.2f,1f);
+
+    int px = 20;
+    int py = 10;
+    private long lastUpdate;
+
+    public Fov(Console parent) {
+        super(parent);
+    }
+
+    @Override public void update() {
+        long now = System.currentTimeMillis();
+        long updateMillis = 30;
+        if ((now - lastUpdate) < updateMillis) return;
+        lastUpdate = now;
+
+
+
+    }
+}

src/main/java/net/fishbulb/jcod/fov/Basic.java

+package net.fishbulb.jcod.fov;
+
+public class Basic extends FovAlgorithm {
+
+    public Basic(FovMap map) {
+        super(map);
+    }
+
+
+}

src/main/java/net/fishbulb/jcod/fov/Diamond.java

+package net.fishbulb.jcod.fov;
+
+public class Diamond {
+}

src/main/java/net/fishbulb/jcod/fov/FovAlgorithm.java

+package net.fishbulb.jcod.fov;
+
+import lombok.Getter;
+import lombok.Setter;
+import net.fishbulb.jcod.util.PlotAlgorithms;
+
+import static net.fishbulb.jcod.util.PlotAlgorithms.bresenham;
+
+public abstract class FovAlgorithm {
+
+    @Getter @Setter
+    private FovMap map;
+
+    protected FovAlgorithm(FovMap map) {
+        this.map = map;
+    }
+
+    class RayCast implements PlotAlgorithms.PlotFunction {
+
+        private final int xo;
+        private final int yo;
+        private final int xd;
+        private final int yd;
+        private final int r2;
+        private final boolean includeWalls;
+
+        RayCast(int xo, int yo, int xd, int yd, int r, boolean includeWalls) {
+            this.xo = xo;
+            this.yo = yo;
+            this.xd = xd;
+            this.yd = yd;
+            this.r2 = r * r;
+            this.includeWalls = includeWalls;
+        }
+
+        public void cast() {
+            bresenham(xo, yo, xd, yd, this);
+        }
+
+        @Override public boolean apply(int x, int y) {
+            if (r2 > 0 && ((x - xo) *(x - xo) + (y - yo) * (y - yo)) > r2) return false;
+            if (!map.contains(x,y)) return false;
+            if (map.isTransparent(x,y)) {
+                map.setFov(x, y, true);
+            } else {
+                map.setFov(x, y, includeWalls);
+                return false;
+            }
+            return true;
+        }
+    }
+
+}

src/main/java/net/fishbulb/jcod/fov/FovMap.java

+package net.fishbulb.jcod.fov;
+
+import lombok.Getter;
+
+public class FovMap {
+    @Getter
+    private int width;
+
+    @Getter
+    private int height;
+
+    class Cell {
+        boolean transparent = true;
+        boolean fov = false;
+
+        Cell(boolean transparent, boolean fov) {
+            this.transparent = transparent;
+            this.fov = fov;
+        }
+
+        Cell(Cell that) {
+            this.transparent = that.transparent;
+            this.fov = that.fov;
+        }
+    }
+
+    private Cell[] cells;
+
+    public FovMap(int width, int height) {
+        cells = new Cell[width * height];
+        for (int i = 0; i < cells.length; i++) {
+            cells[i] = new Cell(false, false);
+        }
+    }
+
+    public FovMap(FovMap that) {
+        width = that.width;
+        height = that.height;
+        cells = new Cell[width * height];
+        for (int i = 0; i < cells.length; i++) {
+            cells[i] = new Cell(that.cells[i]);
+        }
+    }
+
+    public void clear(boolean transparent) {
+        for (Cell c: cells) {
+            c.transparent = transparent;
+            c.fov = false;
+        }
+    }
+
+    public boolean contains(int x, int y) {
+        return (x >= 0 && y >= 0 && x < width && y < height);
+    }
+
+    Cell cellAt(int x, int y) {
+        return cells[x + y * width];
+    }
+
+    public boolean isTransparent(int x, int y) {
+        return cellAt(x, y).transparent;
+    }
+
+    public void setTransparent(int x, int y, boolean transparent) {
+        cellAt(x,y).transparent = transparent;
+    }
+
+    public boolean isFov(int x, int y) {
+        return cellAt(x, y).fov;
+    }
+
+    public void setFov(int x, int y, boolean fov) {
+        cellAt(x, y).fov = fov;
+    }
+
+
+
+}

src/main/java/net/fishbulb/jcod/fov/Permissive.java

+package net.fishbulb.jcod.fov;
+
+public class Permissive {
+}

src/main/java/net/fishbulb/jcod/fov/Restrictive.java

+package net.fishbulb.jcod.fov;
+
+public class Restrictive {
+}

src/main/java/net/fishbulb/jcod/fov/Shadow.java

+package net.fishbulb.jcod.fov;
+
+public class Shadow {
+}