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.
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);
}
}
}
