Cong Vu / Mbed 2 deprecated Project2_cvu31

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //=================================================================
00002 // The main program file.
00003 //
00004 // Copyright 2020 Georgia Tech.  All rights reserved.
00005 // The materials provided by the instructor in this course are for
00006 // the use of the students currently enrolled in the course.
00007 // Copyrighted course materials may not be further disseminated.
00008 // This file must not be made publicly available anywhere.
00009 //==================================================================
00010 
00011 // Project includes
00012 #include "globals.h"
00013 #include "hardware.h"
00014 #include "map.h"
00015 #include "graphics.h"
00016 #include "snake.h"
00017 #include "mbed.h"
00018 #include "Speaker.h"
00019 //#include "wave_player.h"
00020 #include "SDFileSystem.h"
00021 #include <math.h>
00022 #include<stdio.h>
00023 
00024 
00025 
00026 
00027 #define CITY_HIT_MARGIN 1
00028 #define CITY_UPPER_BOUND (SIZE_Y-(LANDSCAPE_HEIGHT+MAX_BUILDING_HEIGHT))
00029 int go_right(int x, int y);
00030 int go_left(int x, int y);
00031 int go_up(int x, int y);
00032 int go_down(int x, int y);
00033 // Helper function declarations
00034 void playSound(char* wav);
00035 void makenoise();
00036 /**
00037  * The main game state. Must include snake locations and previous locations for
00038  * drawing to work properly. Other items can be added as needed.
00039  */
00040 
00041 /**
00042  * Given the game inputs, determine what kind of update needs to happen.
00043  * Possbile return values are defined below.
00044  */
00045 Snake snake;
00046 Speaker mySpeaker(p25);           //define mySpeaker and pin
00047 // Function prototypes
00048 
00049 /**
00050  * Given the game inputs, determine what kind of update needs to happen.
00051  * Possible return values are defined below.
00052  */
00053 #define NO_RESULT 0
00054 #define NO_ACTION 0
00055 #define ACTION_BUTTON 1
00056 #define MENU_BUTTON 2
00057 #define GO_LEFT 3
00058 #define GO_RIGHT 4
00059 #define GO_UP 5
00060 #define GO_DOWN 6
00061 #define GAME_OVER 7
00062 #define FULL_DRAW 8
00063 #define WON 9
00064 #define FOODN 10
00065 #define FOODS 11
00066 #define FOODW 12
00067 #define FOODE 13
00068 
00069 // Get Actions from User (push buttons & accelerometer)
00070 // Based on push button and accelerometer inputs, determine which action
00071 // needs to be performed (may be no action).
00072 int get_action(GameInputs inputs)
00073 {
00074     MapItem* N=get_north(snake.head_x,snake.head_y);
00075     MapItem* S=get_south(snake.head_x,snake.head_y);
00076     MapItem* W=get_east(snake.head_x, snake.head_y);
00077     MapItem* E=get_west(snake.head_x, snake.head_y);
00078     
00079     if (button3 == 0) {     //pause game
00080         while(button3 == 0)
00081             {}
00082         }
00083         
00084     if (button2 == 1) {                     // keep living
00085         if (snake.invincTimer == 0)
00086             snake.invincible = !snake.invincible;
00087         else
00088             snake.invincible = 1;
00089     }
00090     if ((E->type==WALL || N->type==WALL || S->type==WALL ||W->type==WALL) && !snake.invincible)   return GAME_OVER;
00091     if (inputs.ay >= 0.2) return GO_DOWN;
00092     if (inputs.ay < -0.2) return GO_UP;
00093     if (inputs.ax < -0.2) return GO_RIGHT;
00094     if (inputs.ax >= 0.2) return GO_LEFT;
00095     else return NO_ACTION;
00096 }
00097 
00098 void checkCollisions() {
00099     //Check Objects here
00100     if (get_here(snake.head_x,snake.head_y)->type == RANDOM) {
00101         makenoise();
00102         void* d = get_here(snake.head_x,snake.head_y)->data;
00103         if (((int)d % 4) + 13 == 13)
00104             snake.pointLockTime = 8000;
00105         if (((int)d % 4) + 13  == 14)
00106             snake.speedupTime = 16000;
00107         if (((int)d % 4) + 13  == 15)
00108             snake.slowdownTime = 10000;
00109         if (((int)d % 4) + 13  == 16) {
00110             if (snake.length > 1) {
00111             map_erase(snake.locations[snake.length - 2].x, snake.locations[snake.length - 2].y);
00112             map_erase(snake.locations[snake.length - 1].x, snake.locations[snake.length - 1].y);
00113             snake.length -= 2;
00114             }
00115         }
00116         else
00117             snake.pointLockTime = 10000;
00118         return;
00119     }
00120     
00121     if (get_here(snake.head_x,snake.head_y)->type == INVINC) {
00122         makenoise();
00123         snake.invincTimer = 10000;
00124         snake.invincible = 1;
00125     }
00126     
00127     //Check Goodie
00128     if (get_here(snake.head_x,snake.head_y)->type == GOODIE) {
00129         // Speaker
00130         makenoise();
00131         snake.length++;
00132         if (snake.pointLockTime == 0)
00133             snake.score++;
00134     }
00135     
00136     if (get_here(snake.head_x,snake.head_y)->type == INCLENGTH) {
00137         // Speaker
00138         makenoise();
00139         snake.length += 6;
00140     }
00141     
00142     if (get_here(snake.head_x,snake.head_y)->type == MOVING) {
00143         makenoise();
00144         snake.score += 5;          //hit moving will add 5 score
00145     }
00146     
00147     if (get_here(snake.head_x,snake.head_y)->type == POISON) {
00148         makenoise();
00149         snake.pointLockTime += 8000; //8 seccong
00150     }
00151     
00152     if (get_here(snake.head_x,snake.head_y)->type == SPEEDUP) {
00153         makenoise();
00154         snake.speedupTime += 16000; //16 sec
00155     }
00156     
00157     if (get_here(snake.head_x,snake.head_y)->type == SLOWDOWN) {
00158         makenoise();
00159         snake.slowdownTime += 10000; //10 sec
00160     }
00161     
00162     if (get_here(snake.head_x,snake.head_y)->type == DECLENGTH) {
00163         makenoise();
00164         if (snake.length > 1) {
00165             map_erase(snake.locations[snake.length - 2].x, snake.locations[snake.length - 2].y);
00166             map_erase(snake.locations[snake.length - 1].x, snake.locations[snake.length - 1].y);
00167             snake.length -= 2;
00168         }
00169             
00170     }
00171 }
00172 
00173 /**
00174  * Update the game state based on the user action. For example, if the user
00175  * requests GO_UP, then this function should determine if that is possible by
00176  * consulting the map, and update the snake position accordingly.
00177  *
00178  * Return values are defined below. FULL_DRAW indicates that for this frame,
00179  * draw_game should not optimize drawing and should draw every tile, even if
00180  * the snake has not moved.
00181  */
00182 int update_game(int action)
00183 {
00184      
00185    snake.head_px = snake.head_x;
00186    snake.head_py = snake.head_y;   
00187    
00188    int oldx = snake.head_px;
00189    int oldy = snake.head_py;
00190    
00191    map_erase(oldx, oldy);
00192     
00193     switch(action) {
00194         case GO_UP:
00195                 snake.head_y -= 1;  
00196                 
00197                 checkCollisions();
00198                 //Check un-walkable object
00199                 if (get_here(snake.head_x, snake.head_y)->type != SNAKE_HEAD &&
00200                 get_here(snake.head_x, snake.head_y)->walkable == 0
00201                 && !snake.invincible) {
00202                     action = GAME_OVER;
00203                     break;
00204                 }
00205                 //Add snake head now
00206                 add_snake_head(snake.head_x, snake.head_y);
00207                 //Check max length
00208                 if (snake.length == SNAKE_MAX_LENGTH && !snake.invincible) {
00209                     action = GAME_OVER;
00210                     break;
00211                 }
00212             for (int i = 0; i < snake.length; i++) {
00213                 map_erase(oldx, oldy);
00214                 int tempy = snake.locations[i].y;
00215                 snake.locations[i].y = oldy;
00216                 
00217                 int tempx = snake.locations[i].x;
00218                 snake.locations[i].x = oldx;
00219                 
00220                 oldy = tempy;
00221                 oldx = tempx;
00222                 map_erase(oldx, oldy);
00223                 
00224                 if (i < snake.length - 1)
00225                     add_snake_body(snake.locations[i].x, snake.locations[i].y);
00226                 else
00227                     add_snake_tail(snake.locations[i].x, snake.locations[i].y);
00228             } 
00229                  return ACTION_BUTTON;
00230         case GO_LEFT:
00231                snake.head_x -= 1;  
00232                
00233                checkCollisions();
00234                
00235                //Check un-walkable object
00236                 if (get_here(snake.head_x, snake.head_y)->type != SNAKE_HEAD &&
00237                 get_here(snake.head_x, snake.head_y)->walkable == 0
00238                 && !snake.invincible) {
00239                     action = GAME_OVER;
00240                     break;
00241                 }
00242                 
00243                add_snake_head(snake.head_x, snake.head_y);
00244                //Check max length
00245                 if (snake.length == SNAKE_MAX_LENGTH && !snake.invincible) {
00246                     action = GAME_OVER;
00247                     break;
00248                 }
00249             for (int i = 0; i < snake.length; i++) {
00250                 map_erase(oldx, oldy);
00251                 int tempy = snake.locations[i].y;
00252                 snake.locations[i].y = oldy;
00253                 
00254                 int tempx = snake.locations[i].x;
00255                 snake.locations[i].x = oldx;
00256                 
00257                 oldy = tempy;
00258                 oldx = tempx;
00259                 map_erase(oldx, oldy);
00260                 
00261                 if (i < snake.length - 1)
00262                     add_snake_body(snake.locations[i].x, snake.locations[i].y);
00263                 else
00264                     add_snake_tail(snake.locations[i].x, snake.locations[i].y);
00265             } 
00266                  return ACTION_BUTTON;
00267         case GO_DOWN:
00268                 snake.head_y += 1;  
00269                 
00270                 checkCollisions();
00271                 
00272                 //Check un-walkable object
00273                 if (get_here(snake.head_x, snake.head_y)->type != SNAKE_HEAD &&
00274                 get_here(snake.head_x, snake.head_y)->walkable == 0
00275                 && !snake.invincible) {
00276                     action = GAME_OVER;
00277                     break;
00278                 }
00279                 
00280                 add_snake_head(snake.head_x, snake.head_y);
00281                 //Check max length
00282                 if (snake.length == SNAKE_MAX_LENGTH && !snake.invincible) {
00283                     action = GAME_OVER;
00284                     break;
00285                 }
00286             for (int i = 0; i < snake.length; i++) {
00287                 int tempy = snake.locations[i].y;
00288                 snake.locations[i].y = oldy;
00289                 
00290                 int tempx = snake.locations[i].x;
00291                 snake.locations[i].x = oldx;
00292                 
00293                 oldy = tempy;
00294                 oldx = tempx;
00295                 map_erase(oldx, oldy);
00296                 
00297                 if (i < snake.length - 1)
00298                     add_snake_body(snake.locations[i].x, snake.locations[i].y);
00299                 else
00300                     add_snake_tail(snake.locations[i].x, snake.locations[i].y);
00301             }         
00302                  return ACTION_BUTTON;
00303                  
00304         case GO_RIGHT:
00305                snake.head_x += 1;  
00306                
00307                checkCollisions();
00308                
00309                //Over if hit un-walkable object or not invinvible
00310                 if (get_here(snake.head_x, snake.head_y)->type != SNAKE_HEAD &&
00311                 get_here(snake.head_x, snake.head_y)->walkable == 0
00312                 && !snake.invincible) {
00313                     action = GAME_OVER;
00314                     break;
00315                 }
00316                 
00317                add_snake_head(snake.head_x, snake.head_y);
00318                //Check max length
00319                 if (snake.length == SNAKE_MAX_LENGTH && !snake.invincible) {
00320                     action = GAME_OVER;
00321                     break;
00322                 }
00323             for (int i = 0; i < snake.length; i++) {
00324                 int tempy = snake.locations[i].y;
00325                 snake.locations[i].y = oldy;
00326                 
00327                 int tempx = snake.locations[i].x;
00328                 snake.locations[i].x = oldx;
00329                 
00330                 oldy = tempy;
00331                 oldx = tempx;
00332                 map_erase(oldx, oldy);
00333                 
00334                 if (i < snake.length - 1)
00335                     add_snake_body(snake.locations[i].x, snake.locations[i].y);
00336                 else
00337                     add_snake_tail(snake.locations[i].x, snake.locations[i].y);
00338             } 
00339                 return ACTION_BUTTON;
00340            
00341         case GAME_OVER:
00342             {uLCD.color(RED);
00343             uLCD.cls();
00344             uLCD.text_width(3);
00345             uLCD.text_height(3);
00346             uLCD.printf("GAME\n OVER");
00347             uLCD.color(GREEN);
00348             uLCD.text_width(2);
00349             uLCD.text_height(2);
00350             uLCD.printf("\n\n\n\n Score %d", snake.score);
00351             uLCD.color(GREEN);}
00352             while(1 == 1);
00353             }
00354 
00355     if (action == GAME_OVER) {
00356             uLCD.color(RED);
00357             uLCD.cls();
00358             uLCD.text_width(3);
00359             uLCD.text_height(3);
00360             uLCD.printf("GAME\n OVER");
00361             uLCD.color(GREEN);
00362             uLCD.text_width(2);
00363             uLCD.text_height(2);
00364             uLCD.printf("\n\n\n\n Score %d", snake.score);
00365             uLCD.color(GREEN);
00366             while(1 == 1);
00367         }
00368         
00369     return NO_RESULT;
00370     
00371 }
00372 
00373 /**
00374  * Draw the upper status bar.
00375  */
00376 void draw_upper_status()
00377 {
00378     uLCD.line(0, 9, 127, 9, GREEN);
00379 
00380 }
00381 
00382 /**
00383  * Draw the lower status bar.
00384  */
00385 void draw_lower_status()
00386 {
00387     uLCD.line(0, 118, 127, 118, GREEN);
00388 }
00389 
00390 /**
00391  * Draw the border for the map.
00392  */
00393 void draw_border()
00394 {
00395     uLCD.filled_rectangle(0,     9, 127,  14, WHITE); // Top
00396     uLCD.filled_rectangle(0,    13,   2, 114, WHITE); // Left
00397     uLCD.filled_rectangle(0,   114, 127, 117, WHITE); // Bottom
00398     uLCD.filled_rectangle(124,  14, 127, 117, WHITE); // Right
00399 }
00400 
00401 /**
00402  * Entry point for frame drawing. This should be called once per iteration of
00403  * the game loop. This draws all tiles on the screen, followed by the status
00404  * bars. Unless init is nonzero, this function will optimize drawing by only
00405  * drawing tiles that have changed from the previous frame.
00406  */
00407 void draw_game(int draw_option)
00408 {
00409     uLCD.locate(0, 0);
00410     uLCD.text_width(1.5);
00411     uLCD.text_height(1.5);
00412     uLCD.color(RED);
00413     uLCD.printf("Pos:%d %d", snake.head_x, snake.head_y);
00414     
00415     uLCD.locate(10, 0);
00416     uLCD.text_width(1.5);
00417     uLCD.text_height(1.5);
00418     //uLCD.printf("Loc: %d,%d ", snake.head_x, snake.head_y);
00419     uLCD.color(RED);
00420     uLCD.printf("Score:%d", snake.score);
00421 
00422     
00423     // Draw game border first
00424     if(draw_option == FULL_DRAW) {
00425         draw_border();
00426         int u = 58;
00427         int v = 56;
00428         draw_snake_head(u, v);
00429         draw_snake_body(u-11, v);
00430         draw_snake_tail(u-22, v);
00431         int i = 1;
00432         for (; i < snake.length; i++) {
00433             int x = u - (11 * (snake.head_x - snake.locations[i].x));
00434             int y = v - (11 * (snake.head_y - snake.locations[i].y));
00435             if (i < snake.length - 1) {
00436                 add_snake_body(snake.locations[i].x, snake.locations[i].y);
00437                 draw_snake_body(x, y);
00438             }
00439             else {
00440                 add_snake_tail(snake.locations[i].x, snake.locations[i].y);
00441                 draw_snake_tail(x, y);
00442             }
00443         }
00444     }
00445     
00446     // Iterate over all visible map tiles
00447     for (int i = -5; i <= 5; i++) { // Iterate over columns of tiles
00448         for (int j = -4; j <= 4; j++) { // Iterate over one column of tiles
00449             // Here, we have a given (i,j)
00450             // Compute the current map (x,y) of this tile
00451             int x = i + snake.head_x;
00452             int y = j + snake.head_y;
00453 
00454             // Compute the previous map (px, py) of this tile
00455             int px = i + snake.head_px;
00456             int py = j + snake.head_py;
00457 
00458             // Compute u,v coordinates for drawing
00459             int u = (i+5)*11 + 3;
00460             int v = (j+4)*11 + 15;
00461             // Figure out what to draw
00462             DrawFunc draw = NULL;
00463             if (x >= 0 && y >= 0 && x < map_width() && y < map_height()) { // Current (i,j) in the map
00464                 MapItem* curr_item = get_here(x, y);
00465                 MapItem* prev_item = get_here(px, py);
00466                 if (draw_option || curr_item != prev_item) { // Only draw if they're different
00467                     if (curr_item) { // There's something here! Draw it
00468                         draw = curr_item->draw;
00469                     } else { // There used to be something, but now there isn't
00470                         draw = draw_nothing;
00471                     }
00472                 } else if (curr_item && curr_item->type == CLEAR) {
00473                     // This is a special case for erasing things like doors.
00474                     draw = curr_item->draw; // i.e. draw_nothing
00475                 }
00476             } else if (draw_option) { // If doing a full draw, but we're out of bounds, draw the walls.
00477                 draw = draw_wall;
00478             }
00479 
00480             // Actually draw the tile
00481             if (draw) draw(u, v);
00482         }
00483     } 
00484 
00485     // Draw status bars
00486     draw_upper_status();
00487     draw_lower_status();
00488 }
00489 
00490 /**
00491  * Initialize the main world map. Add walls around the edges, interior chambers,
00492  * and plants in the background so you can see motion.
00493  */
00494 void init_main_map()
00495 {
00496     Timer t;
00497     t.start();
00498     Map* map = set_active_map(0);
00499 
00500     pc.printf("plants\r\n");
00501 
00502     pc.printf("Adding walls!\r\n");
00503     add_wall(0,              0,              HORIZONTAL, map_width());
00504     add_wall(0,              map_height()-1, HORIZONTAL, map_width());
00505     add_wall(0,              0,              VERTICAL,   map_height());
00506     add_wall(map_width()-1,  0,              VERTICAL,   map_height());
00507     pc.printf("Walls done!\r\n");
00508     
00509     add_snake_head(snake.locations[0].x, snake.locations[0].y);
00510     add_snake_body(snake.locations[1].x, snake.locations[1].y);
00511     add_snake_tail(snake.locations[2].x, snake.locations[2].y);
00512     
00513     pc.printf("Add extra chamber\r\n");
00514     add_wall(30, 0, VERTICAL, 10);
00515     add_wall(30, 10, HORIZONTAL, 10);
00516     add_wall(39, 0, VERTICAL, 10);
00517     pc.printf("Added!\r\n");
00518 
00519     //ADD POISON, ANY OTHER BUFFS/DEBUFFS HERE!!*******************************************************
00520     //Buffs: Decrement length, Slow (slows time)
00521     //Debuffs: Poison (prevents gaining points for certain time), Speedup thing (literally just 1.5x time or something), 
00522     //Extra:  Random, Strength (prevent death once or something), Pause button (just pause time), Moving object, multiple lives
00523     //Also: Button or sprite to invert controls
00524     
00525     srand(time(0)); // reset seedtime
00526     
00527     for(int i = map_width() + 4; i < map_area(); i += 29) {     // debuff
00528         add_poison(i % map_width() + 4, i / map_width());
00529     }
00530     
00531     for (int i=0; i<3;i++){
00532     add_slowdown(rand()%28+1, rand()%49);       //buff
00533     add_slowdown(rand()%9+40, rand()%49);
00534     add_decrease_length(rand()%28+1, rand()%49);    //buff
00535     add_decrease_length(rand()%9+40, rand()%49);
00536     
00537     add_speedup(rand()%28+1, rand()%49);                    //debuff
00538     add_speedup(rand()%9+40, rand()%49);
00539     
00540     add_random(rand()%9+40, rand()%49, t.read_ms());        //extra randon
00541     add_random(rand()%28+1, rand()%49, t.read_ms());
00542     
00543     add_moving(rand()%28+1, rand()%49);
00544     add_moving(rand()%9+40, rand()%49);
00545     
00546     add_inclength(rand()%28+1, rand()%49);
00547     add_inclength(rand()%9+40, rand()%49);    }    
00548     
00549     add_invinc(9, 5);               // mulitple life
00550     add_slowdown(10, 5);
00551     add_moving(8, 6);
00552     add_inclength(5,7);
00553     for(int i = map_width() + 3; i < map_area(); i += 39) {
00554         //add_goodie(i % map_width(), i / map_width());
00555         add_goodie(rand()%map_width(), rand()% map_height());
00556     }
00557     
00558     // Add stairs to chamber (map 1)
00559     //add_stairs(15, 5, 1, 5, 5);
00560 
00561 //    profile_hashtable();
00562     print_map();
00563 }
00564 
00565 /**
00566  * Program entry point! This is where it all begins.
00567  * This function or all the parts of the game. Most of your
00568  * implementation should be elsewhere - this holds the game loop, and should
00569  * read like a road map for the rest of the code.
00570  */
00571 int main()
00572 {
00573     // First things first: initialize hardware
00574     ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!");
00575 
00576     snake_init(&snake);
00577     // 0. Initialize the maps -- implement this function:
00578     maps_init();
00579     init_main_map();
00580     playSound("/sd/snakeplay.wav");
00581 
00582     // Initialize game state
00583     set_active_map(0);
00584     //snake.head_x = snake.head_y = 5 ;
00585     
00586     GameInputs inputs = read_inputs();
00587             
00588     // Start page
00589                 int difficulty = 0;
00590                 draw_welcome(difficulty, true);
00591                 while (1) {
00592                     inputs = read_inputs();
00593                     if (!inputs.b2) {
00594                         makenoise();
00595                         difficulty++;
00596                         difficulty = difficulty % 3;
00597                         draw_welcome(difficulty, false);
00598                         snake.speedupTime += 16000; //16 sec
00599                         wait_ms(200);
00600                     }
00601                     if (!inputs.b1) {
00602                         // draw_game_over(1);
00603                         makenoise();
00604                         break;
00605                     }
00606                 }
00607     
00608     // Initial drawing
00609     draw_game(FULL_DRAW);
00610     // Main game loop
00611 
00612 
00613    
00614     while(1) {
00615         // Timer to measure game update speed
00616         Timer t;
00617         t.start();
00618 
00619         // 1. Read inputs -- implement this function:
00620         GameInputs inputs = read_inputs();
00621                     
00622         // 2. Determine action (move, act, menu, etc.) -- implement this function:
00623         int action = get_action(inputs);
00624         
00625         // 3. Update game -- implement this function:
00626         int result = update_game(action);
00627         
00628         // 3b. Check for game over based on result
00629         // and if so, handle game over -- implement this.
00630                 
00631         // 4. Draw screen -- provided:
00632         draw_game(result);
00633         
00634         // Compute update time
00635         t.stop();
00636         int dt = t.read_ms();
00637         
00638         
00639         if (dt % 8 == 0 || dt % 8 == 1) {
00640             map_erase(5, 5);
00641             add_moving(10, 10);
00642         }
00643         else if (dt % 8 == 2 || dt % 8 == 3) {
00644             map_erase(10, 10);
00645             add_moving(5, 5);
00646         }
00647         else if (dt % 8 == 4 || dt % 8 == 5) {
00648             map_erase(5, 10);
00649             add_moving(10, 5);
00650         }
00651         else {
00652             map_erase(10, 5);
00653             add_moving(5, 10);
00654         }
00655         
00656         if (snake.invincTimer > 0) {
00657             snake.invincTimer -= 100;
00658             if (snake.invincTimer == 0)
00659                 snake.invincible = 0;
00660         }
00661         
00662         // Display and wait
00663         if (snake.speedupTime > 0 && snake.slowdownTime > 0) {
00664             if (dt < 100) wait_ms(100 - dt);
00665             snake.speedupTime -= 100;
00666             snake.slowdownTime -= 100;
00667         }
00668         else if (snake.speedupTime > 0) {
00669             if (dt < 80) wait_ms(80 - dt);
00670             snake.speedupTime -= 100;
00671         }
00672         else if (snake.slowdownTime > 0) {
00673             if (dt < 125) wait_ms(1000 - dt);
00674             snake.slowdownTime -= 100;
00675         }
00676         else
00677             if (dt < 100) wait_ms(100 - dt);
00678         
00679         //Subtract from point lock time, if it's on
00680         if (snake.pointLockTime > 0) 
00681             snake.pointLockTime -= 100;
00682             
00683     }
00684 }
00685 
00686 // Plays a wavfile
00687 void playSound(char* wav)
00688 {
00689    
00690 }
00691 
00692 // Play speaker
00693 void makenoise()
00694 {
00695     mySpeaker.PlayNote(368.0,0.16,0.1);
00696     mySpeaker.PlayNote(565.0,0.25,0.3);
00697     mySpeaker.PlayNote(400.0,0.18,0.2);  
00698 }