Hi all,
If a method is called where a couple of frames of an animation are played, is there a way to interrupt that?
Yours,
Dennis
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; /** * Write a description of class RibbonPig here. * * @author (Patrick van Kralingen) * @version (0.8) */ public class RibbonPig extends Mob { // Check einde platform private boolean isOnMostOutside = false; private int richting = 1; private int speed = 4; //Behaviour public int behaviourTimer = 10; public int actionRandomiser = 1; public int jumpStrength = -3; //Eigenschappen public double hp = 400.0; private boolean alive = true; //Loot public int dropCalculator = 0; public int mesoValue = 0; public int throwingstarGenerator = 0; // Damage die wordt aangericht door pig aan Rogue private int ribbonPigDamage = 25; private int pigGivenExperience = 250; private Rogue rogue; public RibbonPig(){ } public RibbonPig(Rogue rogue){ this.rogue = rogue; } public void act() { // Methods from the superclass checkLeftWalls(); checkRightWalls(); checkFall(); timer(); // Methods from this class animate(sequence); checkTimer(); behaviourTimer--; checkIfOnEdge(); } public void setSpeed(int speed){ this.speed = speed; } public int getSpeed(){ return speed; } public void checkIfOnEdge(){ if(checkFloor()){ System.out.println("I want to change direction"); changeDirection(); } } public void changeDirection(){ System.out.println(this.getSpeed()); } // Verander de richting van de Pig public void changeDirectionPig(){ if(richting == 1){ richting = 2; animateLeft(); } else if (richting == 2){ richting = 1; animateRight(); } speed = -speed; } public void setRibbonPigDamage(int ribbonPigDamage){ this.ribbonPigDamage = ribbonPigDamage; } public int getRibbonPigDamage(){ return ribbonPigDamage; } // Getters and setters for alive or not public void setAlive(boolean alive){ this.alive = alive; } public boolean getAlive(){ return alive; } // ------------------------------------- private void sendExperienceToRogueObject(){ // xpValue verzenden naar Rogue } public void animate(int sequence) { switch(sequence) { case 0: idle(richting); break; case 1: animateLeft(); break; case 2: animateRight(); break; case 3: die(richting); break; case 4: hitFace(richting); break; default: break; } } /************* *Richting Checker **********/ private void idle(int richting) { if(richting == 1) { animateIdleLeft(); } if (richting == 2) { animateIdleRight(); } } private void hitFace(int richting) { if(richting == 1) { animateHitFaceLeft(); } if (richting == 2) { animateHitFaceRight(); } } private void die(int richting) { if(richting == 1) { animateDieLeft(); } if (richting == 2) { animateDieRight(); } } /************* * * * * *ANIMATIONS * * * **********/ public void animateIdleLeft() { if(frame == 1) { setImage(idleLeft[0]); } else if (frame == 2) { setImage(idleLeft[1]); } else if(frame == 3) { setImage(idleLeft[2]); frame = 0; return; } } public void animateIdleRight() { if(frame == 1) { setImage(idleRight[0]); } else if (frame == 2) { setImage(idleRight[1]); } else if(frame == 3) { setImage(idleRight[2]); frame = 0; return; } } public void animateRight() { if(frame == 1) { setImage(animateRight[0]); } else if (frame == 2) { setImage(animateRight[1]); } else if(frame == 3) { setImage(animateRight[2]); frame = 0; return; } } public void animateLeft() { if(frame == 1) { setImage(animateLeft[0]); } else if (frame == 2) { setImage(animateLeft[1]); } else if(frame == 3) { setImage(animateLeft[2]); frame = 0; return; } } public void animateDieLeft() { if(frame == 1) { setImage(dieLeft[0]); } else if (frame == 2) { } else if(frame == 3) { } else if(frame == 4) { setImage(dieLeft[1]); } else if(frame == 5) { } else if(frame == 6) { } else if(frame == 7) { setImage(dieLeft[2]); getImage().setTransparency(240); } else if(frame == 8) { setImage(dieLeft[2]); getImage().setTransparency(200); } else if(frame == 9) { setImage(dieLeft[2]); getImage().setTransparency(170); } else if(frame == 10) { removeAnimation(); frame = 0; return; } } public void animateDieRight() { if(frame == 1) { setImage(dieRight[0]); } else if (frame == 2) { } else if(frame == 3) { } else if(frame == 4) { setImage(dieRight[1]); } else if(frame == 5) { } else if(frame == 6) { } else if(frame == 7) { setImage(dieRight[2]); getImage().setTransparency(240); } else if(frame == 8) { setImage(dieRight[2]); getImage().setTransparency(200); } else if(frame == 9) { setImage(dieRight[2]); getImage().setTransparency(170); } else if(frame == 10) { removeAnimation(); frame = 0; return; } } public void animateHitFaceLeft() { if(frame == 1) { setImage(HitFaceLeft[0]); return; } else if(frame == 7) { frame = 0; return; } } public void animateHitFaceRight() { if(frame == 1) { setImage(HitFaceRight[0]); return; } else if(frame == 7) { frame = 0; return; } } public void removeAnimation() { getWorld().removeObject(this); } /************* * * * * *BEHAVIOUR * * * **********/ public void checkTimer() { if(behaviourTimer == 0) { behaviourTimer(); } actionRandomiser(); } public void behaviourTimer() { behaviourTimer = Greenfoot.getRandomNumber(400) + 100; // you may want a larger number here actionRandomiser = Greenfoot.getRandomNumber(3); } public void actionRandomiser() { switch (actionRandomiser) { case 0: speed = 0; sequence = 0; break; case 1: speed = 4; sequence = 2; moveRight(); richting = 2; break; case 2: speed = 4; sequence = 1; moveLeft(); richting = 1; break; case 3: speed = 0; sequence = 3; break; } } public void moveRight() { setLocation(getX()+speed, getY()); } public void moveLeft() { setLocation(getX()-speed, getY()); } //HIT /** * */ public void hit(double damage) { hp = hp - damage; if(hp <= 0) { actionRandomiser = 3; createLoot(); behaviourTimer = behaviourTimer + 200; //Greenfoot.playSound("RibbonPig_Die.wav"); setAlive(false); rogue.addRogueExperience(pigGivenExperience); } else { //--life if ( damage >= 150) { sequence = 4; speed = 0; frame = 0; behaviourTimer = behaviourTimer + 200; } } } //Loot Generator public void createLoot() { dropCalculator = Greenfoot.getRandomNumber(100); throwingstarGenerator = Greenfoot.getRandomNumber(100); if (dropCalculator >= 70) { mesoValue = Greenfoot.getRandomNumber(100) + 50; getWorld().addObject(new Meso(mesoValue), getX(), getY()); //Greenfoot.playSound("DropItem.wav"); } else if (dropCalculator <= 3) { getWorld().addObject(new Claw1(), getX(), getY()); //Greenfoot.playSound("DropItem.wav"); } else if (throwingstarGenerator <=2 ) { getWorld().addObject(new WolbiDrop(), getX(), getY()); //Greenfoot.playSound("DropItem.wav"); } } /** * SPRITES INLADEN **/ //Idle left GreenfootImage[] idleLeft = new GreenfootImage[] { new GreenfootImage("ribbonPig_left_stand_0.png"), new GreenfootImage("ribbonPig_left_stand_1.png"), new GreenfootImage("ribbonPig_left_stand_2.png") }; //Idle right GreenfootImage[] idleRight = new GreenfootImage[] { new GreenfootImage("ribbonPig_right_stand_0.png"), new GreenfootImage("ribbonPig_right_stand_1.png"), new GreenfootImage("ribbonPig_right_stand_2.png") }; //Naar links lopen GreenfootImage[] animateLeft = new GreenfootImage[] { new GreenfootImage("ribbonPig_left_move_0.png"), new GreenfootImage("ribbonPig_left_move_1.png"), new GreenfootImage("ribbonPig_left_move_2.png") }; //naar Rechts lopen GreenfootImage[] animateRight = new GreenfootImage[] { new GreenfootImage("ribbonPig_right_move_0.png"), new GreenfootImage("ribbonPig_right_move_1.png"), new GreenfootImage("ribbonPig_right_move_2.png") }; GreenfootImage[] dieLeft = new GreenfootImage[] { new GreenfootImage("ribbonPig_left_die1_0.png"), new GreenfootImage("ribbonPig_left_die1_1.png"), new GreenfootImage("ribbonPig_left_die1_2.png") }; GreenfootImage[] dieRight = new GreenfootImage[] { new GreenfootImage("ribbonPig_right_die1_0.png"), new GreenfootImage("ribbonPig_right_die1_1.png"), new GreenfootImage("ribbonPig_right_die1_2.png") }; GreenfootImage[] HitFaceLeft = new GreenfootImage[] { new GreenfootImage("ribbonPig_left_hit1_0.png") }; GreenfootImage[] HitFaceRight = new GreenfootImage[] { new GreenfootImage("ribbonPig_right_hit1_0.png") }; }