2D Combat System?

Hey guys, I’m currently / still developing a 2D kind of rpg game, inspired by games like Zelda: The Minish Cap and similiars. I already implemented a battle system, which for me means the player was able to attack enemies with a sword hit, cast spells and get attacked by enemies. However the whole thing ended up in quite a mess and wasn’t really robust, maintainable or extandable. I was thinking about that it might be easier or better for my game to implement a combat system in games like Diablo instead.

Does anyone have any recommendations what implementation wise is easier to realize? Furthermore can you recommened any articles about how a good combat system works in detail (regardless of being Diablo style or “realtime” style like zelda)? Something I might get a little bit inspiration from?

Thanks in advance.

pretty vague and extremely open question…

for my latest game the player has an int called myWeaponID, which has the name of the weapon, and when player pushes the attack button, it checkes which bullets to spawn based on the myWeaponID. So the shotgun spawns 3-4 shotgun-bullet types with a random pattern, and the machinegun spawns 1 machinegun-bullet type but has a higher spawn frequency for faster shooting.

that’s probably an answer to your question!

Thanks for the reply, yeah I kept the question quite unspecific to generate a lot of input, hopefully :smiley:
Did you use object pooling for all of your bullet types?

How would you realize that with a melee weapon? Similiar?
That would be my guess:

  1. Check Weapon ID,
  2. Spawn collision rectangle according to weapon ID in hit direction,
  3. Let the collision rectangle disappear after a certain amount of time (when the hit is done)
  4. Apply hit, or don’t

well yeah, my melee weapons usually generate an invisible bullet of a smaller size and no movement.

Bullets are an array of a bulletEntity class, and I re-use the “died” objects. So there’s no memory garbage-collection going on. (I also do this for all other entity objects)

Thanks, that’s a really cool idea. I just figured you had a hit box for the sword or something but the bullet thing makes a lot more sense.

You probably do not want melee attacks to work like range attacks because melee attacks usually must move with the user. That is, their position is relative to the user whereas range attacks exist by themselves. Think: punching someone vs throwing a shoe at them. You do not have to do it this way but it is just something to keep in mind.

Also, combat systems are only as complicated as you make them. In my opinion, at their highest levels, they are all just chunks of code, abilities or attacks, that can be started, stopped/ended, and updated. Even things like weapons fit into this pattern. That hardest part is creating a interface that your engine can call easily. The actual logic part is usually very simple, albeit debugging is always a hassle.

Thanks for the input, I definitly see your point. What about a combat system like the one of Diablo? For example I rightclick an enemy and my character starts auto attacking the target, are hitboxes usually required there? Or is it rather like if the distance to the target is close enough simply go into a battle states and attack each xxx seconds?

idk if this will help any or not.

I am working on my Combat System in a 2D Top Down RPG, I wrote a Cache system to hold the sprites and some info.

as an example when I add new items into my game I do so through this tool, I give the items their bonuses and required levels and skills to equip the item in question. I also added an option to know if the items is a weapon, if it is I have to give it an “attackSpeed” byte I am using 1-5 1 being the slowest 3 is “normal” and 5 is Fastest.

So when I go to begin Combat before each “attack” I check the equipped items and get the attackSpeed based on the equipped item ID

I am doing it this way so you can switch your equipment on the fly in combat, I don’t have a class system, you are what you equip.


Yeah, the second thing you said.

Thanks guys, your input really brought some light into the darkness for me :slight_smile: !