public Entity getEntity(float x, float y, float w, float h, Entity entity) { for (Entity e : entities) { float entityX = e.getPos().x; float entityY = e.getPos().y; float entityW = entityX + e.getSize().x; float entityH = entityY + e.getSize().y; if (x + w > entityX && y + h > entityY && x < entityW && y < entityH && !e.equals(entity)) return e; } return null; }
private void updateEntities() { for (Entity e : entities) { if (e instanceof EntityLiving) { EntityLiving entity = (EntityLiving) e; if (entity.isDead()) { if (entity instanceof EntityMonster) this.getPlayer().removeEntity((EntityMonster) entity); this.removeEntity(e); if (entity instanceof EntityHuman) nbMob--; return; } } e.update(); } }
private void renderEntities() { for (Entity e : entities) { float entityX = e.getPos().x; float entityY = e.getPos().y; float entityW = entityX + e.getSize().x; float entityH = entityY + e.getSize().y; float camX = this.camera.getPosition().x; float camY = this.camera.getPosition().y; float camW = camX + Game.instance.getWidth() / Game.instance.getScale(); float camH = camY + Game.instance.getHeight() / Game.instance.getScale(); if (entityX + entityW < camX) continue; if (entityY + entityH < camY) continue; if (entityX > camW) continue; if (entityY > camH) continue; e.render(); } }