I’m trying to make a game with similar mechanics to Dead Pixel:
Minus the zombies.
Any how, in the game when a player is lower on the screen the zombies are drawn behind him and when he is higher than the zombies the zombie are drawn in front of him. I tried to prototype a system like that myself and i called it a DepthRenderer. This is what I did:
DepthRenderer Class:
import org.newdawn.slick.Graphics;
import com.pickens.enemies.EnemyController;
import com.pickens.player.Player;
public class DepthRenderer {
Player p;
EnemyController ec;
public DepthRenderer(Player p, EnemyController ec) {
this.p = p;
this.ec = ec;
}
public void render(Graphics g) {
ec.drawBack(g);
p.render(g);
ec.drawFront(g);
}
public void update() {
ec.updateDepth();
}
}
EnemyController Class:
public class EnemyController {
public ArrayList<Enemy> enemies = new ArrayList<Enemy>();
public ArrayList<Enemy> front = new ArrayList<Enemy>();
public ArrayList<Enemy> back = new ArrayList<Enemy>();
Enemy temp;
Player p;
public EnemyController(Player p) {
this.p = p;
}
public void drawBack(Graphics g) {
for(int i = 0; i < back.size(); i++) {
temp = back.get(i);
temp.render(g);
}
}
public void drawFront(Graphics g) {
for(int i = 0; i < front.size(); i++) {
temp = front.get(i);
temp.render(g);
}
}
public void update() {
for(int i = 0; i < enemies.size(); i++) {
temp = enemies.get(i);
temp.update();
}
}
public void updateDepth() {
for(int i = 0; i < enemies.size(); i++) {
temp = enemies.get(i);
if(temp.getBounds().getY() >= p.getBounds().getY()) {
front.add(temp);
back.remove(temp);
System.out.println("Added front");
}else{
System.out.println("Added back");
back.add(temp);
front.remove(temp);
}
}
}
public void addEnemy(Enemy e) {
enemies.add(e);
}
public void removeEnemy(Enemy e) {
enemies.remove(e);
}
}
However the game only draws the enemies in front of the player. The player can never get in front of the enemies even if he is lower than the enemy. So what am I doing wrong? In my mind I thought this would work.