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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Mihrusha

Pages: [1]
1
General / How to make setters
« on: September 26, 2021, 09:59:20 am »
How to make setters on sfml parameters?
I transfer functions from the Player class to the Game class, so that most interactions are in this class, I transfer the collision function, for example, a line in the Player class:

this-> pBody.left = j * BoxSize - this-> pBody.width;

where Pbody is FloatRect;
 so I'm trying to do in the Game class
this-> player-> setPBodyLeft (this-> player-> getPBody (). left) = j * BoxSize - this-> player-> getPBody (). width;


writes expression must have mudifiable lvalue error

so here setter and getter and the function itself

void Player :: setPBodyLeft (float x)
{
    this-> pBody.left = x;
}

const sf :: FloatRect Player :: getPBody () const
{
    return this-> pBody;
}


void Game :: PlayerMapCollision (float dir)
{
   
    for (int i = this-> player-> getPBody (). top / BoxSize; i <(this-> player-> getPBody (). top + this-> player-> getPBody (). height) / BoxSize; i ++ )
        for (int j = this-> player-> getPBody (). left / BoxSize; j <(this-> player-> getPBody (). left + this-> player-> getPBody (). width) / BoxSize; j ++ )
        {
            if (TileMap [i] [j] == 'A')
            {
                if (dx> 0 && dir == 0)
                    this-> player-> setPBodyLeft (this-> player-> getPBody (). left) = j * BoxSize -this-> player-> getPBody (). width;
                this-> player-> getPBody (). left = j * BoxSize - this-> player-> getPBody (). width;
                if (dx <0 && dir == 0)
                    this-> player-> getPBody (). left = j * BoxSize + BoxSize;
                if (dy> 0 && dir == 1)
                {
                    this-> player-> getPBody (). top = i * BoxSize - this-> player-> getPBody (). height;
                    dy = 0;
                    OnGround = true;
                }
                if (dy <0 && dir == 1)
                {
                    this-> player-> getPBody (). top = i * BoxSize + BoxSize;
                    dy = 0;
                }
            }

            if (TileMap [i] [j] == 'o')
            {
                TileMap [i] [j] = '';
                this-> health + = 10;
                this-> helthbar.setSize (sf :: Vector2f (health + 10, 20));
            std: cout << health;
            }

        }
 
}

2
General / Re: Gravity and collision problem
« on: August 23, 2021, 08:34:59 pm »
So when i render map phisics dont work properly, but when not render map sprites its work ok

3
General / Gravity and collision problem
« on: August 21, 2021, 03:41:43 pm »
my guy have trouble with top collision - he jump throw it, bottom and side collision works, and have trouble with phisics-> guy can run in air after jumping, so i need its running will be only few milisecond and function stop process if i still press button, or  he fall after some time; Also have touble with top collision.
here code example.
https://gist.github.com/Mihrusha/76427bdd09aa27a27c1f4de4f9525238

Pages: [1]
anything