NPC Help, please

Hello, everyone. I’m making a game that is basically a clone of Pokemon. As those of you who have played know, there are hundreds and hundred of NPCs, each with a name, and something stupid and inane to say. I’m not quite sure how to store these guys. The best example I have is just the stuff from my Java gaming books, where there are no NPCs.

What I’m thinking is that I should have an array of the NPCs, and one class that takes a name (of an NPC), and updates that specific NPC. There would be a method that uses the player’s current position to detect NPC paths within the view (I want to animate the NPC even if only the path, and not the NPC itself, is in view). Then, for each one, it would update it. Oh, and the paths are numbered according to which NPC it is (if the path is 4, it will update npcArray[4]).

Sorry for the convoluted idea. Right now it is the best I have. If there is a better way of doing it, or a good example somewhere in this forum I didn’t find (I looked), I would love if someone could share with me. Oh, and thanks for your help with the last problem I had, too (the keyboard thing).

In tile-based RPGs, I’ve always just made NPCs be regular objects in the map. They were just stored in the object layer of the map with everything else. It was just a 2D array, one element for each position in the map. When they moved, I just set their old position to empty and their new position to their object.

If you have multi-tile sized NPCs you have to either give them multiple tiles in the object layer or just check multiple tiles for things like collisions and drawing. I found the second way to be easier.

I used breadth first search from the player’s location if I had to find an NPC from his name.

If I did it again now, I would probably due the same thing.

An alternative is store NPCs in a separate array along with other scripted objects. I might use quad trees for collision detection (you’ll have to look them up - I don’t know much about them at this point) in this case. I would also have a hash map linking to the npcs by name so that I wouldn’t have to search for them.

Hm, thank you, that was a good reply. I think I might have thought about it the wrong way. I suppose what tripped me up the most is that when the NPCs walk, they of course change images (still, left step, right step). You see, to avoid issues (although perhaps it makes things harder, I don’t know), my main character is drawing separately, not as an object on the map. he just stays in place, points where you tell him to, and marches in place when you make him. I guess I was thinking to do that with the NPC. Although (I just thought of something), the NPCs will still move independently of the map, because I made walking smooth by 12 passes of moving 8 pixels (my tiles are 96 pixels large [Yes, I have 15X9 tiles on my 1440X900 screen]), and the map is dependent on those “steps” to determine position. Soooo… the NPC would stay in one place till he has taken one whole step, at which point he would jump to the next tile, taking his background with him.

So, (thanks for bearing with my rambling- I’m working things out as I type), I guess I would need to implement either individual NPCs, or a separate layer for the NPCs. The problem with the latter option is that I suppose I would suffer the same jumping problem, just without tearing the ground underneath him away, too.

God, this was so much easier when I was programming this game completely incorrectly.

EDIT- Okay, I think I solved one of my problems, by looking at my old (jokingly incorrect) code. I was unsure of how long it would take to update all of the visible NPCs (there could be a few at some points). Buuut, it seems as if I took the number of sprites there were visible, and randomly decided which one to move at a time. So I only need to move one at a time.

I am also piecing together a working way of doing my NPCs.

EDIT 2- Yeah, so I have created a separate layer just for NPCs. I forgot that even though there is a finite point where the NPC switches spots in an array, I can still render it in increments of 8 pixels difference from its previous spot, and after 12 times adjust the layer array. A lot of gratitude to fletchergames for the help. I’d love to program everything now, but it’s one in the morning, and I’ma gonna go to sleep.