Package com.mime.minefront.level

Source Code of com.mime.minefront.level.Level

package com.mime.minefront.level;

import java.util.Random;

import com.mime.minefront.graphics.Sprite;

public class Level {
  public Block[] blocks;
  public final int width, height;

  public Level(int width, int height) {
    this.width = width;
    this.height = height;
    blocks = new Block[width * height];
    Random ran = new Random();
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        Block block = null;
        if (ran.nextInt(8) == 0) {
          block = new SolidBlock();
        } else {
          block = new Block();
          if(ran.nextInt(5) == 0)  {
            block.addSprite(new Sprite(0, 0, 0));
          }
        }
        blocks[x + y * width] = block;
      }
    }
  }

  public Block create(int x, int y) {
    if (x < 0 || y < 0 || x >= width || y >= height) {
      return Block.solidWall;
    }
    return blocks[x + y * width];
  }

}
 
TOP

Related Classes of com.mime.minefront.level.Level

TOP
Copyright © 2018 www.massapi.com. 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.