Jump to content

  • Log In with Google      Sign In   
  • Create Account

Game from Scratch ? C++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
20 replies to this topic

#1 Sugavanas   Members   -  Reputation: 200

Like
0Likes
Like

Posted 15 December 2012 - 08:22 PM

Guys, I am back and now I have started learning C++ and know to create codes( But still on basics Posted Image ) . Can any one of you give me a code for making a game ( like tic tac toe) from scratch in C++. Please also explain it so i could understand it.

Sponsor:

#2 ultramailman   Prime Members   -  Reputation: 1570

Like
11Likes
Like

Posted 15 December 2012 - 08:38 PM

To write your own game from scratch, use this:

int main(void)
{
     return 0;
}

Now you will have to add your own code to it, and turn it into a game.

#3 Dragonsoulj   Crossbones+   -  Reputation: 2110

Like
3Likes
Like

Posted 15 December 2012 - 09:13 PM

Just start small. Take ultramailman's post and go from there. Store the state of the tic-tac-toe game in an array, 9 separate variables, or a string you constantly parse. You can output a grid easily using the pipe | and the dash - characters. Input can be as simple as entering a number from 1 to 9 (or 0 to 8) that represents the space you want to take your turn in. Save that and move on to the next turn. Don't let someone select a space that already has an X or O.

Maybe when that is working, create a little "AI" that you can play against. Get creative, make it a 4x4 grid instead of a 3x3. Just start small, work piece by piece, and you will start to see your game.

#4 GameCreator   Members   -  Reputation: 755

Like
0Likes
Like

Posted 15 December 2012 - 09:51 PM

Are you using an engine or library at all for anything visual or is it all text output at this point?

#5 lride   Members   -  Reputation: 633

Like
2Likes
Like

Posted 15 December 2012 - 10:12 PM

But still on basics


If you are still on basics, you can't make a game.
Learn the language first.
An invisible text.

#6 GameCreator   Members   -  Reputation: 755

Like
2Likes
Like

Posted 15 December 2012 - 11:33 PM

That depends. A random number guessing game is just a few lines of code and doesn't require intricate knowledge of a programming language.

#7 ByteTroll   Crossbones+   -  Reputation: 1382

Like
0Likes
Like

Posted 16 December 2012 - 03:37 AM

That depends. A random number guessing game is just a few lines of code and doesn't require intricate knowledge of a programming language.


GameCreator has a valid point. My suggestion is to start small. Take GameCreator's advice and create a random number game. After you finish that, take a stab at another little game. You need to build up your skills (which is often overlooked by new programmers).


But still on basics


If you are still on basics, you can't make a game.
Learn the language first.

This is the hard, but very real truth. You can't create a game in a language if you do not know the language. Learn your basics and learn them well.

EDIT: I figured I would answer your original question as well. If you look online quite a few companies have released the source code to their games. Id Software's Doom 3 comes to mind. You can find the source code here. With that being said, be prepared to have it handed to you. The level of coding that goes into games is extremely high. With that being said, however, studying other peoples code is an important part of learning to program.

Edited by ByteTroll, 16 December 2012 - 03:44 AM.

▬▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬▬▬▬▬
I see the future in 1's and 0's
▬▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬▬▬▬▬

"This is called programming. The art of typing shit into an editor/IDE is not programming, it's basically data entry. The part that makes a programmer a programmer is their problem solving skills." - Serapth

#8 Radikalizm   Crossbones+   -  Reputation: 2881

Like
1Likes
Like

Posted 16 December 2012 - 04:32 AM

The level of coding that goes into games is extremely high. With that being said, however, studying other peoples code is an important part of learning to program.


I very much agree that studying code is an important factor, but I don't believe it's applicable yet to the OP.
At this stage a good understanding of the language is a priority, especially so with C++ as there are so many ways to write functioning but terribly written C++ code. Source code for finished games might not always reflect the best practices, or might just do some things in a terribly hack-ish way because of time constraints or because something needed to be fixed quickly (I haven't looked at the source code for Doom myself, so I couldn't say whether this applies here).


