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; private GameEntity[][] map; private Node mapNode; public Map(int w, int h){ this.width = w; this.hight = h; //init(); } /** * Creates a default map * */ public void init(){ 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= width || y >= hight) return false; return true; } /** * Returns the object at the pos * * @param x The x pos * @param y The y pos * @return The object in that pos */ public GameEntity getPos(int x, int y){ return map[x][y]; } /** * Sets an object at the pos * * @param e The object * @param x The x pos * @param y The y pos */ public void setPos(GameEntity e, int x, int y){ map[x][y] = e; } /** * Removes a object from that pos * * @param x The x pos * @param y The y pos */ public void removePos(int x, int y){ map[x][y] = null; } /** * Returns the map node * * @return The map node */ public Node getMapNode(){ return mapNode; } public Vector2i getPosIndex(GameEntity u){ for(int i=0; i