Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE mbed wave_player
Fork of PacMan_Skeleton_unlock by
ghost.h@1:fbda247b843b, 2018-03-29 (annotated)
- Committer:
- rconant6
- Date:
- Thu Mar 29 05:05:51 2018 +0000
- Revision:
- 1:fbda247b843b
- Parent:
- 0:be33a1fad8c0
Adding files;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| conantina | 0:be33a1fad8c0 | 1 | /* Gatech ECE2035 2015 SPRING PAC MAN |
| conantina | 0:be33a1fad8c0 | 2 | * Copyright (c) 2015 Gatech ECE2035 |
| conantina | 0:be33a1fad8c0 | 3 | * |
| conantina | 0:be33a1fad8c0 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| conantina | 0:be33a1fad8c0 | 5 | * of this software and associated documentation files (the "Software"), to deal |
| conantina | 0:be33a1fad8c0 | 6 | * in the Software without restriction, including without limitation the rights |
| conantina | 0:be33a1fad8c0 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| conantina | 0:be33a1fad8c0 | 8 | * copies of the Software, and to permit persons to whom the Software is |
| conantina | 0:be33a1fad8c0 | 9 | * furnished to do so, subject to the following conditions: |
| conantina | 0:be33a1fad8c0 | 10 | * |
| conantina | 0:be33a1fad8c0 | 11 | * The above copyright notice and this permission notice shall be included in |
| conantina | 0:be33a1fad8c0 | 12 | * all copies or substantial portions of the Software. |
| conantina | 0:be33a1fad8c0 | 13 | * |
| conantina | 0:be33a1fad8c0 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| conantina | 0:be33a1fad8c0 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| conantina | 0:be33a1fad8c0 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| conantina | 0:be33a1fad8c0 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| conantina | 0:be33a1fad8c0 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| conantina | 0:be33a1fad8c0 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| conantina | 0:be33a1fad8c0 | 20 | * SOFTWARE. |
| conantina | 0:be33a1fad8c0 | 21 | */ |
| conantina | 0:be33a1fad8c0 | 22 | /** @file ghost.h */ |
| conantina | 0:be33a1fad8c0 | 23 | #ifndef GHOST_H |
| conantina | 0:be33a1fad8c0 | 24 | #define GHOST_H |
| conantina | 0:be33a1fad8c0 | 25 | |
| conantina | 0:be33a1fad8c0 | 26 | #include "mbed.h" |
| conantina | 0:be33a1fad8c0 | 27 | //#include "uLCD_4DGL.h" |
| conantina | 0:be33a1fad8c0 | 28 | #include "ghost.h" |
| conantina | 0:be33a1fad8c0 | 29 | #include "map_public.h" |
| conantina | 0:be33a1fad8c0 | 30 | #include "globals.h" |
| conantina | 0:be33a1fad8c0 | 31 | #include "pacman.h" |
| conantina | 0:be33a1fad8c0 | 32 | #include "doubly_linked_list.h" |
| conantina | 0:be33a1fad8c0 | 33 | |
| conantina | 0:be33a1fad8c0 | 34 | extern uLCD_4DGL uLCD; |
| conantina | 0:be33a1fad8c0 | 35 | |
| conantina | 0:be33a1fad8c0 | 36 | |
| conantina | 0:be33a1fad8c0 | 37 | /// The enum defines the motion of a ghost |
| conantina | 0:be33a1fad8c0 | 38 | typedef enum { |
| conantina | 0:be33a1fad8c0 | 39 | GHOST_UP=0, ///< move up |
| conantina | 0:be33a1fad8c0 | 40 | GHOST_DOWN, ///< move down |
| conantina | 0:be33a1fad8c0 | 41 | GHOST_LEFT, ///< move left |
| conantina | 0:be33a1fad8c0 | 42 | GHOST_RIGHT, ///< move right |
| conantina | 0:be33a1fad8c0 | 43 | GHOST_DIED |
| conantina | 0:be33a1fad8c0 | 44 | } GHOST_MOTION; |
| conantina | 0:be33a1fad8c0 | 45 | |
| conantina | 0:be33a1fad8c0 | 46 | |
| conantina | 0:be33a1fad8c0 | 47 | /// This struct contains the status of a ghost |
| conantina | 0:be33a1fad8c0 | 48 | typedef struct |
| conantina | 0:be33a1fad8c0 | 49 | { |
| conantina | 0:be33a1fad8c0 | 50 | unsigned int x; ///< horizontal position in the grid |
| conantina | 0:be33a1fad8c0 | 51 | unsigned int y; ///< vertical position in the grid |
| conantina | 0:be33a1fad8c0 | 52 | unsigned int color; ///< color of the ghost |
| conantina | 0:be33a1fad8c0 | 53 | GHOST_MOTION ghost_motion; ///< the motion of the ghost |
| conantina | 0:be33a1fad8c0 | 54 | } GHOST; |
| conantina | 0:be33a1fad8c0 | 55 | |
| rconant6 | 1:fbda247b843b | 56 | //Initialize an empty doublely linked list |
| conantina | 0:be33a1fad8c0 | 57 | void ghost_init(void); |
| conantina | 0:be33a1fad8c0 | 58 | |
| conantina | 0:be33a1fad8c0 | 59 | /** Create a ghost with given position and color. Then add to the ghost doublely linked list |
| conantina | 0:be33a1fad8c0 | 60 | @param blk_x The horizontal position in the grid. |
| conantina | 0:be33a1fad8c0 | 61 | @param blk_y The vertical position in the grid. |
| conantina | 0:be33a1fad8c0 | 62 | @param color Color of the ghost |
| conantina | 0:be33a1fad8c0 | 63 | */ |
| conantina | 0:be33a1fad8c0 | 64 | void ghost_create(unsigned int blk_x, unsigned int blk_y, unsigned int color); |
| conantina | 0:be33a1fad8c0 | 65 | |
| conantina | 0:be33a1fad8c0 | 66 | /** Draw the ghost in the linked list on the screen |
| conantina | 0:be33a1fad8c0 | 67 | */ |
| conantina | 0:be33a1fad8c0 | 68 | void ghost_show(DLinkedList* list); |
| conantina | 0:be33a1fad8c0 | 69 | |
| conantina | 0:be33a1fad8c0 | 70 | /** Move every ghost in the list randomly on the map for one step |
| conantina | 0:be33a1fad8c0 | 71 | */ |
| conantina | 0:be33a1fad8c0 | 72 | void ghost_random_walk(void); |
| conantina | 0:be33a1fad8c0 | 73 | |
| conantina | 0:be33a1fad8c0 | 74 | /** Return the doubly linked list of ghost |
| conantina | 0:be33a1fad8c0 | 75 | */ |
| conantina | 0:be33a1fad8c0 | 76 | DLinkedList* get_ghost_list(void); |
| conantina | 0:be33a1fad8c0 | 77 | |
| rconant6 | 1:fbda247b843b | 78 | int ghost_collision(DLinkedList* list, int x, int y, int invuln); |
| rconant6 | 1:fbda247b843b | 79 | |
| conantina | 0:be33a1fad8c0 | 80 | |
| conantina | 0:be33a1fad8c0 | 81 | /** Extra Feature Function: |
| conantina | 0:be33a1fad8c0 | 82 | Create a super ghost with given position and color. Then add to the super ghost doublely linked list |
| conantina | 0:be33a1fad8c0 | 83 | A super ghost is itself a max-size-3 linked list. A super ghost is itself a linked list. The head always |
| conantina | 0:be33a1fad8c0 | 84 | walk randomly while the other two node keep track of the two lastest history position. |
| conantina | 0:be33a1fad8c0 | 85 | @param blk_x The horizontal position in the grid. |
| conantina | 0:be33a1fad8c0 | 86 | @param blk_y The vertical position in the grid. |
| conantina | 0:be33a1fad8c0 | 87 | @param color Color of the ghost |
| conantina | 0:be33a1fad8c0 | 88 | */ |
| conantina | 0:be33a1fad8c0 | 89 | void super_ghost_create(unsigned int blk_x, unsigned int blk_y, unsigned int color); |
| conantina | 0:be33a1fad8c0 | 90 | |
| conantina | 0:be33a1fad8c0 | 91 | /** Extra Feature Function: |
| conantina | 0:be33a1fad8c0 | 92 | Move the super ghost in the list randomly on the map for one step |
| conantina | 0:be33a1fad8c0 | 93 | */ |
| conantina | 0:be33a1fad8c0 | 94 | void super_ghost_random_walk(void); |
| conantina | 0:be33a1fad8c0 | 95 | |
| conantina | 0:be33a1fad8c0 | 96 | /** Extra Feature Function: |
| conantina | 0:be33a1fad8c0 | 97 | Return the doubly linked list of super ghost |
| conantina | 0:be33a1fad8c0 | 98 | */ |
| conantina | 0:be33a1fad8c0 | 99 | DLinkedList* get_super_ghost_list(void); |
| conantina | 0:be33a1fad8c0 | 100 | #endif //GHOST_H |
