From f5570c7d08faf482bc4cc0576df4f68676b63c69 Mon Sep 17 00:00:00 2001 From: Deskull Date: Thu, 1 Jan 2015 23:27:30 +0900 Subject: [PATCH] =?utf8?q?=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89?= =?utf8?q?=E3=81=AE=E3=83=95=E3=82=A9=E3=83=BC=E3=82=AB=E3=82=B9=E5=87=A6?= =?utf8?q?=E7=90=86=E3=82=92=E5=AE=9F=E8=A3=85=20/=20Implement=20focusing?= =?utf8?q?=20on=20fields.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Deeangband/GameEngine.cpp | 1 + Deeangband/GameSurfaceSDL.cpp | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Deeangband/GameEngine.cpp b/Deeangband/GameEngine.cpp index 6e3a54f..c2431e4 100644 --- a/Deeangband/GameEngine.cpp +++ b/Deeangband/GameEngine.cpp @@ -115,6 +115,7 @@ namespace Deeangband } creaturePtr->Walk(this->gameLogger, direction); + this->gameSurface->FocusField(creaturePtr->GetPosition()); return true; } diff --git a/Deeangband/GameSurfaceSDL.cpp b/Deeangband/GameSurfaceSDL.cpp index 5c91de6..1f1a676 100644 --- a/Deeangband/GameSurfaceSDL.cpp +++ b/Deeangband/GameSurfaceSDL.cpp @@ -152,7 +152,17 @@ namespace Deeangband SDL_FillRect(windowSurface, &rect, SDL_MapRGBA(windowSurface->format, 50, 20, 10, 255)); SDL_BlitSurface(titleSurface, &title, windowSurface, &title); - if(this->viewFieldPtr) this->drawField(gameWorld, viewFieldPtr, 0, 0, mapDrawingSize.GetX(), mapDrawingSize.GetY()); + if(this->viewFieldPtr) + { + int fx = focusPoint.GetX() - (mapDrawingSize.GetX() / 2); + int fy = focusPoint.GetY() - (mapDrawingSize.GetY() / 2); + if(fx < 0) fx = 0; + if(fy < 0) fy = 0; + if(fx > viewFieldPtr->GetWidth() - mapDrawingSize.GetX()) fx = viewFieldPtr->GetWidth() - mapDrawingSize.GetX(); + if(fy > viewFieldPtr->GetHeight() - mapDrawingSize.GetY()) fy = viewFieldPtr->GetHeight() - mapDrawingSize.GetY(); + + this->drawField(gameWorld, viewFieldPtr, fx, fy, mapDrawingSize.GetX(), mapDrawingSize.GetY()); + } if(this->sideStatusCreatutePtr) this->drawSideCreatureStatus(); if(this->viewCreaturePtr) this->drawCreatureStatus(viewCreaturePtr); if(this->currentSystemMessage.size() > 0) this->drawSystemMessage(); @@ -491,7 +501,7 @@ void GameSurfaceSDL::calcMapDrawingSize(Coordinates *size) { int x, y; SDL_GetWindowSize(window, &x, &y); - size->Set((x - GameSurfaceSDL::sideBarWidth / 24), y / 24); + size->Set((x - GameSurfaceSDL::sideBarWidth) / 24, y / 24 - 1); return; } @@ -511,7 +521,7 @@ void GameSurfaceSDL::drawField(GameWorld *gameWorld, Field *fieldPtr, int x, int if(px < fieldPtr->GetWidth() && py < fieldPtr->GetHeight()) { TAG tag = fieldPtr->GetSquare(px, py)->GetFloorTag(); - SDL_Rect blitRect = {GameSurfaceSDL::sideBarWidth + px * 24, 30 + py * 24 , 24, 24}; + SDL_Rect blitRect = {GameSurfaceSDL::sideBarWidth + (px - x) * 24, 30 + (py - y) * 24 , 24, 24}; SDL_BlitSurface(floorSurfaces[tag], &symbolRect, windowSurface, &blitRect); } } @@ -523,7 +533,7 @@ void GameSurfaceSDL::drawField(GameWorld *gameWorld, Field *fieldPtr, int x, int { updateCreatureGraphics(creatureIt); } - SDL_Rect blitRect = {GameSurfaceSDL::sideBarWidth + creatureIt->second->GetPosition().GetX() * 24, 30 + creatureIt->second->GetPosition().GetY() * 24 , 24, 24}; + SDL_Rect blitRect = {GameSurfaceSDL::sideBarWidth + (creatureIt->second->GetPosition().GetX() - x) * 24, 30 + (creatureIt->second->GetPosition().GetY()- y) * 24 , 24, 24}; SDL_BlitSurface(creatureSurfaces[creatureIt->first], &symbolRect, windowSurface, &blitRect); } } -- 2.11.0