this post was submitted on 15 Jun 2023
9 points (100.0% liked)
Gamedev
15 readers
1 users here now
founded 2 years ago
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
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.