Hello, I have been trying to program a methode which allows me to generate specific routes for specific objects produced in my world constructor. Since im using a GifImages as subactors im aware that ill need to use 2 objects (original and horizontally mirrorred) in order to create the illusuon of making the object turn 180 degrees. the enemies r supposed to either go up and down or left to right. I plan on placing 3 enemies in seperate positions in my world and then use methodes inorder make them move accordingingly. Here are various approaches i have been trying to realise:
Pls ignore the horizonally mirrorred image statement. I already know that this can not be applied on gifs. As u can see I named my method as pathway1, 2 ,3 etc since i want to apply these on a single object, not the whole class. I would really appreciate some tips, solutions or ideas on how i can make this work.
public class Ghost extends Enemy { public GifImage Ghost = new GifImage("Ghost.gif"); public GifImage Ghost1 = new GifImage("Ghost1.gif"); int scalePercent = 25; int i = 105; int a = 2; int b = 105+a; MyWorld myworld = (MyWorld) getWorld(); public Ghost() { shrinkInSize(); setImage(Ghost.getCurrentImage()); } public void act() { pathway1(); //addedToWorld(myworld); } public void shrinkInSize() { for (GreenfootImage gif : Ghost.getImages()) { int wide = gif.getWidth()*scalePercent/100; int high = gif.getHeight()*scalePercent/100; gif.scale(wide, high); } } public void pathway3() { setLocation(getX(),i); setImage(Ghost.getCurrentImage()); if (i == 105) { getImage().mirrorHorizontally(); setImage(Ghost.getCurrentImage()); i++; } if(i == 430) { getImage().mirrorHorizontally(); setImage(Ghost.getCurrentImage()); i--; } } public void pathway2() { setLocation(getX(),getY()); for(i=getY();i<=430;i++) { if((getY() == 430)) { getImage().mirrorHorizontally(); setImage(Ghost.getCurrentImage()); i--; } } } protected void addedToWorld(World myworld) { getWorld(); getWorld().getObjects(Ghost.class); //Ghost ghost = getWorld().getObjects(Ghost.class).get(430); getY(); getX(); setLocation(getX(),getY()); for(i=getY();i<=430;i++) { if((ghost.getY() == 430)) { getWorld().removeObjects(getWorld().getObjectsAt(280, 430, null)); i--; } } } public void pathway11() { setLocation(getX(),i); for(i=105;i<=430;i++) { setImage(Ghost.getCurrentImage()); i++; if((i == 430)) { getWorld().removeObject(this); Actor Ghost1 = getOneIntersectingObject(Ghost1.class); getWorld().addObject(new Ghost1(),280,430); } } } public void pathway1() { setImage(Ghost.getCurrentImage()); getX(); getY(); setLocation(getX(),getY()+a); getY(); setLocation(getX(),getY()+a); if(this.getY()==430) { getWorld().removeObjects(getWorld().getObjectsAt(280, 430, null)); } }