diff --git a/CMT.cpp b/CMT.cpp index b417eaa81..f4387c7a0 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -192,7 +192,9 @@ void SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B) SDL_UpdateRect(ekran, x, y, 1, 1); } int _tmain(int argc, _TCHAR* argv[]) -{ +{ + int xx=0, yy=0; + SDL_Event sEvent; srand ( time(NULL) ); SDL_Surface *screen, *temp; std::vector Sprites; @@ -231,17 +233,65 @@ int _tmain(int argc, _TCHAR* argv[]) mh->init(); THC std::cout<<"Inicjalizacja mapHandlera: "<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: "<defs[0]->ourImages[0].bitmap; //SDL_BlitSurface(ss, NULL, ekran, NULL); - SDL_Delay(5000); - SDL_Quit(); + for(;;) // main loop + { + 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; } else diff --git a/mapHandler.cpp b/mapHandler.cpp index 46f7a640a..9846056d6 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -17,36 +17,41 @@ void mapHandler::init() std::string name = CSemiDefHandler::nameFromType(reader->map.terrain[i][j].tertype); for (int k=0; kdefs.size(); k++) { - if (reader->defs[k]->defName != name) - continue; - else + try { - 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) + if (reader->defs[k]->defName != name) + continue; + else { - 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]); - break; + case 1: + { + 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: - { - 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); + //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 SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32, 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; bxy=by*32; sr->x=bx*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); }