mattkw80; One of the books that I have read that helps explain some of the things you are asking was “Players Making Decisions_ Game Design Essentials” by Zack Hiwiller. It is not about any particular engine or programming language, but instead looks at game design from the point of view of “what do you what the player to achieve ?”. I recommend it.
I’ll check it out - thanks!
Try to make something thats just slightly out of your comfort zone. When implementing something there are many ways to do it that vary heavily based on your game, some are good, some are bad, and many are fine. The only way I know of getting better and figuring out which are good and bad is to try to implement them. So maybe if you want to reproduce stardew then implement one feature at a time. Can you make a guy move around? Can you come up with a system for moving between multiple maps? Can you import the map tiles from a program like Tiled or write your own editor? Etc.
There’s no one magic right way to do things and you will get a better intuition for how to do stuff the more you make things the wrong way.
I can make a guy move around, and tile a map for sure.
I start to fail when it comes to multiple files and classes. So if my current game state is “MENU” when the game first loads… okay, I can make a Title Screen or Menu - all right there in the provided game loop , If (mygamestate == “menu”) { x20 lines of code to draw a menu and handle enough input so player can press ENTER }.
But then the player wants to Play…so they press ENTER… and now the GAME STATE == “PLAY”. My main game file is going to get pretty crowded, quickly. I know I need a LEVEL which has a PLAYER and TILES and ITEMS and MOBS, etc.
^This is where I have a heck of a time. I’ll put each class in it’s own file, that’s no problem.
Tying it all together, that’s where I fall down.
This is where you need to get into OOP/OOD understanding Object Orientated Programming and Design is really going to help you out here.
So I’m not sure exactly what you are asking but I’m going to answer this question I made up instead “Hey my update loop is crowded, how do I go about making it clearer?”
- Having a crowded update loop is not that bad, taking related code and shuffling it into all these classes so that you can’t see the code in context and beside similar code is not great. If your code works then maybe it’s fine?
- The most obvious functions to write are ones that eliminate code reuse, so if you have the same code written out two or more times make it into a function.
- After that I like to try to remove code that is less about game design and more about the framework that the update doesn’t care about. Eg. swapping out a texture is a function that the update loop can call so that updating doesn’t have to worry about how textures are loaded, stored, and drawn.
Charles : “This is where you need to get into OOP/OOD understanding Object Orientated Programming and Design is really going to help you out here.”
^Exactly. This is where I struggle. This is the chasm I’m having trouble getting across.
Yea, it can be a wide one, and from my experience, the best way to learn it is to do it, have you had a bit of a google to get the principles under your belt?
I find the guids you find on this sort of thing, very, very dry lol, so you can come across stuff like this, which is all correct, and propper, but you have no context as to how YOU would apply it, and especially in a game…
I am thinking of doing a series of public posts for beginners, and I think this sort of stuff would be super useful as regard MonoGame.
I was lucky that when I came to XNA I was already a C# programmer, if you are coming to this new to C# and even indeed programming in general, it can be quite hurdle…
I’ve been programming for 15+ years, but not proper OOP. I tend to use VB and Python, where - they certainly allow OOP, they also allow you to … do whatever you want. I’ve had the most gamedev success with Lua Love… no OOP there at all. Proper OOP trips me up. I wish I would have started that way, strictly.
As for the googling - oh yes, I’ve been working on this for 5 years. I get mid point into the HEAD FIRST C# book, and eventually stop, think I’ve done 3 attempts to get through that. I’ve done the Yellow Book… but I don’t recall it showing how to apply OOP in an application. With C#… (or any language really) - it’s not the syntax that trips me up - it always comes back to not knowing how to structure a big project using proper OOP.
Closest I came - was a text based RPG in Python… which I put together solely to see OOP. And it did work, and maybe I need to go back and review what I did there. The idea there was … a GAME has a MAP which has a PLAYER who stands on TILES next to ITEMS and MOBS. If I recall, that was the closest my brain ever came to ‘getting’ it.
If anyone can refer me to a book or article where they had their 'Ah ha! ’ moment, I’d gladly check it out.
I really think starting in VB… and doing 15 years of VB, has screwed me up.
VB (I’m assuming VB6) actually has some OO concepts such as classes. You may have done plenty OO without realising it :).
I’d suggest looking from a different angle - what do you want to do? What game do you want to write? In the past I chose to make computer versions of boardgames as this gave me a ready made spec/design so I just needed to do the programming part.
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.
@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
@Synammon - I will ! Thank you.
We will see how your tutorial fares vs someone who’s brain struggles with OOP.
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
@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.
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.
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.
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.
Thank you all - I will review all of it.