Best way to structure "MOBA Type Game"

So I’ve thought this up a million different ways and I’m still not sure how to go about this.

I have a basic platforming engine written up etc etc, but as far as structuring the “each player with their own spells” I’m not sure how to go about it.

Basically I just need some pseudo-code to point me in the right direction.

I’m not asking for the code to all be written for me, just an example and a direction to go in.

Each champion will NOT need his own logic (just being able to change health, health regen etc etc etc).

Spells obviously on the other hand, will all need their own logic.

I need a rough outline of how to go about this.

Thanks for reading :slight_smile:

Well if each character has roughly the same logic, then they should all be of the same type (class) or subtypes of the same type.
If the spells are different, then have a Spell interface and use composition:


public interface Spell {
    public void cast(); // add applicable arguments like: Player target, etc.
}


public class Player {
   
   Spell spell;

   // additional common logic here  //
}

This way you can create players with different spells easily like so:


Player bjorn = new Player("Bjron", ..., ..., new FireSpell(..., ...));

You still have to write different spell implementations, but the rest of the code only has to deal with the 1 interface.
This can also be done for pretty much anything that is specific to different players, like appearance. You probably do it all the time without thinking about it:


new Player(AssetLoader.getTexture("wizard"));

Same deal.

BurntPizza, thank you so much for your reply!

I just put it into some test code and it ALLLLL makes sense now. Wow so basic and yet I looked right past it.

Thank you so much, I totally know how to go about it all now :).

I will post my results of how it turns out later!

Thanks again, that really put me in the correct mind state too, thanks again!!

Can’t wait for the update! I love watching people learn and grow.

No problem :wink:

Also, for more cool stuff like this, head over to http://gameprogrammingpatterns.com/
(EDIT: it’s not my site, not taking any credit for it)