Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
someboddy

Tutorial-the basics of C++ and game making

Recommended Posts

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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

He's not even done yet and he's not going to teach advanced data structures and crap.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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....

Share this post


Link to post
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".

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...