Getting code for complete games just handed to you is not going to be all too helpful right now, it mostly encourages copy-paste behaviour and unless every technique/pattern/whatever used in the code is thoroughly documented, you probably won't understand the reason why the developer chose to use a certain technique at a certain location, or what the technique is even supposed to do.

The important thing now is to understand how to use the basic paradigms provided by C++ correctly at an elementary level, and how to properly implement problem solutions with these. Learn about the basic OOP principles, learn about what kind of functionality C++ provides to support OOP, learn about what kind of useful stuff the C++ standard library provides, etc. and work your way up starting from a very simple 'hello world' application while applying the concepts you've learned and using the data structures (eg. lists, maps, vectors, queues, stacks, etc.) and functionality you've read about.

Once you have some knowledge of object-oriented design and the tools your language provides it'll become clearer to you how to implement a simple game such as tic-tac-toe yourself.

I gets all your texture budgets!


#9 J. Evola's Apprentice   Members   -  Reputation: 307

Like
-6Likes
Like

Posted 16 December 2012 - 04:57 AM

Here you go: https://github.com/TTimo/doom3.gpl
It's far better than tic-tac-toe.

#10 Memories are Better   Prime Members   -  Reputation: 769

Like
0Likes
Like

Posted 16 December 2012 - 08:56 AM

Copy pasting doesnt work in game programming (or programming for that matter), learn your language well then consider game programming, even using an engine like ogre / panda3d would require you to understand your language. Think of it like this, what you are trying to do is make a movie on your own but in French and you can only understand basic french words, despite having all the equipment and resources you cant speak French very well.

Learn the language then move onto the movie,.. I mean game

#11 DARSC0D3   Members   -  Reputation: 379

Like
0Likes
Like

Posted 16 December 2012 - 10:48 AM

Why won't you do a search online there are tons of game projects that have there source code publicly available.

#12 farmdve   Members   -  Reputation: 194

Like
0Likes
Like

Posted 16 December 2012 - 10:50 AM

And my suggestion, is to to practice with C++ for at least a year. Once you've coded a few stuff, then go to programming games. I know this is harsh, but it's correct.

You'd need to practice with boolean expressions a lot. Statements like if(!(var && !var2) && (!var3 || var4)).

Edited by farmdve, 16 December 2012 - 11:07 AM.


#13 Psilobe   Members   -  Reputation: 193

Like
1Likes
Like

Posted 16 December 2012 - 04:36 PM

Learning a language is important but what is even more so is that you understand different programming principles. Functions, variables, comparisons, operators, containers, loops etc.

I suggest starting with writing small programs that do different things, not just games. Find different ways to manipulate data. Find and solve your own small problems. Try to implement a basic sorting algorithm, that sort of stuff.

When it comes to simple games that doesn't require anything fancy I generally divide the code in to three parts. Input, read user input and handle it accordingly. Update, update the game state accordingly to the game rules. Drawing, draw everything to the screen.

If I want to put together a simple game I just need to figure out how to represent the game state and then fill in these three functions.

#14 JonathanJ1990   Members   -  Reputation: 167

Like
0Likes
Like

Posted 17 December 2012 - 03:39 AM

To write your own game from scratch, use this:

int main(void)
{
	 return 0;
}

Now you will have to add your own code to it, and turn it into a game.


I'm Sorry but this comment made me grin from Ear to Ear lol! As all the others said it's best to start small and move forward. my very first game was a text based CYOA ( Choose Your Own Adventure) , which eventually gave way to a text based RPG, which eventually gave way to a basic platformer, and etc. etc. and I definitely think looking at someone else's code and dissecting it can help but there are some principles you won't understand until you play with them yourself like the game loop . and how to best set up a basic game progress. any how goodluck!

Edited by JonathanJ1990, 17 December 2012 - 03:43 AM.


#15 silv3r.m00n   Members   -  Reputation: 103

Like
0Likes
Like

Posted 18 December 2012 - 05:07 AM

start with javascript if you want to learn quick.
otherwise most of time would be spend on fixing syntax errors in c++

