Narthenian, Part 2

Dialog scene from the game

I got the initial framework for NPCs and dialog set up, and I have uploaded the code to Github. You can find the game in its current, very early state, at https://github.com/jstoddard/narthenian. There are only a couple of NPCs and very simple dialog at this point: They only say one thing at you. There are some data structures and framework for a more complicated dialog system in which there can be some back and forth, with the player selecting a keyword or phrase from a menu to continue the dialog, and with NPCs able to give the player an item or update a quest. These features, however, need a lot more work to be implemented.

NPCs are kept in a vector in the AreaMap in which they are located. In the drawing routine that is run each frame, the game iterates over the NPCs in the current map and identifies and draws the ones that are within the bounds of the screen. The game interprets an ENTER keypress, and in the future the A button on an XBox controller or corresponding button on another gamepad (this was already implemented in the BASIC prototype) as a command called “ACTION1.” When the game receives an ACTION1 command, it looks for an NPC in the tile that the player is facing. If an NPC is there, the game goes into dialog mode, which currently comprises displaying the NPC’s dialog on screen and waiting for the player to hit ENTER again (or SPACE a.k.a. “ACTION2”) before returning to the normal mode of letting the player wander around the map.

Before fleshing out the dialog system with the upcoming features, I will probably set up merchants and inkeepers so that the player can rest and buy weapons, armor, and other items. I think that doing so will go a long way toward making this early stage of the game somewhat fun to play—an important consideration, since I need to spend a lot of time playing it, even in its unfinished state, for testing and bug-catching. I am not sure yet whether I will subclass NPCs for these characters, or make separate classes for them. There are some tradeoffs to consider. If they are subclassed from NPC, a single loop can handle drawing of all three character types, and another single loop can handle the ACTION1 command as discussed above. However, the latter is somewhat complicated by the fact that a merchant or inkeeper will often be behind a counter, so checking will be a little different, and we will want to switch to a shopping system or sleep system that will probably be distinct from the dialog system. This can be handled by moving the checking and mode-switching code from the loop into virtual functions in the NPC class, and just having the loop call those functions instead. The Merchant and Inkeeper subclasses would just override the functions.

Well, I’ll decide what to do over the next day or two. Meanwhile, I have a couple more monsters to add to the world, as I think I mentioned in the last post.

Leave a comment