• 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!

RPG: Efficient Initialization of NPC's and Enemies

C

ChaosX2

Guest
Hello,

I started mapping out the algorithm for how I want to go about initializing enemies in dungeons for my RPG. The enemies will roam the map like how the game Chrono Trigger is set up. I started off by thinking I'll use a nested switch case to set the enemy sprite based on the room and xStart position. But because I have been using data structures recently for other parts of my RPG, it got me thinking that maybe what I want to do can be done more efficiently.

I've used the nested switch-case to initialize NPC's sprites and scrolling text dialogue but because the game will end up having a lot of those (and enemies) that's what got me thinking that maybe I can use a ds_grid to initialize all this stuff. I'd like some feedback, clarification, and guidance on how to go about the things mentioned below in the most efficient manner; whether a data structure is the way to go or what.

~Different items for example can have their sprites all set within one sprite resource, separated by frames. But if I want the enemy to have a walk/run animation, would each enemy (and npc) in the game need it's own sprite resource? Is it possible to scroll between a set number of frames for one sprite resource for NPC's? Ex: Frame 0 - 3 is npc1 walk animation. Frame 4 - 8 is npc2 walk animation.

~With the nested switch-case statement I've used thus far, I've always placed the npc object in the room myself and remember the x position to use within the switch-case. Would I be able to spawn NPC's (and enemies) without having to place the object in the room first?

Thanks for taking the time to read this and hope I've been clear in expressing this.
 

Simon Gust

Member
Hi,
I wouldn't worry too much about keeping things small like putting all animations in one sprite. I think it's just a niusance.
For the enemy initialization I recommend Arrays together with enums, they go well together.
For my game that isn't even an RPG it did it the same way:
Code:
enemy[0, E.ID] = obj_enemy_iu;
enemy[0, E.HP] = 110;
enemy[0, E.AP] = 13;
...
 

Yal

šŸ§ *penguin noises*
GMC Elder
~With the nested switch-case statement I've used thus far, I've always placed the npc object in the room myself and remember the x position to use within the switch-case. Would I be able to spawn NPC's (and enemies) without having to place the object in the room first?
You can actually have the object run arbitrary code after it's created (right-click ----> Creation Code). This can be used to set values to variables, and let you give the object dialogue or enemy IDs directly from the room editor, which I personally think is the best way to do it since you can do changes/tweaks directly in the level.
 
C

ChaosX2

Guest
Hi,
I wouldn't worry too much about keeping things small like putting all animations in one sprite. I think it's just a niusance.
For the enemy initialization I recommend Arrays together with enums, they go well together.
For my game that isn't even an RPG it did it the same way:
Code:
enemy[0, E.ID] = obj_enemy_iu;
enemy[0, E.HP] = 110;
enemy[0, E.AP] = 13;
...
Thanks for the reply! I'll take you up on that. That's actually how I initialized the stats of the characters in your party :). Instead of using 0 as demonstrated in your example, there's an enum in there that designates the proper index by character name. I'll do the same for enemies.

You can actually have the object run arbitrary code after it's created (right-click ----> Creation Code). This can be used to set values to variables, and let you give the object dialogue or enemy IDs directly from the room editor, which I personally think is the best way to do it since you can do changes/tweaks directly in the level.
I'll look into it. I have used that method to set the x, y, and room value of doors when going into and outside of a building in town. Would definitely reduce clutter in my switch case. Thanks!
 

Simon Gust

Member
there's an enum in there that designates the proper index by character name.
As Long as there aren't like 50+ enemies it should be a neat way to do it. The reason I can't do it like that is because of how enemies are handled. I set it up a little bit like a Server and client, so I can only access them by number.
 
Top