Linux Format

DATA TYPES

-

In C/C++, data types can be applied to variables and functions (and methods • in C++). The main data types in C/C++ are:

• Integers (int)

• Decimal values (float)

• String (string or char *)

Boolean (bool)

A lot of the methods used in the GameContro­ller class have been declared of type bool, which means the method returns a true or false value. Some of the methods in the GameContro­ller class have been implemente­d in this way to identify if anything has failed to initialise that the game program needs to work, for example: bool GameContro­ller::getGC_Connection­State()

{

return isGC_Connected;

}

The above method shown is purely there to return the value of isGC_Connected, which identifies whether the game controller is connected to the PC or not. Whatever the value is, it is a Boolean value that is returned, so the method is prewritten with the data type bool to identify it will be returning a Boolean value. If the method was to be declared as void, no data type would be returned. It is good practice to data-type functions and methods, so if any issues occur, it can help identify where a problem might be coming from, because functions that don’t return a value may mean that you have to debug through the code in that function, even though that may not be where the source of the problem is located. if (glfwJoysti­ckPresent(GLFW_JOYSTICK_1)) { isGC_Connected = true;

} else { isGC_Connected = false; } } return isGC_Connected; }

To initialise the controller, the glfwJoySti­ckPresent

function is called – this is a function of the GLFW library. This is why an if condition is implemente­d to see if the GLFW library is initialise­d first.

In GameContro­ller.h, various macros are set up using the #define directive that specify the values of each button press on the game controller. These were manually tested to get the value before implementa­tion into the class (so the implemente­d values are known values):

#define LEFT_BUTTON_DIRECTION 14 #define RIGHT_BUTTON_DIRECTION 12 #define UP_BUTTON_DIRECTION 11

#define DOWN_BUTTON_DIRECTION 13 #define A_BUTTON 0

#define X_BUTTON 2

There may be a possibilit­y that these values will need to be altered depending on the game controller you are using. Hopefully, however the above values be sufficient for your PC-compatible controller.

Newspapers in English

Newspapers from Australia