Page 1 of 3 123 LastLast
Results 1 to 15 of 35
  1. #1
    Toymaker's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Location
    Hannah, Montana
    Posts
    659
    Reputation
    14
    Thanks
    193
    My Mood
    Amused

    Game Development

    C++ Game Development [Tutorial] p1
    by Toymaker

    0. Introductions
    1. To Get Started
    2. To Make It Run
    3. For It's Engine
    4. To Get It Safe
    5. The GoodByes
    6. Get The Quiz!
    7. Common Questions


    0.(Introductions) In light of MPGH's own Game Engine, (Jetaengine) being well on it's way, I decided to make this simple tutorial for those of you interested in getting started with learning to create and secure games.


    1.(To Get Started) All you need to get started is the standard Bloodshev Dev-C++ compiler and this tutorial. It is your creativity that will bring the most success.

    2.(To Make It Run) I've compiled and working and simple model of a text based game for you to use and/or add onto sometime, to get you started. You'll notice a key concept to game creation is 'running while playing,' as my while loop gives away. This is a simple model of you fighting the computer. It does not even do random damage or have a working SP system. I suggest you try it out to make sure you understand it. It is all too basic of code for me to waste time explaining to you.

    Code:
    #include <iostream>
    using namespace std;
    int uhp = 100;
    int usp = 10;
    int mp = 100;
    int ms = 10;
    int turn = 1;
    int atk;
    int dmg;
    int main() {
        system("title GameName");
    while ( uhp > 0 ) {
          if ( turn == 1 ) {
               turn--;
               cout<<"It is YOUR turn hero.n";
               cout<<"Your HP is: "<<uhp<<"n";
               cout<<"Your SP is: "<<usp<<"n";
               cout<<"Decide Your Next Moven";
               cout<<"1. Punch(10 DMG 0 SP)n";
               cout<<"2. Psyki(20 DMG 5 SP)n";
               cin>>atk;
               if ( atk == 1 ) {
               dmg = 10;
               cout<<"You do: "<<dmg<<" DMGn";
               mp = mp - dmg;
               cout<<"Monstr Life: "<<mp<<"n";
               }
               else {
               dmg = 20;
               cout<<"You do: "<<dmg<<" DMGn";
               mp = mp - dmg;
               usp = usp - 5;
               cout<<"Monstr Life: "<<mp<<"n";
               }
               if ( turn == 0 ) {
                    turn++;
                    cout<<"Computer AIs Turnn";
                    cout<<"Computer Hits Youn";
                    cout<<"Suffer: 10 Damagen";
                    uhp = uhp - 10;
                    cout<<"New HP: "<<uhp<<"n";
                    }
                    if ( mp < 5 ) { 
                         cout<<"You Just Wonn";
                         system("pause");
                         exit(0);
                    }
                    }
                    }
                    cout<<"Thanks For Playinn";
                    system("pause");
                    }
    3.(For It's Engine) The idea of a game engine is to make an option for users to input unique information. It can be simple or complex. In my example, using the game above, you will see how to use a script file to determine the players name as if one small feature of a game engine. If you add the cpp code below to your game and create a few locations for it to output the variable, it will say the players uniquely set name every where.

    Code:
    Add To .Cpp
    
    string playername;
    ifstream b_file ( "script.txt" );
    b_file>> playername;
    cout<<"Welcome Player: " <<playername<< "n";
    
    Add To .Txt
    McAnthony

    4.(To Get It Safe) This is the big one. You don't want users leaking or cracking your game! I will break this section up into two parts.

    A. You don't want users to be able to leak a free version of your game. with that noted, you created a demo version in which you Trial protect so users can only load it so many times. You use the same concept as the engine code above but you want to hide it and change it a bit. In this example your players can only play 5 times before paying:

    Code:
    Add To .Cpp
    
    int loudcount;
    ifstream b_file ( "loadcounter.txt" );
    b_file>> loadcount;
    if ( loadcount > 5 ) {
    cout<<"You've played to much!n";
    exit(0);
    }
    
    Add To .Txt
    1
    B. You will notice, perhaps in cracking basic password programs, a common hacker can just debug your program and change one jump of memory to a no operation in memory and avoid it. In layman terms, in the "if you can use or not" code they can cancel out the 'or not' part so it always loads. A basic way to beat this, noting the Offset and Bytes are in decimal and not hexadecimal during compile time, is to check the memory's integrity. If the ASM code is like this:

    4D0: 1111 | CMP YOURPASS TO CORRECTPASS
    4D4: 2222 | IFWRONG GOTO WRONG LOCATION
    4D8: 3333 | IFRIGHT GOTO RIGHT LOCATION

    A hacker could simply 9090 (NoOperation) the 4D4 IFWRONG line so all that's left is the 4D8 IFRIGHT line. So you can use ReadProcessMemory to check for non changed values.

    Code:
        int address = 0x4D4;
        int value;
        DWORD pid;
    	GetWindowThreadProcessId(hwnd,&pid);
            HANDLE phandle = OpenProcess(PROCESS_ALL_ACCESS,0,pid);
                     ReadProcessMemory(phandle,(LPVOID)address,&value,2,0);
                     cout << value;
                     getch();
                            if ( value != 2222 ) {
                            cout<<" You must be hackingn";
                            system("pause");
                            }
    5. End Of Tutorial It's basic and quick but leaves room for a lot of learning direction and I hope you learn from it or are inspired with ideas. I must additionally credit using google to find certain code snippets and method ideas.

    6.(GET THE QUIZ). As far as this quiz goes perhaps you can pass it! You simply need to achieve the following goals (Notice: If you do this quiz you can submit it here for additional group learning and thank you):

    1. Add a working SP system to the TBG, (Text Based Game), so your player can only use the stronger attack two times total.
    2. Increase the security of your safety measures through encryption or obscuring the information and or path locations

    7.(Common Questions) Q. How do I do a save game feature? A. You simply ask the user to load a game or start a new one and if they want to load a game it reads from a .txt file that, if they saved the game saved, wrote information to. You could do an auto-save on escape and it'd store the HP/SP of you and the monster in a .txt file for auto-loading next execution, for testing and example.
    Last edited by Toymaker; 04-17-2009 at 09:56 AM.

  2. The Following 8 Users Say Thank You to Toymaker For This Useful Post:

    dude117 (05-22-2010),Fantomfury26 (08-28-2010),floke (09-10-2010),he287069521 (07-06-2011),Illuminatus (09-10-2010),rwkeith (07-25-2009),whitten (07-16-2009),why06jz (10-07-2009)

  3. #2
    SyrupyMonkeh's Avatar
    Join Date
    Apr 2009
    Location
    In the HAX0Rmainserver
    Posts
    198
    Reputation
    10
    Thanks
    11
    Great TuT much appreciated, ty

  4. #3
    Toymaker's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Location
    Hannah, Montana
    Posts
    659
    Reputation
    14
    Thanks
    193
    My Mood
    Amused
    Yeah, I get asked for tutorials like these a lot and am happy to help promote higher thinking in this programming section than calculators and hello world.
    Last edited by Toymaker; 04-17-2009 at 09:57 AM.

  5. #4
    trenhryan's Avatar
    Join Date
    Apr 2009
    Posts
    13
    Reputation
    10
    Thanks
    0
    woah that crazy

  6. #5
    joshzex's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    Sydney
    Posts
    77
    Reputation
    10
    Thanks
    27
    My Mood
    Happy
    i still dont get it

  7. #6
    Toymaker's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Location
    Hannah, Montana
    Posts
    659
    Reputation
    14
    Thanks
    193
    My Mood
    Amused
    It's true I didn't exactly baby people through the tutorial. I am however going to continue the series very soon. You should be able to learn from it still by trying to use it and fixing it up, etc. You need motivation to 'get it.'

  8. #7
    GG2GG's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    United Kingdom
    Posts
    3,382
    Reputation
    21
    Thanks
    4,294,967,295
    My Mood
    Blah
    so i heard gg2gg prawnt this and waiting for next pvt lesson

  9. #8
    pingwasha's Avatar
    Join Date
    Apr 2009
    Gender
    male
    Posts
    30
    Reputation
    10
    Thanks
    1
    would packing your files be count as added security??

  10. #9
    chris12x1's Avatar
    Join Date
    Sep 2008
    Gender
    male
    Location
    asd
    Posts
    72
    Reputation
    10
    Thanks
    3
    My Mood
    Angry
    i get this error:
    56 C:\Documents and Settings\chris diaz\Desktop\Untitled1.cpp variable `std::ifstream b_file' has initializer but incomplete type
    57 C:\Documents and Settings\chris diaz\Desktop\Untitled1.cpp expected constructor, destructor, or type conversion before '>>' token
    57 C:\Documents and Settings\chris diaz\Desktop\Untitled1.cpp expected `,' or `;' before '>>' token
    58 C:\Documents and Settings\chris diaz\Desktop\Untitled1.cpp expected constructor, destructor, or type conversion before '<<' token
    58 C:\Documents and Settings\chris diaz\Desktop\Untitled1.cpp expected constructor, destructor, or type conversion before '<<' token
    60 C:\Documents and Settings\chris diaz\Desktop\Untitled1.cpp `Add' does not name a type

  11. #10
    Toymaker's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Location
    Hannah, Montana
    Posts
    659
    Reputation
    14
    Thanks
    193
    My Mood
    Amused
    so i heard gg2gg prawnt this and waiting for next pvt lesson
    Already in progress =p

    would packing your files be count as added security??
    In this case, yes but don't rely on it.

    i get this error:
    56 Cocuments and Settingschris diazDesktopUntitled1.cpp variable `std::ifstream b_file' has initializer but incomplete type
    57 Cocuments and Settingschris diazDesktopUntitled1.cpp expected constructor, destructor, or type conversion before '>>' token
    57 Cocuments and Settingschris diazDesktopUntitled1.cpp expected `,' or `;' before '>>' token
    58 Cocuments and Settingschris diazDesktopUntitled1.cpp expected constructor, destructor, or type conversion before '<<' token
    58 Cocuments and Settingschris diazDesktopUntitled1.cpp expected constructor, destructor, or type conversion before '<<' token
    60 Cocuments and Settingschris diazDesktopUntitled1.cpp `Add' does not name a type
    If you download and install the recent version of dev-C++ compiler and leave it standard, it compiles fine for me. I'm not sure if you made any changes or use a different compiler or version.

    But, the errors make it appear you're missing some simple ; marks and are missing two definitions.

  12. #11
    orx's Avatar
    Join Date
    Jun 2008
    Gender
    male
    Location
    Estonia
    Posts
    59
    Reputation
    11
    Thanks
    4
    Yea in c++ its easy to just make a game using maths , anyways , downloaded directx sdk today , and a game programming ebook , 1035 pages to read <.< , about directx programming , as soon , as i finish learning this shit , i will release my own chess game or something , just for learning , but still , its 3d , and looks very good 8-)

    OrX

  13. #12
    waqup08's Avatar
    Join Date
    Aug 2008
    Posts
    12
    Reputation
    10
    Thanks
    0
    My Mood
    Breezy
    so im guessing this is uh.. console application not a windows application? o.o

  14. #13
    Toymaker's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Location
    Hannah, Montana
    Posts
    659
    Reputation
    14
    Thanks
    193
    My Mood
    Amused
    Yes, waqup08 it is. Jetamay has some examples of windowed ones. The point of this was to teach game flow and physical logic, quite briefly at that.

  15. #14
    whitten's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Posts
    1,459
    Reputation
    21
    Thanks
    491
    nice post bro!
    helped lots.
    i may get into this shit.

  16. #15
    rwkeith's Avatar
    Join Date
    Jul 2008
    Gender
    male
    Posts
    457
    Reputation
    11
    Thanks
    79
    My Mood
    Angelic
    Bravo, I am a game programmer myself. I found your tutorial easy to understand and I learned a little on game protection. Next open tutorial you should bring up key protection or user id's and password's.
    Goals In Life:
    [X] Become an Advanced Member
    [X]Release a tut on mpgh
    [0]Post 300 posts
    [X]Make a working hack
    [X] Learn c++

Page 1 of 3 123 LastLast

Similar Threads

  1. Game Development Section - Whos managing that?
    By jeremy6996 in forum General
    Replies: 9
    Last Post: 03-14-2011, 01:34 AM
  2. Game Development
    By InsanityJ- in forum General
    Replies: 12
    Last Post: 10-03-2010, 09:40 PM
  3. If you could tell game developers one thing...
    By Retarded Cheesecake in forum General
    Replies: 5
    Last Post: 12-20-2009, 02:28 PM
  4. Direct-X Tutorials (Game Development)
    By Dave84311 in forum C++/C Programming
    Replies: 12
    Last Post: 02-27-2009, 11:15 AM
  5. Game Development section
    By radnomguywfq3 in forum General
    Replies: 12
    Last Post: 12-11-2008, 04:08 PM

Tags for this Thread