Jump to content

Tutorial-the basics of C++ and game making


Recommended Posts

  • Replies 68
  • Created
  • Last Reply

Top Posters In This Topic

Sorry, I forgot about this topic.

 

You can define your own datatypes from other datatypes. You do it like this:

typedef int array[30];

 

Because we puted the keyword "typedef" befor the decleration, "array" is not a variable. "array" is now a datatype of an integer array with 30 places. You can now declare "array"s like this:

array a;
a[5]=2;

 

 

You can combine few variables into one datatype, using the keyword "struct". You do it like this:

typedef struct
{
 char name[20];
 int age;
 int id;
} person;

We now created a new datatype: the "person" datatype. Inside every variable of the type "person", there are the variables "name","age" and "id". How do you use it? like this:

person man;
man.age=31;
man.id=788246739;

 

It's that simple.

 

That will be all for today. Class dismissed.

Link to comment
Share on other sites

If you have a pointer to a struct:

[/code]

person *man;

man=new person;

you don't have to reach the inner variables of the struct like this:
[CODE](*man).age

 

You can instend do it like this:

man->age

 

 

One thing I forgor to tell you about typedefs. You have to put the outside of functions, like this:

 

#include<iostream.h>

typedef char string[20];

void main()
{
 bla bla bla
}

 

That will be all for today. Class dismissed.

Link to comment
Share on other sites

  • 1 month later...

Umm, dude, im taking C++ classes this year, and all this your teaching everyone down here is only merely enough to make a simple program like a calculater , the best game we have done this year is Black Jack, you only taught half a year of C++ class there.

Link to comment
Share on other sites

When I say game making, I don't mean to teach you Directx or OpenGL. I will teach you the basic logic of game making.

 

Anyways, today's lesson is about Classes.

 

A Class is basicly a struct with functions. This may sound like a small addition, but it's actualy opened the path to a new generation of programing languages (Like ".net").

 

Class can contain 3 levels of variables/functions:

1. public: You can use the variable/function from eveywhere.

2. private: You can only use the variable/function from other functions inside the Class

3. protected: I will get to this later.

 

Here is an example of a Class:

Class Point // Class's names are usualy begining with capital letter
{
 private://begining of the private zone
  int x;
  int y;
 public://begining of the public zone
  void setx(int nx)
   {
    x=nx;
   }
  void sety(int ny)
   {
    y=ny;
   }
  int getx()
   {
    return x;
   }
  int gety()
   {
    return y;
   }
};

 

You can use the class like this:

Point p;
p.setx(12);
p.sety(5);
cout<<"("<<p.getx()<<","<<p.gety<<")";

The output will be, ofcourse, "(12,5)".

 

This topic can be pretty hurd to understand, so if you have any questions, don't be to shy to ask.

Link to comment
Share on other sites

Umm, dude, im taking C++ classes this year, and all this your teaching everyone down here is only merely enough to make a simple program like a calculater , the best game we have done this year is Black Jack, you only taught half a year of C++ class there.

 

he's already taught C, that's enough to make a game.

 

all that's left is:

inheritance

polymorphism

templates

linked lists

operator overloading

exceptions

 

and that's the language pretty much, give or take a few small features.

 

if you want to learn to make a game, you're going to have to look up an API and learn software design.

Link to comment
Share on other sites

If he has taught enough then how come I can't understand the coding for Little Fighters 2 9.0, a jap game that died a few months ago....

Because what someboddy teached was only the basics, game coding is far from "basics".

Link to comment
Share on other sites

I will not teach you API or DirectX. These are very complex stuff. I will teach you the logic of game making, like the game loop and buffers. If you want to make games with graphics and stuff, you will have to learn it yourself.

 

btw: What I tought you is not enouth to make a game, not even ascii game. I still need to teach you some console and dos functions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...