Hi I am trying to build the game engine from the book SDL Game Development by Shaun Mitchell, the book is very hard to follow and frequently gives examples of code with out saying which file to put it in or telling you any parts that need deleting. I was on the section Listening for and handling axis movement which I got to compile fine and moved a character around on the screen with the joy stick. I move on to the next section Dealing with joystick button input where it tells me to add
|
std::vector<std::vector<bool>> m_buttonStates;
|
the book does not say where this should go so I put it in InputHandler.h in the InputHandler class as private
1 2 3 4
|
bool getButtonState(int joy, int buttonNumber)
{
return m_buttonStates[joy] [buttonNumber];
}
|
the book did not say where this should go so I put it in the public section of the InputHandler class in InputHandler.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
for (int i = 0; i < SDLNumJoysticks(); i++)
{
SDL_Joystick* joy = SDL_JoystickOpen(i);
if(SDL_JoystickOpened(i))
{
m_joysticks.push_back(joy);
m_joystickValues.push_back(std::make_pair(new
Vector2D(0,0),new Vector2D(0,))));
std::vector<bool> tempButtons;
for(int j = 0; j < SDL_JoystickNumButtons(joy); j++)
{
tempButtons.push_back(false);
}
m_buttonStates.push_back(tempButtons);
}
}
|
with the last section the book suggests I put the fragment of code in the initialiseJoysticks function in InputHandler.cpp in the DealingWithJoystickButtonInput section but it does not say if I have to delete any code from the previous version of the file in Listening for and handling axis movement. Please can someone help me sort out the braces in the nested if else and for loops in InputHandler.cpp initialiseJoystick function in DealingWithJoystickButtonInput as I am a noob and finding it really hard to sort out these nested loops. Thanks
also the book suggested I add
1 2 3 4 5 6 7 8 9 10 11 12 13
|
if(event.type == SDL_JOYBUTTONDOWN)
{
int whichOne = event.jaxis.which;
m_buttonStates[whichOne][event.jbutton.button] = true;
}
if(event.type == SDL_JOYBUTTONUP)
{
int whichOne = event.jaxis.which;
m_buttonStates[whichOne][event.jbutton.button] = false;
}
|
I put this in the update function, is that where it should go? the book doesn't say.
ListeningForAndHandlingAxisMovement - InputHandler.h
https://drive.google.com/open?id=1r49khpoieE74IVCv4XjvpEs3EXBq0037
ListeningForAndHandlingAxisMovement- InputHandler.cpp
https://drive.google.com/open?id=10pqx2BPJ-AfMfUhxpaLrRNAFi6PKkAWn
DealingWithJoyStickButtonInput - InputHandler.cpp
https://drive.google.com/open?id=1N7BjuRDep-ru2tc9gw5l-2yl-pzDbFNW