I would like to allow the user to click a door so that the background changes and the location of the characters in the game are set to make it look like they entered a room. This is my code:
This code is in the UserWalk1 class instead of the CafeteriaDoor class. I need it there because I do not know how to do object interaction passing two objects to another one, and I need to do that to be able to set the location of both UserWalk1 and EloraWalk1 once CafeteriaDoor is clicked. When I try it out and click the door, cafeteriadoor, the variable 'bgNumber' does not increment and stays as 5, which is why the background does not change. My guess is that even if I click the door, the program does not consider it clicked so the if statement is ignored? When I tried using the Greenfoot.mouseClicked() in the CafeteriaDoor class, it worked because I placed 'this', itself, in the parameter. However, I cannot set the location of both UserWalk1 and EloraWalk1. I can only set the location of one. How do I fix this?
int background = 0; int totalBG = 26;
public void changeBackground() { int bgNumber = background % totalBG; CafeteriaDoor cafeteriadoor = new CafeteriaDoor(); .... else if(bgNumber == 5) { getWorld().setBackground("Cafeteria Entrance.JPG"); getWorld().addObject(cafeteriadoor, 429, 146); if(Greenfoot.mouseClicked(cafeteriadoor)) { background++; setLocation(125, 243); elorawalk1.setLocation(60, 270); } } else if(bgNumber == 6) { getWorld().setBackground("Cafeteria 1.JPG"); getWorld().removeObject(cafeteriadoor); }