# DKdowneR

Member

7

0 Neutral

• Rank
Newbie

• Interests
Programming
1. ## Player out of tile map

x = 94. that's the problem. Map width, last block of the map got 94 index. As I said in a title, player runs outta map.
2. ## Player out of tile map

posX is a value that decrease if position X of Player is higher than or equal (1280/2) - playerWidth and if Player moves right. if moves left and position X of Player is lower than or equal (1280/2) - playerWidth, posX increase. The player and map moving formula are : //moving right if (posX >= (System::getFM()->getW() / 2) - getHitBoxX() && System::getSM()->GetGame()->getMoveMap())// && System::getSM()->GetGame()->getPosX() >= -1760) { System::getSM()->GetGame()->MoveMap(-moveSpeed, 0); } // player posX else posX += moveSpeed; moveAnim = true; // moving left if (posX <= (System::getFM()->getW() / 2) - getHitBoxX() && System::getSM()->GetGame()->getMoveMap() && System::getSM()->GetGame()->getPosX() < 0) { System::getSM()->GetGame()->MoveMap(-moveSpeed, 0); } else if (posX - System::getSM()->GetGame()->getPosX() + moveSpeed >= 0 && posX >= 0) { // player posX posX += moveSpeed; } else if (posX >= 0) { UpdatePosX(moveSpeed + 1); } moveAnim = true; Getgame returns GameplayScreen instace, move map is a method that add moveSpeed to posX of map. getMoveMap() returns boolean, if true, map can move, if false, it cannot. Lactose, posX is always negative or 0. Yxjmir, that's right. I gave a bad example. It's 40 because if posX = 5, still I can see only 40 block and a piece of 41, and then I add 1 to get 1 more blocks. It returns ~41. as you can see, on the right site there are pieces of blocks.
3. ## Player out of tile map

What you think it is? It returns last block, so if window is 1280 width, it returns 40, that's only what I need it to do and in draw for loop, loop through 0 to 40. So, it renders 40 block instead of ~90. If start block = 5, end = 45, etc. so, always depends on window it returns everything to render only that what need to be on the screen, nothing more, nuting less.
4. ## Player out of tile map

What do you mean by skip block?
5. ## Player out of tile map

Earth = 0. It means that I want to render first map. Do change nothing. If it would not be 0, the map would not load. Map loads properly, though.
6. ## Player out of tile map

I'm planning to do with Y direction. It doesnt matter that it's x < xEnd or x <= xEnd, because I add 1 right in the method. They looks like this: int GameplayScreen::getStartBlockX() { return (int)(-posX + (int)posX % 32) / 32; } int GameplayScreen::getEndBlockX() { return (int)(-posX + (int)posX % 32 + System::getFM()->getW()) / 32 + 1; } Also I don't think that I should check for x is negative, because it's always positive getW() returns window width.
7. ## C++ Player out of tile map

Hi! I made a tile map reading from a file. Almost everything works good, but when a player go out of map, program runs into an error and says that "vector subscript out of range". My question is how to make check for it Drawing map : void GameplayScreen::DrawMap(SDL_Renderer *renderer) { for (int y = map.size() - 1; y >= 0; --y) { for (int x = getStartBlockX(), xEnd = getEndBlockX(); x < xEnd && x < map[y].size(); ++x) { if (map[y][x] != "0,0") { int tempX = atoi(map[y][x].substr(0, map[y][x].find(',')).c_str()); int tempY = atoi(map[y][x].substr(map[y][x].find(',') + 1).c_str()); srcRect.x = tempX * 32; srcRect.y = tempY * 32; srcRect.w = 32; srcRect.h = 32; destRect.x = x * 32 + posX; destRect.y = (y * 32 + posY); destRect.w = 32; destRect.h = 32; vBlock[Earth]->Draw(renderer, srcRect, destRect); } } } } getStartBlockX returns first map block, getEndBlockX returns last, so it's like render on screen only a piece of map, not all blocks. tempX returns x coordinate of tile image, tempY y coordinate. So, for example, if map is like : 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 1,0 2,0 0,3 1,0 1,0 0,0 is first block image, 1,0 is one next to the first, 0,3 is 2 under the first block etc.
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!