• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Need tips for NPCs

N

Nuss

Guest
So in my game, I want to make NPCs that will walk around the town, but I want them to specifically stay in the town and not wander out of it. I also want to make them say something if you press near them (their text will be displayed with a dialog box at the bottom of the screen with an animated portrait of them. Kind of like Cave Story+.)
I don't know very much code and I haven't started making the NPCs yet because I would like to know how to approach making these NPCs.
If you post any code, I won't simply copy and paste it, instead I'll type it in and adjust it as I need, that way I actually get a tiny bit of experience.
If you need examples of how the portraits will look, I can make a mock up for you.

Btw, the game is a 2D platforming metroid-vania styled shooter that is still extremely early in development.
 

CloseRange

Member
Best thing I can suggest is just follow tutorials that interest you and just do those.
It's hard but honestly you should follow along an entire platforming tutorial or something and learn coding before making your own game.
Once you have gotten good enough at programming you can make a whole game without needing any help or tutorials and when you need something game specific (like an npc who doesn't walk out of range in a platform game) you can do it on your own for the first time.

But that's just a thought.
For an npc not leaving the a town first you need a way to define the bounds of the town. Best thing to do is have invisible walls that you place on the bounds of the town.
1) Have the npc set a direction to move.
2) at that same moment set an alarm to some value (for example alarm[0] = room_speed*5; this means 5 seconds)
3) in the step event always have the object moving in the target direction.
4) in the alarm event, repeat steps 1 and 2
5) in the step event constantly check if you are about to hit that invisible wall.
6) if you're about to hit that wall, repeat steps 1 and 2

as for dialog
1) in the step event check if you are close enough to the npc
2) if you are, check if you have pressed a button (the talk button)
3) if you do, check if there is a dialog object in existstance.
4) if there isn't create a dialog object and set its text and what image to display
IN THE DIALOG OBJECT
6) draw the text in the draw event (along with the sprite)
7) in the step event check if you press the 'continue' key
8) if so delete the dialog object
IN THE PLAYER OBJECT (note this can be skipped if you want the player to move while there is text)
9) check if a dialog object exists
10) if one does exist, stop all other movement

And there is more you can add if you, for say, want to chain dialog messages. (chaining might use a form of recursion or arrays or setting id's to dialog objects)
 
N

Nuss

Guest
Best thing I can suggest is just follow tutorials that interest you and just do those.
It's hard but honestly you should follow along an entire platforming tutorial or something and learn coding before making your own game.
Once you have gotten good enough at programming you can make a whole game without needing any help or tutorials and when you need something game specific (like an npc who doesn't walk out of range in a platform game) you can do it on your own for the first time.

But that's just a thought.
For an npc not leaving the a town first you need a way to define the bounds of the town. Best thing to do is have invisible walls that you place on the bounds of the town.
1) Have the npc set a direction to move.
2) at that same moment set an alarm to some value (for example alarm[0] = room_speed*5; this means 5 seconds)
3) in the step event always have the object moving in the target direction.
4) in the alarm event, repeat steps 1 and 2
5) in the step event constantly check if you are about to hit that invisible wall.
6) if you're about to hit that wall, repeat steps 1 and 2

as for dialog
1) in the step event check if you are close enough to the npc
2) if you are, check if you have pressed a button (the talk button)
3) if you do, check if there is a dialog object in existstance.
4) if there isn't create a dialog object and set its text and what image to display
IN THE DIALOG OBJECT
6) draw the text in the draw event (along with the sprite)
7) in the step event check if you press the 'continue' key
8) if so delete the dialog object
IN THE PLAYER OBJECT (note this can be skipped if you want the player to move while there is text)
9) check if a dialog object exists
10) if one does exist, stop all other movement

And there is more you can add if you, for say, want to chain dialog messages. (chaining might use a form of recursion or arrays or setting id's to dialog objects)
Thanks for the tips! And yeah, this game I am just kind of experimenting with and I don't really have release plans as it's more of a thing I work on to pass the time.
 
O

Owen Skelly

Guest
Well first you can make a basic sprite. 64x64 make it semi transparent by adjusting the image alpha. Make a new layer in your room and title it collision. Place those collisions as if they were boundaries for the npcs. Then hide that layer. Then write out your if place meeting and fill that out for every direction. Up, down, left, right. Then if the Npcs collide with it make a var called direction. Choose an irandom between 1 and 360 and set that to direction to make them randomly walk away. Hope this helped.
 
Top