/** * Spawn a character, and all his linked "persoSprites". * * @param perso */ public void spawnPerso(Perso perso) { SpriteEntity entity = perso; entity.setScrX((int) perso.x); entity.setScrY((int) perso.y); spawnSprite(entity); // Spawn connected sprites if (perso.getPersoSprites().size() != 0) { for (Element element : perso.getPersoSprites()) { spawnSprite(element); } } // Store walkable entities if (ElementDescription.isPlatform(perso.getDesc())) { entity.initMover(); walkableEntities.add(entity); } EngineZildo.persoManagement.addPerso(perso); }
/** * Spawn a sprite with minimal requirements: * * <ul> * <li>build an entity with given parameters * <li>add it to the sprite engine * * @param x * @param y * @param p_foreground TRUE=above the other sprites (GUI) / FALSE=in-game sprite * @param p_reverse reverse flag * @param p_adjustPos TRUE=center the element / FALSE=no location adjustment */ public SpriteEntity spawnSprite( SpriteDescription desc, int x, int y, boolean p_foreground, Reverse p_reverse, boolean p_adjustPos) { int nBank = desc.getBank(); int nSpr = desc.getNSpr(); if (desc.isPushable()) { // || nSpr == 179) { // Particular sprite (Block that Zildo can move, chest...) return spawnElement( nBank, nSpr, x, y, 0, Reverse.NOTHING, Rotation.NOTHING); // + spr.getTaille_y() / 2 - 3, // 0); } // SpriteEntity informations SpriteEntity entity; ElementDescription elemDesc = null; if (desc instanceof ElementDescription) { elemDesc = (ElementDescription) desc; } boolean weapon = false; if (elemDesc != null) { ItemKind kind = ItemKind.fromDesc(elemDesc); weapon = kind != null && kind.isWeapon(); } if (!p_foreground && weapon) { entity = new ElementWeapon(x, y); } else if (desc == ElementDescription.LAUNCHER1) { entity = new ElementLauncher(x, y); entity.setAjustedX(x); entity.setAjustedY(y); } else if (desc.getBank() == SpriteBank.BANK_GEAR) { entity = new ElementGear(x, y); entity.setAjustedX(x); entity.setAjustedY(y); } else if (desc == ElementDescription.QUAD1) { EngineZildo.multiplayerManagement.spawnQuad(x, y); return null; } else { entity = new SpriteEntity(x, y, true); int adjustX = 0; int adjustY = 0; SpriteModel spr = getSpriteBank(desc.getBank()).get_sprite(nSpr); adjustX = -(spr.getTaille_x() >> 1); if (p_adjustPos) { adjustY = -(spr.getTaille_y() >> 1); } else { adjustY = -spr.getTaille_y(); } entity.setAjustedX(x + adjustX); entity.setAjustedY(y + adjustY); } entity.setNSpr(nSpr); entity.setNBank(nBank); entity.setForeground(p_foreground); entity.reverse = p_reverse; spawnSprite(entity); // Store walkable entities if (ElementDescription.isPlatform(desc)) { entity.initMover(); walkableEntities.add(entity); } return entity; }