Advertisement
timscampi

Outbreak - map.lib

Oct 17th, 2011
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.49 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // Outbreak - MAP DRAWING LIBRARY                                             //
  3. // Version 0.1 - 10/13/2011                                                   //
  4. // Created by: Julien 'Timscampi' Machiels                                    //
  5. // Under GPL v3 licence                                                       //
  6. ////////////////////////////////////////////////////////////////////////////////
  7.  
  8. ////////////////////////////////////////////////////////////////////////////////
  9. //// Refreshes the map each frame //////////////////////////////////////////////
  10. ////////////////////////////////////////////////////////////////////////////////
  11. procedure frame(x,y,xmax,ymax,color : byte);
  12. var tracex, tracey : byte;
  13. begin
  14.     // Top map border
  15.         textcolor(color);  
  16.         gotoxy(x,y);
  17.         write(chr(201));   
  18.         for tracex := x+1 to xmax do
  19.             begin
  20.                 gotoxy(tracex,y);
  21.                 write(chr(205));
  22.             end;
  23.         gotoxy(xmax+1,y);
  24.         write(chr(187));
  25.         // Bottom map border
  26.         gotoxy(x,ymax+1);
  27.         write(chr(200));   
  28.         for tracex := x+1 to xmax do
  29.             begin
  30.                 gotoxy(tracex,ymax+1);
  31.                 write(chr(205));
  32.             end;
  33.         gotoxy(xmax+1,ymax+1);
  34.         write(chr(188));
  35.         // Left map border
  36.         for tracey := y+1 to ymax do
  37.             begin
  38.                 gotoxy(x,tracey);
  39.                 write(chr(186));
  40.             end;
  41.         // Left map border
  42.         for tracey := y+1 to ymax do
  43.             begin
  44.                 gotoxy(xmax+1,tracey);
  45.                 write(chr(186));
  46.             end;
  47. end;
  48.  
  49. procedure drawmap;
  50. var y,x,map_x, map_y    : integer;
  51. begin
  52.     clrscr;
  53.     map_x := 0;
  54.     map_y := 0;
  55.     frame(map_padx,map_pady,map_padx+map_width,map_pady+map_height,3);
  56.     // Map drawing
  57.     // FIX: drawing gliches
  58.     // TODO: limit drawing to actual map
  59.     for y := (nPlayerY - (map_height div 2)) to (nPlayerY + (map_height div 2)) do
  60.         begin
  61.             for x := (nPlayerX - (map_width div 2)) to (nPlayerX + (map_width div 2)) do
  62.                 begin
  63.                     gotoxy(map_padx+map_x+1,map_pady+map_y+1); // FIX: Nasty alignement hack
  64.                     if ((x < 1) or (x >= mapx+1)) or ((y < 1) or (y >= mapy+1)) then
  65.                         begin
  66.                             nType := 4; // Void
  67.                         end
  68.                     else
  69.                         begin
  70.                             nType := map[y,x]+1; // FIX: Nasty tile_tb hack
  71.                         end;
  72.                     textcolor(tile_db[nType].txtcol);
  73.                     textbackground(tile_db[nType].bkgcol);
  74.                     write(chr(tile_db[nType].txt));
  75.                     textcolor(15);
  76.                     textbackground(0);
  77.                     inc(map_x);
  78.                 end;
  79.             map_x := 0;
  80.             inc(map_y);
  81.         end;
  82. end;
  83.  
  84. ////////////////////////////////////////////////////////////////////////////////
  85. //// Refreshes the player each frame ///////////////////////////////////////////
  86. ////////////////////////////////////////////////////////////////////////////////
  87. // TODO: make the player free to move when the screen hits the map's border
  88. procedure drawchar;
  89.     begin
  90.         textcolor(14);
  91.         gotoxy(19,12);
  92.         write('@');
  93.     end;
  94.  
  95. ////////////////////////////////////////////////////////////////////////////////
  96. //// Checks if the next movement is possible ///////////////////////////////////
  97. ////////////////////////////////////////////////////////////////////////////////
  98. function isPassable(x, y : integer) : boolean;
  99.     begin
  100.         // Check if the player is inside the map
  101.         if ((x< 1) or (x >= mapx+1)) or ((y < 2) or (y >= mapy+2)) then
  102.             begin
  103.                 isPassable := FALSE;
  104.             end
  105.         else
  106.             begin
  107.                 nType := map[y-1,x];
  108.                 isPassable := not tile_db[nType].passable;
  109.             end;
  110.     end;
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement