If I just have C++ and say SDL or Raylib, how do I structure game code to keep it scalable (ie not a huge mess when I add more levels, items, mechanics, etc)? I have been able to make very simple stuff but the moment I try to add to it, it always gets out of hand and I can’t really refactor it without starting fresh.

  • Stardust@kbin.social
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    No one has mentioned this yet, but break it up into multiple files or at least separate out some of your logic. You might also consider using a simple database for things like levels, items, etc, so that adding a new item follows a pre-established item scheme. The easiest kind to implement is just a bunch of files with values separated by ‘,’ if you are absolutely determined not to use any libraries.

    Ideally, your logic for potion item effects and the actual item potion should not be in the exact same place. Instead, your potion should do something like have an ‘effect’ set, so if you later wanted to add yet another potion, you could end up with a database table looking like this:

    Itemname | Effect | Effectvalue | Spawn | Use
    Potion, ChangeHP, 10, common, Drink
    Better Potion, ChangeHP, 20, rare, Drink
    Sword, ChangeHP, -5, common, Weapon
    Staff, ScaleDMGwithStat, Wisdom, bossdrop, Weapon

    Do a loop creating a new member/extension of the Item class with the inputs from the table, attach a simple function called Use that looks up that data and decides what to do as appropriate to the effect.

    This will help a lot in keeping things nice and clean. Simply adding a single new item or monster should not be forcing you to start fresh.