mapHandler.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "stdafx.h"
  2. #include "mapHandler.h"
  3. #include "CSemiDefHandler.h"
  4. #include "SDL_rotozoom.h"
  5. #include "SDL_Extensions.h"
  6. extern SDL_Surface * ekran;
  7. void mapHandler::init()
  8. {
  9. terrainBitmap = new SDL_Surface **[reader->map.width];
  10. for (int ii=0;ii<reader->map.width;ii++)
  11. terrainBitmap[ii] = new SDL_Surface*[reader->map.height]; // allocate memory
  12. for (int i=0; i<reader->map.width; i++)
  13. {
  14. for (int j=0; j<reader->map.height;j++)
  15. {
  16. TerrainTile zz = reader->map.terrain[i][j];
  17. std::string name = CSemiDefHandler::nameFromType(reader->map.terrain[i][j].tertype);
  18. for (int k=0; k<reader->defs.size(); k++)
  19. {
  20. if (reader->defs[k]->defName != name)
  21. continue;
  22. else
  23. {
  24. SDL_Surface * n;
  25. int ktora = reader->map.terrain[i][j].terview;
  26. terrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
  27. //TODO: odwracanie
  28. switch ((reader->map.terrain[i][j].siodmyTajemniczyBajt)%4)
  29. {
  30. case 1:
  31. {
  32. terrainBitmap[i][j] = CSDL_Ext::rotate01(terrainBitmap[i][j]);
  33. break;
  34. }
  35. case 2:
  36. {
  37. terrainBitmap[i][j] = CSDL_Ext::hFlip(terrainBitmap[i][j]);
  38. break;
  39. }
  40. case 3:
  41. {
  42. terrainBitmap[i][j] = CSDL_Ext::rotate03(terrainBitmap[i][j]);
  43. break;
  44. }
  45. }
  46. //SDL_BlitSurface(terrainBitmap[i][j],NULL,ekran,NULL); SDL_Flip(ekran);SDL_Delay(50);
  47. break;
  48. }
  49. }
  50. }
  51. }
  52. }
  53. SDL_Surface * mapHandler::terrainRect(int x, int y, int dx, int dy)
  54. {
  55. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  56. int rmask = 0xff000000;
  57. int gmask = 0x00ff0000;
  58. int bmask = 0x0000ff00;
  59. int amask = 0x000000ff;
  60. #else
  61. int rmask = 0x000000ff;
  62. int gmask = 0x0000ff00;
  63. int bmask = 0x00ff0000;
  64. int amask = 0xff000000;
  65. #endif
  66. SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32,
  67. rmask, gmask, bmask, amask);
  68. for (int bx=0; bx<dx; bx++)
  69. {
  70. for (int by=0; by<dy; by++)
  71. {
  72. SDL_Rect * sr = new SDL_Rect;
  73. sr->y=by*32;
  74. sr->x=bx*32;
  75. sr->h=sr->w=32;
  76. SDL_BlitSurface(terrainBitmap[bx][by],NULL,su,sr);
  77. //SDL_BlitSurface(su,NULL,ekran,NULL);SDL_Flip(ekran);
  78. }
  79. }
  80. return su;
  81. }