Jump to content
  • Advertisement
Sign in to follow this  
Keyeszx

Would this be the right way to think about a game

This topic is 1346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've tried reading books and various sources for making a game but I tend to get lost as I get more into it.

 

I was wondering if I could have something simple and the game still work? I don't have any code but I've been trying to think of a simplified way to think about the code, simple enough that it'll run.

class game
{
   main()
   {
      createWindow();
      gameLoop()
      {
         Update();
         Render();
      }
      closeWindow();
      return 0;
   }

   Update()
   {
      CreateObjectEntities();
      Input();
      UpdateObjectEntities();
   }
   
   Render()
   {
      //I have no idea what kind of methods go in here
   }

   CreateObjectEntities()
   {
      //Creates objects and add them to an array? I don't really know how to handle this
   }

   Input()
   {
      //Looks for input and updates player
   }

   UpdateObjectEntities()
   {
      //AI method that updates all the NPC characters
      //Method that checks if anyone was hit, killed, falling, etc.
      //Any other methods to update anything?
   }
};

If I went about making a simple game with psuedo-code as like a guideline would this be fine? Am I forgetting anything, I know I probably am? Would something need to be put in a different order? How should I go about handling rendering things? Should I put all the object/entities made that will be displayed into an array and then in the render method read from that array and render through the information given in that?

 

Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement

Yes, that could work for a game, but you should start writing one, don't spend too much time thinking about it, you are already on track. If you're not confident enough to start one from scratch follow a tutorial, it's a good way to start.

 

Some changes I'd make are:

  • Before the gameLoop you should initialize more things, not only the window. If you make, say, a basic Pong clone, you can intialize both paddles and the ball there.
  • "CreateObjectEntities" in your pseudocode will be done every iteration of the game loop. I wouldn't do that, updating other ObjectEntities should be the trigger to create new ones (you update a training building and create a new soldier if a timer finished).
  • 2 things about "Input()"... first, when you translate this to actual code, do not use "Input" as the name of a method, use a verb, "GetInput" or something like that. Second, your comment was "//Looks for input and updates player". The player probably should be an ObjectEntity, so the update should be done in UpdateObjectEntities with the rest, the "Input" method should only transform a generic event ("space bar pressed") to game related events ("shot key pressed").

You can use arrays to hold all the objects and sometimes you want more than one array (one for drawable objects, another for non drawable objects, etc...). But, really, start making a simple game, it's easier to learn one thing after another than everything at the beginning.

Share this post


Link to post
Share on other sites
One thing I've learned about beginning Game Programming: don't think about it too hard. Just start or follow a tutorial to help ha get started. Of you think about it too hard when you're a beginner you will get lost and never get done. Just start and don't worry about things too much. Your first couple games will not have the best code design at all . Just code and finish the game. Take notes about what felt like should had been easier. Can even ask for a code review here. Then in your next game try to implement those details you learned or took note of. If you keep doing this while making simple games before you know it you will have no problem knowing how a game works and how the next game you want to make should work.

Share this post


Link to post
Share on other sites

To add to chad smiths comment, you can also always go back and rewrite / refactor old code of yours.

 

This can be actually very enlighting and a good lesson in just how much you improved since you last touched the code. It can also be quite the chore because you have to redo a lot of code, and sometimes you feel like you are "changing the running system" for no good reason.

 

It is only when you take some a year old, horrible code, and try to plugin some additional functionality (it is going to be a pain, if you have not written it well and with that in mind), and afterwards you rewrite the code and have the additional functionality plugged into the rewritten code effortlessly, that you see how much well (re)-written code can make your life easy.

Still, without the horrible first version, you wouldn't be able to come up with the better one, and would still have nothing. Or you would be writing the horrible version right now smile.png

 

 

Never be afraid that your code might be horrible. 1) You can always go back and rewrite, if you are not on a deadline, 2) if you are on a deadline, either you are already a good programmer and expected to churn out quality code in a short time, or it likely will not matter that your code is horrible (a lot of code in the real world is badly written, but functional, in my expierience. It is what happens when you put an inexpierienced or not highly motivated programmer under pressure, and are not expierienced enough yourself to judge to result)...

 

and finally 3) You learn by making mistakes. Don't expect someone to tell you all the mistakes you could possibly make, noone is inventive enough for that. Don't look for shortcuts when the only one to just invest more of your 24h per day into churning out code and learning from your mistakes.

 

 

 

my 2 cents as a professional programmer that is still regularly shocked at how bad his code was in this thing he coded a year ago smile.png

Edited by Gian-Reto

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!