Ransom Conant / Mbed 2 deprecated MbedPacman

Dependencies:   4DGL-uLCD-SE mbed wave_player

Fork of PacMan_Skeleton_unlock by ECE 2035 TA

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers map.cpp Source File

map.cpp

00001 /* Gatech ECE2035 2015 SPRING PAC MAN
00002  * Copyright (c) 2015 Gatech ECE2035
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00020  * SOFTWARE.
00021  */
00022 
00023 #include "map_private.h"
00024 
00025 GRID map[NUM_GRID];
00026 int remaining_cookie = 0;
00027 
00028 void map_init(){
00029     int i;
00030     int start_x = (SIZE_X-GRID_SIZE*NUM_GRID_X)/2;
00031     int start_y = (SIZE_Y-GRID_SIZE*NUM_GRID_Y);
00032     char temp_wall_type[] = DEFAULT_MAP;
00033 
00034     for(i=0;i<NUM_GRID;i++){
00035         map[i].x = start_x + IDX2X(i)*GRID_SIZE;
00036         map[i].y = start_y + IDX2Y(i)*GRID_SIZE;
00037         switch(temp_wall_type[i]){
00038             case MAP_ATTRIBUTE_WALL:
00039                 map[i].status = GRID_WALL;
00040                 break;
00041             case MAP_ATTRIBUTE_COOKIE:
00042                 map[i].status = GRID_COOKIE;
00043                 remaining_cookie++;
00044                 break;
00045             case MAP_ATTRIBUTE_SUPER_COOKIE:
00046                 map[i].status = GRID_SUPER_COOKIE;
00047                 remaining_cookie++;
00048                 break;
00049             default:
00050                 map[i].status = GRID_EMPTY;
00051                 break;
00052         }
00053     }
00054     map_draw();
00055 }
00056 
00057 void map_draw(){
00058     int i;
00059     for(i=0;i<NUM_GRID;i++){
00060         map_draw_grid(IDX2X(i), IDX2Y(i));
00061     }
00062 }
00063 
00064 void map_draw_grid(unsigned grid_x, unsigned grid_y)
00065 {
00066     unsigned i=XY2IDX(grid_x,grid_y);
00067     if(map[i].status==GRID_WALL)
00068     {
00069         uLCD.filled_rectangle(map[i].x, map[i].y, map[i].x+GRID_SIZE-1, map[i].y+GRID_SIZE-1, WALL_COLOR);
00070     }
00071     else if(map[i].status==GRID_COOKIE)
00072     {
00073         uLCD.filled_circle(map[i].x+GRID_RADIUS, map[i].y+GRID_RADIUS, COOKIE_RADIUS, COOKIE_COLOR);
00074     }
00075     else if(map[i].status==GRID_SUPER_COOKIE)
00076     {
00077         uLCD.filled_circle(map[i].x+GRID_RADIUS, map[i].y+GRID_RADIUS, SUPER_COOKIE_RADIUS, COOKIE_COLOR);
00078     }
00079 }
00080 
00081 GRID map_get_grid_status(int grid_x, int grid_y){
00082     return map[XY2IDX(grid_x,grid_y)];
00083 }
00084 
00085 bool map_eat_cookie(int grid_x, int grid_y){
00086     int idx=XY2IDX(grid_x,grid_y);
00087     if(map[idx].status==GRID_COOKIE || map[idx].status==GRID_SUPER_COOKIE){
00088         map[idx].status = GRID_EMPTY;
00089         remaining_cookie--;
00090         return 1;
00091     }
00092     return 0;
00093 }
00094 
00095 int map_remaining_cookie(void){
00096     return remaining_cookie;
00097 }
00098