Im making a simulation and one of the actors in my simulation is a monster that drags villagers off the screen. How would i make the villager follow the monster actor so it looks like its being grabbed?
villager code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Villager here. * * @author (your name) * @version (a version number or a date) */ public class Villager extends Pedestrian { private GreenfootImage image; public Villager(int dir) { super(dir); image = getImage(); image.scale(image.getWidth() - 340, image.getHeight() - 340); setImage(image); } /** * Act - do whatever the Villager wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(); } public void rooted() { speed = maxSpeed/2; image = new GreenfootImage("rootedvillager.png"); image.scale(image.getWidth() - 340, image.getHeight() - 340); setImage(image); } public void frogged() { speed = maxSpeed/3; image = new GreenfootImage("frog.png"); image.scale(image.getWidth() - 65, image.getHeight() - 65); setImage(image); } public void grabbed() { } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class motorcycle here. * * @author (your name) * @version (a version number or a date) */ public class Prowler extends Vehicle { /** * Act - do whatever the motorcycle wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public Prowler(VehicleSpawner origin) { super(origin); // call the superclass' constructor GreenfootImage image = getImage(); image.scale(image.getWidth() - 200, image.getHeight() - 200); 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 () { Pedestrian p = (Pedestrian)getOneObjectAtOffset((int)speed + getImage().getWidth()/2, 0, Pedestrian.class); if (p != null){ p.grabbed(); return true; } return false; } }