Эй, я работаю над небольшим проектом в slick2D, я пытаюсь добавить взаимодействие между игроком и npc, где вы можете щелкнуть, чтобы выбрать ответ.Slick2D обновление текста/опции щелчка
public class House extends BasicGameState {
Image house;
Image message;
int msgID = 0;
...
public House(int state) {
}
public void init(GameContainer gc, StateBasedGame sbg)
throws SlickException {
...
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g)
throws SlickException {
house.draw(playerPositionX, playerPositionY);
player.draw(shiftX, shiftY);
if (exitHouse == true){
g.drawString("Would you like to exit the house? Y/N", 520, 270);
}
if (msgID == 1){
message.draw(0, 570);
mollerFace.draw(39, 610);
ttf.drawString(46,588, "Moller");
ttf.drawString(180, 609, "'Ello fella, you interested in some russian dolls?");
ttf.drawString(908, 613, "- Russian dolls?");//option 1
ttf.drawString(908, 633, "- No");//option2
if (Play.spokeToMarkus){
ttf.drawString(908, 653, "- Biscuits?");//option3 hidden
}
} else if (msgID == 2){
message.draw(0, 570);
mollerFace.draw(39, 610);
ttf.drawString(46,588, "Moller");
ttf.drawString(180, 609, "Russian dolls are a set of dolls where each doll is different size, designed to fit in each other.");
ttf.drawString(180, 636, "I can't recall how it's related to the module but it somehow is! ");
ttf.drawString(908, 613, "- Interesting");//option 1
if (Play.spokeToMarkus){
ttf.drawString(908, 633, "- Biscuits?");//option 2 hidden
}
}
else if (msgID == 3){
message.draw(0, 570);
mollerFace.draw(39, 610);
ttf.drawString(46,588, "Moller");
ttf.drawString(180, 609, "Biscuits? I don't really have any biscuits but I know where to get them from.");
ttf.drawString(180, 636, "But first I'm dying, get me something to drink and I'll help ya' out");
ttf.drawString(908, 613, "- Fine");//option 1
}
}
public void update(GameContainer gc, StateBasedGame sbg, int delta)
throws SlickException {
Input input = gc.getInput();
// move up
if (input.isKeyDown(Input.KEY_UP)) {
up(delta);
}
// move down
if (input.isKeyDown(Input.KEY_DOWN)) {
down(delta);
}
// move left
if (input.isKeyDown(Input.KEY_LEFT)) {
left(delta);
}
// move right
if (input.isKeyDown(Input.KEY_RIGHT)) {
right(delta);
}
//speaking to moller
if (msgID == 1){
//option 1
if ((Mouse.getX() > 907 && Mouse.getX()< 1023)
&& (Mouse.getY() > 88 && Mouse.getY() < 107)) {
if (input.isMouseButtonDown(0)) {
msgID = 2;
System.out.println("1");
}
}
//option 2
if ((Mouse.getX() > 907 && Mouse.getX()< 940)
&& (Mouse.getY() > 69 && Mouse.getY() < 83)) {
if (input.isMouseButtonDown(0)) {
msgID = 0;
System.out.println("2");
}
}
//option 3
if ((Mouse.getX() > 907 && Mouse.getX()< 982)
&& (Mouse.getY() > 46 && Mouse.getY() < 66)) {
if (input.isMouseButtonDown(0)) {
if(Play.spokeToMarkus){
msgID = 3;
System.out.println("3");
}
}
}
}
if (msgID == 2){
//option 1
if ((Mouse.getX() > 907 && Mouse.getX()< 1023)
&& (Mouse.getY() > 88 && Mouse.getY() < 107)) {
if (input.isMouseButtonDown(0)) {
msgID = 0;
System.out.println("4");
}
}
//option 2
if ((Mouse.getX() > 907 && Mouse.getX()< 983)
&& (Mouse.getY() > 69 && Mouse.getY() < 83)) {
if (input.isMouseButtonDown(0)) {
if(Play.spokeToMarkus){
msgID = 3;
System.out.println("5");
}
}
}
}
if (msgID == 3){
//option 1
if ((Mouse.getX() > 907 && Mouse.getX()< 1023)
&& (Mouse.getY() > 88 && Mouse.getY() < 107)) {
if (input.isMouseButtonDown(0)) {
msgID = 0;
System.out.println("6");
}
}
}
при запуске игры: говоря ВСНП MsgID становится 1, то игрок имеет 2 варианта «Русские куклы» и «нет». Предполагается, что нажатие «русских кукол» приведет пользователя к следующему сообщению (msgID = 2), в котором пользователь может ответить «интересным», который возвращает их в msgID = 0.
Моя проблема в том, «русские куклы», метод обновления повторно запускается и, таким образом, мгновенно выбирает «интересную». Я попытался исправить это, но не имел успеха, когда я выбираю «русские куклы», системные выходы («1, 4») с одного клика.
Щелчок по первому варианту дважды выбирает первый вариант и, следовательно, возвращает плеер в исходное состояние. Не может показаться, что исправить:/