Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.util.ArrayList;
- import java.util.List;
- import main.Entity.particle.Particle;
- import main.Entity.Entity;
- import main.Entity.projectile.Projectile;
- import main.Entity.spawner.Spawner;
- import main.tile.Tile;
- public class Level {
- protected int width, height;
- protected int[] tilesInt;
- protected int[] tiles;
- protected int tile_size;
- private List<Entity> entities = new ArrayList<Entity>();
- private List<Projectile> projectiles = new ArrayList<Projectile>();
- private List<Particle> particles = new ArrayList<Particle>();
- public static Level spawnLevel = new Level ("/spawn.png");
- public Level(int width, int height) {
- this.width = width;
- this.height = height;
- tilesInt = new int[width * height];
- generateLevel();
- }
- public Level(String path) {
- loadLevel(path);
- generateLevel();
- add(new Spawner(392, 1695, Spawner.Type.PARTICLE, 50, this));
- }
- protected void loadLevel(String path) {
- }
- protected void generateLevel() {
- }
- public void update() {
- for (int i = 0; i < particles.size(); i++) {
- particles.get(i).update();
- }
- for (int i = 0; i < entities.size(); i++) {
- entities.get(i).update();
- }
- for (int i = 0; i < projectiles.size(); i++) {
- projectiles.get(i).update();
- }
- }
- public void remove() {
- for (int i = 0; i < particles.size(); i++) {
- if (particles.get(i).isRemoved()) particles.remove(i);;
- }
- for (int i = 0; i < entities.size(); i++) {
- if (entities.get(i).isRemoved()) entities.remove(i);
- }
- for (int i = 0; i < projectiles.size(); i++) {
- if (projectiles.get(i).isRemoved()) projectiles.remove(i);
- }
- }
- public List<Projectile> getProjectiles() {
- return projectiles;
- }
- private void time() {
- }
- public boolean solidCollision(double x, double y, double xa, double ya, int size) {
- boolean solid = false;
- for (int c = 0; c < 4; c++) {
- int xt = (((int) x + (int) xa) + c % 2 * size / 5) >> 4;
- int yt = (((int) y + (int) ya) + c / 2 * size / 5) >> 4;
- if (getTile(xt, yt).solid()) solid = true;
- }
- return solid;
- }
- public void render(int xScroll, int yScroll, Screen screen) {
- screen.setOffset(xScroll, yScroll);
- int x0 = xScroll >> 4;
- int x1 = (xScroll + screen.width + 16) >> 4;
- int y0 = yScroll >> 4;
- int y1 = (yScroll + screen.height + 16) >> 4;
- for (int y = y0; y < y1; y++) {
- for(int x = x0; x < x1; x++) {
- getTile(x, y).render(x, y, screen);
- }
- }
- for (int i = 0; i < particles.size(); i++) {
- particles.get(i).render(screen);
- }
- for (int i = 0; i < entities.size(); i++) {
- entities.get(i).render(screen);
- }
- for (int i = 0; i < projectiles.size(); i++) {
- projectiles.get(i).render(screen);
- }
- }
- public void add(Entity e) {
- e.init(this);
- if (e instanceof Particle) {
- particles.add((Particle) e);
- } else if (e instanceof Projectile) {
- projectiles.add((Projectile) e);
- } else {
- entities.add(e);
- }
- }
- //Grass = 0xFF00FF00
- //Rock = 0xFFb4b4b4
- //Flower = 0xFFFFFF00
- public Tile getTile(int x, int y) {
- if (x < 0 || y < 0 || x >= width || y >= height) return Tile.voidTile;
- if (tiles [x + y * width] == Tile.colour_grass) return Tile.grass;
- if (tiles [x + y * width] == Tile.colour_flower) return Tile.flower;
- if (tiles [x + y * width] == Tile.colour_woodFloor) return Tile.woodFloor;
- if (tiles [x + y * width] == Tile.colour_water) return Tile.water;
- if (tiles [x + y * width] == Tile.colour_rockWall) return Tile.rockWall;
- if (tiles [x + y * width] == Tile.colour_rockPath) return Tile.rockPath;
- return Tile.voidTile;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement