All there but errors need fixing

Dependencies:   mbed

Overview:

Rookie Tetris is a jigsaw style game based on the classic Tetris.

A block will appear at the top of the screen, you must move it (your options for movement are left, right and down - you cannot move up the board). The block will stop when it if placed either on the floor of the board or on-top of another block.

Your goal is to fill a complete row of the board with the blocks; when you do so the row will delete and the pattern above it will drop down. The game is over when your pattern is tall enough to reach to the top of the board!

Controls:

Use the joystick to move your block! Your block cannot move out of the parameters of the board.

Pot 2 controls the contrast of the screen.

main.cpp

Committer:
el18rs
Date:
2020-06-01
Revision:
7:80e1c83b9b6a
Parent:
6:39cbec524483
Child:
8:cebb2aca8e19

File content as of revision 7:80e1c83b9b6a:

/*
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"

// set defaults 
#define TETROMINO_WIDTH 4
#define TETROMINO_HEIGHT 4
// #define TETROMINO_SIZE 4
#define TETROMINO_SPEED 1
#define HEIGHT 48
#define WIDTH 84
// STRUCTS //

struct UserInput {
    Direction d;
    float mag;
};

// OBJECTS //

N5110 lcd;
Gamepad pad;
TetrisGame tetris;

// PROTOTYPES //

void init();
void update_game(UserInput input);
void render();
void welcome();
int score = 0;

// int ScreenHeight = 84;
// int ScreenWidth = 48;

// FUNCTIONS // 

int main()
{
    int fps = 6; // 6 frames per second 
    
    init(); // initialise and display welcome screen
    welcome(); // wait for user to press start
    
    render(); // draw initial frame 
    wait(1.0f/fps); // wait one frame period 
    
// game loop
    while(1) {
        tetris.read_input(pad); // read input 
        tetris.update(pad, lcd);
        //play_game(); // update game state 
        render(); // render the display
        wait(1.0f/fps); // wait one frame period 
        break;
        
}
}


// initialise classes and libraries
void init() {
    lcd.init(); // initialise lcd 
    pad.init(); // initialise Gamepad
    
    // initialise the game with correct tetromino sizes etc
    tetris.init(WIDTH/2 - 2, 4, 4, 4, 1);
    
}

void render() { // draws each frame on the lcd 

    lcd.clear(); // clear screen
    tetris.draw(lcd); // re-draw 
    lcd.refresh(); // refresh screen
}

// welcome screen display
void welcome() {
    
    lcd.printString("    TETRIS      ",0,1);
    lcd.printString("  Press Start   ",0,4);
    lcd.refresh();
    
    // flash LEDs untile start button pressed
    while (pad.start_pressed() == false) {
        lcd.setContrast(pad.read_pot1());
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
}