Results 1 to 9 of 9

Thread: NPC engine

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Sweden
    Posts
    174

    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).

  2. #2
    Zaei
    Guest
    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.

  3. #3
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    You can make each NPC have a variable which tells if it's a shop, a roaming NPC, an NPC standing still, etc
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Sweden
    Posts
    174

    Wink

    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]

  5. #5
    Zaei
    Guest
    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.

  6. #6
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    VB Code:
    1. If NPC.Left+NPC.Width<Screen.Left Or _
    2.   NPC.Top+NPC.Height<Screen.Top Or _
    3.   NPC.Left>Screen.Left+Screen.Width Or _
    4.   NPC.Top>Screen.Top+Screen.Height Then
    5.     'Don't draw it
    6. End If

    That should help
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Sweden
    Posts
    174
    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]

  8. #8
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Sweden
    Posts
    174
    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
  •  



Click Here to Expand Forum to Full Width