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.

Committer:
el18rs
Date:
Mon Jun 01 16:39:13 2020 +0000
Revision:
8:cebb2aca8e19
Parent:
7:80e1c83b9b6a
Child:
9:58103274b2ab
welcome works

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18rs 2:55092965eadd 1 /*
eencae 0:b7f1f47bb26a 2 ELEC2645 Embedded Systems Project
eencae 0:b7f1f47bb26a 3 School of Electronic & Electrical Engineering
eencae 0:b7f1f47bb26a 4 University of Leeds
eencae 0:b7f1f47bb26a 5 2019/20
eencae 0:b7f1f47bb26a 6
el18rs 1:35dba0833c7d 7 Name: Ruby Smith
el18rs 1:35dba0833c7d 8 Username: el18rs
el18rs 1:35dba0833c7d 9 Student ID Number: 201259470
el18rs 1:35dba0833c7d 10 Date: 22/05/20
eencae 0:b7f1f47bb26a 11 */
eencae 0:b7f1f47bb26a 12
eencae 0:b7f1f47bb26a 13 // includes
eencae 0:b7f1f47bb26a 14 #include "mbed.h"
eencae 0:b7f1f47bb26a 15 #include "Gamepad.h"
eencae 0:b7f1f47bb26a 16 #include "N5110.h"
el18rs 3:522c6f850e91 17 #include "TetrisGame.h"
el18rs 3:522c6f850e91 18
el18rs 4:7ddd287a5d28 19 // set defaults
el18rs 3:522c6f850e91 20 #define TETROMINO_WIDTH 4
el18rs 3:522c6f850e91 21 #define TETROMINO_HEIGHT 4
el18rs 4:7ddd287a5d28 22 // #define TETROMINO_SIZE 4
el18rs 4:7ddd287a5d28 23 #define TETROMINO_SPEED 1
el18rs 4:7ddd287a5d28 24 #define HEIGHT 48
el18rs 4:7ddd287a5d28 25 #define WIDTH 84
el18rs 4:7ddd287a5d28 26 // STRUCTS //
el18rs 3:522c6f850e91 27
el18rs 3:522c6f850e91 28 struct UserInput {
el18rs 3:522c6f850e91 29 Direction d;
el18rs 3:522c6f850e91 30 float mag;
el18rs 3:522c6f850e91 31 };
el18rs 3:522c6f850e91 32
el18rs 4:7ddd287a5d28 33 // OBJECTS //
el18rs 4:7ddd287a5d28 34
el18rs 3:522c6f850e91 35 N5110 lcd;
el18rs 3:522c6f850e91 36 Gamepad pad;
el18rs 3:522c6f850e91 37 TetrisGame tetris;
el18rs 3:522c6f850e91 38
el18rs 4:7ddd287a5d28 39 // PROTOTYPES //
el18rs 4:7ddd287a5d28 40
el18rs 3:522c6f850e91 41 void init();
el18rs 3:522c6f850e91 42 void update_game(UserInput input);
el18rs 3:522c6f850e91 43 void render();
el18rs 3:522c6f850e91 44 void welcome();
el18rs 4:7ddd287a5d28 45 int score = 0;
eencae 0:b7f1f47bb26a 46
el18rs 3:522c6f850e91 47 // int ScreenHeight = 84;
el18rs 3:522c6f850e91 48 // int ScreenWidth = 48;
el18rs 2:55092965eadd 49
el18rs 4:7ddd287a5d28 50 // FUNCTIONS //
el18rs 2:55092965eadd 51
el18rs 3:522c6f850e91 52 int main()
el18rs 2:55092965eadd 53 {
el18rs 4:7ddd287a5d28 54 int fps = 6; // 6 frames per second
el18rs 2:55092965eadd 55
el18rs 4:7ddd287a5d28 56 init(); // initialise and display welcome screen
el18rs 4:7ddd287a5d28 57 welcome(); // wait for user to press start
el18rs 4:7ddd287a5d28 58
el18rs 4:7ddd287a5d28 59 render(); // draw initial frame
el18rs 4:7ddd287a5d28 60 wait(1.0f/fps); // wait one frame period
el18rs 2:55092965eadd 61
el18rs 4:7ddd287a5d28 62 // game loop
el18rs 3:522c6f850e91 63 while(1) {
el18rs 4:7ddd287a5d28 64 tetris.read_input(pad); // read input
el18rs 6:39cbec524483 65 tetris.update(pad, lcd);
el18rs 4:7ddd287a5d28 66 //play_game(); // update game state
el18rs 4:7ddd287a5d28 67 render(); // render the display
el18rs 4:7ddd287a5d28 68 wait(1.0f/fps); // wait one frame period
el18rs 4:7ddd287a5d28 69 break;
el18rs 4:7ddd287a5d28 70
el18rs 4:7ddd287a5d28 71 }
el18rs 4:7ddd287a5d28 72 }
el18rs 3:522c6f850e91 73
el18rs 4:7ddd287a5d28 74
el18rs 4:7ddd287a5d28 75 // initialise classes and libraries
el18rs 4:7ddd287a5d28 76 void init() {
el18rs 4:7ddd287a5d28 77 lcd.init(); // initialise lcd
el18rs 4:7ddd287a5d28 78 pad.init(); // initialise Gamepad
el18rs 2:55092965eadd 79
el18rs 4:7ddd287a5d28 80 // initialise the game with correct tetromino sizes etc
el18rs 8:cebb2aca8e19 81 tetris.init(4,4);
el18rs 2:55092965eadd 82
el18rs 2:55092965eadd 83 }
el18rs 2:55092965eadd 84
el18rs 4:7ddd287a5d28 85 void render() { // draws each frame on the lcd
el18rs 4:7ddd287a5d28 86
el18rs 4:7ddd287a5d28 87 lcd.clear(); // clear screen
el18rs 4:7ddd287a5d28 88 tetris.draw(lcd); // re-draw
el18rs 4:7ddd287a5d28 89 lcd.refresh(); // refresh screen
eencae 0:b7f1f47bb26a 90 }
eencae 0:b7f1f47bb26a 91
el18rs 4:7ddd287a5d28 92 // welcome screen display
el18rs 3:522c6f850e91 93 void welcome() {
el18rs 3:522c6f850e91 94
el18rs 7:80e1c83b9b6a 95 lcd.printString(" TETRIS ",0,1);
el18rs 7:80e1c83b9b6a 96 lcd.printString(" Press Start ",0,4);
el18rs 3:522c6f850e91 97 lcd.refresh();
el18rs 3:522c6f850e91 98
el18rs 4:7ddd287a5d28 99 // flash LEDs untile start button pressed
el18rs 3:522c6f850e91 100 while (pad.start_pressed() == false) {
el18rs 3:522c6f850e91 101 lcd.setContrast(pad.read_pot1());
el18rs 3:522c6f850e91 102 pad.leds_on();
el18rs 3:522c6f850e91 103 wait(0.1);
el18rs 3:522c6f850e91 104 pad.leds_off();
el18rs 3:522c6f850e91 105 wait(0.1);
el18rs 3:522c6f850e91 106 }
el18rs 4:7ddd287a5d28 107 }