|
-
Oct 24th, 2001, 12:15 PM
#1
Thread Starter
Addicted Member
NPC engine
I need help with an NPC engine to my RPG. I have no idea of how this would be done so any help is welcome.
The engine should include both shops'n stuffs, and people walking around (which is the main problem) the town. The engine is just tile-base (i'm somewhat new to it, so i start with that).
-
Oct 24th, 2001, 02:35 PM
#2
Since you just want roaming NPCs, this is fairly easy.
You should create a class for an NPC, and have several variable in the class. An "Idle" Boolean to tell you when it not doing anything, A direction vector (POINTAPI, or custom type), a distance (long, integer, or byte variable), and a few methods to do various things(set position, get position, etc). Now, when you update your objects, just check to see if the NPC is idle. If so, clear the idle bool, select a random direction, a random distance, etc, and move the NPC at a certain speed, until it's gone it's distance. Then set the idle flag to true.
Z.
-
Oct 24th, 2001, 05:34 PM
#3
Frenzied Member
You can make each NPC have a variable which tells if it's a shop, a roaming NPC, an NPC standing still, etc
-
Oct 25th, 2001, 03:25 AM
#4
Thread Starter
Addicted Member
So i'm going to make a NPC class which includes an Idle boolean varaible, if it's true, then it randimizes direction and lenght, the idle value is kept false until it's done, the NPC moves 1 (or whatever) point each time, until it's done, then the idle value becomes true. The class should also include info about whenever it's a shop, roaming NPC or standing NPC. I think i get it 
But how do i know if i have to draw the NPC or not (if it's outside the screen)?
[In time of development time stands still]
-
Oct 25th, 2001, 06:35 AM
#5
Check the position against the edges of the screen. If the screen's top left corner is at 100, 100 in your world, with a screen width of 640x480, you know that if any NPC is not within a rectangle starting at 100, 100 with width and height 640x480, dont draw it.
Z.
-
Oct 25th, 2001, 07:56 AM
#6
Frenzied Member
VB Code:
If NPC.Left+NPC.Width<Screen.Left Or _
NPC.Top+NPC.Height<Screen.Top Or _
NPC.Left>Screen.Left+Screen.Width Or _
NPC.Top>Screen.Top+Screen.Height Then
'Don't draw it
End If
That should help
-
Oct 26th, 2001, 01:46 AM
#7
Thread Starter
Addicted Member
I get it. I'll just have some problemes with the speed, and covering the "traces" of the NPC's, but i can manage to fix that myself.
Thanks for the help
[In time of development time stands still]
-
Oct 26th, 2001, 02:46 PM
#8
Frenzied Member
You're welcome 
If you really wanna make your game more interesting, you could also have a simple script, like a group of variables like this: one would define the condition (player touches the NPC, player attacks the NPC, etc), another one would defind the action (set a flag, attack the player, move somewhere else...) and one or 2 more variables would be the parameters, like the number or name of the flag, or the coordinates where it's going to move to.
If you really wanna make it better, you could even have an array of these things for each NPC, and for each of them an array of conditions, an array of actions and an array of parameters for each action or condition Of course this is a bit more complicated and it's not needed, but if you think you can do it, give it a try
-
Oct 27th, 2001, 08:04 AM
#9
Thread Starter
Addicted Member
I will, thanks for the help
[In time of development time stands still]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|