Update code.
Fix Bug in TiledMap
This commit is contained in:
parent
29c4a7752b
commit
ddee7a399d
|
@ -57,8 +57,8 @@ void TiledMap::setRectSize(int RectSize)
|
||||||
|
|
||||||
void TiledMap::setViewPoint(int Line, int Col)
|
void TiledMap::setViewPoint(int Line, int Col)
|
||||||
{
|
{
|
||||||
Line=std::min(std::max(Line,0),sp->l);
|
Line=std::min(std::max(Line,0),sp->l-1);
|
||||||
Col=std::min(std::max(Col,0),sp->c);
|
Col=std::min(std::max(Col,0),sp->c-1);
|
||||||
sp->vpline=Line;
|
sp->vpline=Line;
|
||||||
sp->vpcol=Col;
|
sp->vpcol=Col;
|
||||||
}
|
}
|
||||||
|
|
22
main.cpp
22
main.cpp
|
@ -4,10 +4,12 @@ using namespace MiniEngine;
|
||||||
|
|
||||||
#include "TiledMap.h"
|
#include "TiledMap.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <ctime>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int AppMain()
|
int AppMain()
|
||||||
{
|
{
|
||||||
|
srand(time(NULL));
|
||||||
Window wnd("TiledMap",1024,768);
|
Window wnd("TiledMap",1024,768);
|
||||||
Renderer rnd=wnd.getRenderer();
|
Renderer rnd=wnd.getRenderer();
|
||||||
|
|
||||||
|
@ -42,9 +44,7 @@ int AppMain()
|
||||||
rc.y=center.y-(vl-i)*width-width/2;
|
rc.y=center.y-(vl-i)*width-width/2;
|
||||||
rc.w=rc.h=width;
|
rc.w=rc.h=width;
|
||||||
|
|
||||||
SDL_Rect a=rc.toSDLRect();
|
if(rc.hasIntersection(wnd.getSize()))
|
||||||
SDL_Rect b=wnd.getSize().toSDLRect();
|
|
||||||
if(SDL_HasIntersection(&a,&b)==SDL_TRUE)
|
|
||||||
{
|
{
|
||||||
switch(tmap[i][j].tid)
|
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();
|
rnd.update();
|
||||||
};
|
};
|
||||||
lp.add(SDL_QUIT,[&](){lp.stop();});
|
lp.add(SDL_QUIT,[&](){lp.stop();});
|
||||||
lp.add(SDL_KEYDOWN,[&](Event& e)
|
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)
|
switch(e.key.keysym.sym)
|
||||||
{
|
{
|
||||||
case SDLK_KP_PLUS:
|
case SDLK_KP_PLUS:
|
||||||
|
@ -108,6 +119,11 @@ int AppMain()
|
||||||
lp.needupdate();
|
lp.needupdate();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
{
|
||||||
|
lp.stop();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
lp.run();
|
lp.run();
|
||||||
|
|
Reference in New Issue
Block a user