frogger game revision
Dependencies: 4DGL-uLCD-SE MMA8452 SDFileSystem mbed wave_player
Fork of ECE2035_FroggerGame_SUM2015 by
map/map.cpp@9:47f07aa85f1a, 2016-02-01 (annotated)
- Committer:
- ssong86
- Date:
- Mon Feb 01 06:43:06 2016 +0000
- Revision:
- 9:47f07aa85f1a
- Parent:
- 6:5ed435a31cc7
frogger
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ece2035ta | 6:5ed435a31cc7 | 1 | /* Gatech ECE2035 2015 SUMMER ROBOFROGGER |
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) { |
leuyentran | 0:7fe3c940e4b5 | 88 | if ((grid_x!=4)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) { |
leuyentran | 0:7fe3c940e4b5 | 93 | if ((grid_x!=12)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 | |
ssong86 | 9:47f07aa85f1a | 108 | double map_eat_candy(int grid_x, int grid_y){ |
leuyentran | 0:7fe3c940e4b5 | 109 | int idx=XY2IDX(grid_x,grid_y); |
ssong86 | 9:47f07aa85f1a | 110 | int smallCandy=0,bigCandy=0; |
ssong86 | 9:47f07aa85f1a | 111 | double score=0; |
ssong86 | 9:47f07aa85f1a | 112 | if(map[idx].status==GRID_CANDY) |
ssong86 | 9:47f07aa85f1a | 113 | { |
ssong86 | 9:47f07aa85f1a | 114 | map[idx].status = GRID_ROAD; |
ssong86 | 9:47f07aa85f1a | 115 | smallCandy++; |
ssong86 | 9:47f07aa85f1a | 116 | num_candy--; |
ssong86 | 9:47f07aa85f1a | 117 | score = 0.1*smallCandy+score; |
ssong86 | 9:47f07aa85f1a | 118 | return score; |
ssong86 | 9:47f07aa85f1a | 119 | } |
leuyentran | 0:7fe3c940e4b5 | 120 | |
ssong86 | 9:47f07aa85f1a | 121 | else if(map[idx].status==GRID_BIG_CANDY){ |
leuyentran | 0:7fe3c940e4b5 | 122 | map[idx].status = GRID_ROAD; |
ssong86 | 9:47f07aa85f1a | 123 | bigCandy++; |
leuyentran | 0:7fe3c940e4b5 | 124 | num_candy--; |
ssong86 | 9:47f07aa85f1a | 125 | score = score+bigCandy; |
ssong86 | 9:47f07aa85f1a | 126 | return score; |
leuyentran | 0:7fe3c940e4b5 | 127 | } |
leuyentran | 0:7fe3c940e4b5 | 128 | return 0; |
leuyentran | 0:7fe3c940e4b5 | 129 | } |
leuyentran | 0:7fe3c940e4b5 | 130 | |
leuyentran | 0:7fe3c940e4b5 | 131 | int map_remaining_candy(void){ |
leuyentran | 0:7fe3c940e4b5 | 132 | return num_candy; |
leuyentran | 0:7fe3c940e4b5 | 133 | } |
leuyentran | 0:7fe3c940e4b5 | 134 |