My first game

Started by
16 comments, last by wasted_druid 18 years, 10 months ago
Thanks very much to all of you. I've downloaded dev-c++ since most of you suggested it. I must say that i'm a bit confused because i don't understand what are some of things you where talking about ;) (ex. SDL, gcc, stl or pointers).
Hope i'll learn that soon.
Advertisement
Quote:Original post by Adams555
Hello. As for a compiler, there are some free ones that I have heard of, (http://www.thefreecountry.com/compilers/cpp.shtml) look at that website, a quick search produced it, and it seems to have some good results.

Anyway, I was able to get Microsoft Visual C++ 6.0 professional for $50 on ebay. That is, if you like 6.0 better than .net... I haven't tried .net, but I like 6.0 a lot. (.net is basically Visual C++ 7.0, with elements of Java in it I believe)..
Visual Studio .Net is considered generally superior to 6 in terms of standards compliance. Furthermore, you can program in the same old C++ as 6.0. C++.Net is a completely seperate entity, fyi.

I was learning some basics and have encountered small problem. Which type of data i need to use to declere words? I know that "int" is for numbers. Next thing is that when i try to to divide to numbers i get answer "0", why? All other operations are giving normall answers.
I recommend Microsoft Visual C++.Net 2005 Express Edition. It is still in the beta stage so you can download it for free from MSDN's Lab site.

Degra
Quote:Original post by Shuger
I was learning some basics and have encountered small problem. Which type of data i need to use to declere words?


Textual data is most easily handled in C++ with the type std::string. That is to say, objects of class "string", which is declared in the "std" namespace. You will need to #include the <string> header - this is NOT the same as <cstring> or <string.h>; those are backwards-compatibility headers for C-style code.

In C, you will have to rely on some hackery - it is well documented and gets supported reasonably well by library functions, but is still quite tricky. The basic idea* is that "char" - a numeric, one-byte type - is used to represent a single letter of text. Thus to represent text, one arranges to have a block of sequential char-typed values in memory somewhere, and then gets a pointer to them - a char *. To handle these properly requires quite a bit of background knowledge on pointers and memory allocation, unfortunately.

In the same way that literal numbers of type 'int' can be used in your code by just typing the number, you can use "string literals" by wrapping them in double-quotes. (There are special rules for dealing with string literals that have double-quote or other strange characters in them.) BUT beware! These are of type char*, not std::string - even in C++. Now, a std::string will be able to "deal with" a char*, but because char*'s are pointers, they don't work so nicely with each other. In particular, you can't "add" them (string them together) conveniently. The easiest solution here is to create a temporary string from one of them.

Quote:I know that "int" is for numbers. Next thing is that when i try to to divide to numbers i get answer "0", why? All other operations are giving normall answers.


"int" is for integer numbers. Operating on two integer values yields another integer; for division, this means the remainder gets thrown away. This "integer division" is actually very useful in a lot of game programming contexts, especially in combination with the modulo operator (represented by a % symbol), which produces the remainder for such a division.

To get a decimal result, you will need to use a floating-point type, such as "float" or "double". However, these have their own pitfalls.

* There are *many* simplifications here. Experienced programmers are encouraged to spot them all as an exercise.

// Sample (tested!) code to illustrate the ideas.#include <iostream> // for input and output#include <string> // for the std::string typeusing namespace std; // tells the compiler to look in the std namespace// for any identifiers (global variables, type names, etc.) that it can't// find definitions for in our own code.int main() {  // In C++, main() should return int, never void.  string message = "hi "; // we can initialize a string using a char*  message += "there!"; // adding char* to a string works too  3 + 4; // a computation on its own is valid, but won't "do anything" unless  // you store the result somewhere or otherwise cause a side effect (like  // outputting the result). I'm just doing this to show:  // "hi " + "there!"; <-- not valid! Both pointers; can't add them.  // Anyway, a good compiler will give you a warning for doing something like  // this (or can at least be configured to do so), but will still compile your  // code.  cout << message << endl; // output the message.  char x = 8;  int y = 3;  // Notice I declared y as a char type; this is to show that the individual  // "char"acters of a char* are actually numeric values - the console maps  // them into display characters via ASCII.  // Output the division as a fraction.  // We'll do this by showing the whole number part, then a space, then  // the remainder, then a slash, then the divisor.  cout << "8/3 = " << (x/y) << ' ' << (x%y) << '/' << y << endl;  // Note that *single* quotes produce a character literal, not a string  // literal. Thus it can only hold one byte, but it's not a pointer, it's  // an integral type - so you can do arithmetic with it. Now, to do  // *meaningful* arithmetic is the hard part ;) There's really only one  // trick you are likely to rely on there:  cout << static_cast<char>('0' + x) << endl;  // Here we sum '0' - which is 48, because of that encoding - and 8, to get 56  // - which is '8' as a printable character. The trick is that digits '0'   // through '9' are sequential in ASCII. However, to print the character '8'  // rather than the numeric value 56, we need to "cast" the result back to  // a char type - because summing the two chars actually gave us an int.  // To finish off, let's show the division as a floating-point value. We'll  // cast x to a floating-point type, in this case "double". Division between  // "mixed" types (one floating-point and one integral) gives a floating-point  // result, according to the rules of the language.  cout << "8/3 = " << (static_cast<double>(x) / y) << endl;}
I'm suprised nobody said Code::Blocks. Its still beta, but its pretty good (though, I'm sticking with MVSC++ 6 for now.)
Thanks Zahlman for explaining it to me.
I was reading some tutorials and now i understand a bit more of if statements, functions, structures,cases and loops.And also a little bit of pointers(Althought i don't see any use of it so far). What else should i learn to start making some basic game?
I also wanted to ask about graphical aspect of program. Everything i have so far wrote is running in dos-alike window. This reminds me programs written in pascal;).
Do i need to know other c++ commands or maybe graphic is totally seperate aspect?

BTW: Sorry for my english, i know that i often make mistakes but i'm trying to do my be
My view on pointers when I started was this:
I learned what they were and the basics of how they worked, then I forgot about 'em. I programmed happily until one day I needed to do something, and a pointer was perfect for it. Then I used a pointer. Now I see more and more things a pointer will work well for.

Don't try to push yourself too hard, and consider getting a beginner book. Books are nice because they (usually) start simple, build off their own material adding slowly until you have a basic understanding. Sure you could get the same information off the web, but it takes more time, it's not all the same writing style, and other sundry downfalls. Good luck.
----------------------------------------------------------No matter how eloquently you state your argument, the fact remains that the toilet seat is a bistable device. Therefore it's natural position is no more down than it is up.[SDL Smooth Tile Scrolling]

This topic is closed to new replies.

Advertisement