diff --git a/src/ei/game/gamestate/InGameState.java b/src/ei/game/gamestate/InGameState.java index ff4aff8..2229467 100644 --- a/src/ei/game/gamestate/InGameState.java +++ b/src/ei/game/gamestate/InGameState.java @@ -21,7 +21,7 @@ public class InGameState extends GameState{ rootNode = new Node("InGameNode"); map = new Map(20,20); - map.init(); + map.init("data/map/default"); InGameMouseInput mouse = new InGameMouseInput(map); super.getInput().addInput(mouse); diff --git a/src/ei/game/scene/Map.java b/src/ei/game/scene/Map.java index 99656f5..9b58269 100644 --- a/src/ei/game/scene/Map.java +++ b/src/ei/game/scene/Map.java @@ -1,16 +1,34 @@ package ei.game.scene; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.LinkedList; + import ei.engine.math.Vector2f; import ei.engine.math.Vector2i; import ei.engine.math.Vector3f; import ei.engine.scene.Node; import ei.engine.scene.Sprite; +import ei.engine.texture.TextureLoader; +import ei.engine.util.MultiPrintStream; import ei.game.player.GaiaPlayer; import ei.game.player.Player; import ei.game.player.PlayerHandler; import ei.game.scene.map.Stone; public class Map { + public static final int MAP_GRASS = 0; + public static final int MAP_SAND = 1; + public static final int MAP_REDMUD = 2; + + public static final int OBJ_STONE = 1; + private static final int POS_SIZE = 50; private int width; private int hight; @@ -22,7 +40,11 @@ public class Map { this.hight = h; //init(); } - + + /** + * Creates a default map + * + */ public void init(){ map = new GameEntity[width][hight]; @@ -44,6 +66,107 @@ public class Map { } } + /** + * Loads the map from a file + * + * @param file The map file name without extension + */ + public void init(String file){ + int[][] mapData; + int[][] objData; + try { + mapData = getMapData(file+".map"); + objData = getMapData(file+".obj"); + } catch (IOException e) { + MultiPrintStream.out.println("Error Loading Map: "+e); + e.printStackTrace(); + return; + } + width = mapData.length; + hight = mapData[0].length; + map = new GameEntity[width][hight]; + + // init textures + mapNode = new Node("MapNode"); + for(int i=0; i tempData = new LinkedList(); + + MultiPrintStream.out.println("Loading Map file: "+file); + InputStreamReader isr = new InputStreamReader( + getClass().getClassLoader().getResourceAsStream(file)); + BufferedReader infil = new BufferedReader(isr); + + String rad=""; + while(rad!=null){ + rad = infil.readLine(); + if(rad != null) + tempData.addLast(rad); + } + + // calculate the size of the map + int xSize = 0; + int ySize = tempData.size(); + for(int i=0; i