After declaring an int variable pVelY in a class defintion, I have attempted to implement it in a source definition. I am getting errors saying that pVelY was not declared in this scope. It is strange to me since pVelX looks exactly the same in how it is implemented, yet it builds just fine. Can someone tell me what is going on? I can show more code if necessary.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
//worlds.h
class World1
{
public:
//unrelated code
void movePlayerEvent(SDL_Event&);
void movePlayer();
//unrelated code
private:
//unrelated code
int pVelX;
int PVelY;
//unrelated code
};
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
//worlds.cpp
#include "worlds.h"
//ton of unrelated code
void World1::movePlayerEvent(SDL_Event& e)
{
if (e.type == SDL_KEYDOWN)
{
switch(e.key.keysym.sym)
{
case SDLK_UP:
if (this->getPlayerRectPosY() == 0)
playerBase.y++;
playerBase.y--; break;
case SDLK_DOWN:
if (this->getPlayerRectPosY() == 768 - this->getPlayerRectH())
playerBase.y--;
playerBase.y++; break;
case SDLK_LEFT:
if (this->getPlayerRectPosX() == 0)
playerBase.x++;
playerBase.x--; break;
case SDLK_RIGHT:
if (this->getPlayerRectPosX() == 1024- this->getPlayerRectW())
playerBase.x--;
playerBase.x++; break;
}
}
else if (e.type == SDL_JOYAXISMOTION)
{
if (e.jaxis.which == 0)//controller 0
{
if (e.jaxis.axis == 0)// x axis
{
if (e.jaxis.value < -CONTROLLER_DEAD_ZONE)
pVelX = -1;
else if (e.jaxis.value > CONTROLLER_DEAD_ZONE)
pVelX = 1;
else
pVelX = 0;
}
else if (e.jaxis.axis == 1)//y axis
{
if (e.jaxis.value < -CONTROLLER_DEAD_ZONE)
pVelY = -1;
else if (e.jaxis.value > CONTROLLER_DEAD_ZONE)
pVelY = 1;
else
pVelY = 0;
}
}
}
}
void World1::movePlayer()
{
playerBase.x+= pVelX;
if(playerBase.x < 0 || (playerBase.x + playerBase.w > 1024))
playerBase.x-= pVelX;
playerBase.y+= pVelY;
if(playerBase.y < 0 || (playerBase.y +playerBase.h > 768))
playerBase.y-= pVelY;
}
|
Here are the build messages:
||=== Build: Debug in KnightQuest (compiler: GNU GCC Compiler) ===|
C:\Users\Kevin\Documents\Codeblocks\KnightQuest\worlds.cpp||In member function 'void World1::movePlayerEvent(SDL_Event&)':|
C:\Users\Kevin\Documents\Codeblocks\KnightQuest\worlds.cpp|126|error: 'pVelY' was not declared in this scope|
C:\Users\Kevin\Documents\Codeblocks\KnightQuest\worlds.cpp|129|error: 'pVelY' was not declared in this scope|
C:\Users\Kevin\Documents\Codeblocks\KnightQuest\worlds.cpp|132|error: 'pVelY' was not declared in this scope|
C:\Users\Kevin\Documents\Codeblocks\KnightQuest\worlds.cpp||In member function 'void World1::movePlayer()':|
C:\Users\Kevin\Documents\Codeblocks\KnightQuest\worlds.cpp|144|error: 'pVelY' was not declared in this scope|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
Any clue why this is happening?