Hey there,
I'm programming a little game. You have to walk through different rooms and find an exit. In front of the exit, there is a lock that needs to be opened. The code for the lock is the following:
The code get's called by another Class called Player. It say's:
Now to my problem: I want to have a little bit of time between the image of the lock getting changed and the lock getting deleted, so you can actually see the opened Lock. Adding a delay will pause the whole program, which is not what I want. Are there any options to pause the code of/delay only one Actor?
public class KeyLock extends Actor
{
/**
* Act - do whatever the KeyLock wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
}
public void open(){
setImage("KeyLockOpen.png");
GameWorld world=(GameWorld)getWorld();
world.removeObject(this);
}
}public class Player extends Actor
{
private boolean hasKey;
public Player(){
hasKey=true;
}
public void act(){
openLocks();
}
public void openLocks(){
KeyLock northLock=(KeyLock)getOneObjectAtOffset(0,-this.getImage().getHeight()/2-3,KeyLock.class);
KeyLock eastLock=(KeyLock)getOneObjectAtOffset(this.getImage().getWidth()/2+3,0,KeyLock.class);
KeyLock southLock=(KeyLock)getOneObjectAtOffset(0,this.getImage().getHeight()/2+3,KeyLock.class);
KeyLock westLock=(KeyLock)getOneObjectAtOffset(-this.getImage().getWidth()/2-3,0,KeyLock.class);
if(northLock!=null&&hasKey==true&&Greenfoot.isKeyDown("e")){
northLock.open();
}
if(eastLock!=null&&hasKey==true&&Greenfoot.isKeyDown("e")){
eastLock.open();
}
if(southLock!=null&&hasKey==true&&Greenfoot.isKeyDown("e")){
southLock.open();
}
if(westLock!=null&&hasKey==true&&Greenfoot.isKeyDown("e")){
westLock.open();
}
}
}