#16 darkhaven3   Members   -  Reputation: 160

Like
0Likes
Like

Posted 18 December 2012 - 06:37 AM

I really feel like as a beginner vanilla C is going to be more intuitive and straightforward than trying to learn C++ out the door.

I know I'm probably sounding facetious, but frankly, C versus C++ provides scant, almost zero advantage one way or another as either way whether you write C++ or not you're going to be compiling C at the end of the day, and is all up to whether or not you think you need the concept of distinct objects that are protected from access from one another and things like generic code or compile-time code generation, or operator overloading to make a decent program.

Give C a try if you're on the basics, and see if you pick it up faster than C++. If you *need* some feature of C++ at some point later for any reason, then by all means, use C++ if it suits you at that point.

I also laughed uproariously at ultramailman's post.

Edited by darkhaven3, 18 December 2012 - 06:38 AM.


#17 Riphath   Members   -  Reputation: 151

Like
0Likes
Like

Posted 18 December 2012 - 07:08 AM

I really feel like as a beginner vanilla C is going to be more intuitive and straightforward than trying to learn C++ out the door.


Honestly, I feel if the OP is learning C++, let them learn C++ without telling them they need to learn regular old C. They're both Turing-complete languages, each with pros and cons. I personally find C++ to be more intuitive than C, but if someone is learning C then I'm not going to suggest switching because of my personal taste. (sorry Posted Image I just feel like discussions of which language is better, especially with C/C++, are totally pointless and especially don't help a beginner)

But if you want to learn to program a game like tic-tac-toe, there are a number of tutorials out on the web, and many books you could get that would help you along. I don't know where your skills are, but try searching around the net for beginner c++ lessons, or checking out your local library for books on programming or c++ if you can't afford to buy one. But like everyone else has been saying, be careful about not copy-pasting, or you won't learn anything! When you do find a tutorial or a book or whatever, play around with the code and see what happens; try and make it better, or try and make it do something different. This way you aren't just copy-pasting, you're actually figuring out what the stuff you're typing in actually does. I hope that helps! Posted Image

#18 darkhaven3   Members   -  Reputation: 160

Like
0Likes
Like

Posted 18 December 2012 - 07:54 AM

They're both Turing-complete languages, each with pros and cons.

Absolutely. I might find that using generic programming or templates is by and large leaving the door open for bad programming practice, but I appreciate and accept that you will probably feel that my usage of structs and function pointers is archaic and meaningless. I don't mean to make it sound like I'm saying "C is better than C++" or even "C++ sucks", I am simply sharing my feelings that as a beginner I found the idea of just writing a function and being able to call it a much simpler process than having to worry about whether or not other objects should be allowed to see it.

Of course that is completely arbitrary and up to subjective evaluation by anyone at any point, and by no means do I mean to represent my opinion as fact. I apologize.

I personally find C++ to be more intuitive than C, but if someone is learning C then I'm not going to suggest switching because of my personal taste. (sorry Posted Image I just feel like discussions of which language is better, especially with C/C++, are totally pointless and especially don't help a beginner)


Like I said, I meant what I said in an absolutely subjective manner and I did not mean to present my opinion as anything but. I've just always seen C as a more attractive option for game programming as a personal preference, and I am sure I'm not the only person who might feel that way is all.

#19 Sugavanas   Members   -  Reputation: 200

Like
0Likes
Like

Posted 18 December 2012 - 08:43 AM

Give C a try if you're on the basics, and see if you pick it up faster than C++. If you *need* some feature of C++ at some point later for any reason, then by all means, use C++ if it suits you at that point.


actually i think i can learn c++ fast

#20 Riphath   Members   -  Reputation: 151

Like
0Likes
Like

Posted 18 December 2012 - 07:20 PM

Of course that is completely arbitrary and up to subjective evaluation by anyone at any point, and by no means do I mean to represent my opinion as fact. I apologize.


It's ok! This is a forum, after all. You're allowed to express your opinion. Posted Image It's just my opinion that if you talk about which language is best for beginners to start with to no end, you'll never stop being a beginner unless you actually start just programming!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS