Browse Source

parse collision tile coordinates from level data

mesinger 6 years ago
parent
commit
607c933cc5

BIN
lib/SnuviEngine.jar


+ 4 - 0
src/me/hammerle/supersnuvi/Game.java

@@ -688,4 +688,8 @@ public class Game extends Engine
     {
     {
         SoundUtils.closeSounds();
         SoundUtils.closeSounds();
     }
     }
+
+    public Level[] getLevels() {
+        return levels;
+    }
 }
 }

+ 26 - 1
src/me/hammerle/supersnuvi/Main.java

@@ -1,10 +1,35 @@
 package me.hammerle.supersnuvi;
 package me.hammerle.supersnuvi;
 
 
+import me.hammerle.supersnuvi.gamelogic.Level;
+import me.hammerle.supersnuvi.gamelogic.LevelPathParser;
+import me.hammerle.supersnuvi.util.Pair;
+
+import java.util.Iterator;
+import java.util.Set;
+
 public class Main
 public class Main
 {
 {
     public static void main(String[] args)
     public static void main(String[] args)
     {
     {
         Game game = new Game();
         Game game = new Game();
-        game.run();
+
+        Level[] levels = game.getLevels();
+
+        Set<Pair<Integer, Integer>> coordinates = LevelPathParser.getCoordinatesOfCollisionTiles(levels[0]);
+
+        Iterator<Pair<Integer, Integer>> it = coordinates.iterator();
+
+        while(it.hasNext()){
+            System.out.println(it.next());
+        }
+
+//        for(Level lvl : levels) {
+//
+//            Set<Pair<Integer, Integer>> coordinates = LevelPathParser.getCoordinatesOfCollisionTiles(lvl);
+//
+//
+//        }
+
+         game.run();
     }
     }
 }
 }

+ 41 - 0
src/me/hammerle/supersnuvi/gamelogic/LevelPathParser.java

@@ -0,0 +1,41 @@
+package me.hammerle.supersnuvi.gamelogic;
+
+import me.hammerle.supersnuvi.Game;
+import me.hammerle.supersnuvi.tiles.Tile;
+import me.hammerle.supersnuvi.util.CollisionObject;
+import me.hammerle.supersnuvi.util.Pair;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class LevelPathParser {
+
+    public static Set<Pair<Integer, Integer>> getCoordinatesOfCollisionTiles(Level lvl){
+
+        Set<Pair<Integer, Integer>> res = new HashSet<>();
+
+        if(lvl == null) return res;
+
+        LevelData lvldata = lvl.getData();
+
+        int backgroundIndex = lvldata.getBackgroundIndex();
+        int width = lvldata.getWidth();
+        int height = lvldata.getHeight();
+
+        for(int x = 0; x < width; x++){
+            for(int y = 0; y < height; y++){
+
+                int tileid = lvldata.getTile(backgroundIndex, x, y);
+                Tile tile = Game.get().getTile(tileid);
+
+                if(tile.getMovementBox(x, y, lvl) != CollisionObject.NULL_BOX){
+
+                    Pair<Integer, Integer> point = new Pair<>(x, y);
+                    res.add(point);
+                }
+            }
+        }
+
+        return res;
+    }
+}

+ 45 - 0
src/me/hammerle/supersnuvi/util/Pair.java

@@ -0,0 +1,45 @@
+package me.hammerle.supersnuvi.util;
+
+public final class Pair<L, R> {
+
+    private L lhs;
+    private R rhs;
+
+    public Pair(L lhs, R rhs) {
+        this.lhs = lhs;
+        this.rhs = rhs;
+    }
+
+    public L getLhs() {
+        return lhs;
+    }
+
+    public void setLhs(L lhs) {
+        this.lhs = lhs;
+    }
+
+    public R getRhs() {
+        return rhs;
+    }
+
+    public void setRhs(R rhs) {
+        this.rhs = rhs;
+    }
+
+    @Override
+    public String toString() {
+        return "(" + lhs + ", " + rhs + ")";
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+
+        if(obj instanceof Pair){
+
+            if(((Pair) obj).lhs.equals(this.lhs) && ((Pair) obj).rhs.equals(this.rhs))
+                return true;
+        }
+
+        return false;
+    }
+}