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 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(); } }