Ransom Conant / Mbed 2 deprecated MbedPacman

Dependencies:   4DGL-uLCD-SE mbed wave_player

Fork of PacMan_Skeleton_unlock by ECE 2035 TA

Revision:
1:fbda247b843b
Parent:
0:be33a1fad8c0
--- a/ghost.cpp	Fri Feb 24 17:33:27 2017 +0000
+++ b/ghost.cpp	Thu Mar 29 05:05:51 2018 +0000
@@ -148,24 +148,51 @@
 
 
 void ghost_init(void){
-    //Your code here
+    ghostDLL = create_dlinkedlist();
 }
 
 // Public functions
 void ghost_create(unsigned int blk_x, unsigned int blk_y, unsigned int color)
 {
-    //Your code here  
+    GHOST* newGhost = (GHOST*)malloc(sizeof(GHOST));
+    newGhost->x = blk_x;
+    newGhost->y = blk_y;
+    newGhost->color = color;
+    insertHead(ghostDLL, (void*)newGhost);
 }
 
 DLinkedList* get_ghost_list(void) {
     //Your code here
-    return NULL;
+    return ghostDLL;
 }
 
 void ghost_show(DLinkedList* list)
 {
     //Your code here
     //Functions like map_draw_grid, clean_blk, draw_ghost may be useful
+    GHOST* newGhost = (GHOST*)getHead(list);
+    while(newGhost){
+        draw_ghost(newGhost->x,newGhost->y,newGhost->color);
+        newGhost = (GHOST*)getNext(list);
+    }
+}
+
+int ghost_collision(DLinkedList* list, int pac_x, int pac_y, int invuln){
+    GHOST* newGhost = (GHOST*)getHead(list);
+    while(newGhost){
+        if(newGhost->x == pac_x && newGhost->y == pac_y){
+            if(invuln > 0){
+                newGhost->ghost_motion = GHOST_DIED;
+                return 10;
+            }
+            else{
+                return 1;
+            }
+        
+        }
+        newGhost = (GHOST*)getNext(list);
+    }
+    return 0;
 }
 
 void ghost_random_walk(void)