Hello, I'm trying to implement a tilemap engine for making a tetris or jump n run... the collision detection works but i have no clue why the programm crashes if i touch the border of the window... everytime I get out of the window the following message appears:
terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check
Aborted
here is my movement:
if(isMovingUp) {
unsigned int x = hero.getPosition().x / 32;
unsigned int y = hero.getPosition().y / 32 - 1;
if(y >= 0) {
if(map.getTile(x, y).collision == false) {
hero.setPosition(x * 32, y * 32);
}
}
}
if(isMovingDown) {
unsigned int x = hero.getPosition().x / 32;
unsigned int y = hero.getPosition().y / 32 + 1;
if(y < map.getSize().y) {
if(map.getTile(x, y).collision == false) {
hero.setPosition(x * 32, y * 32);
}
}
}
if(isMovingLeft) {
unsigned int x = hero.getPosition().x / 32 - 1;
unsigned int y = hero.getPosition().y / 32;
if(y >= 0) {
if(map.getTile(x, y).collision == false) {
hero.setPosition(x * 32, y * 32);
}
}
}
if(isMovingRight) {
unsigned int x = hero.getPosition().x / 32 + 1;
unsigned int y = hero.getPosition().y / 32;
if(x < map.getSize().x) {
if(map.getTile(x, y).collision == false) {
hero.setPosition(x * 32, y * 32);
}
}
}