mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
* [new] przesuwanie mapy strzałkami
* [new] zakańczanie programu przez naciśnięce 'q' lub iksa w oknie
This commit is contained in:
parent
3cbe31545d
commit
b531cf169a
56
CMT.cpp
56
CMT.cpp
@ -193,6 +193,8 @@ void SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B)
|
|||||||
}
|
}
|
||||||
int _tmain(int argc, _TCHAR* argv[])
|
int _tmain(int argc, _TCHAR* argv[])
|
||||||
{
|
{
|
||||||
|
int xx=0, yy=0;
|
||||||
|
SDL_Event sEvent;
|
||||||
srand ( time(NULL) );
|
srand ( time(NULL) );
|
||||||
SDL_Surface *screen, *temp;
|
SDL_Surface *screen, *temp;
|
||||||
std::vector<SDL_Surface*> Sprites;
|
std::vector<SDL_Surface*> Sprites;
|
||||||
@ -231,17 +233,65 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||||||
mh->init();
|
mh->init();
|
||||||
THC std::cout<<"Inicjalizacja mapHandlera: "<<tmh.getDif()<<std::endl;
|
THC std::cout<<"Inicjalizacja mapHandlera: "<<tmh.getDif()<<std::endl;
|
||||||
//SDL_Rect * sr = new SDL_Rect(); sr->h=64;sr->w=64;sr->x=0;sr->y=0;
|
//SDL_Rect * sr = new SDL_Rect(); sr->h=64;sr->w=64;sr->x=0;sr->y=0;
|
||||||
SDL_Surface * teren = mh->terrainRect(0,0,32,24);
|
SDL_Surface * teren = mh->terrainRect(xx,yy,32,24);
|
||||||
THC std::cout<<"Przygotowanie terenu do wyswietlenia: "<<tmh.getDif()<<std::endl;
|
THC std::cout<<"Przygotowanie terenu do wyswietlenia: "<<tmh.getDif()<<std::endl;
|
||||||
SDL_BlitSurface(teren,NULL,ekran,NULL);
|
SDL_BlitSurface(teren,NULL,ekran,NULL);
|
||||||
|
SDL_FreeSurface(teren);
|
||||||
SDL_Flip(ekran);
|
SDL_Flip(ekran);
|
||||||
THC std::cout<<"Wyswietlenie terenu: "<<tmh.getDif()<<std::endl;
|
THC std::cout<<"Wyswietlenie terenu: "<<tmh.getDif()<<std::endl;
|
||||||
|
|
||||||
//SDL_Surface * ss = ac->defs[0]->ourImages[0].bitmap;
|
//SDL_Surface * ss = ac->defs[0]->ourImages[0].bitmap;
|
||||||
//SDL_BlitSurface(ss, NULL, ekran, NULL);
|
//SDL_BlitSurface(ss, NULL, ekran, NULL);
|
||||||
|
|
||||||
SDL_Delay(5000);
|
for(;;) // main loop
|
||||||
SDL_Quit();
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(SDL_PollEvent(&sEvent)) //wait for event...
|
||||||
|
{
|
||||||
|
if(sEvent.type==SDL_QUIT)
|
||||||
|
return 0;
|
||||||
|
else if (sEvent.type==SDL_KEYDOWN)
|
||||||
|
{
|
||||||
|
switch (sEvent.key.keysym.sym)
|
||||||
|
{
|
||||||
|
case SDLK_LEFT:
|
||||||
|
{
|
||||||
|
xx--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (SDLK_RIGHT):
|
||||||
|
{
|
||||||
|
xx++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (SDLK_UP):
|
||||||
|
{
|
||||||
|
yy--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (SDLK_DOWN):
|
||||||
|
{
|
||||||
|
yy++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (SDLK_q):
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SDL_FillRect(ekran, NULL, SDL_MapRGB(ekran->format, 0, 0, 0));
|
||||||
|
SDL_BlitSurface(mh->terrainRect(xx,yy,32,24),NULL,ekran,NULL);
|
||||||
|
SDL_Flip(ekran);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{ continue; }
|
||||||
|
|
||||||
|
SDL_Delay(100); //give time for another apps
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -17,36 +17,41 @@ void mapHandler::init()
|
|||||||
std::string name = CSemiDefHandler::nameFromType(reader->map.terrain[i][j].tertype);
|
std::string name = CSemiDefHandler::nameFromType(reader->map.terrain[i][j].tertype);
|
||||||
for (int k=0; k<reader->defs.size(); k++)
|
for (int k=0; k<reader->defs.size(); k++)
|
||||||
{
|
{
|
||||||
if (reader->defs[k]->defName != name)
|
try
|
||||||
continue;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
SDL_Surface * n;
|
if (reader->defs[k]->defName != name)
|
||||||
int ktora = reader->map.terrain[i][j].terview;
|
continue;
|
||||||
terrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
|
else
|
||||||
//TODO: odwracanie
|
|
||||||
switch ((reader->map.terrain[i][j].siodmyTajemniczyBajt)%4)
|
|
||||||
{
|
{
|
||||||
case 1:
|
SDL_Surface * n;
|
||||||
|
int ktora = reader->map.terrain[i][j].terview;
|
||||||
|
terrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
|
||||||
|
//TODO: odwracanie
|
||||||
|
switch ((reader->map.terrain[i][j].siodmyTajemniczyBajt)%4)
|
||||||
{
|
{
|
||||||
terrainBitmap[i][j] = CSDL_Ext::rotate01(terrainBitmap[i][j]);
|
case 1:
|
||||||
break;
|
{
|
||||||
|
terrainBitmap[i][j] = CSDL_Ext::rotate01(terrainBitmap[i][j]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
terrainBitmap[i][j] = CSDL_Ext::hFlip(terrainBitmap[i][j]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
terrainBitmap[i][j] = CSDL_Ext::rotate03(terrainBitmap[i][j]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case 2:
|
//SDL_BlitSurface(terrainBitmap[i][j],NULL,ekran,NULL); SDL_Flip(ekran);SDL_Delay(50);
|
||||||
{
|
|
||||||
terrainBitmap[i][j] = CSDL_Ext::hFlip(terrainBitmap[i][j]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 3:
|
|
||||||
{
|
|
||||||
terrainBitmap[i][j] = CSDL_Ext::rotate03(terrainBitmap[i][j]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//SDL_BlitSurface(terrainBitmap[i][j],NULL,ekran,NULL); SDL_Flip(ekran);SDL_Delay(50);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch (...)
|
||||||
|
{ continue; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,6 +71,8 @@ SDL_Surface * mapHandler::terrainRect(int x, int y, int dx, int dy)
|
|||||||
#endif
|
#endif
|
||||||
SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32,
|
SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32,
|
||||||
rmask, gmask, bmask, amask);
|
rmask, gmask, bmask, amask);
|
||||||
|
if (((dx+x)>((reader->map.width)-1) || (dy+y)>((reader->map.height)-1)) || ((x<0)||(y<0) ) )
|
||||||
|
throw new std::string("Poza zakresem");
|
||||||
for (int bx=0; bx<dx; bx++)
|
for (int bx=0; bx<dx; bx++)
|
||||||
{
|
{
|
||||||
for (int by=0; by<dy; by++)
|
for (int by=0; by<dy; by++)
|
||||||
@ -74,7 +81,8 @@ SDL_Surface * mapHandler::terrainRect(int x, int y, int dx, int dy)
|
|||||||
sr->y=by*32;
|
sr->y=by*32;
|
||||||
sr->x=bx*32;
|
sr->x=bx*32;
|
||||||
sr->h=sr->w=32;
|
sr->h=sr->w=32;
|
||||||
SDL_BlitSurface(terrainBitmap[bx][by],NULL,su,sr);
|
|
||||||
|
SDL_BlitSurface(terrainBitmap[bx+x][by+y],NULL,su,sr);
|
||||||
|
|
||||||
//SDL_BlitSurface(su,NULL,ekran,NULL);SDL_Flip(ekran);
|
//SDL_BlitSurface(su,NULL,ekran,NULL);SDL_Flip(ekran);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user