Thread: Starting game programming

  1. #16
    Registered User
    Join Date
    Jun 2002
    Posts
    267
    Originally posted by JoshG
    What else does c++ add besides classes?
    • Function prototyping
    • Anonymous unions
    • Constructors and destructors
    • Exceptrions with try/catch blocks
    • External function linkages
    • Function overloading
    • Inline functions
    • Namespaces
    • Bit Field types
    • New and Delete operators
    • Operator overloading
    • Different STL
    • Template classes
    • Template functions


    C++ is not just "C with classes"

  2. #17
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Originally posted by JoshG
    What else does c++ add besides classes?
    I think that C++ is object-oriented programming.
    what does signature stand for?

  3. #18
    a lot of those things you mentioned you can do in C. Like prototyping, or external functions.

  4. #19
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Can you do type casting in C??
    what does signature stand for?

  5. #20
    Registered User
    Join Date
    Jun 2002
    Posts
    267
    Originally posted by frenchfry164
    a lot of those things you mentioned you can do in C. Like prototyping, or external functions.
    heh, ok, well this was true for old-style C... it's not applicable anymore

  6. #21
    Registered User
    Join Date
    Jun 2002
    Posts
    267
    Originally posted by Ruski

    I think that C++ is object-oriented programming.
    OOP is a methodology, or a way to structure and write a program; since an object is an intangible thing, you can create an "object" with just about any language you want, there is no constant "this is an object; this is not". C++ is considered an object-oriented language because it has built-in support for creating, managing, and using user-defined objects through the use of classes and all the goodies thereof (operator overloading)

    make sense?

  7. #22
    you can do OOP with C, just wasn't as good as what C++ has made it

    I don't think you can do typecasting in C. You might be able to, correct me if I am wrong.

  8. #23
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Anyone?? I asked a simple question
    what does signature stand for?

  9. #24
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    I'm fairly sure that you *can* do type casting in C...out of "C For Dummies, Volume I"

    [QUOTE]
    You can type cast any variable. Often the
    Code:
    (float)
    is used as shown here when you're manipulating integer values. Another common case is when you're dealing with C language functions that require specific types of values. For example, the
    Code:
    sin
    function computes the sine of an angle (yawn), but it requires a
    Code:
    double
    value. If you only passed it an integer variable
    Code:
    x
    , you would have to uyse the following statement:

    Code:
    result=sin((double)x);
    Here, the integer variable
    Code:
    x
    is converted into a double for processing by the
    Code:
    sin
    function. The result is saved in the
    Code:
    result
    varaible.[/PHP]

    So, yes, you CAN do type casting in C.
    Away.

  10. #25
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    ack, sorry guys, that looks ugly, I didn't realize it put the monospaced font on a seperate line every time ):
    Away.

  11. #26
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    You can do type casting in C. I am just curious can you do type casting in c++ with an object? Say you have a class fu and an object thefu that is 12 bytes. Then say you have a class bar (12 bytes also) and a object thebar, could you (fu)thebar ?

    BTW, I have no idea why you would want to do this, just wondering.

  12. #27
    well try it yourself.

    oh, and a reason why you would want to do it, is if you made a function that returns a fu, and you want to pass a thebar to it.

  13. #28
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    [QUOTE]Originally posted by blackrat364
    I'm fairly sure that you *can* do type casting in C...out of "C For Dummies, Volume I"

    You can type cast any variable. Often the
    Code:
    (float)
    is used as shown here when you're manipulating integer values. Another common case is when you're dealing with C language functions that require specific types of values. For example, the
    Code:
    sin
    function computes the sine of an angle (yawn), but it requires a
    Code:
    double
    value. If you only passed it an integer variable
    Code:
    x
    , you would have to uyse the following statement:

    Code:
    result=sin((double)x);
    Here, the integer variable
    Code:
    x
    is converted into a double for processing by the
    Code:
    sin
    function. The result is saved in the
    Code:
    result
    varaible.[/PHP]
    Thanks For The Answer

    So, yes, you CAN do type casting in C.
    what does signature stand for?

  14. #29
    rams09
    Guest
    wow. thanks a lot for all the replies !

  15. #30
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    You can type cast object in C++. The typecasted object will have only the members that are shared between the 2, so it will be typecast as the "lesser" of the 2.

    I do this in my current game. I have 3 similar objects (they're all actually derived from a single base class, but for simplicity here we'll treat them as wholly unique; still works the same).

    Object 1 - CTrooper
    Object 2 - CBot
    Object 3 - CWall

    All 3 classes have these members in common:
    [code]
    //variables
    RECT rcSrc;
    LPDIRECTDRAWSURFACE7 sfSurface;
    POINT ptBlt;
    //functions
    void Clip(RECT rcViewable);
    void Blt(LPDIRECTDRAWSURFACE7 sfDest);
    [code]

    CTrooper adds a bunch of variables and functions to allow for adjust health, speed, firing accuracy, courage, getting input, etc.

    Code:
    //some examples of CTrooper's unique members
    int iCourage;
    void AdjustCourage(int iAdjust);
    int GetInput(long lBtn, long lLastBtn, POINT ptMouse);
    CBot adds a bunch of variables and functions to allow for determining how "smart" it is, get firing accuracy, determining actions base on AI, etc.

    Code:
    //a few examples
    int iIntelligence;
    int GetAction(int iIncomingCommands);
    CWall only has a few additional items like wall "health" etc (the game will allow for misplaced shots to damage terrain, etc.

    Code:
    //ditto
    int iDamage;
    void UpdateSrcForDamage();
    I have an array of pointers to the lowest level object, in this case CWall. So, if I have a total of 3 of these objects in the game (that would be one of each) then I have an array of 3 CWall pointers.

    Code:
    CTrooper ctrprSam;
    CBot cbotFred;
    CWall cwallWall;
    CWall *pcwall[3];
    In my blitting code I first copy the addresses of each of my original objects into the array of CWall pointers.

    Code:
    pcwall[0]=&ctrprSam;
    pcwall[1]=&cbotFred;
    pcwall[2]=&cwallWall;
    Then I loop through the array of CWall pointers and sort them based on their ptBlt.y value (the higher up the screen they are the sooner they should be blitted, so they don't cover up someone/thing who's in front of them), and then run the Blit routine.

    Code:
    pcwallWall->Blt(sfBack);
    Here's a more simple, generic example using structs (same principles apply):
    Code:
    struct num1
    {
        int i;
        long l;
        char c;    
    };
    
    struct num2
    {
        int i;
        long l;
    };
    
    num1 nm1;
    num2 nm2;
    num2 *pnm2;
    
    nm1.i=10;
    nm1.l=3600001;
    nm1.c='a';
    
    pnm2=&nm1;
    
    cout<<pnm2->i<<endl; //would output 10
    cout<<pnm2->l<<endl; //would output 3600001

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Starting 2D Game Programming...
    By Junior89 in forum Game Programming
    Replies: 8
    Last Post: 06-20-2006, 08:47 PM
  2. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-22-2006, 12:23 AM
  3. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-26-2006, 12:14 AM
  4. Game structure, any thoughts?
    By Vorok in forum Game Programming
    Replies: 2
    Last Post: 06-07-2003, 01:47 PM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM