ECE 2036 Project

Dependencies:   mbed wave_player 4DGL-uLCD-SE

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Gatech ECE2035 2017 FALL MAZE RUNNER
00002 * Copyright (c) 2017 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 header files for platform
00024 #include "mbed.h"
00025 
00026 // Include header files for pacman project
00027 #include "globals.h"
00028 #include "math_extra.h"
00029 #include "physics.h"
00030 #include "game.h"
00031 #include "wall.h"
00032 #include "doublely_linked_list.h "
00033 
00034 // Hardware initialization
00035 DigitalIn left_pb(p21);     // push button
00036 DigitalIn right_pb(p22);    // push button
00037 DigitalIn up_pb(p23);       // push button
00038 DigitalIn down_pb(p24);     // push button
00039 uLCD_4DGL uLCD(p9,p10,p11); // LCD (serial tx, serial rx, reset pin;)
00040 Serial pc(USBTX,USBRX);     // used by Accelerometer
00041 MMA8452 acc(p28, p27, 100000);  // Accelerometer
00042 //SDFileSystem sd(p5, p6, p7, p8, "sd");  // SD card and filesystem
00043 
00044 DigitalOut redLED(p25);     // Red LED
00045 DigitalOut greenLED(p26);   // Green LED
00046 Speaker speaker(p18);       // Speaker
00047 
00048 // Menu screen drawing functions
00049 void do_main_menu();
00050 void do_setup_menu();
00051 void do_help_menu();
00052 void do_level_start(int);
00053 void do_level_complete(int, int);
00054 void do_game_over();
00055 
00056 // Level creation method declaration
00057 DLinkedList* create_blank_level();
00058 DLinkedList* create_level_1();
00059 DLinkedList* create_level_2();
00060 DLinkedList* create_level_3();
00061 
00062 // Parameters. Declared in globals.h
00063 const float mass = 0.001;
00064 const int radius = 4;
00065 const float bounce = 0.5;
00066 int sound = 1;
00067 
00068 /** Main() is where you start your implementation */
00069 int main()
00070 {
00071     ////////////////////////////
00072     // Power-on initialization
00073     ////////////////////////////
00074 
00075     // Turn up the serial data rate so we don't lag
00076     uLCD.baudrate(3000000);
00077     pc.baud(115200);
00078 
00079     // Initialize the buttons
00080     // Each *_pb variable is 0 when pressed
00081     left_pb.mode(PullUp);
00082     right_pb.mode(PullUp);
00083     up_pb.mode(PullUp);
00084     down_pb.mode(PullUp);
00085 
00086     // Other hardware initialization here (SD card, speaker, etc.)
00087 
00088     DLinkedList* levels = create_dlinkedlist();
00089     insertTail(levels, create_level_1());
00090     insertTail(levels, create_level_2());
00091     insertTail(levels, create_level_3());
00092 
00093     do_main_menu();
00094 
00095     ///////////////
00096     // Reset loop
00097     ///////////////
00098     // This is where control between major phases of the game happens
00099     // This is a good place to add choose levels, add the game menu, etc.
00100 
00101     // Start with the first level
00102     DLinkedList* arena = (DLinkedList*)getHead(levels);
00103     int level = 1;
00104 
00105     int gameOver = 0;
00106     while(gameOver == 0) {
00107 
00108         do_level_start(level);
00109 
00110         uLCD.cls();
00111 
00112         // (Re)Initialze game state
00113         Physics state = {0};
00114         int ix, iy;
00115         state.px = ix = ((Ball*)getTail(arena))->x;     // Initial position of ball
00116         state.py = iy = ((Ball*)getTail(arena))->y;
00117         state.vx = 0.0;         // Initial velocity of ball
00118         state.vy = 0.0;
00119 
00120         // Delegate to the game loop to execute the level
00121         // run_game() is in game.cpp
00122         int ret = run_game(arena, &state);
00123 
00124         // If we hit the goal, advance to the next level
00125         if (ret <= 30) {
00126 
00127             do_level_complete(level++, ret);
00128 
00129             // Destroy the arena and entities once we're done with the level
00130             destroyList(arena);
00131 
00132             // Get the next level
00133             arena = (DLinkedList*)getNext(levels);
00134             // If the next level is NULL, game over!
00135             if (arena == NULL) {
00136                 gameOver = 1;
00137             }
00138 
00139         } else {
00140 
00141             if (ret == 32) {
00142                 // Show help screen
00143                 do_help_menu();
00144             } else {
00145                 // Collision effect
00146                 redLED = 1;
00147                 for (int i = 4; i < 29; i++) {
00148                     redLED = !redLED;
00149                     int tone = (29 - i) * 5 + 100;
00150                     speaker.PlayNote(tone, 0.01, sound);
00151                     uLCD.circle(64, 64, i, RED);
00152                     uLCD.circle(64, 64, i - 1, 0xFFCC00);
00153                     uLCD.circle(64, 64, i - 2, WHITE);
00154                     uLCD.circle(64, 64, i - 3, 0);
00155                 }
00156             }
00157 
00158             // If we hit a pothole, restart the level by redrawing all elements
00159             // and resetting the state
00160             ArenaElement* elem = (ArenaElement*)getHead(arena);
00161             do {
00162                 switch(elem->type) {
00163                     case WALL:
00164                         // Redraw walls
00165                         ((Wall*)elem)->should_draw = 1;
00166                         break;
00167                     case BALL:
00168                         // Reset ball position
00169                         ((Ball*)elem)->x = ix;
00170                         ((Ball*)elem)->y = iy;
00171                         break;
00172                     case HOLE:
00173                         // Redraw holes
00174                         ((Hole*)elem)->should_draw = 1;
00175                         break;
00176                     case GOAL:
00177                         // Redraw goal
00178                         ((Goal*)elem)->should_draw = 1;
00179                         break;
00180                     default:
00181                         break;
00182                 }
00183             } while(elem = (ArenaElement*)getNext(arena));
00184 
00185         }
00186 
00187     }
00188 
00189     do_game_over();
00190 
00191 }
00192 
00193 void do_main_menu()
00194 {
00195 
00196     int cont = 1;
00197     while (cont) {
00198 
00199         uLCD.cls();
00200         uLCD.color(WHITE);
00201         uLCD.printf("\n\n");
00202         uLCD.printf("   Maze Runner!   ");
00203         uLCD.printf("\n\n");
00204         uLCD.printf("      Play        ");
00205         uLCD.printf("\n");
00206         uLCD.printf("      Setup       ");
00207         uLCD.printf("\n");
00208         uLCD.printf("      Help        ");
00209         uLCD.printf("\n\n");
00210 
00211         uLCD.rectangle(15, 34, 112, 51, WHITE);
00212         uLCD.rectangle(15, 51, 112, 67, WHITE);
00213         uLCD.rectangle(15, 67, 112, 84, WHITE);
00214         uLCD.rectangle(16, 35, 111, 51, WHITE);
00215         uLCD.rectangle(16, 51, 111, 67, WHITE);
00216         uLCD.rectangle(16, 67, 111, 83, WHITE);
00217 
00218         int offset = 35;
00219         uLCD.rectangle(16, 0 + offset, 111, 16 + offset, BLUE);
00220 
00221         int rpb = right_pb;
00222         int upb = up_pb;
00223         int dpb = down_pb;
00224         int rpb2 = rpb;
00225         int upb2 = upb;
00226         int dpb2 = dpb;
00227 
00228         int cont2 = 1;
00229         while(cont2) {
00230 
00231             int crpb = right_pb;
00232             int cupb = up_pb;
00233             int cdpb = down_pb;
00234 
00235             if (!cupb && upb && upb2) {
00236                 uLCD.rectangle(16, 0 + offset, 111, 16 + offset, WHITE);
00237                 if (offset > 35) {
00238                     offset -= 16;
00239                 }
00240                 uLCD.rectangle(16, 0 + offset, 111, 16 + offset, BLUE);
00241                 speaker.PlayNote(100, 0.01, sound);
00242             }
00243 
00244             if (!cdpb && dpb && dpb2) {
00245                 uLCD.rectangle(16, 0 + offset, 111, 16 + offset, WHITE);
00246                 if (offset < 67) {
00247                     offset += 16;
00248                 }
00249                 uLCD.rectangle(16, 0 + offset, 111, 16 + offset, BLUE);
00250                 speaker.PlayNote(100, 0.01, sound);
00251             }
00252 
00253             if (!crpb && rpb && rpb2) {
00254 
00255                 uLCD.rectangle(16, 0 + offset, 111, 16 + offset, GREEN);
00256                 speaker.PlayNote(100, 0.01, sound);
00257                 wait(0.25);
00258 
00259                 if (offset == 51) {
00260                     do_setup_menu();
00261                     cont2 = 0;
00262                 } else if (offset == 67) {
00263                     do_help_menu();
00264                     cont2 = 0;
00265                 } else {
00266                     cont = 0;
00267                     cont2 = 0;
00268                 }
00269 
00270             }
00271 
00272             rpb2 = rpb;
00273             upb2 = upb;
00274             dpb2 = dpb;
00275             rpb = crpb;
00276             upb = cupb;
00277             dpb = cdpb;
00278 
00279         }
00280 
00281     }
00282 
00283 }
00284 
00285 void do_setup_menu()
00286 {
00287 
00288     int cont = 1;
00289     while (cont) {
00290 
00291         uLCD.cls();
00292         uLCD.color(WHITE);
00293         uLCD.printf("\n\n");
00294         uLCD.printf("      Setup       ");
00295         uLCD.printf("\n\n");
00296         if (sound) {
00297             uLCD.printf("    Sound ON      ");
00298         } else {
00299             uLCD.printf("    Sound OFF     ");
00300         }
00301 
00302         int offset = 35;
00303         uLCD.rectangle(16, 0 + offset, 111, 16 + offset, BLUE);
00304 
00305         int lpb = left_pb;
00306         int rpb = right_pb;
00307 
00308         int cont2 = 1;
00309         while(cont2) {
00310 
00311             int clpb = left_pb;
00312             int crpb = right_pb;
00313 
00314             if (!crpb && rpb) {
00315                 uLCD.rectangle(16, 0 + offset, 111, 16 + offset, GREEN);
00316                 wait(0.25);
00317                 if (sound == 1) {
00318                     sound = 0;
00319                 } else {
00320                     sound = 1;
00321                 }
00322                 speaker.PlayNote(100, 0.01, sound);
00323                 cont2 = 0;
00324             }
00325 
00326             if (!clpb && lpb) {
00327                 speaker.PlayNote(100, 0.01, sound);
00328                 cont = 0;
00329                 cont2 = 0;
00330             }
00331 
00332             lpb = clpb;
00333             rpb = crpb;
00334 
00335         }
00336 
00337     }
00338 
00339 }
00340 
00341 void do_help_menu()
00342 {
00343     uLCD.cls();
00344     uLCD.color(WHITE);
00345     uLCD.printf("\n\n");
00346     uLCD.printf("      Help        ");
00347     uLCD.printf("\n\n");
00348 
00349     uLCD.printf("Tilt the game to  ");
00350     uLCD.printf("get through the   ");
00351     uLCD.printf("maze to the ");
00352     uLCD.color(GREEN);
00353     uLCD.printf("green ");
00354     uLCD.color(WHITE);
00355     uLCD.printf("dot. Don't touch  ");
00356     uLCD.printf("the ");
00357     uLCD.color(RED);
00358     uLCD.printf("red");
00359     uLCD.color(WHITE);
00360     uLCD.printf(" dots!     ");
00361     uLCD.printf("\n");
00362 
00363     uLCD.color(BLUE);
00364     uLCD.printf("UP");
00365     uLCD.color(WHITE);
00366     uLCD.printf(" saves state.   ");
00367     uLCD.printf("\n");
00368 
00369     uLCD.color(BLUE);
00370     uLCD.printf("DOWN");
00371     uLCD.color(WHITE);
00372     uLCD.printf(" jumps to the ");
00373     uLCD.printf("last saved state. ");
00374 
00375     while(left_pb) {}
00376 
00377     speaker.PlayNote(100, 0.01, sound);
00378 
00379 }
00380 
00381 void do_level_start(int level)
00382 {
00383 
00384     uLCD.cls();
00385     uLCD.color(WHITE);
00386     uLCD.printf("\n\n\n\n");
00387     uLCD.printf("     Level %d      ", level);
00388     uLCD.printf("\n\n\n");
00389 
00390     uLCD.rectangle(16, 19, 103, 51, WHITE);
00391 
00392     uLCD.printf("  ");
00393     for (int i = 3; i > 0; i--) {
00394         redLED = 1;
00395         uLCD.printf("%i... ", i);
00396         speaker.PlayNote(293.665, 0.25, sound);
00397         redLED = 0;
00398         wait(0.75);
00399     }
00400     greenLED = 1;
00401     uLCD.printf("\n\n       Go!");
00402     speaker.PlayNote(391.995, 0.75, sound);
00403     greenLED = 0;
00404 
00405 }
00406 
00407 void do_level_complete(int level, int time)
00408 {
00409 
00410     uLCD.cls();
00411     uLCD.color(WHITE);
00412     uLCD.printf("\n\n\n\n");
00413     uLCD.printf("     Level %d      \n", level);
00414     uLCD.printf("    Complete!     ");
00415     uLCD.printf("\n\n\n");
00416     uLCD.printf("  Score:  %d/30   ", time);
00417 
00418     uLCD.rectangle(16, 19, 103, 67, WHITE);
00419 
00420     greenLED = 1;
00421     speaker.PlayNote(391.995, 0.12, sound);
00422     greenLED = 0;
00423     wait(0.12);
00424     greenLED = 1;
00425     speaker.PlayNote(493.883, 0.12, sound);
00426     speaker.PlayNote(587.330, 0.24, sound);
00427     greenLED = 0;
00428     wait(1);
00429 
00430 }
00431 
00432 void do_game_over()
00433 {
00434     uLCD.cls();
00435     uLCD.color(WHITE);
00436     uLCD.printf("\n\n\n\n");
00437     uLCD.printf("    Game Over!    ");
00438     uLCD.printf("\n\n\n");
00439 
00440     uLCD.rectangle(16, 19, 103, 51, WHITE);
00441 
00442     uLCD.printf("  Press the blue  ");
00443     uLCD.printf("  button to play  ");
00444     uLCD.printf("      again!      ");
00445 
00446 
00447 
00448     greenLED = 1;
00449     speaker.PlayNote(587.330, 0.2, sound);
00450     greenLED = 0;
00451     wait(0.2);
00452     greenLED = 1;
00453     speaker.PlayNote(587.330, 0.1, sound);
00454     wait(0.1);
00455     greenLED = 0;
00456     speaker.PlayNote(587.330, 0.2, sound);
00457     greenLED = 1;
00458     speaker.PlayNote(493.883, 0.2, sound);
00459     greenLED = 0;
00460     speaker.PlayNote(587.330, 0.1, sound);
00461     wait(0.1);
00462     greenLED = 1;
00463     speaker.PlayNote(783.991, 0.5, sound);
00464     greenLED = 0;
00465 }
00466 
00467 /** Creates the first level. */
00468 DLinkedList* create_level_1()
00469 {
00470     DLinkedList* arena = create_dlinkedlist();
00471 
00472     // Initialize the walls
00473     Wall* walls[12];
00474     walls[0] = create_wall(HORIZONTAL, 0, 2, 127, bounce);  // top
00475     walls[1] = create_wall(HORIZONTAL, 0, 127, 127, bounce);// bottom
00476     walls[2] = create_wall(VERTICAL, 0, 2, 127, bounce);    // left
00477     walls[3] = create_wall(VERTICAL, 127, 2, 127, bounce);  // right
00478     walls[4] = create_wall(VERTICAL, 21, 21, 84, bounce);
00479     walls[5] = create_wall(VERTICAL, 42, 2, 42, bounce);
00480     walls[6] = create_wall(VERTICAL, 63, 21, 106, bounce);
00481     walls[7] = create_wall(VERTICAL, 84, 64, 32, bounce);
00482     walls[8] = create_wall(VERTICAL, 42, 84, 21, bounce);
00483     walls[9] = create_wall(HORIZONTAL, 21, 64, 42, bounce);
00484     walls[10] = create_wall(HORIZONTAL, 21, 105, 21, bounce);
00485     walls[11] = create_wall(HORIZONTAL, 84, 64, 43, bounce);
00486 
00487     // Add the walls to the arena
00488     for (int i = 0; i < 12; i++)
00489         insertTail(arena, (void*)walls[i]);
00490 
00491     // Initialize the goal
00492     Goal* goal = (Goal*) malloc(sizeof(Goal));
00493     goal->type = GOAL;
00494     goal->x = 95;
00495     goal->y = 80;
00496     goal->should_draw = 1;
00497 
00498     // Add goal to the arena
00499     insertTail(arena, (void*)goal);
00500 
00501     // Initialize the ball
00502     Ball* ball = (Ball*) malloc(sizeof(Ball));
00503     ball->type = BALL;
00504     ball->x = 31;
00505     ball->y = 95;
00506 
00507     // Add ball to the arena
00508     insertTail(arena, (void*)ball);
00509 
00510     return arena;
00511 }
00512 
00513 /** Creates the second level. */
00514 DLinkedList* create_level_2()
00515 {
00516     DLinkedList* arena = create_dlinkedlist();
00517 
00518     // Initialize the walls
00519     Wall* walls[15];
00520     walls[0] = create_wall(HORIZONTAL, 0, 2, 127, bounce);  // top
00521     walls[1] = create_wall(HORIZONTAL, 0, 127, 127, bounce);// bottom
00522     walls[2] = create_wall(VERTICAL, 0, 2, 127, bounce);    // left
00523     walls[3] = create_wall(VERTICAL, 127, 2, 127, bounce);  // right
00524     walls[4] = create_wall(VERTICAL, 64, 2, 21, bounce);
00525     walls[5] = create_wall(HORIZONTAL, 0, 21, 32, bounce);
00526     walls[6] = create_wall(VERTICAL, 32, 21, 43, bounce);
00527     walls[7] = create_wall(VERTICAL, 96, 21, 22, bounce);
00528     walls[8] = create_wall(HORIZONTAL, 64, 43, 63, bounce);
00529     walls[9] = create_wall(HORIZONTAL, 32, 64, 32, bounce);
00530     walls[10] = create_wall(HORIZONTAL, 64, 85, 32, bounce);
00531     walls[11] = create_wall(VERTICAL, 64, 85, 42, bounce);
00532     walls[12] = create_wall(HORIZONTAL, 0, 85, 32, bounce);
00533     walls[13] = create_wall(VERTICAL, 32, 85, 22, bounce);
00534     walls[14] = create_wall(HORIZONTAL, 96, 107, 31, bounce);
00535 
00536     // Add the walls to the arena
00537     for (int i = 0; i < 15; i++)
00538         insertTail(arena, (void*)walls[i]);
00539 
00540     // Initialize a hole
00541     Hole* hole = (Hole*) malloc(sizeof(Hole));
00542     hole->type = HOLE;
00543     hole->x = 96;
00544     hole->y = 64;
00545     hole->should_draw = 1;
00546 
00547     // Add hole to the arena
00548     insertTail(arena, (void*)hole);
00549 
00550     // Initialize the goal
00551     Goal* goal = (Goal*) malloc(sizeof(Goal));
00552     goal->type = GOAL;
00553     goal->x = 112;
00554     goal->y = 21;
00555     goal->should_draw = 1;
00556 
00557     // Add goal to the arena
00558     insertTail(arena, (void*)goal);
00559 
00560     // Initialize the ball
00561     Ball* ball = (Ball*) malloc(sizeof(Ball));
00562     ball->type = BALL;
00563     ball->x = 16;
00564     ball->y = 96;
00565 
00566     // Add ball to the arena
00567     insertTail(arena, (void*)ball);
00568 
00569     return arena;
00570 }
00571 
00572 /** Creates the third level. */
00573 DLinkedList* create_level_3()
00574 {
00575     DLinkedList* arena = create_dlinkedlist();
00576 
00577     // Initialize the walls
00578     Wall* walls[15];
00579     walls[0] = create_wall(HORIZONTAL, 0, 2, 127, bounce);  // top
00580     walls[1] = create_wall(HORIZONTAL, 0, 127, 127, bounce);// bottom
00581     walls[2] = create_wall(VERTICAL, 0, 2, 127, bounce);    // left
00582     walls[3] = create_wall(VERTICAL, 127, 2, 127, bounce);  // right
00583     walls[4] = create_wall(HORIZONTAL, 0, 18, 107, bounce);
00584     walls[5] = create_wall(VERTICAL, 107, 18, 92, bounce);
00585     walls[6] = create_wall(HORIZONTAL, 64, 110, 43, bounce);
00586     walls[7] = create_wall(HORIZONTAL, 43, 91, 42, bounce);
00587     walls[8] = create_wall(VERTICAL, 43, 91, 36, bounce);
00588     walls[9] = create_wall(HORIZONTAL, 0, 91, 21, bounce);
00589     walls[10] = create_wall(VERTICAL, 21, 73, 18, bounce);
00590     walls[11] = create_wall(HORIZONTAL, 21, 73, 64, bounce);
00591     walls[12] = create_wall(VERTICAL, 85, 37, 36, bounce);
00592     walls[13] = create_wall(HORIZONTAL, 21, 37, 64, bounce);
00593     walls[14] = create_wall(HORIZONTAL, 0, 55, 43, bounce);
00594 
00595     // Add the walls to the arena
00596     for (int i = 0; i < 15; i++)
00597         insertTail(arena, (void*)walls[i]);
00598 
00599     // Initialize a hole
00600     Hole* hole = (Hole*) malloc(sizeof(Hole));
00601     hole->type = HOLE;
00602     hole->x = 96;
00603     hole->y = 82;
00604     hole->should_draw = 1;
00605 
00606     // Add hole to the arena
00607     insertTail(arena, (void*)hole);
00608 
00609     // Initialize a hole
00610     Hole* hole2 = (Hole*) malloc(sizeof(Hole));
00611     hole2->type = HOLE;
00612     hole2->x = 64;
00613     hole2->y = 55;
00614     hole2->should_draw = 1;
00615 
00616     // Add hole to the arena
00617     insertTail(arena, (void*)hole2);
00618 
00619     // Initialize the goal
00620     Goal* goal = (Goal*) malloc(sizeof(Goal));
00621     goal->type = GOAL;
00622     goal->x = 11;
00623     goal->y = 82;
00624     goal->should_draw = 1;
00625 
00626     // Add goal to the arena
00627     insertTail(arena, (void*)goal);
00628 
00629     // Initialize the ball
00630     Ball* ball = (Ball*) malloc(sizeof(Ball));
00631     ball->type = BALL;
00632     ball->x = 21;
00633     ball->y = 110;
00634 
00635     // Add ball to the arena
00636     insertTail(arena, (void*)ball);
00637 
00638     return arena;
00639 }
00640 
00641 /** Creates a level with only bounding walls and a ball. */
00642 DLinkedList* create_blank_level()
00643 {
00644     DLinkedList* arena = create_dlinkedlist();
00645 
00646     // Initialize the walls
00647     Wall* walls[4];
00648     walls[0] = create_wall(HORIZONTAL, 0, 2, 127, bounce);  // top
00649     walls[1] = create_wall(HORIZONTAL, 0, 127, 127, bounce);// bottom
00650     walls[2] = create_wall(VERTICAL, 0, 0, 127, bounce);    // left
00651     walls[3] = create_wall(VERTICAL, 127, 0, 127, bounce);  // right
00652 
00653     // Add the walls to the arena
00654     for (int i = 0; i < 4; i++)
00655         insertTail(arena, (void*)walls[i]);
00656 
00657     // Initialize the ball
00658     Ball* ball = (Ball*) malloc(sizeof(Ball));
00659     ball->type = BALL;
00660     ball->x = 20;
00661     ball->y = 20;
00662 
00663     // Add ball to the arena
00664     // NOTE: The ball should always be last in the arena list, so that the other
00665     // ArenaElements have a chance to compute the Physics updates before the
00666     // ball applies forward euler method.
00667     insertTail(arena, (void*)ball);
00668 
00669     return arena;
00670 }