I have a monster in my simulation that upon contact with a villager, I want it to grab it, stop moving for 2 seconds, and then replace the villagers image with a poison cloud signifying it killed it. In order to do this I want to have the image of the villager object replaced with the poison cloud after the 2-second mark and then have the monster actor let go of the new image of the poison cloud and keep moving. How would I do something like this?
This is what i have so far but the monster isnt stopping at all on contact with the villager
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * The Car subclass */ public class Acidmon extends Vehicle { private Actor grabbed; int timer = 200; public Acidmon(VehicleSpawner origin) { super(origin); // call the superclass' constructor GreenfootImage image = getImage(); image.scale(image.getWidth() - 120, image.getHeight() - 350); setImage(image); maxSpeed = 1.5 + ((Math.random() * 30)/5); speed = maxSpeed; yOffset = 0; } public void act() { drive(); checkHitPedestrian(); if (checkEdge()){ getWorld().removeObject(this); } } /** * When a Car hit's a Pedestrian, it should knock it over */ public boolean checkHitPedestrian () { if (grabbed == null) { grabbed = getOneObjectAtOffset((int)speed + getImage().getWidth()/2, 0, Villager.class); } if (grabbed != null) { grabbed.setLocation(getX()+15, getY());//adjust '30' value as needed for (int i = 0; i < timer; i++) { timer--; speed = 0; } speed = maxSpeed; if (grabbed.isAtEdge()) { getWorld().removeObject(grabbed); grabbed = null; } } return grabbed != null; } }