pocket tanks
Dependencies: 4DGL-uLCD-SE pockettanks SDFileSystem mbed wave_player
Fork of ECE2035_FroggerGame_SUM1025 by
map/map.cpp@3:8f68c00dd75a, 2015-10-22 (annotated)
- Committer:
- ece2035ta
- Date:
- Thu Oct 22 03:47:32 2015 +0000
- Revision:
- 3:8f68c00dd75a
- Parent:
- 1:172fbc00199c
hi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leuyentran | 0:7fe3c940e4b5 | 1 | /* Gatech ECE2035 2015 SPRING PAC MAN |
leuyentran | 0:7fe3c940e4b5 | 2 | * Copyright (c) 2015 Gatech ECE2035 |
leuyentran | 0:7fe3c940e4b5 | 3 | * |
leuyentran | 0:7fe3c940e4b5 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
leuyentran | 0:7fe3c940e4b5 | 5 | * of this software and associated documentation files (the "Software"), to deal |
leuyentran | 0:7fe3c940e4b5 | 6 | * in the Software without restriction, including without limitation the rights |
leuyentran | 0:7fe3c940e4b5 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
leuyentran | 0:7fe3c940e4b5 | 8 | * copies of the Software, and to permit persons to whom the Software is |
leuyentran | 0:7fe3c940e4b5 | 9 | * furnished to do so, subject to the following conditions: |
leuyentran | 0:7fe3c940e4b5 | 10 | * |
leuyentran | 0:7fe3c940e4b5 | 11 | * The above copyright notice and this permission notice shall be included in |
leuyentran | 0:7fe3c940e4b5 | 12 | * all copies or substantial portions of the Software. |
leuyentran | 0:7fe3c940e4b5 | 13 | * |
leuyentran | 0:7fe3c940e4b5 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
leuyentran | 0:7fe3c940e4b5 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
leuyentran | 0:7fe3c940e4b5 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
leuyentran | 0:7fe3c940e4b5 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
leuyentran | 0:7fe3c940e4b5 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
leuyentran | 0:7fe3c940e4b5 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
leuyentran | 0:7fe3c940e4b5 | 20 | * SOFTWARE. |
leuyentran | 0:7fe3c940e4b5 | 21 | */ |
leuyentran | 0:7fe3c940e4b5 | 22 | |
leuyentran | 0:7fe3c940e4b5 | 23 | #include "map_private.h" |
leuyentran | 0:7fe3c940e4b5 | 24 | |
leuyentran | 0:7fe3c940e4b5 | 25 | GRID map[NUM_GRID]; |
leuyentran | 0:7fe3c940e4b5 | 26 | int num_candy = 0; |
leuyentran | 0:7fe3c940e4b5 | 27 | |
leuyentran | 0:7fe3c940e4b5 | 28 | void map_init(){ |
leuyentran | 0:7fe3c940e4b5 | 29 | int i; |
leuyentran | 0:7fe3c940e4b5 | 30 | int start_x = (SIZE_X-GRID_SIZE*NUM_GRID_X)/2; |
leuyentran | 0:7fe3c940e4b5 | 31 | int start_y = (SIZE_Y-GRID_SIZE*NUM_GRID_Y); |
leuyentran | 0:7fe3c940e4b5 | 32 | char temp_wall_type[] = DEFAULT_MAP; |
leuyentran | 0:7fe3c940e4b5 | 33 | |
leuyentran | 0:7fe3c940e4b5 | 34 | for(i=0;i<NUM_GRID;i++){ |
leuyentran | 0:7fe3c940e4b5 | 35 | map[i].x = start_x + IDX2X(i)*GRID_SIZE; |
leuyentran | 0:7fe3c940e4b5 | 36 | map[i].y = start_y + IDX2Y(i)*GRID_SIZE; |
leuyentran | 0:7fe3c940e4b5 | 37 | switch(temp_wall_type[i]){ |
leuyentran | 0:7fe3c940e4b5 | 38 | case MAP_ATTRIBUTE_SIDE_WALK: |
leuyentran | 0:7fe3c940e4b5 | 39 | map[i].status = GRID_SIDE_WALK; |
leuyentran | 0:7fe3c940e4b5 | 40 | break; |
leuyentran | 0:7fe3c940e4b5 | 41 | case MAP_ATTRIBUTE_SIDE_WALK_2: |
leuyentran | 0:7fe3c940e4b5 | 42 | map[i].status = GRID_SIDE_WALK_2; |
leuyentran | 0:7fe3c940e4b5 | 43 | break; |
leuyentran | 0:7fe3c940e4b5 | 44 | case MAP_ATTRIBUTE_CANDY: |
leuyentran | 0:7fe3c940e4b5 | 45 | map[i].status = GRID_CANDY; |
leuyentran | 0:7fe3c940e4b5 | 46 | num_candy++; |
leuyentran | 0:7fe3c940e4b5 | 47 | break; |
leuyentran | 0:7fe3c940e4b5 | 48 | case MAP_ATTRIBUTE_BIG_CANDY: |
leuyentran | 0:7fe3c940e4b5 | 49 | map[i].status = GRID_BIG_CANDY; |
leuyentran | 0:7fe3c940e4b5 | 50 | num_candy++; |
leuyentran | 0:7fe3c940e4b5 | 51 | break; |
leuyentran | 0:7fe3c940e4b5 | 52 | case MAP_ATTRIBUTE_V_LINE: |
leuyentran | 0:7fe3c940e4b5 | 53 | map[i].status = GRID_V_LINE; |
leuyentran | 0:7fe3c940e4b5 | 54 | break; |
leuyentran | 0:7fe3c940e4b5 | 55 | case MAP_ATTRIBUTE_ROAD_L: |
leuyentran | 0:7fe3c940e4b5 | 56 | map[i].status = GRID_ROAD_L; |
leuyentran | 0:7fe3c940e4b5 | 57 | break; |
leuyentran | 0:7fe3c940e4b5 | 58 | case MAP_ATTRIBUTE_ROAD_R: |
leuyentran | 0:7fe3c940e4b5 | 59 | map[i].status = GRID_ROAD_R; |
leuyentran | 0:7fe3c940e4b5 | 60 | break; |
leuyentran | 0:7fe3c940e4b5 | 61 | default: |
leuyentran | 0:7fe3c940e4b5 | 62 | map[i].status = GRID_ROAD; |
leuyentran | 0:7fe3c940e4b5 | 63 | break; |
leuyentran | 0:7fe3c940e4b5 | 64 | } |
leuyentran | 0:7fe3c940e4b5 | 65 | } |
leuyentran | 0:7fe3c940e4b5 | 66 | map_draw(); |
leuyentran | 0:7fe3c940e4b5 | 67 | } |
leuyentran | 0:7fe3c940e4b5 | 68 | |
leuyentran | 0:7fe3c940e4b5 | 69 | void map_draw(){ |
leuyentran | 0:7fe3c940e4b5 | 70 | int i; |
leuyentran | 0:7fe3c940e4b5 | 71 | for(i=0;i<NUM_GRID;i++){ |
leuyentran | 0:7fe3c940e4b5 | 72 | map_draw_grid(IDX2X(i), IDX2Y(i)); |
leuyentran | 0:7fe3c940e4b5 | 73 | } |
leuyentran | 0:7fe3c940e4b5 | 74 | } |
leuyentran | 0:7fe3c940e4b5 | 75 | |
leuyentran | 0:7fe3c940e4b5 | 76 | void map_draw_grid(unsigned grid_x, unsigned grid_y) |
leuyentran | 0:7fe3c940e4b5 | 77 | { |
leuyentran | 0:7fe3c940e4b5 | 78 | unsigned i=XY2IDX(grid_x,grid_y); |
leuyentran | 0:7fe3c940e4b5 | 79 | if(map[i].status==GRID_SIDE_WALK) { |
leuyentran | 0:7fe3c940e4b5 | 80 | uLCD.filled_rectangle(map[i].x, map[i].y, map[i].x+GRID_SIZE-1, map[i].y+GRID_SIZE-1, SIDE_WALK_COLOR); |
leuyentran | 0:7fe3c940e4b5 | 81 | } else if(map[i].status==GRID_SIDE_WALK_2) { |
leuyentran | 0:7fe3c940e4b5 | 82 | uLCD.filled_rectangle(map[i].x, map[i].y, map[i].x+GRID_SIZE-1, map[i].y+GRID_SIZE-1, SIDE_WALK_COLOR_2); |
leuyentran | 0:7fe3c940e4b5 | 83 | } else if(map[i].status==GRID_CANDY) { |
leuyentran | 0:7fe3c940e4b5 | 84 | uLCD.filled_circle(map[i].x+GRID_RADIUS, map[i].y+GRID_RADIUS, CANDY_RADIUS, CANDY_COLOR); |
leuyentran | 0:7fe3c940e4b5 | 85 | } else if(map[i].status==GRID_BIG_CANDY) { |
leuyentran | 0:7fe3c940e4b5 | 86 | uLCD.filled_circle(map[i].x+GRID_RADIUS, map[i].y+GRID_RADIUS, BIG_CANDY_RADIUS, CANDY_COLOR); |
leuyentran | 0:7fe3c940e4b5 | 87 | } else if(map[i].status==GRID_ROAD_L) { |
ece2035ta | 1:172fbc00199c | 88 | if ((grid_x!=3)and ((grid_y%3)!=2)) { |
leuyentran | 0:7fe3c940e4b5 | 89 | //draw line on the LEFT |
leuyentran | 0:7fe3c940e4b5 | 90 | uLCD.filled_rectangle(map[i].x, map[i].y, map[i].x+1, map[i].y+GRID_SIZE-1, LINE_COLOR); |
leuyentran | 0:7fe3c940e4b5 | 91 | } |
leuyentran | 0:7fe3c940e4b5 | 92 | } else if(map[i].status==GRID_ROAD_R) { |
ece2035ta | 1:172fbc00199c | 93 | if ((grid_x!=11)and ((grid_y%3)!=2)) { |
leuyentran | 0:7fe3c940e4b5 | 94 | //draw line on the RIGHT |
leuyentran | 0:7fe3c940e4b5 | 95 | uLCD.filled_rectangle(map[i].x+GRID_SIZE-1, map[i].y, map[i].x+GRID_SIZE, map[i].y+GRID_SIZE-1, LINE_COLOR); |
leuyentran | 0:7fe3c940e4b5 | 96 | } |
leuyentran | 0:7fe3c940e4b5 | 97 | } else if(map[i].status==GRID_V_LINE) { |
leuyentran | 0:7fe3c940e4b5 | 98 | if ((((grid_x%2)==1)and ((grid_y%2)==0)) or (((grid_x%2)==0)and ((grid_y%2)==1))) { |
leuyentran | 0:7fe3c940e4b5 | 99 | uLCD.filled_rectangle(map[i].x, map[i].y, map[i].x+GRID_SIZE-1, map[i].y+GRID_SIZE-1, WHITE); |
leuyentran | 0:7fe3c940e4b5 | 100 | } |
leuyentran | 0:7fe3c940e4b5 | 101 | } |
leuyentran | 0:7fe3c940e4b5 | 102 | } |
leuyentran | 0:7fe3c940e4b5 | 103 | |
leuyentran | 0:7fe3c940e4b5 | 104 | GRID map_get_grid_status(int grid_x, int grid_y){ |
leuyentran | 0:7fe3c940e4b5 | 105 | return map[XY2IDX(grid_x,grid_y)]; |
leuyentran | 0:7fe3c940e4b5 | 106 | } |
leuyentran | 0:7fe3c940e4b5 | 107 | |
ece2035ta | 1:172fbc00199c | 108 | bool map_the_end(int grid_x, int grid_y){ |
leuyentran | 0:7fe3c940e4b5 | 109 | int idx=XY2IDX(grid_x,grid_y); |
ece2035ta | 1:172fbc00199c | 110 | if (map[idx].status==GRID_V_LINE){ |
leuyentran | 0:7fe3c940e4b5 | 111 | return 1; |
leuyentran | 0:7fe3c940e4b5 | 112 | } |
leuyentran | 0:7fe3c940e4b5 | 113 | return 0; |
leuyentran | 0:7fe3c940e4b5 | 114 | } |
leuyentran | 0:7fe3c940e4b5 | 115 | |
ece2035ta | 1:172fbc00199c | 116 | bool map_eat_candy(int grid_x, int grid_y, double &score){ |
ece2035ta | 1:172fbc00199c | 117 | int idx=XY2IDX(grid_x,grid_y); |
ece2035ta | 1:172fbc00199c | 118 | |
ece2035ta | 1:172fbc00199c | 119 | if(map[idx].status==GRID_CANDY || map[idx].status==GRID_BIG_CANDY) { |
ece2035ta | 1:172fbc00199c | 120 | map[idx].status = GRID_ROAD; |
ece2035ta | 1:172fbc00199c | 121 | num_candy--; |
ece2035ta | 1:172fbc00199c | 122 | if(map[idx].status==GRID_CANDY){ |
ece2035ta | 1:172fbc00199c | 123 | score+=1; |
ece2035ta | 1:172fbc00199c | 124 | } |
ece2035ta | 1:172fbc00199c | 125 | else if (map[idx].status==GRID_BIG_CANDY) { |
ece2035ta | 1:172fbc00199c | 126 | score+=2.5; |
ece2035ta | 1:172fbc00199c | 127 | return 1; |
ece2035ta | 1:172fbc00199c | 128 | } |
ece2035ta | 1:172fbc00199c | 129 | } |
ece2035ta | 1:172fbc00199c | 130 | return 0; |
ece2035ta | 1:172fbc00199c | 131 | } |
leuyentran | 0:7fe3c940e4b5 | 132 | int map_remaining_candy(void){ |
ece2035ta | 1:172fbc00199c | 133 | return num_candy; |
leuyentran | 0:7fe3c940e4b5 | 134 | } |
leuyentran | 0:7fe3c940e4b5 | 135 |