Hi,
I am currently creating a game using SFML 2.0. Basically it is a top-down shooter and I am having difficulty with the statement below. Which shoots an arrow when the space bar is pressed.
There are four statements which depend on the way the player sprite (archSprite) is facing.
This is determined from the source.y which is calculated by this function -
int getCellY(DirectionKeys direction)
{
return (direction*64);
}
I am following the logic that the statement
int dir = source.y/64;
Will find out the direction the sprite is facing with the spritesheet I am using
0 = Up
1 = Left
2 = Down
3 = Right
This statement shoots correctly for everything except shooting right
if(keypress == sf::Keyboard::Space && keyPressed)
{
int tblt = this->_game_data.curr_bullet;
this->_arr_bullet_data[tblt].active = true;
//every 100th bullet it is set to the up rotation
int dir = source.y/64;
if (dir == 0)
{
_arr_bullet_spr[tblt].rotate(90);
this->_arr_bullet_data[tblt].startpos = this->archSprite.getPosition() + sf::Vector2f(64,-42);
this->_arr_bullet_data[tblt].direction = sf::Vector2f(0,-1);
}
else if (dir == 1)
{
_arr_bullet_spr[tblt].rotate(360);
this->_arr_bullet_data[tblt].startpos = this->archSprite.getPosition() + sf::Vector2f(-22,0);
this->_arr_bullet_data[tblt].direction = sf::Vector2f(-1,0);
}
else if (dir = 2)
{
_arr_bullet_spr[tblt].rotate(270);
this->_arr_bullet_data[tblt].startpos = this->archSprite.getPosition() + sf::Vector2f(0,96);
this->_arr_bullet_data[tblt].direction = sf::Vector2f(0,1);
}
else if (dir = 3)
{
_arr_bullet_spr[tblt].setRotation(180);
this->_arr_bullet_data[tblt].startpos = this->archSprite.getPosition() + sf::Vector2f(0,0);
this->_arr_bullet_data[tblt].direction = sf::Vector2f(1,0);
}
this->_arr_bullet_spr[tblt].setPosition(this>_arr_bullet_data[tblt].startpos);
this->_game_data.curr_bullet++;
}
Can anyone figure out why my arrow for direction right is shooting down and the arrow is not rotating?
It is like the statement for shooting right is being ignored all together.
Can anyone please advise?
Many Thanks