I no longer have the portal class implemented, so can't show code from it. However hereHere is the code im using to render it as a tile:
EDIT: After attempting to reintroduce the portal class in the way that @Reg suggested, i had the following error:
Portal Class:
package com.ritcat14.GotYourSix.entity;
import com.ritcat14.GotYourSix.Game;
import com.ritcat14.GotYourSix.graphics.Screen;
import com.ritcat14.GotYourSix.graphics.Sprite;
import com.ritcat14.GotYourSix.level.Level;
public class Portal extends Entity {
private int x = 0, y = 0;
private Level currLevel = null, locationLevel = null;
public static Portal Level1 = new Portal(1,1,Level.spawn, Level.level1);
public static Portal Level2 = new Portal(2,1,Level.spawn, Level.level2);
public static Portal Level3 = new Portal(3,1,Level.spawn, Level.level3);
public Portal(int x, int y, Level currLevel, Level locationLevel){
this.x = x;
this.y = y;
this.currLevel = currLevel;
this.locationLevel = locationLevel;
sprite = Sprite.portal;
}
public Portal(int x, int y, Level currLevel){
this.x = x;
this.y = y;
this.locationLevel = Level.spawn;
this.currLevel = currLevel;
sprite = Sprite.portal;
}
public void update(){
System.out.println(this);
// --> null?? System.out.println(currLevel);
System.out.println(currLevel.getClientPlayer());
System.out.println(currLevel.getClientPlayer().getBounds());
if (this.getBounds().intersects(currLevel.getClientPlayer().getBounds())) {
Game.getGame().changeLevel(locationLevel);
remove();
}
}
public void render(Screen screen){
screen.renderSprite(x, y, sprite, true);
}
}
The change level method works fine, the issue seems to be that the current level doesn't actually exist. This is how im adding the portals to the level in the Level.spawn
level:
public class SpawnLevel extends Level {
public SpawnLevel(String path) {
super(path, false);
}
protected void loadLevel(String path){
try{
BufferedImage image = ImageIO.read(SpawnLevel.class.getResource(path));
int w = width = image.getWidth();
int h = height = image.getHeight();
tiles = new int[w * h];
image.getRGB(0, 0, w, h, tiles, 0, w);
}catch(IOException e){
e.printStackTrace();
System.out.println("Failed to load level file.");
}
generateLevel();
}
public void setPlayerLocation(){
for (int i = 0; i < getPlayers().size(); i ++){
getPlayers().get(i).setLocation(new Vector2i(5 * 16, 70 * 16));
}
}
protected void generateLevel(){
add(Portal.Level1);
add(Portal.Level2);
add(Portal.Level3);
//no enemies!
}
}
Any ideas? The currLevel is apparently null