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)