/** * Spawns a mob somewhere on the map. Ensures it doesn't intersect anything and is on a spawn tile * * @param mob * @return */ public boolean spawnMob(Mob mob) { float x = mob.getX(); float y = mob.getY(); TextureSet textureSet = mob.getWalkingTextureSet(); // Check mob isn't out of bounds. if (x < 0 || x > getMapWidth() - textureSet.getWidth() || y > getMapHeight() - textureSet.getHeight()) { return false; } // Check mob doesn't intersect anything. for (Entity entity : entities) { if (entity instanceof Character && (mob.intersects(entity.getX(), entity.getY(), entity.getWidth(), entity.getHeight()) || mob.collidesX(0) || mob.collidesY(0))) { return false; } } if (getSpawnLayer().getCell((int) x / getTileWidth(), (int) y / getTileHeight()) == null) { return false; } entities.add(mob); return true; }