117 lines
2.9 KiB
C++
117 lines
2.9 KiB
C++
#include "MiniEngine/MiniEngine.h"
|
|
#include "MiniEngine/MiniEngine_Event.h"
|
|
using namespace MiniEngine;
|
|
|
|
#include "TiledMap.h"
|
|
#include <cstdlib>
|
|
using namespace std;
|
|
|
|
int AppMain()
|
|
{
|
|
Window wnd("TiledMap",1024,768);
|
|
Renderer rnd=wnd.getRenderer();
|
|
|
|
TiledMap tmap(20,15,20);
|
|
for(int i=0;i<20;i++)
|
|
{
|
|
for(int j=0;j<15;j++)
|
|
{
|
|
TiledBox box;
|
|
box.tid=-1-rand()%2;
|
|
if(box.tid==-2) box.color=RGBA(255,0,0,0);
|
|
tmap[i][j]=box;
|
|
}
|
|
}
|
|
tmap.setViewPoint(10,7);
|
|
|
|
Looper lp;
|
|
lp.updater=[&]()
|
|
{
|
|
Point center(1024/2,768/2);
|
|
int vl,vc;
|
|
tmap.getViewPoint(vl,vc);
|
|
int width=tmap.getRectSize();
|
|
|
|
rnd.clear();
|
|
for(int i=0;i<20;i++)
|
|
{
|
|
for(int j=0;j<15;j++)
|
|
{
|
|
Rect rc;
|
|
rc.x=center.x-(vc-j)*width-width/2;
|
|
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)
|
|
{
|
|
switch(tmap[i][j].tid)
|
|
{
|
|
case -1:
|
|
break;
|
|
case -2:
|
|
rnd.setColor(tmap[i][j].color);
|
|
rnd.fillRect(rc);
|
|
rnd.setColor(RGBA(0,0,0,0));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
rnd.update();
|
|
};
|
|
lp.add(SDL_QUIT,[&](){lp.stop();});
|
|
lp.add(SDL_KEYDOWN,[&](Event& e)
|
|
{
|
|
switch(e.key.keysym.sym)
|
|
{
|
|
case SDLK_KP_PLUS:
|
|
printf("Plus Pressed.\n");
|
|
tmap.setRectSize(tmap.getRectSize()+10);
|
|
lp.needupdate();
|
|
break;
|
|
case SDLK_KP_MINUS:
|
|
printf("Minus Presse.\n");
|
|
tmap.setRectSize(tmap.getRectSize()-10);
|
|
lp.needupdate();
|
|
break;
|
|
case SDLK_DOWN:
|
|
{
|
|
int vx,vy;
|
|
tmap.getViewPoint(vx,vy);
|
|
tmap.setViewPoint(vx+1,vy);
|
|
lp.needupdate();
|
|
}
|
|
break;
|
|
case SDLK_UP:
|
|
{
|
|
int vx,vy;
|
|
tmap.getViewPoint(vx,vy);
|
|
tmap.setViewPoint(vx-1,vy);
|
|
lp.needupdate();
|
|
}
|
|
break;
|
|
case SDLK_LEFT:
|
|
{
|
|
int vx,vy;
|
|
tmap.getViewPoint(vx,vy);
|
|
tmap.setViewPoint(vx,vy-1);
|
|
lp.needupdate();
|
|
}
|
|
break;
|
|
case SDLK_RIGHT:
|
|
{
|
|
int vx,vy;
|
|
tmap.getViewPoint(vx,vy);
|
|
tmap.setViewPoint(vx,vy+1);
|
|
lp.needupdate();
|
|
}
|
|
break;
|
|
}
|
|
});
|
|
lp.run();
|
|
|
|
return 0;
|
|
}
|