I am still working on my hud , And I can dump simple messages to it. Now I am at the point where I am starting to think… How do I implement player->NPC dialog(conversation) and How do I allow for line wrapping/ scrolling of my “Text Area” I cannot use swing or awt as I am just using the drawString method to place messages on my HUD. Anyone got any pointers on how to start on this?
Are these messages taking place in like Final Fantasy style speech windows? The problem is knowing when to wrap?
Java2D brought some new stuff to Fonts, allowing you to figure out exactly how big Strings will be and such, that may be helpful.
String myString = "a string";
Font myFont = new Font(...);
FontRenderContext context = myGraphics2D.getFontRenderContext();
Rectangle2D myStringsSize = myFont.getStringBounds( myString, context );
int myStringHeight = myFont.getLineMetrics(myString, context).getHeight();
getLineMetrics().getHeight() will probably return more height than you care about, as it considers, leading, ascenders, descenders, accents, the whole nine yards. I always took that value and just truncated it a tad.
With that info you can know when to wrap, you just have to consider not chopping words in half. But this stuff isn’t particularly fast. A monospaced bitmap “font” would make this a lot easier.
[quote]Are these messages taking place in like Final Fantasy style speech windows?
[/quote]
Yes I am shooting for that. Thanks for the reply. But The other hard part is implimenting the speech/conversation.
Does anybody know where to start on this? ???
I take it you want to do the standard sort of …
<Phrase id = 1>
<InitialStatement>
Hello Adventurer, what can I do for you?
</InitalStatement>
<ReplyOption id="1" action="goto 2">
I need money!
</ReplyOption>
<Reply Option id="2" action="goto 3">
I need food!
</ReplyOption>
<Reply Option id="3" action="end">
Nothing thanks.
</ReplyOption>
</Phrase>
I guess I’d go for an XML document describing each characters conversation skills. Then have an object model that has elements:
Statement, Reply, Action
Where Action might be:
Add New Option
Move to Statement
End Conversation
Give Object
Get Object
Just some ideas…
Kev
I kinda see where your going w/ this and I am really good at working w/ xml but I am kind of confused as to what “go to” is intended to do. Can You please explain further?
What about some kind of finite state machine for all NPCs? Create a generic “speech fsm” class that that can be loaded with conversation options, and the player’s choices during conversations determines which direction the fsm goes in.
It’d be a lot of work initially, but once implemented the quality of your conversations are only limited to the writing itself.
I can try
The “goto” is the XML is probably a pretty poor way to use XML. Better might be to have an actual ELEMENT for Action, then have sub tags underneath for each of the types of action.
The “goto” would move you to another statement. To explain further I’ll give you a nice long piece of XML
<Conversation NPC="fred the baker">
<Statement id="1">
<Text>Hail Adventurer, what can I do for you today?</Text>
<Reply Text="I need money!">
<GotoStatement target="2"/>
</Reply>
<Reply Text="I need food!">
<GotoStatement target="3"/>
</Reply>
<Reply Text="Nothing thanks!">
<GotoStatement target="4"/>
</Reply>
</Statement>
<Statement id="2">
<Text>Hey, I think you're in the wrong place, you might want to try the bank!</Text>
<Reply Text="Ah, Ok!">
<GotoStatement target="1"/>
</Reply>
</Statement>
<Statement id="3">
<Text>Would you like to buy some bread? Only 1 gold piece!</Text>
<Reply Text="Yes please">
<GiveObject type="gold" quantity="1"/>
<GetObject type="bread" quantity="5"/>
<GotoStatement target="1"/>
</Reply>
<Reply Text="No thanks.">
<GotoStatement target="1"/>
</Reply>
</Statement>
<Statement id="4">
<Text>Farewell then, do feel free to drop bye again!</Text>
<Reply Text="Farewell">
<EndConvo/>
</Reply>
</Statement>
</Conversation>
So the baker would start with:
“Hail Adventurer, what can I do for you today?”
You’d be given the options
- I need money!
- I need food!
- Nothing thanks.
Choosing each of the options would lead to other statements and other options…
Is this any clearer/any use?
Kev
;D Much better kevin; thanks for putting so much effort into your reply. I’ll be working on this soon.
Huh, I figured JBanes would have had some input on this topic
I have an implimentation up and running. One Problem if I go into dialog Mode when say a character and NPC collides, as soon as I select a reply that ends the conversation, I get collided w/ again, so Dialog starts again, Leaving my player stuck in endless conversation.
[quote]Huh, I figured JBanes would have had some input on this topic
[/quote]
Sorry, not omnipresent. God didn’t see fit to give me that trait. At least not yet. ;D:
[quote]I have an implimentation up and running. One Problem if I go into dialog Mode when say a character and NPC collides, as soon as I select a reply that ends the conversation, I get collided w/ again, so Dialog starts again, Leaving my player stuck in endless conversation.
[/quote]
You need to set the conversation state to “done” until you leave the presence of the character and come back.
Either
- Set a “dirty” flag, that indicates that the collision has been delt with and needs to be “uncolided” before it should be activated again.
or
- Easier still, make it a key press to talk to someone.
Kev
[quote]* Easier still, make it a key press to talk to someone.
Kev
[/quote]
I think this is the best way game play wise, only how do I know If I should go into conversation or not (Get sprite within certain radius?)
Sounds like a plan. Spose it depends on what you interface uses… is the mouse supported? If so, allow clicking on the appropriate NPC.
If not, then maybe the character “in front” of the player. If you do this, remember to highlight the player that will be talked to if the user presses the “talk” button. Always good to give the user feedback as much as possible
At the outside, you might just keep it as it now, when a player collides with an NPC, they can press a button to starting talking. That way you can choose the NPC by touching them. Alot of RPGs tho, you can talk to people that are some distance from you (behind a fence, on an stage, etc…)
Kev
Eureka!!! I was just thinking, and I realized that the best way to handle it is to prevent another collision once talking starts. i.e. Move the character back a few pixels once he collides. Another option is to only start the conversation only if playerpos+movementRate causes a collision. When the collision occurs, you should make sure not to move the character. (As if the NPC is a wall.)
All Is Going well w/ my speech system. But I just don’t understand how to implement wrapping so it will work for any string. What I want is ->
What do do want Hero?
Reply 1.
Reply 2 Wraps because it is very
long.
Reply 3
I am currently hightlighting the selected reply a certain color. and I would like to continue doing this. The sun examples of LineBreakMeasurer will break this I Think.
???
as tortoise said,
int myStringHeight = myFont.getLineMetrics(myString, context).getHeight();
will get your line height, and then just use the longest unwrapped section of text to determine the width of the highliting… then you could draw a colored rectangle beneath the text you want to hilight.