ECE 2036 Project
Dependencies: mbed wave_player 4DGL-uLCD-SE
Diff: main.cpp
- Revision:
- 0:cf4396614a79
- Child:
- 2:2042f29de6b7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Nov 03 18:48:48 2017 +0000 @@ -0,0 +1,124 @@ +/* Gatech ECE2035 2017 FALL MAZE RUNNER +* Copyright (c) 2017 Gatech ECE2035 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +// Include header files for platform +#include "mbed.h" + +// Include header files for pacman project +#include "globals.h" +#include "math_extra.h" +#include "physics.h" +#include "game.h" +#include "wall.h" +#include "doublely_linked_list.h" + +// Hardware initialization +DigitalIn left_pb(p21); // push button +DigitalIn right_pb(p22); // push button +DigitalIn up_pb(p23); // push button +DigitalIn down_pb(p24); // push button +uLCD_4DGL uLCD(p9,p10,p11); // LCD (serial tx, serial rx, reset pin;) +Serial pc(USBTX,USBRX); // used by Accelerometer +MMA8452 acc(p28, p27, 100000); // Accelerometer +SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD card and filesystem (mosi, miso, sck, cs) + +// Level creation method declaration +DLinkedList* create_blank_level(); + +// Parameters. Declared in globals.h +const float mass = 0.001; +const int radius = 4; +const float bounce=0.5; + +/** Main() is where you start your implementation */ +int main() +{ + //////////////////////////// + // Power-on initialization + //////////////////////////// + // Turn up the serial data rate so we don't lag + uLCD.baudrate(3000000); + pc.baud(115200); + + // Initialize the buttons + // Each *_pb variable is 0 when pressed + left_pb.mode(PullUp); + right_pb.mode(PullUp); + up_pb.mode(PullUp); + down_pb.mode(PullUp); + + // Other hardware initialization here (SD card, speaker, etc.) + + /////////////// + // Reset loop + /////////////// + // This is where control between major phases of the game happens + // This is a good place to add choose levels, add the game menu, etc. + while(1) + { + // Initialze game state + DLinkedList* arena = create_blank_level(); + Physics state = {0}; + state.px = 64.0; // Position in the center of the screen + state.py = 64.0; + state.vx = 0.0; // Initially unmoving + state.vy = 0.0; + + // Delegate to the game loop to execute the level + // run_game() is in game.cpp + run_game(arena, &state); + + // Destory the arena and entities once we're done with the level + destroyList(arena); + } +} + +/** Creates a level with only bounding walls and a ball. */ +DLinkedList* create_blank_level() +{ + DLinkedList* arena = create_dlinkedlist(); + + // Initialize the walls + Wall* walls[4]; + walls[0] = create_wall(HORIZONTAL, 0, 0, 127, bounce); // top + walls[1] = create_wall(HORIZONTAL, 0, 127, 127, bounce);// bottom + walls[2] = create_wall(VERTICAL, 0, 0, 127, bounce); // left + walls[3] = create_wall(VERTICAL, 127, 0, 127, bounce); // right + + // Add the walls to the arena + for (int i = 0; i < 4; i++) + insertTail(arena, (void*)walls[i]); + + // Initialize the ball + Ball* ball = (Ball*) malloc(sizeof(Ball)); + ball->type = BALL; + ball->x = 20; + ball->y = 20; + + // Add ball to the arena + // NOTE: The ball should always be last in the arena list, so that the other + // ArenaElements have a chance to compute the Physics updates before the + // ball applies forward euler method. + insertTail(arena, (void*)ball); + + return arena; +} \ No newline at end of file