74 lines
1.9 KiB
Java
74 lines
1.9 KiB
Java
package de.samdev.colorrunner.game.world.map.provider;
|
|
|
|
import com.badlogic.gdx.math.Rectangle;
|
|
|
|
import de.samdev.colorrunner.game.renderer.AbstractGameRenderer;
|
|
import de.samdev.colorrunner.game.world.CRGameWorld;
|
|
import de.samdev.colorrunner.game.world.entities.CRGameEntity;
|
|
import de.samdev.colorrunner.game.world.entities.gameentities.floor.FloorTileEntity;
|
|
import de.samdev.colorrunner.game.world.map.CRTiledMap;
|
|
|
|
public class StaticMapProvider extends MapProvider {
|
|
|
|
private static final int CHUNK_SIZE = 16;
|
|
|
|
private CRTiledMap map;
|
|
|
|
private int mapRightBoundary = 0;
|
|
public int mapPlayerPos = 0;
|
|
public int mapMaxWidth = 0;
|
|
|
|
public StaticMapProvider(CRTiledMap m) {
|
|
map = m;
|
|
mapMaxWidth = map.getWidth();
|
|
}
|
|
|
|
@Override
|
|
public boolean isNextEndlessMenu(){
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public MapProvider createNew() {
|
|
StaticMapProvider mapProvider = new StaticMapProvider(map);
|
|
return mapProvider;
|
|
}
|
|
|
|
@Override
|
|
public void init(CRGameWorld world) {
|
|
mapRightBoundary = appendMap(world);
|
|
}
|
|
|
|
private int appendMap(CRGameWorld world) {
|
|
int height = map.getHeight();
|
|
int width = map.getWidth();
|
|
|
|
int xstart = mapRightBoundary;
|
|
int xend = mapRightBoundary + CHUNK_SIZE;
|
|
|
|
if (xend > width) xend = width;
|
|
|
|
for (int x = xstart; x < xend; x++) {
|
|
for (int y = 0; y < height; y++) {
|
|
float px = x * FloorTileEntity.FLOORTILE_WIDTH;
|
|
float py = (height - y) * FloorTileEntity.FLOORTILE_WIDTH;
|
|
|
|
CRGameEntity e = CRTiledMap.CreateTile(world, map.getGID(x, y), px, py);
|
|
if (e != null) world.addEntity(e);
|
|
}
|
|
}
|
|
|
|
return xend;
|
|
}
|
|
|
|
@Override
|
|
public void update(CRGameWorld world, Rectangle player) {
|
|
|
|
mapPlayerPos = (int)(player.x / FloorTileEntity.FLOORTILE_WIDTH);
|
|
|
|
while (player.x + AbstractGameRenderer.MAX_GAME_WIDTH*2 > mapRightBoundary * FloorTileEntity.FLOORTILE_WIDTH && mapRightBoundary < mapMaxWidth) {
|
|
mapRightBoundary = appendMap(world);
|
|
}
|
|
}
|
|
}
|