I am struggling on finding a way to delay an attack in my game. I have a character that is moving, and I want it to stop moving for a few moments before it can move again. I tried googling solutions but i cant seem to find a way to do this.I think its because of the way I arranged the code, because im really new to Greenfoot. How can I add this delay?
import lang.stride.*; import java.util.*; import greenfoot.*; /** * */ public class Person extends Actor { private boolean isAttacking = false; /** * */ public Person() { GreenfootImage image = getImage(); image.scale(500, 500); setImage(image); } /** * Act - do whatever the Person wants to do. This method is called whenever the 'Act' or 'Run' button gets pressed in the environment. */ final public void act() { int health = 100; int damage = 5; int power = 0; long lastAdded = System.currentTimeMillis(); if (Greenfoot.isKeyDown("right") && ! isAttacking) { setLocation(getX() + 5, getY()); } if (Greenfoot.isKeyDown("left") && ! isAttacking) { setLocation(getX() - 5, getY()); } long curTime = System.currentTimeMillis(); if ("x".equals(Greenfoot.getKey())) { isAttacking = true; atac(); Greenfoot.delay(5); } } /** * */ public void atac() { Attack attack = new Attack(); getWorld().addObject(attack, getX() + 50, getY()); } }