Creating an easily Customizable Configuration

Talk about making games.

Creating an easily Customizable Configuration

Postby Hblade » Wed Dec 21, 2011 4:38 pm

Hello everyone. Hblade here, and today we will be creating a Database / Configuration which will let you customize the basic settings and prevent changing tons of code when you want to change 1 simple thing. This is useful if you want to change the views size, the player's start HP, or anything like that.

We will also be creating 1 variable that acts as all Global variables for the game. Alright, first go ahead and create the key variables that are used in most every game. We will also be using a gamepad setup code here too.
Code: Select all
int GLOBAL_VARIABLES[1000], BUTTONS[8];
double AXIS[2];
char *key;

Now name this global code "Variables", and click add. Now you have a blank screen, and now we want to add Macros, or Definitions #define for example. These macros will control the basic and most important settings in the game.
Code: Select all
//Global Variables
    #define PlayerHP GLOBAL_VARIABLES[0]
    #define PlayerX GLOBAL_VARIABLES[1]
    #define PlayerY GLOBAL_VARIABLES[2]
    #define ViewX GLOBAL_VARIABLES[3]
    #define ViewY GLOBAL_VARIABLES[4]

//Basic Settings
    #define JumpHeight 7
    #define MoveSpeed 5
    #define StartHealth 3
    #define PlayerName "Namevac"
    #define PlayerStartX 0
    #define PlayerStartY 0

//View Settings
    #define ViewWidth 640
    #define ViewHeight 480
    #define GameFPS 30
    #define ViewStartX -320
    #define ViewStartY -240
 
//Controls
    #define XAXIS AXIS[0]
    #define YAXIS AXIS[1]
    #define BTN_1 BUTTONS[0]
    #define BTN_2 BUTTONS[1]
    #define BTN_3 BUTTONS[2]
    #define BTN_4 BUTTONS[3]
    #define BTN_5 BUTTONS[4]
    #define BTN_6 BUTTONS[5]
    #define BTN_7 BUTTONS[6]
    #define BTN_8 BUTTONS[8]
   
    #define KeyRight key[KEY_RIGHT]
    #define KeyLeft key[KEY_LEFT]
    #define KeyDown key[KEY_DOWN]
    #define KeyUp key[KEY_UP]
    #define KeyJump key[KEY_x]

Name this Settings and click add.

Now, at any given point in the game, we can change these settings if needed. For example if you wanted to use ASWD instead, but decided to wait until half-way through the game and then finally say "Hey I want to use these keys instead", all you have to do is modify key[KEY_RIGHT] to key[KEY_d] for example from this 1 global code, or if you wanted to change his name, simple as changing the name in this. and it'll be used throughout the game. Now we're going to put this to use.

Now lets put this to good use. Create an actor called "Player". Then go back to global code, and create a script that will actually use the settings you did.
Code: Select all
void
SetUp() {
    PlayerHP=StartHealth;
    PlayerX=PlayerStartX;
    Player.x=PlayerX;
    PlayerY=PlayerStartY;
    Player.y=PlayerY;
    view.x=ViewStartX;
    view.y=ViewStartY;
        }

This will start the view and player off in the default positions you told them to be in the config. Now, go to Create Actor of the player, and put this in
Code: Select all
//view
SetUp();

and move your player outside of the view to test. He should appear where you told him to. In this case, he should appear in the center of the screen.

Now you have a basic database, you should alter it to fit with your needs for your game. You've learned how to make one, now the rest is up to you. Hope this helped.


EDIT:
You must put the comment //view with it. (Thank skydereign :3)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Creating an easily Customizable Configuration

Postby skydereign » Wed Dec 21, 2011 9:51 pm

Actor variables can't be changed in global code if the script that actually calls the function does not have any reference to the actor. I've mentioned this problem to you, makslane recommends adding a comment with the actor's name in the script so it will know to update the actor's variables (view).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Creating an easily Customizable Configuration

Postby Hblade » Wed Dec 21, 2011 10:01 pm

Oh yeah now I remember. Thanks, I knew there was something you said but couldn't remember what it was xP
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest