Game doesn't work properly, but it's a 'form' of Tetris.

Dependencies:   N5110 mbed

Committer:
el14kb
Date:
Sat May 07 14:36:03 2016 +0000
Revision:
2:dc75e15229ee
Game doesn't work entirely, but it's a 'form' of Tetris.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el14kb 2:dc75e15229ee 1 /**
el14kb 2:dc75e15229ee 2
el14kb 2:dc75e15229ee 3 @file main.h
el14kb 2:dc75e15229ee 4
el14kb 2:dc75e15229ee 5 @Header file to denote the various functions, global variables, and definitions.
el14kb 2:dc75e15229ee 6
el14kb 2:dc75e15229ee 7
el14kb 2:dc75e15229ee 8 @Author: Kristian Bridges
el14kb 2:dc75e15229ee 9 @SID:200859491
el14kb 2:dc75e15229ee 10
el14kb 2:dc75e15229ee 11 @brief: University of Leeds Elec2645 (Embedded systems project)
el14kb 2:dc75e15229ee 12
el14kb 2:dc75e15229ee 13 @Date: May 2016
el14kb 2:dc75e15229ee 14
el14kb 2:dc75e15229ee 15 */
el14kb 2:dc75e15229ee 16
el14kb 2:dc75e15229ee 17 #ifndef MAIN_H
el14kb 2:dc75e15229ee 18
el14kb 2:dc75e15229ee 19 #define MAIN_H
el14kb 2:dc75e15229ee 20
el14kb 2:dc75e15229ee 21 #include "mbed.h"
el14kb 2:dc75e15229ee 22
el14kb 2:dc75e15229ee 23 #include "Pieces.h"
el14kb 2:dc75e15229ee 24
el14kb 2:dc75e15229ee 25 #include "N5110.h"
el14kb 2:dc75e15229ee 26
el14kb 2:dc75e15229ee 27 // --------------- Peripherals - Input --------------
el14kb 2:dc75e15229ee 28
el14kb 2:dc75e15229ee 29 /**
el14kb 2:dc75e15229ee 30
el14kb 2:dc75e15229ee 31 @namespace joystick
el14kb 2:dc75e15229ee 32
el14kb 2:dc75e15229ee 33 @brief joystick that allows me to move in the x and y direction. Two potentiometers allow this functionality, as well as a button, which allows additional
el14kb 2:dc75e15229ee 34 functionality.
el14kb 2:dc75e15229ee 35
el14kb 2:dc75e15229ee 36 */
el14kb 2:dc75e15229ee 37
el14kb 2:dc75e15229ee 38 AnalogIn potX(PTB2);
el14kb 2:dc75e15229ee 39 AnalogIn potY(PTB3);
el14kb 2:dc75e15229ee 40 DigitalIn joyButton(PTB11);
el14kb 2:dc75e15229ee 41
el14kb 2:dc75e15229ee 42 /**
el14kb 2:dc75e15229ee 43
el14kb 2:dc75e15229ee 44 @namespace Button A
el14kb 2:dc75e15229ee 45
el14kb 2:dc75e15229ee 46 @brief DigitalIn button that calls an interrupt to rotate the tetris piece anticlockwise.
el14kb 2:dc75e15229ee 47
el14kb 2:dc75e15229ee 48 */
el14kb 2:dc75e15229ee 49
el14kb 2:dc75e15229ee 50 DigitalIn buttonA(PTB18);
el14kb 2:dc75e15229ee 51
el14kb 2:dc75e15229ee 52 /**
el14kb 2:dc75e15229ee 53
el14kb 2:dc75e15229ee 54 @namespace Button B
el14kb 2:dc75e15229ee 55
el14kb 2:dc75e15229ee 56 @brief DigitalIn button that calls an interrupt to rotate the tetris piece clockwise.
el14kb 2:dc75e15229ee 57
el14kb 2:dc75e15229ee 58 */
el14kb 2:dc75e15229ee 59
el14kb 2:dc75e15229ee 60 DigitalIn buttonB(PTB19);
el14kb 2:dc75e15229ee 61
el14kb 2:dc75e15229ee 62 // -------------- Peripherals - Output --------------
el14kb 2:dc75e15229ee 63
el14kb 2:dc75e15229ee 64 /**
el14kb 2:dc75e15229ee 65
el14kb 2:dc75e15229ee 66 @namespace Nokia 5110 LCD
el14kb 2:dc75e15229ee 67
el14kb 2:dc75e15229ee 68 @brief 84*48 black and white pixel display.
el14kb 2:dc75e15229ee 69 @brief VCC, GND, SCE, RST, D/C, MOSI, SCLK, LED
el14kb 2:dc75e15229ee 70
el14kb 2:dc75e15229ee 71 */
el14kb 2:dc75e15229ee 72
el14kb 2:dc75e15229ee 73 N5110 lcd (PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3);
el14kb 2:dc75e15229ee 74
el14kb 2:dc75e15229ee 75 // -------------- Variables --------------
el14kb 2:dc75e15229ee 76
el14kb 2:dc75e15229ee 77 int g_bank_index = 0; /*!<Index for the menu */
el14kb 2:dc75e15229ee 78 int g_bank_index_copy = 4; /*!<Backup index to ensure the menu doesn't continuously refresh the pixels on the screen */
el14kb 2:dc75e15229ee 79 volatile int g_joyFlag = 0; /*!<Interrupt for the joystick */
el14kb 2:dc75e15229ee 80 volatile int g_rotate_clock_flag = 0; /*!<Interrupt for the B button */
el14kb 2:dc75e15229ee 81 volatile int g_rotate_anticlock_flag = 0; /*!<Interrupt for the A button */
el14kb 2:dc75e15229ee 82 int currentState[45][40]; /*!<Array to store the current playfield state */
el14kb 2:dc75e15229ee 83 volatile int g_call_game_Flag = 0; /*!<Interrupt to call the game functions */
el14kb 2:dc75e15229ee 84 float timer = 1.0; /*!<Value for the game ticker */
el14kb 2:dc75e15229ee 85 int xP; /*!<Current x position */
el14kb 2:dc75e15229ee 86 int yP; /*!<Current y position */
el14kb 2:dc75e15229ee 87 int next_xP; /*!<Next x position */
el14kb 2:dc75e15229ee 88 int next_yP; /*!<Next y position */
el14kb 2:dc75e15229ee 89 int level; /*!<Stores the level */
el14kb 2:dc75e15229ee 90 int line_check; /*!<Checks whether 10 lines have been cleared */
el14kb 2:dc75e15229ee 91 int total_lines; /*!<Total lines cleared */
el14kb 2:dc75e15229ee 92 int current_shape; /*!<Current shape in play */
el14kb 2:dc75e15229ee 93 int piece_in_play; /*!<States whether there's a piece in play */
el14kb 2:dc75e15229ee 94 int orientation; /*!<Stores the orientation of the piece */
el14kb 2:dc75e15229ee 95 int score; /*!<Stores the score */
el14kb 2:dc75e15229ee 96 int game_over; /*!<States whether the game is over */
el14kb 2:dc75e15229ee 97 int orientation_copy; /*!<Keeps track of whether a rotation has occured */
el14kb 2:dc75e15229ee 98 int currentPiece[10][10]; /*!<Current piece in play */
el14kb 2:dc75e15229ee 99 float initial_x,initial_y; /*!<Initial x and y position of the joystick */
el14kb 2:dc75e15229ee 100 float current_x,current_y; /*!<Current x and y position of the joystick */
el14kb 2:dc75e15229ee 101 int button; /*!<State of the joystick button */
el14kb 2:dc75e15229ee 102 int buttonA; /*!<State of the anticlockwise button */
el14kb 2:dc75e15229ee 103 int buttonB; /*!<State of the clockwise button */
el14kb 2:dc75e15229ee 104
el14kb 2:dc75e15229ee 105 // -------------- Functions --------------
el14kb 2:dc75e15229ee 106
el14kb 2:dc75e15229ee 107 /**
el14kb 2:dc75e15229ee 108
el14kb 2:dc75e15229ee 109 @namespace Menu
el14kb 2:dc75e15229ee 110
el14kb 2:dc75e15229ee 111 @brief Renders the menu based on the direction of the joystick.
el14kb 2:dc75e15229ee 112 @brief An index keeps track of which menu item is currently selected.
el14kb 2:dc75e15229ee 113 @brief Index also allows the appropriate function to be called.
el14kb 2:dc75e15229ee 114
el14kb 2:dc75e15229ee 115 */
el14kb 2:dc75e15229ee 116 void menu();
el14kb 2:dc75e15229ee 117
el14kb 2:dc75e15229ee 118 /**
el14kb 2:dc75e15229ee 119
el14kb 2:dc75e15229ee 120 @namespace cal
el14kb 2:dc75e15229ee 121
el14kb 2:dc75e15229ee 122 @brief Calibrates the joystick, as well as the other input peripherals.
el14kb 2:dc75e15229ee 123
el14kb 2:dc75e15229ee 124 */
el14kb 2:dc75e15229ee 125 void cal();
el14kb 2:dc75e15229ee 126
el14kb 2:dc75e15229ee 127 /**
el14kb 2:dc75e15229ee 128
el14kb 2:dc75e15229ee 129 @namespace joyUpdate
el14kb 2:dc75e15229ee 130
el14kb 2:dc75e15229ee 131 @brief Updates the direction of the joystick based on tolerances.
el14kb 2:dc75e15229ee 132
el14kb 2:dc75e15229ee 133 */
el14kb 2:dc75e15229ee 134 void joyUpdate();
el14kb 2:dc75e15229ee 135
el14kb 2:dc75e15229ee 136 /**
el14kb 2:dc75e15229ee 137
el14kb 2:dc75e15229ee 138 @namespace game
el14kb 2:dc75e15229ee 139
el14kb 2:dc75e15229ee 140 @brief Carries out the necessary functions to render and update the game of tetris, although, the actual game doesn't work correctly.
el14kb 2:dc75e15229ee 141
el14kb 2:dc75e15229ee 142 */
el14kb 2:dc75e15229ee 143 void game();
el14kb 2:dc75e15229ee 144
el14kb 2:dc75e15229ee 145 /**
el14kb 2:dc75e15229ee 146
el14kb 2:dc75e15229ee 147 @namespace options
el14kb 2:dc75e15229ee 148
el14kb 2:dc75e15229ee 149 @brief Allows the user to change the led brightness. More functions can be implemented if needed, such as options to change the parameter
el14kb 2:dc75e15229ee 150 @brief of the game.e
el14kb 2:dc75e15229ee 151
el14kb 2:dc75e15229ee 152 */
el14kb 2:dc75e15229ee 153 void options();
el14kb 2:dc75e15229ee 154
el14kb 2:dc75e15229ee 155 /**
el14kb 2:dc75e15229ee 156
el14kb 2:dc75e15229ee 157 @namespace orientation
el14kb 2:dc75e15229ee 158
el14kb 2:dc75e15229ee 159 @brief Changes the orientation of the piece in play if either of the rotation interrupts are called.
el14kb 2:dc75e15229ee 160
el14kb 2:dc75e15229ee 161 */
el14kb 2:dc75e15229ee 162 void orientation();
el14kb 2:dc75e15229ee 163
el14kb 2:dc75e15229ee 164 /**
el14kb 2:dc75e15229ee 165
el14kb 2:dc75e15229ee 166 @namspace draw_piece
el14kb 2:dc75e15229ee 167
el14kb 2:dc75e15229ee 168 @brief Checks the current piece array with the currentState array for any collisions at the next x,y-position. If a collision has been detected,
el14kb 2:dc75e15229ee 169 @brief the piece will be saved to the currentState array, and the next piece will be spawned.
el14kb 2:dc75e15229ee 170
el14kb 2:dc75e15229ee 171 @brief If a collision hasn't been detected, then the piece will be rendered onto the playfield.
el14kb 2:dc75e15229ee 172
el14kb 2:dc75e15229ee 173 */
el14kb 2:dc75e15229ee 174 void draw_piece();
el14kb 2:dc75e15229ee 175
el14kb 2:dc75e15229ee 176 /**
el14kb 2:dc75e15229ee 177
el14kb 2:dc75e15229ee 178 @namespace array_checker
el14kb 2:dc75e15229ee 179
el14kb 2:dc75e15229ee 180 @brief Checks the currentState array for any elements that are 'on' throughout the top row.
el14kb 2:dc75e15229ee 181 @brief If there are any elements 'on', then the game finishes and returns back to the main menu.
el14kb 2:dc75e15229ee 182 @brief Some features are missing, such as the complete line checker, but the overall feature didn't work; this can be improved upon for a fully working
el14kb 2:dc75e15229ee 183 @brief game of tetris.
el14kb 2:dc75e15229ee 184
el14kb 2:dc75e15229ee 185 */
el14kb 2:dc75e15229ee 186 void array_checker();
el14kb 2:dc75e15229ee 187
el14kb 2:dc75e15229ee 188 /**
el14kb 2:dc75e15229ee 189
el14kb 2:dc75e15229ee 190 @namespace piece_generator
el14kb 2:dc75e15229ee 191
el14kb 2:dc75e15229ee 192 @brief Generates the next tetris piece, as well as the initial piece orientation, and the initial x and y coordinates.
el14kb 2:dc75e15229ee 193 @brief Spawning of random shapes doesn't entirely work. Not sure whether it is the location of the seed, but further investigation into the issue is needed.
el14kb 2:dc75e15229ee 194
el14kb 2:dc75e15229ee 195 */
el14kb 2:dc75e15229ee 196 void piece_generator();
el14kb 2:dc75e15229ee 197
el14kb 2:dc75e15229ee 198 /**
el14kb 2:dc75e15229ee 199
el14kb 2:dc75e15229ee 200 @namespace anticlockwise
el14kb 2:dc75e15229ee 201
el14kb 2:dc75e15229ee 202 @brief An ISR that sets a global variable to 1, and calls the piece to be rotated anticlockwise.
el14kb 2:dc75e15229ee 203
el14kb 2:dc75e15229ee 204 */
el14kb 2:dc75e15229ee 205 void anticlockwise();
el14kb 2:dc75e15229ee 206
el14kb 2:dc75e15229ee 207 /**
el14kb 2:dc75e15229ee 208
el14kb 2:dc75e15229ee 209 @namespace clockwise
el14kb 2:dc75e15229ee 210
el14kb 2:dc75e15229ee 211 @brief An ISR that sets a global variable to 1, and calls the piece to be rotated clockwise.
el14kb 2:dc75e15229ee 212
el14kb 2:dc75e15229ee 213 */
el14kb 2:dc75e15229ee 214 void clockwise();
el14kb 2:dc75e15229ee 215
el14kb 2:dc75e15229ee 216 /**
el14kb 2:dc75e15229ee 217
el14kb 2:dc75e15229ee 218 @namespace gameCheck_isr
el14kb 2:dc75e15229ee 219
el14kb 2:dc75e15229ee 220 @brief An ISR that sets a global variable to 1, and calls several functions from within the game function.
el14kb 2:dc75e15229ee 221
el14kb 2:dc75e15229ee 222 */
el14kb 2:dc75e15229ee 223 void gameCheck_isr();
el14kb 2:dc75e15229ee 224
el14kb 2:dc75e15229ee 225
el14kb 2:dc75e15229ee 226
el14kb 2:dc75e15229ee 227 #endif