All there but errors need fixing

Dependencies:   mbed

main.cpp

Committer:
el18rs
Date:
2020-05-24
Revision:
3:522c6f850e91
Parent:
2:55092965eadd
Child:
4:7ddd287a5d28

File content as of revision 3:522c6f850e91:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
2019/20

Name: Ruby Smith
Username: el18rs
Student ID Number: 201259470
Date: 22/05/20
*/

// includes
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "TetrisGame.h"

#define TETROMINO_WIDTH 4
#define TETROMINO_HEIGHT 4

struct UserInput {
    Direction d;
    float mag;
};

N5110 lcd;
Gamepad pad;
TetrisGame tetris;

void init();
void update_game(UserInput input);
void render();
void welcome();


// int ScreenHeight = 84;
// int ScreenWidth = 48;
// string block[7] // store tetromino blocks as a w-string




/* int Rotate(int px, int py, int r)
{
    int pi = 0;
    switch (r % 4);
    {
        case 0: pi = py * 4 + px; // shape width = 4
        break;
        
        case 1: pi = 12 + py - (px * 4); // rotates the shape by 90 degrees
        break;
        
        case 2: pi = 15 - (py * 4) - px; // rotates the shape by 180 degrees
        break; 
        
        case 3: pi = 3 - py + (px * 4); // rotates the shape by 270 degrees
        break;
        
        }
        return pi;
    }
*/

int main()
{
    int fps = 6;
    
    init();
    welcome();
    
    render();
    wait(1.0f/fps);
    
    while(1) {
        tetris.read_input(pad);
        tetris.update(pad);
        render();
        wait(1.0f/fps);
    }
}

void init()
{
    lcd.init();
    padinit();
    
    tetris.init(TETROMINO_WIDTH, TETROMINO_HEIGHT);
    
}

void render()
{
    lcd.clear();
    tetris.draw(lcd);
    lcd.refresh();
}

void welcome() {
    
    lcd.printString("      TETRIS      ",0,1);
    lcd.printString("    Press Start   ",0,4);
    lcd.refresh();
    
    while (pad.start_pressed() == false) {
        lcd.setContrast(pad.read_pot1());
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
}