I have a player class setup with each object having it's own sprite. It draws to the screen like i want it to and to the position i set it to, but when i try to move the object around like you normally would by using something like 'player.move(x, y);', it just refuses to move.
I'm quite new to programming and game development in general so i'm quite hesitant to share my code in fear of looking like an idiot, but here goes.
This is my player class.
class Player
{
private:
int health;
bool isAlive;
Sprite playerSprite;
public:
Player(int h, Sprite &pSprite){ health = h; playerSprite = pSprite; }
~Player(){}
void drawSprite();
void setPos(float x, float y);
void makeMove(float velx, float vely);
};
Excuse all the common errors you will see in my class, it will be refined over time.
Anyway, the way i have it setup is that, i call a function in the main game loop called 'playerControl' and pass my player object to it, then inside the function, i have this:
void playerControl(Player player)
{
if(Keyboard::isKeyPressed(Keyboard::Left)){
player.makeMove(-1.5f, 0);
}
else if(Keyboard::isKeyPressed(Keyboard::Right)){
player.makeMove(1.5f, 0);
}
else if(Keyboard::isKeyPressed(Keyboard::Space)){
player.makeMove(0, -2.5f);
}
}
.makeMove is a function from the 'Player' class:
void Player::makeMove(float velx, float vely){
playerSprite.move(velx, vely);
}
Using this setup, i though i would be able to move the Player object that i passed to the function around. Nothing happens though. It draws to the screen but after that, it won't move.
Am i going about this the wrong way? Well, i know i am but how wrong?