Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 NPC Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Avarita




PostPosted: Sat Dec 31, 2005 8:37 am   Post subject: NPC Help

I'm making an RPG and I got most of the other things all worked out. However, I do not know how to create NPC's and palce them on a map and have them interact with the player whenever they stand next to an NPC and talk with them. Can someone please help me with this?

Another thing I need help on is that I want to change the control of the game. For example, when the player beats a boss or something, maybe NPC's will change, the maps will be changed. How do I accomplish this?
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Dec 31, 2005 11:18 am   Post subject: (No subject)

Make the NPC's about the same way that you made the player characters. The only differences are that you can't control them and that they have a dialogue(s) associated with them.

I assume you know about classes and inheritence, since making an RPG without this would be crazy. So, you've got your PlayerCharacter class, I assume. Generalize that to be a Character class, then have the PC and NPC classes inherit the Character class.

As for the second question: When you beat the boss, call some procedures that will alter the world the way you like it. The procedures should be part of the NPC/Character class or the Map class.
Avarita




PostPosted: Sat Dec 31, 2005 11:35 am   Post subject: (No subject)

Thanks, I'll try your method. I'll post if I need further help.
Avarita




PostPosted: Sat Jan 07, 2006 5:43 pm   Post subject: (No subject)

So now I have an NPC class with the map that they are located in, their position on the map and what they say when interacted with. How do I find out if the player is standing next to an NPC so that s\he may talk with the NPC?

Also, how do I include cut scenes where thep layer can do nothing while my premade script controls everything. Normally, this wouldn't be a problem but I want to include cut scenes at specific points in the game, liek maybe after the player defeats a boss or walks over a particular position.
Cervantes




PostPosted: Sat Jan 07, 2006 7:22 pm   Post subject: (No subject)

If you're using a grid system, just check if the player is in an adjacent grid. Or perhaps within two grid spaces, without certain types of objects in between, like walls. Otherwise, you might try Math.Distance.

Re cut scenes: It depends on how you have your structure set up. I should think that, ideally, you'd have some procedure to dialogue with NPC's, and they provide options for what to say, etc. If you want a cut-scene, just don't give the user any options. You might set some boolean flag to false to prevent them from clicking other things.

It's hard to answer your questions, because they are so general. Ask a general question, you get a general answer. I don't even know if this is text-based or graphical.
Avarita




PostPosted: Sat Jan 07, 2006 8:53 pm   Post subject: (No subject)

It's a graphical rpg.

I'm indeed using the tile system. So when you are telling me to check adjacent squares, I'm suppose to check the adjacent squares for every single NPC for the current map right?

Something like this?...
use for loop to check through every NPC, if NPC is adjacent, do a procedure to show the particular text of NPC.

For cut scenes, something like this maybe?...

code:

procedure performCutScene (scene : string)
    if scene = "scene 1" then
        perform_scene1
    elsif scene = "scene 2" then
        perform_scene2
    elsif ...
        perform_scene...
    end if
end procedure

loop
    if player_control then
        checkKeyInput
    end if
    if cutscene not= "" then
        performCutScene (cutscene)
        cutscene = ""
    end if
    render_game
end loop


And then each cut_scene procedure would have it's own screen rendering code.[/code]
Cervantes




PostPosted: Sat Jan 07, 2006 10:08 pm   Post subject: (No subject)

A graphical rpg, you say? We have a pattern with those... let's hope you can break it. Wink

You could check adjacency with each NPC on the map. Note that if this slows things down, you can segregate the map into larger grid sections, and only compare adjacency for NPC's within the same big grid as you (or an adjacent big grid, in the event that you and the NPC are on the boarder of a big grid line).

As for the code you posted, a few things: a case statement would much better serve. But even yet, you basically created the performCutScene procedure to relate a string to a procedure. You have to determine the magical string in the main program, so why not just type out the procedure's real name?

If you have some better reason for having a performCutScene procedure, you might want to consider saving yourself from making a very long if/case structure. You can store procedures in variables, believe it or not. It's just very limited. I'm not in Windows at the moment, so I can't give you a full demonstration, but I can tell you it will begin with
code:

var cut_scene : array 1 .. 10 of procedure p
md




PostPosted: Sat Jan 07, 2006 10:22 pm   Post subject: (No subject)

Another way you could do it is to store a list of all objects in each grid tile in your grid, that way ify ou want to know if something is on a particular tile you just need to search a short list. Checking for an NPC adjacent to the PC would be as simple as searching the lists for the 8 adjacent tiles.
Sponsor
Sponsor
Sponsor
sponsor
Avarita




PostPosted: Sat Jan 07, 2006 10:42 pm   Post subject: (No subject)

Hey, putting procedures into variables actually work! Thx for that info.

I think I know how do it now, thx! As for your idea Cornflakes, it seems to take too long to input everything onto specific tiles and maybe I would like for NPCs to walk around a bit too.
md




PostPosted: Sat Jan 07, 2006 11:10 pm   Post subject: (No subject)

it's really not that hard, but it does require extra work. It would increase speed if you have lots and lots of objects in the map though.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: