1 /* 2 Pacman Arena 3 Copyright (C) 2003 Nuno Subtil 4 5 This program is free software; you can redistribute it and/or 6 modify it under the terms of the GNU General Public License 7 as published by the Free Software Foundation; either version 2 8 of the License, or (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 */ 19 20 /* $Id: map.h,v 1.2 2003/11/22 17:32:10 nsubtil Exp $ */ 21 22 #ifndef _MAP_H 23 #define _MAP_H 24 25 #define MAP_WALL_NONE 0 26 #define MAP_WALL_VERTICAL 1 27 #define MAP_WALL_HORIZONTAL 2 28 #define MAP_WALL_LL 3 29 #define MAP_WALL_LR 4 30 #define MAP_WALL_UL 5 31 #define MAP_WALL_UR 6 32 /* only ghosts may traverse this wall */ 33 #define MAP_WALL_GHOST_ONLY 7 34 35 #define MAP_CONTENT_NONE 0 36 #define MAP_CONTENT_FOOD 1 37 #define MAP_CONTENT_PILL 2 38 #define MAP_CONTENT_TELEPORT 3 39 40 #define MAP_FLAGS_NONE 0 41 #define MAP_FLAG_PACMAN_START_POSITION 1 42 #define MAP_FLAG_GHOST_START_POSITION 2 43 #define MAP_FLAG_BOMB 4 44 45 /* pacman food */ 46 47 /* eat once */ 48 #define FOOD_TYPE_NORMAL 0 49 /* respawns after being eaten */ 50 #define FOOD_TYPE_RESPAWN 1 51 /* respawns, disappears */ 52 #define FOOD_TYPE_INTERMITTENT 2 53 54 #define FOOD_STATUS_ACTIVE 0 55 #define FOOD_STATUS_EATEN 1 56 57 struct pacman_food 58 { 59 int type; 60 int status; 61 float time; 62 63 /* INTERMITTENT: food disappears after being active for active_time seconds */ 64 float active_time; 65 /* INTERMITTENT: food fades out during last fade_out seconds */ 66 float fade_out; 67 68 /* INTERMITTENT/RESPAWN: food respawns after inactive_time seconds */ 69 float inactive_time; 70 /* INTERMITTENT/RESPAWN: food fades in during last fade_in seconds */ 71 float fade_in; 72 }; 73 74 75 /* pacman pills */ 76 77 #define PILL_STATUS_ACTIVE 0 78 #define PILL_STATUS_EATEN 1 79 80 /* angular frequency (rad/s) */ 81 #define PILL_BOB_FREQUENCY 4.0 82 83 struct pacman_pill 84 { 85 int status; 86 float phase; 87 }; 88 89 90 /* teleports */ 91 92 struct teleport 93 { 94 int dest_x, dest_y; 95 int direction; 96 }; 97 98 99 /* map tile */ 100 101 struct map_tile 102 { 103 /* wall type */ 104 int wall; 105 106 /* content type (food, pill, teleport, etc) */ 107 int content; 108 /* content data */ 109 union 110 { 111 struct pacman_food food; 112 struct pacman_pill pill; 113 struct teleport teleport; 114 } c_data; 115 116 /* tile flags */ 117 int flags; 118 119 /* ghost direction towards nearest spawn on this tile */ 120 int ghost_dir; 121 /* ghost direction when ghost is alive (for exits, etc) */ 122 int ghost_dir_alive; 123 }; 124 125 struct map 126 { 127 int width; 128 int height; 129 130 struct map_tile **tiles; 131 }; 132 133 #define MAP(map, x, y) map->tiles[y][x] 134 #define MAP_CONTENT_DATA(map, x, y) map->tiles[y][x].content_data 135 #define MAP_CAN_ENTER(map, x, y) (x >= 0 && x < map->width && y >= 0 && y < map->height && MAP(map, x, y).wall == MAP_WALL_NONE)// && MAP(map, x, y).content != MAP_CONTENT_TELEPORT) 136 #define MAP_CAN_ENTER_GHOST(map, x, y) (x >= 0 && x < map->width && y >= 0 && y < map->height && (MAP(map, x, y).wall == MAP_WALL_NONE || MAP(map, x, y).wall == MAP_WALL_GHOST_ONLY))// && MAP(map, x, y).content != MAP_CONTENT_TELEPORT) 137 138 #define MAP_FOOD(map, x, y) MAP(map, x, y).c_data.food 139 #define MAP_PILL(map, x, y) MAP(map, x, y).c_data.pill 140 #define MAP_TELEPORT(map, x, y) MAP(map, x, y).c_data.teleport 141 142 struct map *map_load_from_ascii(char **game_map, char **ghost_map, int width, int height); 143 void map_free(struct map *map); 144 void map_update(struct map *map, float delta); 145 int map_collision_square(struct game *game, int x, int y); 146 int map_detect_collision(struct game *game, float start_pos[3], float end_pos[3], int ret[2]); 147 int map_inside(struct game *game, int x, int y); 148 149 #endif 150