I need feedback on my design for the dialogue feature I am working on. If you have any recommendations on your design or how I can structure the code better, I will gladly listen to them. Working on a role playing game has been tough but the codebase grows so much in a week! I would think I would be used to this after finished working on small prototypes of simple games.
This feature right now is for one Soldier NPC that is a talking quest givers for my role playing pc game in Java. Future npcs will inherit the below instance variables from a class called NPC.
public class Soldier extends Sprite implements Collidable,Talkable
{
// This is an enum of 4 possible states: attacking, healing, running and idle
private ActionState state;
private SoldierIdleAnimation soldierIdleAnimation;
// for bounding box collision to trigger the talk button indicator
private Rectangle rectangle;
// This is the question mark image on the top of its head when a quest is not done
private QuestNotFinishedImage questNotFinishedImage;
// This is the exclaimation point mark to indicate you have satisfied the requirements for the quest.
private QuestFinishedImage questFinishedImage;
// This is an enum with 2 possible states: Finished and NotFinished
private QuestState questState;
// This is an indicator that pops up when you are near the soldier which means you are near enough to talk to it
private NPCTalkImage npcTalkImage;
// This gets turned on when the main character is near the soldier to trigger the talk button indicator
private boolean canTalk;
// This is the dialogue bar for the npc. Each npc will get their own dialogue bar.
private NPCDialogueBox npcDialogueBox;
// This gets turned on when the main character presses the T button
private boolean isTPressed;
// This is also an enum with 2 possible states: isRunning or IsNotRunning
private Dialogue dialogue;
}
The second question I have is: does this code look overkill for a colliding with talking npcs algorithm for my main character class
for(int i = 0; i < charactersToAdd.size();i++)
{
Talkable character = (Talkable) charactersToAdd.get(i);
/* make sure the rectangle is not from the main character
* because you do not want to collide with yourself
*/
if(character != this)
{
// get rectangle from the characters in the list besides main character
Rectangle rectangle = character.getRectangle();
// if main characters bounding box collides with the npc bounding box
if(getRectangle().intersects(rectangle) )
{
// make the talk button indicator appear
character.setTalk(true, isTPressed);
}
else
{
// make the talk button indicator disappear
character.setTalk(false,isTPressed);
}
}
}
}
The third question is how much should I plan when making an RPG? So far development has been okay. Every feature had its failure before finally getting it to work properly. I was able to get by so far with what I have done with a rough outline of the working implemented feature in my head.
This is the first time I am working on an RPG. Working on this type of game made me remember how much code is required to get something simple to work.