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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | 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 )); } } |