Commits

Anonymous committed 35fb595

FOV Demo working
changed a few things so it would run on OSX using jre 6 due to lwjgl error. Updated pom to point to 0.9.9 branch of libGDX.

  • Participants
  • Parent commits c2e8ae6

Comments (0)

Files changed (6)

     <name>JCOD Parent</name>
 
     <properties>
-        <gdx.version>0.9.8-SNAPSHOT</gdx.version>
+        <gdx.version>0.9.9-SNAPSHOT</gdx.version>
     </properties>
 
     <repositories>

File src/main/java/net/fishbulb/jcod/demo/Demo.java

             Constructor ctor = klass.getDeclaredConstructor(Console.class);
             ctor.setAccessible(true);
             return (DemoApplet) ctor.newInstance(root);
-        } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
-            throw new RuntimeException(e);
+        } catch ( NoSuchMethodException e ) {
+        	throw new RuntimeException(e);
+        } catch ( InvocationTargetException e ) {
+        	throw new RuntimeException(e);
+        } catch ( InstantiationException e ) {
+        	throw new RuntimeException(e);
+        } catch ( IllegalAccessException e ) {
+        	throw new RuntimeException(e);
         }
     }
 

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

 package net.fishbulb.jcod.demo;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import com.badlogic.gdx.Input;
 import com.badlogic.gdx.graphics.Color;
 import net.fishbulb.jcod.Console;
+import net.fishbulb.jcod.fov.EliasFOV;
+import net.fishbulb.jcod.fov.FOVSolver;
+import net.fishbulb.jcod.fov.RayCastingFOV;
+import net.fishbulb.jcod.fov.RippleFOV;
+import net.fishbulb.jcod.fov.ShadowFOV;
+import net.fishbulb.jcod.fov.SpreadFOV;
 import net.fishbulb.jcod.util.BlendMode;
 import net.fishbulb.jcod.util.CharCodes;
+import net.fishbulb.jcod.util.ColorUtils;
 
 public class Fov extends DemoApplet {
     String[] map = new String[]{
     int px = 20;
     int py = 10;
 
+    List<FOVSolver> fovs = new ArrayList<FOVSolver>();
+    FOVSolver currentFov;
+    
     private long lastUpdate;
 
     public Fov(Console parent) {
     }
 
     private void initFov() {
+    	fovs.add(new RayCastingFOV());
+    	fovs.add(new EliasFOV());
+    	fovs.add(new RippleFOV());
+    	fovs.add(new ShadowFOV());
+    	fovs.add(new SpreadFOV());
+    	currentFov = fovs.get(0);
     }
 
-    @Override public void update() {
+	@Override public void update() {
         long now = System.currentTimeMillis();
         long updateMillis = 30;
         if ((now - lastUpdate) < updateMillis) return;
         console.print(1, 0, "WASD: Move around");
         console.print(1, 1, "L: Light Walls");
         console.print(1, 2, "T: Torch (not yet)");
-        console.print(1, 3, "X: Algorithm");
+        console.print(1, 3, "X: Algorithm, current: " + currentFov.toString().substring(22));
 
         console.setDefaultForeground(Color.BLACK);
 
         console.putChar(px, py, '@', BlendMode.None);
-//        algo.computeFov(px, py, 0, lightWalls);
 
+        float[][] lights = currentFov.calculateFOV(getResistanceMap(map), px, py, torchRadius);
+        
         for (int y = 0; y < height; y++) {
             for (int x = 0; x < width; x++) {
                 char c = map[y].charAt(x);
-//                boolean lit = light.isFov(x, y);
-                boolean lit = false;
                 switch (c) {
                     case '=':
                         console.putChar(x, y, CharCodes.OEM.DHLINE, BlendMode.None);
                     case ' ':
-                        console.setCharBackground(x, y, lit ? lightGround : darkGround);
+                        console.setCharBackground(x, y, ColorUtils.lerp(darkGround, lightGround, lights[x][y]));
                         break;
                     case '#':
-                        console.setCharBackground(x, y, lit ? lightWall : darkWall);
+                    	if(lightWalls){
+                    		console.setCharBackground(x, y, ColorUtils.lerp(darkWall, lightWall, lights[x][y]));
+                    	} else {
+                    		console.setCharBackground(x, y, darkWall);
+                    	}
                         break;
                 }
             }
     }
 
 
-    private void moveTo(int x, int y) {
+    private float[][] getResistanceMap(String[] map2) {
+		float[][] trans = new float[width][height];
+    	for(int y = 0; y < height; y++) {
+			for(int x = 0; x < width; x++) {
+				String temp = map2[y].substring(x, x+1);
+				if(temp.equals("#")){
+					trans[x][y] = 1;
+				} else if(temp.equals("=")){
+					trans[x][y] = 0.5f;
+				} else {
+					trans[x][y] = 0;
+				}
+			}
+		}
+    	return trans;
+	}
+
+	private void moveTo(int x, int y) {
         if (map[y].charAt(x) == ' ') {
             console.putChar(px, py, ' ', BlendMode.None);
             px = x;
             case Input.Keys.D:
                 moveTo(px + 1, py);
                 return true;
+            case Input.Keys.X:
+            	int index = fovs.indexOf(currentFov);
+            	index = (index + 1 >= fovs.size()) ? 0 : index+1;
+            	currentFov = fovs.get(index);
+            	return true;
             case Input.Keys.T:
                 // TODO: torch effect
             case Input.Keys.L:

File src/main/java/net/fishbulb/jcod/display/BaseTileset.java

 
     @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
     @Getter @Setter
-    private Map<Character, Tile> tileMap = new HashMap<>();
+    private Map<Character, Tile> tileMap = new HashMap<Character, Tile>();
 
     @Override public int columns() {
         return 0;

File src/main/java/net/fishbulb/jcod/fov/RayCastingLOS.java

 
     @Override
     public boolean isReachable(float[][] resistanceMap, int startx, int starty, int targetx, int targety, float force, float decay, RadiusStrategy radiusStrategy) {
-        path = new LinkedList<>();
+        path = new LinkedList<Point>();
         float maxRadius = force / decay;
         float x1 = startx + 0.5f;
         float y1 = starty + 0.5f;

File src/main/java/net/fishbulb/jcod/util/Elias.java

 
 
     public static List<Point> line(double startx, double starty, double endx, double endy) {
-        path = new LinkedList<>();
+        path = new LinkedList<Point>();
         width = (int) (Math.max(startx, endx) + 1);
         height = (int) (Math.max(starty, endy) + 1);
         lightMap = new float[width][height];