0

I'm fighting with this for like few days, and I have no idea, how to do that, so I'd like to ask you for help. I've got no idea how collision should look like right here, so player could jump through 'down zone' of the block, and stay right on the block.

block.cpp

bool block::CollidingWithPlayer(character& player) { 
    for (int i = 1; i < MAX_BLOCKS; i++) {
        if (player.x + player.width >= coordinateX[i] && player.x <= coordinateX[i] + width[i] && player.y + player.height >= coordinateY[i] && player.y <= coordinateY[i] + block_height) {
            player.onGround = true;
            return true;
        }
    }
}

character.cpp

void character::startJump(map& Map, character& player) {
    if (onGround)
    {
        vel[1] = -11.0;
        onGround = false;
    }
}
void character::updateJump(block& Block, character& player) {
    if (!onGround) {
        Block.CollidingWithPlayer(player);
        vel[1] += 0.5;
        y += vel[1];
        x += vel[0];
    }
    if (y > 460){
        y = 460;
        vel[1] = 0.0;
        onGround = true;
        vel[0] = 0.0;
    }

    if ((x + width >= START_OF_RIGHT_WALL && x <= WALL_WIDTH + START_OF_RIGHT_WALL) || (x + width >= START_OF_LEFT_WALL &&x <= START_OF_LEFT_WALL + WALL_WIDTH)){
    vel[0] *= -1;
    bound = true;
    if (direction == 1)
        direction = 2;
    else if (direction == 2)
        direction = 1;
    }
}
  • It's not clear what works in your code and what doesn't. I'd consider, for the time being, removing the jumping and just control your characters y position via arrow keys. Doing so will make it far easier to debug where the issue in your code is. You can move your character up to be underneath the platform, then see if they can move through. Halfway through see if they can move down or not. Then move them all the way through, and then down again. You'll be able to see in your debugger where the issue lies. – Tas Nov 08 '17 at 21:42
  • Thanks for reply, the issue is that, so when I jump, my character gets stucked in block, because the collision condition is always true. It's like i can jump few times "inside the block", before I leave it. I'd need condition like, which would check only from the top-side of the block, if player is on it. – Maciej Wroński Nov 08 '17 at 21:46

0 Answers0