sorted entity rendering
This commit is contained in:
@@ -4,11 +4,13 @@ import de.miaurizius.jgame2d.core.enums.GameState;
|
||||
import de.miaurizius.jgame2d.core.handlers.*;
|
||||
import de.miaurizius.jgame2d.entity.Entity;
|
||||
import de.miaurizius.jgame2d.entity.Player;
|
||||
import de.miaurizius.jgame2d.entity.objects.SuperObject;
|
||||
import de.miaurizius.jgame2d.tile.TileManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -47,6 +49,7 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
public Player player = new Player(this, keyH);
|
||||
public Entity[] obj = new Entity[10];
|
||||
public Entity[] npc = new Entity[10];
|
||||
ArrayList<Entity> entityList = new ArrayList<>();
|
||||
|
||||
// GAME STATE
|
||||
public GameState gameState;
|
||||
@@ -127,9 +130,15 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
|
||||
// GAME
|
||||
tileM.draw(graphics2d);
|
||||
for (Entity superObject : obj) if (superObject != null) superObject.draw(graphics2d);
|
||||
for(Entity npc : npc) if(npc != null) npc.draw(graphics2d);
|
||||
player.draw(graphics2d);
|
||||
|
||||
// ENTITY RENDER SYSTEM
|
||||
entityList.add(player);
|
||||
for(Entity entity : npc) if(entity != null) entityList.add(entity);
|
||||
for(Entity entity : obj) if(entity != null) entityList.add(entity);
|
||||
entityList.sort(Comparator.comparingInt(o -> o.worldY));
|
||||
for(Entity entity : entityList) entity.draw(graphics2d);
|
||||
entityList.clear();
|
||||
|
||||
ui.draw(graphics2d);
|
||||
|
||||
long drawEnd = System.nanoTime();
|
||||
|
||||
Reference in New Issue
Block a user