Crypt Mbed

Dependencies:   mbed wave_player 4DGL-uLCD-SE USBHost

main_old.cpp

Committer:
amcentag
Date:
2021-12-09
Revision:
0:9d0cdfe46974

File content as of revision 0:9d0cdfe46974:

////#include "mbed.h"
////#include "uLCD_4DGL.h"
////#include "rtos.h"
//
//uLCD_4DGL uLCD(p9,p10,p11);
//
//Thread thread_clk;
//Thread thread_proc;
//
//InterruptIn Wbn(p21);
//InterruptIn Abn(p22);
//InterruptIn Sbn(p23);
//InterruptIn Dbn(p24);
////PinDetect Wbn(p21);
////PinDetect Abn(p22);
////PinDetect Sbn(p23);
////PinDetect Dbn(p24);
//
//const int gb_SIZE = 14;
//
////current state of the game
//int gameBoard[gb_SIZE][gb_SIZE];
////used to optimize draw function
//int changeBoard[gb_SIZE][gb_SIZE];
////lock on both boards
//Mutex boardM;
//
////displays if it's currently a clickable action or not
//DigitalOut beat(LED1);
//
////counts up to 100
//int counter;
////level in the game (for choosing bpm)
//int level;
//
//int currAction; // 1 is W, 2 is A, 3 is S, 4 is D
//int actLock; // locks actions out after first action until next beat
//Mutex actM; // mutex on currAction
//
////method declarations
//int levelTimes();
//void action(int i);
//void actionW();
//void actionA();
//void actionS();
//void actionD();
//void clk();
//void processAction();
//void drawSquare(int i, int j, int temp);
//void drawGB();
//
//
////returns the thread wait time for each level
//int levelTimes() {
//    if (level == 1) {
//        return 100;
//    } else {
//        return 1;
//    }
//}
//
////handles actions for button press
//void action(int i) {
//    //get lock for action
//    int c = -1;
//    actM.lock();
//    //if (actLock) {
//        //lock out further actions
//        actLock = 0;
//        //check if action is within beat (beat center is 100)
//        c = counter;
//        //if (c >= 76 || c <= 25) {
//            currAction = i;
//        //}
//    //}
//    actM.unlock();
//    //make changes to game board if action was recorded
////    if (c != -1) {
////        processAction();
////    }
//}
//void actionW() {
//    action(1);
//}
//void actionA() {
//    action(2);
//}
//void actionS() {
//    action(3);
//}
//void actionD() {
//    action(4);
//}
//
//void clk() {
//    // Game code waits for input on a timer
//    beat = 1;
//    // Have clock increment a counter from 0 upZ to 100 (wait time depends on song [level])
//    for(;;) {
//        Thread::wait(levelTimes());
//        counter++;
//        if (counter > 100) {
//            counter = 1;
//        }
//        //reset ability to make action on half beat
//        if (counter == 50) {
//            actLock = 1;
//            currAction = 0;
//        }
//        //indicate when a press is on beat. May need to alter according to calibration
//        if (counter == 25 || counter == 75) {
//            beat = !beat;
//        }
//    }
//}
//
//void processAction() {
//    // On timed update from T1, assess player action, then assess enemy actions (enemies not implemented)
//        // Grab grid lock
//        // Update grid backing game information based on player action
//    while(1) {
//    if (currAction != 0) {
//        for (int i = 0; i < gb_SIZE; i++) {
//            for (int j = 0; j < gb_SIZE; j++) {
//                if (gameBoard[i][j] == 1) { // player is here
//                    boardM.lock();
//                    gameBoard[i][j] = 0;
//                    changeBoard[i][j] = 1;
//                    if (currAction == 1) {
//                        if (j > 0) {
//                            gameBoard[i][(j - 1)] = 1;
//                            changeBoard[i][(j - 1)]++;
//                        }
//                    } else if (currAction == 2) {
//                        //if (i > 0) {
//                            gameBoard[(i - 1)][j] = 1;
//                            changeBoard[(i - 1)][j]++;
//                        //}
//                    } else if (currAction == 3) {
//                        if (j < gb_SIZE) {
//                            gameBoard[i][(j + 1)] = 1;
//                            changeBoard[i][(j + 1)]++;
//                        }
//                    } else {
//                        if (i < gb_SIZE) {
//                            gameBoard[(i + 1)][j] = 1;
//                            changeBoard[(i + 1)][j]++;
//                        }
//                    }
//                    boardM.unlock();
//                }
//            }
//        }
//        currAction = 0;
//        //draw board
//        drawGB();
//    }
//    }
//}
//
//void drawSquare(int i, int j, int temp) {
//    if (temp == 0) { // empty
//        uLCD.filled_rectangle(i * 9 + 1, j * 9 + 1, i * 9 + 8, j * 9 + 8, 0xFFFF00);
//    } else if (temp == 1) { //person
//        uLCD.filled_rectangle(i * 9 + 1, j * 9 + 1, i * 9 + 8, j * 9 + 8, 0xFFFF00);
//        uLCD.filled_rectangle(i * 9 + 3, j * 9 + 3, i * 9 + 6, j * 9 + 6, 0xFF0000);
//    }
//}
//
//void drawGB() {
//    //draw all squares from gameboard which changeboard indicates are changed
//    for (int i = 0; i < gb_SIZE; i++) {
//        for (int j =0; j < gb_SIZE; j++) {
//            if (changeBoard[i][j] > 0) {
//                int temp = gameBoard[i][j];
//                boardM.lock();
//                changeBoard[i][j] = 0;
//                boardM.unlock();
//                drawSquare(i, j, temp);
//            }
//        }
//    }
//}
//
//
//
//// void t4() {
////     //If 2 player mode selected, duplicate T1 functionality
//// }
//
//int main2()
//{
//    Wbn.mode(PullUp);
//    Abn.mode(PullUp);
//    Sbn.mode(PullUp);
//    Dbn.mode(PullUp);
//    Wbn.rise(&actionW);
//    Abn.rise(&actionA);
//    Sbn.rise(&actionS);
//    Dbn.rise(&actionD);
//    level = 1;
//    //initialize lcd
//    uLCD.cls();
//    uLCD.baudrate(3000000);
//    uLCD.background_color(0xFFFF00);
//    uLCD.cls();
//    uLCD.color(BLACK);
//    //display char # select menu TODO, Skipped for now
//    //wait on input for char select TODO, Skipped for nowha
//    //add calibration screen TODO, Skipped for now
//    // draw board grid
//    for (int i = 0; i < 128; i+=9) {
//        uLCD.line(0, i, 127, i, 0);
//        uLCD.line(i, 0, i, 127, 0);
//    }
//    //initialize threads
//    //initialize another thread if 2 chars TODO, Skipped for now
//    
//    //Andrew - initializing gameBoard to try to get a moving character demo
//    for(int i = 0; i < gb_SIZE; i++) {
//        for(int j = 0; j < gb_SIZE; j++) {
//            gameBoard[i][j] = 0;
//        }
//    }
//    gameBoard[0][0] = 1;
//    changeBoard[0][0] = 1;
//    drawGB();
//    thread_clk.start(clk);
//    thread_clk.start(processAction);
//    
//    while(1){}
//    //play speaker TODO Not sure how
//}