Skip to content

Commit

Permalink
Fixed scrolling bug
Browse files Browse the repository at this point in the history
  • Loading branch information
TanishTuteja committed Apr 16, 2022
1 parent a21e4ae commit 296530e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void LGame::handleEvent(SDL_Event &e)

void LGame::update()
{
camera = {camera.x, camera.y, window.getWidth(), window.getHeight()};
camera = {camera.x, camera.y, window.getWidth() - tasksVPWidth, window.getHeight() - 3 * gyRenderOffset - 5 * gyPadding};
// Move the dot
for (int i = 0; i < players.size(); i++)
{
Expand All @@ -85,10 +85,11 @@ void LGame::update()
{
SDL_Rect NPCbox = NPCs[i].getBox();
int NPCtileX = (NPCbox.x + NPCbox.w / 2) / mTileWidth;
int NPCtileY = (NPCbox.y + NPCbox.h / 2) / mTileHeight ;
std::cout << NPCtileX << " " << NPCtileY << "\n" ;
if( (( tileX >= NPCtileX-1 ) && (tileX <= NPCtileX+1 )) && (( tileY >= NPCtileY-1 ) && (tileY <= NPCtileY+1 ))){
std :: cout << "collision with " << NPCs[i].getName() << "\n" ;
int NPCtileY = (NPCbox.y + NPCbox.h / 2) / mTileHeight;
std::cout << NPCtileX << " " << NPCtileY << "\n";
if (((tileX >= NPCtileX - 1) && (tileX <= NPCtileX + 1)) && ((tileY >= NPCtileY - 1) && (tileY <= NPCtileY + 1)))
{
std ::cout << "collision with " << NPCs[i].getName() << "\n";
}
}
entities[tileType].collided(players[0], displayText);
Expand Down Expand Up @@ -435,7 +436,7 @@ bool LGame::initObjs()
Player opponent(ashTexture, *this, 32, 32, 3, 1, 2, 0);
players.push_back(opponent);

camera = {0, 0, window.getWidth(), window.getHeight()};
camera = {0, 0, window.getWidth() - tasksVPWidth, window.getHeight() - 3 * gyRenderOffset - 5 * gyPadding};

if (!window.loadTexture(tilesTexture, "resources/tileset.png"))
{
Expand Down
2 changes: 1 addition & 1 deletion Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class LGame : public LScreen
bool hasTask(int task);
void replaceTask(std::pair<int, std::string> task);
void replaceTask(int task);
int getTileType( int x , int y ) ;
int getTileType(int x, int y);
};

#endif

0 comments on commit 296530e

Please sign in to comment.