java - Slick2D updating text/click options -
java - Slick2D updating text/click options -
hey im working on little project in slick2d, im trying add together interaction between player , npc can click select reply.
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 exit 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, interested in 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 set of dolls each doll different size, designed fit in each other."); ttf.drawstring(180, 636, "i can't recall how it's related module 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? don't have biscuits know them from."); ttf.drawstring(180, 636, "but first i'm dying, me drink , 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 if (input.iskeydown(input.key_up)) { up(delta); } // move downwards 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 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"); } } }
while running game: when speaking npc msgid becomes 1, player has 2 options "russian dolls" , "no". clicking "russian dolls" supposed take user next message (msgid = 2), in user can reply "interesting" takes them msgid = 0.
my problem when clicking "russian dolls", update method re-run , selects "interesting" instantly. tried prepare had no success, when select "russian dolls", scheme outputs("1, 4") single click.
clicking on first alternative selects first alternative twice , hence returns player original state. can't seem fix:/
so happening here takes input of while mouse button downwards while mouse button downwards execute involved with. need here have not mouse downwards need create if statement this. know sudo code.
boolean ismousebuttondown = false; if(inputformousebutton == true && ismousebuttondown == false && msgid == 2){ //do ever in if statement going next chat ismousebuttondown = true; } if(inputformousebutton == false && ismousebuttondown == true){ ismousebuttondown = false; }
try in code.
java slick2d
Comments
Post a Comment