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 - nsteiner25

Pages: [1]
1
General / Re: Difficulty with wall collision (FIXED)
« on: August 08, 2023, 12:35:13 am »
Update: I fixed it, it had nothing to do with this function, but with how I was printing the walls

Also, this is my first time posting to this board, is there something I am supposed to do when my problem is solved

2
General / Re: Difficulty with wall collision
« on: August 08, 2023, 12:27:34 am »
tbh I put my original function into chatGPT and got that, but it had the same issue so I just left it

here's my new function, but it still does the same thing:

for (size_t j = 0; j < enemies.size(); j++) {
        size_t i;
        for (i = 0; i < walls.size(); i++) {
            if (walls->wall.getGlobalBounds().intersects(enemies[j]->enemySprite.getGlobalBounds())) {
                delete enemies[j];
                enemies.erase(enemies.begin() + j);
                walls->hp--;

                if (walls->hp <= 0) {
                    delete walls;
                    walls.erase(walls.begin() + i);
                }
            }
        }
    }

side note, the walls are now pointers

3
General / Difficulty with wall collision (FIXED)
« on: August 05, 2023, 05:37:30 pm »
In my game I have enemies that move down the screen, and if they hit a wall, the hp of that wall goes down and the enemy is deleted. Once the hp of the wall is 0, the wall is deleted. Everything seems to work fine until around the 5th or 6th wall is deleted. There are three rows of walls stacked in a brick-like formation, and when one of the walls in the second or third row is deleted and there still exists a wall in a row above it, that one above it is also deleted.

Here is my code:

void Wall::updateWalls(std::vector<Wall>& walls, std::vector<Enemy*>& enemies){
    for (size_t j = 0; j < enemies.size(); j++) {
   
        bool wallErased = false;

        size_t i;
        for (i = 0; i < walls.size(); i++) {
            if (walls.wall.getGlobalBounds().intersects(enemies[j]->enemySprite.getGlobalBounds())) {
                enemies.erase(enemies.begin() + j);
                walls.hp--;

                if (walls.hp <= 0) {
                    wallErased = true;
                    break;
                }
            }
        }
        if (wallErased) {
            walls.erase(walls.begin() + i);
            i--;
        }
    }
}

Pages: [1]
anything