Update code.

Fix Bug in TiledMap
master
Kirigaya Kazuto 2017-05-09 11:06:44 +08:00
parent 29c4a7752b
commit ddee7a399d
2 changed files with 21 additions and 5 deletions

View File

@ -57,8 +57,8 @@ void TiledMap::setRectSize(int RectSize)
void TiledMap::setViewPoint(int Line, int Col)
{
Line=std::min(std::max(Line,0),sp->l);
Col=std::min(std::max(Col,0),sp->c);
Line=std::min(std::max(Line,0),sp->l-1);
Col=std::min(std::max(Col,0),sp->c-1);
sp->vpline=Line;
sp->vpcol=Col;
}

View File

@ -4,10 +4,12 @@ using namespace MiniEngine;
#include "TiledMap.h"
#include <cstdlib>
#include <ctime>
using namespace std;
int AppMain()
{
srand(time(NULL));
Window wnd("TiledMap",1024,768);
Renderer rnd=wnd.getRenderer();
@ -42,9 +44,7 @@ int AppMain()
rc.y=center.y-(vl-i)*width-width/2;
rc.w=rc.h=width;
SDL_Rect a=rc.toSDLRect();
SDL_Rect b=wnd.getSize().toSDLRect();
if(SDL_HasIntersection(&a,&b)==SDL_TRUE)
if(rc.hasIntersection(wnd.getSize()))
{
switch(tmap[i][j].tid)
{
@ -59,11 +59,22 @@ int AppMain()
}
}
}
Rect rc;
rc.x=center.x-width/2;
rc.y=center.y-width/2;
rc.w=rc.h=width;
rnd.setColor(RGBA(0,255,0,0));
rnd.fillRect(rc);
rnd.setColor(RGBA(0,0,0,0));
rnd.update();
};
lp.add(SDL_QUIT,[&](){lp.stop();});
lp.add(SDL_KEYDOWN,[&](Event& e)
{
int vl,vc;
tmap.getViewPoint(vl,vc);
printf("Position: Line %d Col %d\n",vl,vc);
switch(e.key.keysym.sym)
{
case SDLK_KP_PLUS:
@ -108,6 +119,11 @@ int AppMain()
lp.needupdate();
}
break;
case SDLK_ESCAPE:
{
lp.stop();
}
break;
}
});
lp.run();