Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

How to design world, player, obstacles etc classes so they can communicate, which class does what?

$
0
0
2 few years have passed since I last tried to make my own game and like always I had to give up because I encountered an unsolvable problem. And here I go again, hitting the same brickwall with no solution in sight. My question is: How exactly do I design all my classes so that coupling is minimal when they need to talk to one another somehow. Let's look at one prime example: The player exists inside a "world", an environment, where other entities also reside, enemies, obstacles, chests, whatever. Now the question is, who is responsible for moving the player? The player class itself in something like Player::Update()? But then how does it know if it hit an obstacle or walks on an ice-tile or got pushed back by a boulder that hit him? For that it would somehow need to talk to the world class, or the boulder class would need to talk to the player and tell it "hey I hit you please move back 3 tiles"? Last time I tried to create a game I had huuuuuge "pass down" chains where class D was instantiated inside C but class D needed class F so I also needed to pass an instance of that into C, which didn't need it itself and since it was created inside class B, class B also needed that instance of class F. So I passed that instance along like 10 levels deep in each constructor... Not confusing at all, right? Or maybe should the "world"/level class somehow coordinate everything, move everything, since it knows where everything is, but then how does it know the objects movement logic? How does separation of concerns fall into this, since optimally, every class should only have 1 responsibility. So what should each one do? I don't even know how to describe it properly, hopefully you can understand what I mean. Can someone give me a graph of how everything should be "connected"? Which class should "own"/instantiate what, should the player be instantiated by/inside the world class, or from outside and then passed in? But then in what part of the code should he get instantiated, the main loop? I tried looking for open source projects so I can see how they did it but all of them are wayyyyy too big and I don't even know in which of the 50000 files I need to start looking. Does anyone maybe know a very simple open source game with a similar structure that I can study? (Platformer, or something like zelda, something with a world/obstalces/player etc).

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>