/** * Reach or run away from a given character. * * @param p_perso target character * @param p_fear TRUE=avoid / FALSE=reach */ public void reachAvoidTarget(Perso p_perso, boolean p_fear) { float sx = x; float sy = y; cptMouvement = 0; float ddx = p_perso.getX(); float ddy = p_perso.getY(); if (p_fear) { // Character should run away instead of reach the character p_perso ddx = 2 * x - ddx; ddy = 2 * y - ddy; } if ((int) ddx > (int) sx) { setX(getX() + Constantes.MONSTER_SPEED); } else if ((int) ddx < (int) x) { setX(getX() - Constantes.MONSTER_SPEED); } if ((int) ddy > (int) y) { setY(getY() + Constantes.MONSTER_SPEED); } else if ((int) ddy < (int) y) { setY(getY() - Constantes.MONSTER_SPEED); } setPos_seqsprite((getPos_seqsprite() + 1) % 512); if (EngineZildo.mapManagement.collide((int) x, (int) y, this)) { // Le monstre est gêné par un obstacle if (!EngineZildo.mapManagement.collide((int) sx, (int) y, this)) { setX(sx); } else if (!EngineZildo.mapManagement.collide((int) x, (int) sy, this)) { setY(sy); } else { setX(sx); setY(sy); setPos_seqsprite(0); pathFinder.setTarget(null); setAlerte(false); setAttente(10); // On replace la zone de déplacement autour de l'ennemi setZone_deplacement( EngineZildo.mapManagement.range(x - 16 * 5, y - 16 * 5, x + 16 * 5, y + 16 * 5)); } } if (!isGhost()) { // Replace angle if character isn't ghost (moved by script) if (x > sx) { angle = Angle.EST; } else if (x < sx) { angle = Angle.OUEST; } else if (y > sy) { angle = Angle.SUD; } else { angle = Angle.NORD; } if (p_fear) { angle = Angle.rotate(angle, 2); } } if (sx != x && sy != y) { // Diagonal moves setX(sx + (x - sx) * 0.8f); setY(sy + (y - sy) * 0.8f); } }
@Override public void die(boolean p_link, Perso p_shooter) { super.die(p_link, p_shooter); if (info == PersoInfo.ENEMY) { // Monster just died. We check, a bonus may appear. int k, m; SpriteAnimation anim = null; k = 1 + (int) (Math.random() * 6); m = 0; ElementDescription itemDesc = carriedItem; if (carriedItem != null) { anim = SpriteAnimation.FROMGROUND; } switch (k) { case 5: case 6: anim = SpriteAnimation.BLUE_DROP; break; case 3: case 4: anim = SpriteAnimation.GOLDCOIN; break; case 1: anim = SpriteAnimation.GOLDCOIN; m = 2; break; } if (anim != null) { EngineZildo.spriteManagement.spawnSpriteGeneric( anim, (int) x, (int) y, floor, m, null, itemDesc); } } }
/** * Common animation for PNJ. Do following things: * * <ol> * <li>Run <b>custom action</b>, if any * <li>Is he dead, or dialoguing ? If so, quit. * <li><b>Jump</b> movement, if he is doing so. * <li><b>Projection</b>, if character is being wounded. * <li><b>Reach</b> his target, if any. * <li>Common move based on {@link MouvementPerso}. * <li>Call to specific {@link #move()} method. * </ol> * * @param compteur_animation */ @Override public void animate(int compteur_animation) { super.animate(compteur_animation); // If character has a delegate action, then do nothing else if (action != null) { blinkIfWounded(); return; } if ((getPv() == 0 && !isWounded()) || getDialoguingWith() != null) { return; } if (mouvement == MouvementZildo.SAUTE) { moveJump(); } else { blinkIfWounded(); move(); } if (!askedVisible) { setVisible(false); } }
// ///////////////////////////////////////////////////////////////////////////////////// // stopBeingWounded // ///////////////////////////////////////////////////////////////////////////////////// @Override public void stopBeingWounded() { setPx(0.0f); setPy(0.0f); setX((int) getX()); setY((int) getY()); setWounded(false); initPersoFX(); super.stopBeingWounded(); }
@Override public void setDesc(SpriteDescription p_desc) { super.setDesc(p_desc); switch ((PersoDescription) desc) { case ABEILLE: case CORBEAU: case VAUTOUR: case CHAUVESOURIS: case SPECTRE: case OISEAU_VERT: flying = true; } }
// ///////////////////////////////////////////////////////////////////////////////////// // manageCollision // ///////////////////////////////////////////////////////////////////////////////////// // -create collision zone for this character // ///////////////////////////////////////////////////////////////////////////////////// @Override public void manageCollision() { if ((getInfo() == PersoInfo.ENEMY || getInfo() == PersoInfo.SHOOTABLE_NEUTRAL) && getPv() > 0) { // Add this collision record to collision engine super.manageCollision(); /* * List<Element> elem=new ArrayList<Element>(); elem.add(this); elem.addAll(persoSprites); for (Element * e:elem) { if (e.isSolid()) { Collision c=e.getCollision(); SpriteModel spr=e.getSprModel(); if (c == * null) { int size=(spr.getTaille_x() + spr.getTaille_y()) / 4; c=new Collision((int) e.x, (int) e.y, size, * getAngle(), this, DamageType.BLUNT, null); } c.cy-=spr.getTaille_y() / 2; c.cy-=e.z; * //EngineZildo.collideManagement.addCollision(c); } } */ } }
// ///////////////////////////////////////////////////////////////////////////////////// // beingWounded // ///////////////////////////////////////////////////////////////////////////////////// // IN : cx,cy : enemy's position // ///////////////////////////////////////////////////////////////////////////////////// // Invoked when this character gets wounded by any enemy (=ZILDO) // ///////////////////////////////////////////////////////////////////////////////////// @Override public void beingWounded(float cx, float cy, Perso p_shooter, int p_damage) { project(cx, cy, 6); this.setMouvement(MouvementZildo.TOUCHE); this.setWounded(true); if (quel_deplacement.isAlertable()) { this.setAlerte(true); // Zildo is detected, if it wasn't done ! } this.setPv(getPv() - p_damage); this.setSpecialEffect(EngineFX.PERSO_HURT); EngineZildo.soundManagement.broadcastSound(BankSound.MonstreTouche, this); super.beingWounded(cx, cy, p_shooter, p_damage); }
/** * Ajouter un personnage et sa position sur la carte des position du joueur. * * @param perso le personnage à ajouter */ public void ajoutPerso(Perso perso) { this.posPersonnage.put(perso.getPos(), perso); }