Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: 4th Shooting statement not working in SFML game.  (Read 1467 times)

0 Members and 1 Guest are viewing this topic.

PapaSmurf

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
4th Shooting statement not working in SFML game.
« on: March 14, 2015, 04:10:33 pm »
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

grok

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • Email
Re: 4th Shooting statement not working in SFML game.
« Reply #1 on: March 14, 2015, 07:36:59 pm »
Quote
else if (dir = 2)
change it to
Quote
else if (dir == 2)

same goes for
Quote
else if (dir = 3)

 

anything