I've only been using greenfoot for about a week now, and I'm working on this isometric puzzle game that involves using keys to move a box(character) along a set of tiles based on the tiles' location relative to the actor. However, when I use the method getOneObjectAtOffset to get the tile in the specific direction, I don't think it's getting the location of the correct tile. It is important that the box moves along the tiles, because I want to change this a bit so that the box will be able to move up walls. Also, binding the box's movement to the tiles would probably allow me to design levels a bit faster.
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 | import greenfoot.*; /** * Write a description of class character here. * * @author (your name) * @version (a version number or a date) */ public class character extends Actor { public int frame= 1 ; public void act() { if (Greenfoot.isKeyDown( "d" )) { floor movetilePOSZ= (floor)getOneObjectAtOffset(((voxy)getWorld()).flrwidth/- 2 ,((voxy)getWorld()).flrheight/ 2 ,floor. class ); if (movetilePOSZ.getX()<getX()&&movetilePOSZ.getY()>getY()) { setLocation(movetilePOSZ.getX(),movetilePOSZ.getY()); } else { setLocation(getX(),getY()); } for (frame= 1 ;frame<= 7 ;frame++) { Greenfoot.delay( 2 ); setImage( "zboxy" +frame+ ".png" ); //setLocation(getX()-((voxy)getWorld()).flrwidth/14,getY()+((voxy)getWorld()).flrheight/14); } setImage( "boxystat.png" ); Greenfoot.delay( 5 ); } if (Greenfoot.isKeyDown( "e" )) { floor movetileNEGZ= (floor)getOneObjectAtOffset(((voxy)getWorld()).flrwidth/ 2 ,((voxy)getWorld()).flrheight/- 2 ,floor. class ); if (movetileNEGZ.getX()<getX()&&movetileNEGZ.getY()>getY()) { setLocation(movetileNEGZ.getX(),movetileNEGZ.getY()); } else { setLocation(getX(),getY()); } for (frame= 7 ;frame>= 1 ;frame--) { Greenfoot.delay( 2 ); setImage( "zboxy" +frame+ ".png" ); //setLocation(getX()+((voxy)getWorld()).flrwidth/14,getY()-((voxy)getWorld()).flrheight/14); } setImage( "boxystat.png" ); Greenfoot.delay( 5 ); } if (Greenfoot.isKeyDown( "w" )) { floor movetileNEGX= (floor)getOneObjectAtOffset(((voxy)getWorld()).flrwidth/- 2 ,((voxy)getWorld()).flrheight/- 2 ,floor. class ); if (movetileNEGX.getX()<getX()&&movetileNEGX.getY()>getY()) { setLocation(movetileNEGX.getX(),movetileNEGX.getY()); } else { setLocation(getX(),getY()); } for (frame= 1 ;frame<= 7 ;frame++) { Greenfoot.delay( 2 ); setImage( "xboxy" +frame+ ".png" ); //setLocation(getX()-((voxy)getWorld()).flrwidth/14,getY()-((voxy)getWorld()).flrheight/14); } setImage( "boxystat.png" ); Greenfoot.delay( 5 ); } if (Greenfoot.isKeyDown( "f" )) { floor movetilePOSX= (floor)getOneObjectAtOffset(((voxy)getWorld()).flrwidth/ 2 ,((voxy)getWorld()).flrheight/ 2 ,floor. class ); if (movetilePOSX.getX()<getX()&&movetilePOSX.getY()>getY()) { setLocation(movetilePOSX.getX(),movetilePOSX.getY()); } else { setLocation(getX(),getY()); } for (frame= 7 ;frame>= 1 ;frame--) { Greenfoot.delay( 2 ); setImage( "xboxy" +frame+ ".png" ); //setLocation(getX()+((voxy)getWorld()).flrwidth/14,getY()+((voxy)getWorld()).flrheight/14); } setImage( "boxystat.png" ); Greenfoot.delay( 5 ); } } } |