use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class LauncherModel method fired.
/**
* Called when fire is performed.
*
* @param initial The fire launch initial speed for force transfer.
* @throws LionEngineException If the fired object is not a {@link Launchable}.
*/
private void fired(Direction initial) {
for (int i = 0; i < listenable.size(); i++) {
listenable.get(i).notifyFired();
}
for (final LaunchableConfig launchableConfig : launchables) {
final Media media = Medias.create(launchableConfig.getMedia());
final Featurable featurable = factory.create(media);
try {
final Launchable launchable = featurable.getFeature(Launchable.class);
if (launchableConfig.getDelay() > 0) {
delayed.add(new DelayedLaunch(source, launchableConfig, initial, featurable, launchable));
} else {
launch(launchableConfig, initial, featurable, launchable);
}
} catch (final LionEngineException exception) {
featurable.getFeature(Identifiable.class).destroy();
throw exception;
}
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class CollisionFunctionConfig method imports.
/**
* Create the collision function from node.
*
* @param parent The parent reference (must not be <code>null</code>).
* @return The collision function data.
* @throws LionEngineException If error when reading node.
*/
public static CollisionFunction imports(XmlReader parent) {
Check.notNull(parent);
final XmlReader node = parent.getChild(FUNCTION);
final CollisionFunctionType type = node.getEnum(CollisionFunctionType.class, TYPE);
try {
switch(type) {
case LINEAR:
return new CollisionFunctionLinear(node.getDouble(A), node.getDouble(B));
// $CASES-OMITTED$
default:
throw new LionEngineException(type);
}
} catch (final IllegalArgumentException | NullPointerException exception) {
throw new LionEngineException(exception, ERROR_TYPE + type);
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class Minimap method prepare.
/**
* Fill minimap surface with tile color configuration.
*
* @throws LionEngineException If surface has not been loaded ({@link #load()} may have not been called).
*/
@Override
public void prepare() {
if (surface == null) {
throw new LionEngineException(ERROR_SURFACE);
}
final Graphic g = surface.createGraphic();
final int v = map.getInTileHeight();
final int h = map.getInTileWidth();
for (int ty = 0; ty < v; ty++) {
for (int tx = 0; tx < h; tx++) {
final Tile tile = map.getTile(tx, ty);
final ColorRgba color = getTileColor(tile);
if (!NO_TILE.equals(color)) {
g.setColor(color);
g.drawRect(tx, v - ty - 1, 0, 0, false);
}
}
}
g.dispose();
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class ToolsAwt method getImage.
/**
* Get an image from an input stream.
*
* @param input The image input stream.
* @return The loaded image.
* @throws IOException If error when reading image.
* @see #setLoadStrategy(ImageLoadStrategy)
*/
public static BufferedImage getImage(InputStream input) throws IOException {
final BufferedImage buffer = ImageIO.read(input);
if (buffer == null) {
throw new IOException("Invalid image !");
}
final BufferedImage copy;
switch(imageLoadStragegy) {
case FAST_LOADING:
copy = buffer;
break;
case FAST_RENDERING:
copy = copyImageDraw(buffer);
break;
case LOW_MEMORY:
copy = copyImage(buffer);
break;
default:
throw new LionEngineException(imageLoadStragegy);
}
return copy;
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class FactoryGraphicTest method afterAll.
/**
* Terminate engine.
*/
@AfterAll
static void afterAll() {
try {
UtilFile.deleteFile(new File(System.getProperty("java.io.tmpdir"), FactoryGraphicTest.class.getSimpleName()));
} catch (final LionEngineException exception) {
Verbose.exception(exception);
}
Medias.setLoadFromJar(null);
Graphics.setFactoryGraphic(null);
Engine.terminate();
}
Aggregations