2021-05-24 10:52:50

Hi,
I want to make a weapon system based on weapon levels. Let's imagine I have a Pistol, who supposedly has three levels, differing in weapon's description, reload speed, damage and range. How should I design it cleverly? Now there's just Pistol1, Pistol2, Pistol3 inheriting from the base pistol class, but its stupid as fuck!
I just want to develop a little fun game.
By the way, why I can't find solutions on my own? Its not good to ask for help every so often.

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2021-05-24 10:56:31

Why not create a WeaponLevel class? You could have something like:

class WeaponLevel:
    description: str
    reload_speed: float
    # ...


class Weapon:
    name: str
    levels: List[WeaponLevel]
    # ...

Then you could create weapons with arbitrary levels?

Not sure if that's the best way, but it's what springs to mind as an immediate thought.

-----
I have code on GitHub

2021-05-24 12:58:04

Good operation, but there are different types of weapons. Sword does not need to reload, but has different properties. This is the problem.

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2021-05-24 14:43:00

then create 2 classes. shootables and swingables?

2021-05-24 16:26:11

There should also be throwables then. Well, your idea is good, I just wonder about other ways, just to know.

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2021-05-24 16:55:55

Yeah, the term you're looking to google is object oriented programming.  It's already been covered here, but there's a lot of good info on how to do this kind of thing if you go find books and stuff on it.

There are lots of other ways to handle the problem, but they're all more complicated and I wouldn't try for anything until you've usefully done something with OOP.

My Blog
Twitter: @ajhicks1992

2021-05-24 20:23:19

Recoil and Cone Of Fire are two other aspects of many ranged weapons, most Diablo style games usually use modifieres that adjust such stats like +10 to range and -10 to CoF for greater range and accuracy. From a design standpoint you may find it easier to break your weapons down into categories, Melee, Ranged, Explosive, etc. and work from there.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2021-05-25 10:30:59

Thank you @6 and @7. I study OOP vigorously now.

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com