I'm making a game where when the character unleashes a power and hits a rival, the rival's life decreases.
But I can only shorten the life of the rival character when he is touched only once.
Is there a way to count times the "isTouching" function is repeated?
Whenever the "energia" class touches the "jiren" class, the life bar (which I created in the form of an image) changes the image to an image where the life bar is weakened. However, I don't know how to do an "if" to repeat the procedure when the classes "energia" and "jiren" play for the second time...
/** * Write a description of class jiren here. * * @author (your name) * @version (a version number or a date) */ public class jiren extends Actor { /** * Act - do whatever the jiren wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { apanhar (); limite(); vida(); } public void vida(){ } public void importa_socos(){ goku1 goku1 = new goku1(); if(isTouching(goku1.class)){ setImage("jirenap2.png"); Greenfoot.delay(3); setImage("jirenap1.png"); Greenfoot.delay(3); setImage("jirenap1.png"); Greenfoot.delay(3); setImage("jirenap1.png"); Greenfoot.delay(3); } } private void limite (){ if (getX()>1200) setLocation(1200, getY()); if (getX()<20) setLocation(20, getY()); if (getY()<100) setLocation(getX(),100); if (getY()>520) setLocation(getX(),520); } public void apanhar(){ if(isTouching(energia.class)){ removeTouching(energia.class); //Greenfoot.playSound("Explosão - Golpe na Parede.wav"); Greenfoot.delay(1); setLocation(getX(), getY() +20); setImage("jirenap2.png"); Greenfoot.delay(1); setImage("jirenap3.png"); Greenfoot.delay(30); setImage("Jirenteleporte1.png"); Greenfoot.delay(1); //Greenfoot.playSound("Teletransporte - 01.wav"); setImage("Jirenteleporte2.png"); Greenfoot.delay(1); jiren_vida_1 jiren_vida_1 = (jiren_vida_1)getWorld().getObjects(jiren_vida_1.class).get(0); jiren_vida_1.apanhar_1(); } else{ setImage("jirenbase1.png"); //Greenfoot.delay(10); //setImage("jirenbase2.png"); // Greenfoot.delay(10); } } }