Package m33.entities

Examples of m33.entities.Map


    // Toolkit tk = Toolkit.getDefaultToolkit();
    // levelImg = tk.getImage(loader.getURL("level1.png"));
  }

  public void loadLevel(EntityManager em) {
    level1 = new Level(em);
    loaded = true;

    double milli = System.currentTimeMillis();

    tm.newLevel(level1);
View Full Code Here


    hero.load("hero.png");

    level = new Map(entities);
    hero.updateMap(level); // I also set spawn point here

    camera = new Camera();

    hero.setCamera(camera);
    level.setCamera(camera);
    entities.setCamera(camera);
View Full Code Here

    // Level size is fixed for now, it may become dynamic
    level = new char[1000][2000];
    anchor = 990;

    loadSingleFile("chunkTest");
    Chunk ch = new Chunk();

    totRow = tempRow;
    totCol = 0;

    /*
     * for now it load all the chunks in series, from 1 to 4, and it compose
     * them in a single level
     */
    for (int i = 0; i < 10; i++) {

      int j = rand.nextInt(6) + 1;
      //int j = 2; // to test a single chunk
      if(i == 0){
        ch = cm.getChunk(0);
       
        // Chunk 0 MUST define a spawn point
        spawnX = (totCol + ch.getSpawnX()) * TILE_SIZE;
        spawnY = (anchor - ch.getAnchorIn() + ch.getSpawnY()) * TILE_SIZE;
      } else {
        ch = cm.getChunk(j);
      }
     
      char[][] a = ch.getArray();

      for (int r = 0; r < a.length; r++) {
        for (int c = 0; c < a[0].length; c++) {
          level[r + anchor - ch.getAnchorIn()][c + totCol] = a[r][c];
        }
      }

      // create entities
      for (int k = 0; k < ch.getMovNum(); k++) {
        int sx = (ch.sx[k] + totCol) * TILE_SIZE;
        int ex = (ch.ex[k] + totCol) * TILE_SIZE;
        int sy = (ch.sy[k] + anchor - ch.getAnchorIn()) * TILE_SIZE;
        int ey = (ch.ey[k] + anchor - ch.getAnchorIn()) * TILE_SIZE;
        Platform p = new Platform(sx, ex, sy, ey);
        p.setId(1);
        p.setNumWH(ch.getNumW(), ch.getNumH());
     
        em.add(p);
      }

      anchor = anchor - (ch.getAnchorIn() - ch.getAnchorOut());

      totCol += a[0].length;
    }
   
    // Level ends before the last chunk
    endLevel = totCol;
   
    ch = cm.getChunk(0);
    char[][] a = ch.getArray();

    for (int r = 0; r < a.length; r++) {
      for (int c = 0; c < a[0].length; c++) {
        level[r + anchor - ch.getAnchorIn()][c + totCol] = a[r][c];
      }
    }
    totCol += a[0].length;

    ROWS = totRow;
View Full Code Here

  }

  private void loadSingleFile(String chunkName) {
    try {
      char[][] temp = new char[50][50];
      Chunk tempChunk = new Chunk();
      char[][] tempArray = new char[0][0];

      // Open the file that is the first command line parameter
      FileInputStream fstream = new FileInputStream("data/levels/"
          + chunkName + ".txt");
      // Get the object of DataInputStream
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;
      // Read File Line By Line
      while ((strLine = br.readLine()) != null) {
        if (strLine.startsWith("<")) {
          tempRow = 0;
          // command
          String[] tokens = strLine.split("[ ]+");
          for (int i = 0; i < tokens.length; i++) {
            String[] command = tokens[i].split(":");
            if (command[0].equals("time")) { // time
              // save time
            } else if (command[0].equals("chunk")) {
              int id = Integer.parseInt(command[1]); // chunk ID
              // create chunk
              tempChunk = new Chunk();
              // save chunk ID
              tempChunk.setID(id);
              cm.add(id, tempChunk);
            } else if (command[0].equals("size")) { // size
              int row = Integer.parseInt(command[1]);
              int col = Integer.parseInt(command[2]);

              tempChunk.setChunk(row, col);
              tempArray = tempChunk.getArray();
            } else if (command[0].equals("anchor")) { // anchor
              int aIn = Integer.parseInt(command[1]);
              int aOut = Integer.parseInt(command[2]);
              tempChunk.setAnchors(aIn, aOut);
            } else if (command[0].equals("movNum")) { // movable
                                  // number
              int num = Integer.parseInt(command[1]);
              tempChunk.setPlatformNum(num);
            } else if (command[0].equals("mov")) { // movable
                                // platforms
              int sx = Integer.parseInt(command[1]);
              int ex = Integer.parseInt(command[2]);
              int sy = Integer.parseInt(command[3]);
              int ey = Integer.parseInt(command[4]);
              tempChunk.setPlatform(sx, ex, sy, ey);
            } else if (command[0].equals("numWH")){
              int numW = Integer.parseInt(command[1]);
              int numH = Integer.parseInt(command[2]);
              tempChunk.platformWH(numW, numH);
            } else if (command[0].equals("spawn")){
              int spawnX = Integer.parseInt(command[1]);
              int spawnY = Integer.parseInt(command[2]);
              tempChunk.setSpawn(spawnX, spawnY);
            }
          }

        } else {
          // fill array
View Full Code Here

  private int anchor;

  public Level(EntityManager entities) {
    rand = new Random();
    cm = new ChunkManager();
    em = entities;

    // Level size is fixed for now, it may become dynamic
    level = new char[1000][2000];
    anchor = 990;
View Full Code Here

    hero.setCamera(camera);
    level.setCamera(camera);
    entities.setCamera(camera);

    death = new Death();
    death.setCamera(camera);
   
  }
View Full Code Here

    //entities = new EntityManager();
  }

  public void gameReset() {
    // should I create a reset method in entityManager?
    entities = new EntityManager();
   
    hero = new Hero();
    hero.load("hero.png");

    level = new Map(entities);
View Full Code Here

  public void gameReset() {
    // should I create a reset method in entityManager?
    entities = new EntityManager();
   
    hero = new Hero();
    hero.load("hero.png");

    level = new Map(entities);
    hero.updateMap(level); // I also set spawn point here
View Full Code Here

    entities = new EntityManager();
   
    hero = new Hero();
    hero.load("hero.png");

    level = new Map(entities);
    hero.updateMap(level); // I also set spawn point here

    camera = new Camera();

    hero.setCamera(camera);
View Full Code Here

      for (int k = 0; k < ch.getMovNum(); k++) {
        int sx = (ch.sx[k] + totCol) * TILE_SIZE;
        int ex = (ch.ex[k] + totCol) * TILE_SIZE;
        int sy = (ch.sy[k] + anchor - ch.getAnchorIn()) * TILE_SIZE;
        int ey = (ch.ey[k] + anchor - ch.getAnchorIn()) * TILE_SIZE;
        Platform p = new Platform(sx, ex, sy, ey);
        p.setId(1);
        p.setNumWH(ch.getNumW(), ch.getNumH());
     
        em.add(p);
      }

      anchor = anchor - (ch.getAnchorIn() - ch.getAnchorOut());
View Full Code Here

TOP

Related Classes of m33.entities.Map

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.