1 /* 2 * Copyright 2010, 2014 Peter Olsson 3 * 4 * This file is part of Brum Brum Rally. 5 * 6 * Brum Brum Rally is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * Brum Brum Rally is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef MAP_H 21 #define MAP_H 22 23 #include <string> 24 #include "SDL.h" 25 26 class NetworkMessage; 27 class InputBinaryFile; 28 class OutputBinaryFile; 29 30 const int TILE_SIZE = 32; 31 32 const int MAX_MAP_X = 10; 33 const int MAX_MAP_Y = 7; 34 35 // Directions 36 const int LEFT = 0x01; 37 const int RIGHT = 0x02; 38 const int UP = 0x04; 39 const int DOWN = 0x08; 40 41 // Road connections 42 const int ROAD_HORIZONTAL = LEFT | RIGHT; 43 const int ROAD_VERTICAL = UP | DOWN; 44 const int ROAD_LEFT_UP = LEFT | UP; 45 const int ROAD_LEFT_DOWN = LEFT | DOWN; 46 const int ROAD_RIGHT_UP = RIGHT | UP; 47 const int ROAD_RIGHT_DOWN = RIGHT | DOWN; 48 49 // A map should be seen as a real map. 50 // It is just a description of a track; 51 class Map 52 { 53 public: 54 static Map generate(); 55 void zeroFill(); 56 int getRoadCount() const; // gives #tiles occupied by road 57 double getScore() const; 58 const Uint8* operator[](int y) const; 59 int getFinishX() const; 60 int getFinishY() const; 61 int getFinishDir() const; 62 int getDecoration(int x, int y) const; 63 std::string getTilesetName() const; 64 void write(NetworkMessage& msg) const; 65 void read(NetworkMessage& msg); 66 void write(OutputBinaryFile& out) const; 67 void read(InputBinaryFile& in); 68 bool isValid() const; 69 private: 70 void makeTrack(); 71 void makeConnection(int lowerX, int upperX, int lowerY, int upperY, int connectionX1, int connectionY1, int connectionDir1, int connectionX2, int connectionY2, int connectionDir2); 72 void center(); 73 74 Uint8 map[MAX_MAP_Y][MAX_MAP_X]; 75 Uint8 decoration[MAX_MAP_Y][MAX_MAP_X]; 76 std::string tileset; 77 int finishX; 78 int finishY; 79 int finishDir; 80 }; 81 82 #endif 83