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.

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

    if you arent using a game engine then you are creating a game engine. i found this out using monogame with c#. monogame has tons of classes to help you and even a game loop but there is still so much to build

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

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

    The game engine is the integration point for your content. If you’re running into architectural issues that require you to start afresh, it’s probably because you haven’t figured out the requirements for your game and the type of content it requires. For example, if you’re making a Super Mario clone, then it’s pretty easy to design an engine for it since you know exactly what the game will look like at the end. Like @boaratio suggested, don’t try making a generic off the shelf engine, which is something you’ll inadvertently do if you don’t know what game you’re making.

    Then spend some time learning about game engine design. The book “Game Engine Architecture” by Json Gregory is a good introduction, and probably all you’ll need. It’s kind of short and doesn’t go super deep on anything, but it does give you good perspective on everything, and is a good jumping off point for everything else. This ebook also has good content: https://gameprogrammingpatterns.com/ (in particular, read the chapter on state machines)

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

    As someone that has been a professional developer for 20-ish years, and has always dabbled in game development since I was a kid, I can share a couple bits of advice. I’ve written a couple different purpose built engines, and have used a few of the current popular ones as well.

    • Plan your engine before you write a single line of code. It’s fine to do some experiments to work out the technical details of your chosen language/library, but don’t just start coding without planning.
    • Draw a diagram (whether it’s UML or something less formal) of what your engine would need to look like to accommodate the type of game you’re making.
    • Don’t attempt to make a general purpose engine that is fit for any type of game - make sure it works for your chosen game/genre because designing the kitchen sink of engines is futile.
    • Don’t fall prey to the current design paradigm de jour. First it was Entity-Component Systems, then it was Behavior Trees, etc. I know that OO Design has fallen by the wayside, but attempting to learn some new game development/engine methodology in addition to making a game is going to be way more work than it’s worth. More often than not, the simple solution is the best one.
    • Don’t be afraid to refactor. If you’ve programmed yourself into a corner where your engine is hampering your content additions, walk away, and come back with a fresh perspective to see if refactoring can save you time and headache.

    I know none of this is specific to any particular language or tech stack, but that’s the point. Don’t get bogged down in the minutia of it, and instead focus on the big picture. I hope that at least helps a bit - and be sure to share your progress!