Crossing the Gap from Beginner to Intermediate - how are games structured?

OOP/OOD is of course about objects and the relationships between them. You had a good start on your text based RPG. Your main objects were MAP, PLAYER, TILE, LOOT and MOB. A MAP has TILES. A TILE has LOOT and/or MOB on them. That is a great start on OOP. You need to think on what objects your game will have then abstract them as class. In the class think about the properties, actions and relationships between the object. A PLAYER moves between tiles, that is an action. Create a method in the player class that moves them from one tile to another. What fighting a PLAYER or MOB has a weapon. There is a new object, add a class for it. The player may cast spells or has abilities, those are class. Keep breaking it down farther and farther until you are at the lowest level.

1 Like

@jonathan - Oh yeah, I can make Classes and objects no problem. I’d like to think I understand all the individual OOP concepts listed in the link Charles posted… encapsulation, polymorphism, inheritance, etc. etc. I’ve done countless tutorials on objects - where you make a DOG class or a TEACHER class or a STUDENT class, and then change their properties, run their methods, etc.

Sorry I’m having so much trouble even describing what my problem actually is.

It more along the lines of - within the game loop… working with hundreds of objects from a dozen or so different classes. I think I’m starting to understand… that these things would be in lists. So when the game update loop runs…

Player is standing on Dirt in Level 1 on the game.
Monster1 is standing on Dirt in Level 1 on the game.
Monster2 is standing on Water in Level 1 on the game.
Monster2.drop(“COIN”)

<next turn / loop>

Coin is created.
Coin is standing on Dirt in Level 1 on the game.
Player is standing on Dirt in Level 1 on the game.
Monster1 is standing on Dirt in Level 1 on the game.
Monster2 is standing on Water in Level 1 on the game.

<next turn / loop>

Coin is standing on Dirt in Level 1 on the game.
Player is standing on Dirt in Level 1 on the game.
Player.get(“COIN”)
Monster1 is standing on Dirt in Level 1 on the game.
Monster2 is standing on Water in Level 1 on the game.

So far - I’ve been searching for MONOGAME tutorials, and coming up a little short - I’m going to change my search / see if I can find some XNA full game tutorials. Maybe if I pull someone else’s game apart, I’ll clue in to what I’m missing.

You could try my MonoGame tutorial series Shadow Monsters. It follows OOP and shows how to organize entities. Shadow Monsters - Game Programming Adventures

1 Like

@Synammon - I will ! Thank you.

We will see how your tutorial fares vs someone who’s brain struggles with OOP.

1 Like

You’re most of the way there i think.

What I do is all my objects have an Update method and a Draw method.
(I use an Interface to enforce this - they are really useful for this kind of thing).
I have a list of everything in the game and in the monogame update() I just go through the list and call update on everything.
In the Draw() I do the same and call Draw() on everything.
You can put whatever you like into the update() and draw() for each class.
So the monster update could create a coin object, set its location to the ground under the monster, and then add the coin to the list.
Another monster type, might fire a bullet towards the player at regular intervals.
The player update might involve moving the player a little bit towards where the mouse is.
etc

1 Like

@mattkw80, if you havent seen it already, I have a public git repo here, It’s probably not the greatest example of OOP, but it’s a place to start.

Hope it helps, any questions you have on it I have a post on here where I post updates I make to it here.

1 Like

Thanks everyone - I’ll go through the last several posts in detail asap.

This is the most helpful and friendly DEV forum, I’ve ever been on.

1 Like

I’m a bit late to the party, but if you haven’t seen it yet, I’d like to share CS50’s Introduction to Game Development course.
It’s been available for free on YouTube for a while now.

I suggest that you first watch it all the way through before you try to code any of the examples just so you have a good overview of what’s being covered.
There are some good OOP concepts in there as well as Game State management from beginner to advanced.

It should help you out a lot.

1 Like

Back in the day Microsoft had example content for exactly the sort of issue you’re having. It seems some of it still exists in different places; have a look here at the “Windows Game State Management” Sample:

https://marketplace.visualstudio.com/publishers/XNAGSEducation

I’d recommend manually typing it in yourself from the example rather than copy/past or just “using as is”, it is just an example after all.

2 Likes

Thank you all - I will review all of it.

3 Likes