ELEC2645 Joseph Allison 200860349

Dependencies:   N5110 Tetris mbed

Revision:
3:8c5362716f4c
Parent:
2:61caca4dd3f0
Child:
4:7160c74529f7
--- a/main.h	Thu Apr 07 15:42:46 2016 +0000
+++ b/main.h	Tue Apr 12 12:48:26 2016 +0000
@@ -5,9 +5,14 @@
 @date 27/3/2016
 */
 
+#ifndef MAIN_H
+#define MAIN_H
+
 #include "mbed.h"
+
+#include "time.h"
 #include "N5110.h"
-#include "time.h"
+
 #include "Tetris.h"
 
 #define E  3034
@@ -22,11 +27,15 @@
 #define HG 1276
 #define HA 1136
 
+
+
+
+
+
 //         VCC,    SCE,   RST,   D/C,   MOSI,  SCLK,   LED
 N5110 lcd (PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3);
 Serial pc(USBTX,USBRX);
 
-//Tetris a (A1);
 
 /** Creates Tertis instance*/
 Tetris tetris;
@@ -37,10 +46,13 @@
 /** Creates music ticker instace*/
 Ticker musicticker;
 
-/** Creates Timeout instances that are used to stop button double clicks */
+/** Creates Timeout instances that is used to stop the left button double clicks */
 Timeout lefttimeout;
+/** Creates Timeout instances that is used to stop the right button double clicks */
 Timeout righttimeout;
+/** Creates Timeout instances that is used to stop the spin button double clicks */
 Timeout spintimeout;
+/** Creates Timeout instances that is used to stop the down button double clicks */
 Timeout downtimeout;
 
 
@@ -56,138 +68,279 @@
 */
 PwmOut buzzer(PTA1);
 
-InterruptIn left(PTC0);
-InterruptIn right(PTC9);
-InterruptIn spin(PTC5);
-InterruptIn down(PTC7);
-
-//****
-int musiccounter = 0;
-
-int score = 0; /*!< */
-int completedlines = 0;
-int level = 1;
-double gamespeed = 0.8; //how often a block moves down
-
-//****
-int pieceposition[2] = {4,0}; //set position of the current dropping piece ***
-int orientation = 0;
-int currentshape = 3;
-int nextpiece;
-int shapebagcounter = 0;
-
-int nextshape[7];//stores the next 7 shapes to be used - 7 bag system
-
-/**
-Performs instuctions necessary to start the game
-*/
-void gameSetup(); 
-
-/**
-Sets a 3x3  sets a pixel cell in the game area at position (x,y)
-@param x - cells horizontal position
-@param y - cells vertical position
-*/
-void gamePixel(int x,int y); 
 
 /**
-Sets a 3x3  clears a pixel cell in the game area at position (x,y)
-@param x - cells horizontal position
-@param y - cells vertical position
+@namespace left
+@brief The interrupt input of the left button
+*/
+InterruptIn left(PTC0);
+/**
+@namespace right
+@brief The interrupt input of the right button
 */
-void clearGamePixel(int x, int y); 
-
+InterruptIn right(PTC9);
 /**
-Clears the game area
+@namespace spin
+@brief The interrupt input of the spin button
 */
-void clearGame(); 
+InterruptIn spin(PTC5);
+/**
+@namespace down
+@brief The interrupt input of the down button
+*/
+InterruptIn down(PTC7);
 
 /**
-Sets the information for the user on the left side of the screen 
-@param score
-@param level
-@param next
+Creates the game menu and wait for user input
 */
-void gameInfo(int score,int level,int next);
-
+void gameMenu();
+/**
+Checks if any of the flags are one
+*/
+void checkGameFlags();
 /**
-Places a game piece on the screen
-@param x - cells horizontal position
-@param y - cells vertical position
-@param shape - the shape that is being placed
+Displays the help screen text and waits for user input
 */
-void piecePlace(int x,int y,int shape); //places a piece
-
+void helpScreen();
 /**
-Clears a game piece on the screen
-@param x - cells horizontal position
-@param y - cells vertical position
-@param shape - the shape that is being cleared
+Sets the gamearea array to its initial state
 */
-void pieceClear(int x,int y,int shape); //clears a spesific shape
-
+void setGameAreaArray();
 /**
 Randomly generates new bag of 7
 */
 void newShapeBag();
-
+/**
+Moves the piece in the game area
+@param x - How far the piece is moved horizontally
+@param y - How far the piece is moved vertically
+@param spin - How far the piece is spun round
+*/
 void movePiece(int x, int y,int spin);
-void movePieceRight();//moves the piece right
-void movePieceLeft();//moves the piece left
-void spinPiece(); //spins the piece clockwise
-void movePieceDown(); //movespiece
+/**
+Moves the piece right
+*/
+void movePieceRight();
+/**
+Moves the piece left
+*/
+void movePieceLeft();
+/**
+Spins the piece clockwise
+*/
+void spinPiece();
+/**
+Moves the piece downwards
+*/
+void movePieceDown(); 
+
+/**
+Returns turn if piece placement is valid
+@param xpos - The horizontal position of where to piece is moving to
+@param ypos - The vertical position of where to piece is moving to
+@param orientation - The orientation the piece will be in when it moves
+*/
+bool movePossible(int xpos, int ypos, int orientation); //returns turn if piece placement is valid
+
+/**
+Places the next piece in the game area
+*/
+void newpiece();
 
 /**
-Returns turn if piece placement is valid **********
+Adds the placed piece to the game area array
 */
-bool movePossible(int xpos, int ypos, int orientation); //returns turn if piece placement is valid
-void newpiece();
 void pieceToGameArray();
+/**
+Checks each row of the game area to see if there are any rows complete
+*/
 void checkCompleteLine();
-void setGameArea(); //sets the game area from the game area array
+/**
+Removes any completed rows
+@param rowscomplete[4] - An array with of upto 4 row numbers
+*/
 void removeCompleteLines(int rowscomplete[4]);
+/**
+Sets the game area from the game area array
+*/
+void setGameArea(); 
+/**
+Resets the Ticker to chance the speed at which a piece falls
+*/
 void setTicker(float time);
+/**
+Fucntions called by the ticker to set g_timer_flag = 1
+*/
+void moveDownTicker();
+/**
+Fucntions called by the ticker to set g_left = 1
+*/
+void left_isr();
+/**
+Fucntions called by the ticker to set g_right = 1
+*/
+void right_isr();
+/**
+Fucntions called by the ticker to set g_spin = 1
+*/
+void spin_isr();
+/**
+Fucntions called by the ticker to set g_down = 1
+*/
+void down_isr();
+/**
+Fucntions called by the ticker to set g_music = 1
+*/
+void music_isr();
+
+
+/**
+Fucntions called by the timeout to set g_lefttimeout  = 1
+*/
+void lefttimeout_isr();
+/**
+Fucntions called by the timeout to set g_righttimeout  = 1
+*/
+void righttimeout_isr();
+/**
+Fucntions called by the timeout to set g_spintimeout  = 1
+*/
+void spintimeout_isr();
+/**
+Fucntions called by the timeout to set g_downtimeout  = 1
+*/
+void downtimeout_isr();
 
 
 /**
-Fucntions called by the button interupts to set the flags ******
+True if the game is running
+*/
+bool gameplaying = true;
+/**
+True if the game menu is being displayed
+*/
+bool gamemenu = true;
+
+/**
+True if the game music is playing
+*/
+bool musicplaying = true;
+/**
+Counts through the notes in the array
 */
-void moveDownTicker();
-void left_isr();
-void right_isr();
-void spin_isr();
-void down_isr();
-
-void music_isr();
+int musiccounter = 0;  
+/**
+Stores the next 7 shapes to be used - 7 bag system 
+*/
+int nextshape[7];
+/**
+Stores the players current score
+*/
+int score = 0; 
+/**
+The current level the user is on
+*/
+int level = 1;
+/**
+The number of lines the user has completed
+*/
+int completedlines = 0;
+/**
+The time between each downward movement of the piece
+*/
+double gamespeed = 0.8; //how often a block moves down
 
-void lefttimeout_isr();
-void righttimeout_isr();
-void spintimeout_isr();
-void downtimeout_isr();
+/**
+Stores the postion of the piece (x,y)
+*/
+int pieceposition[2] = {4,0}; //set position of the current dropping piece ***
+/**
+The orientation of the piece
+*/
+int orientation = 0;
+/**
+The current piece on the screen
+*/
+int currentshape = 3;
+/**
+The next piece to be played on the screen
+*/
+int nextpiece;
+/**
+Counts through the shape in the 7 system bag of shapes
+*/
+int shapebagcounter = 0;
 
-//interupt and ticker flags
+/**
+Stores all the shapes I,J,L,O,T,S,Z all stored as Hex values
+*/
+int shapes[7][4] = {{0x00F0,0x4444,0x0F00,0x2222},{0x0071,0x0226,0x0470,0x0322},{0x0074,0x0622,0x0170,0x0223},{0x0033,0x0033,0x0033,0x0033},{0x0072,0x0262,0x0270,0x0232},{0x0036,0x0462,0x0360,0x0231},{0x0063,0x0264,0x0630,0x0132}};
+/**
+Stores the current state of the game area. Used for checking collison
+*/
+int gamearea[12][16]; 
+
+/**
+Stores the notes used to play the music
+*/
+int musisnotes[64] = {E,E,E,GSharp,B,B,G,E,A,A,A,C,HE,HE,HD,C,B,B,B,C,HD,HD,HE,HE,C,C,A,A,A,A,A,A,
+                        HF,HF,HF,HG,HA,HA,HG,HF,HE,HE,HE,HF,HE,HE,HD,C,B,B,B,C,HD,HD,HE,HE,C,C,A,A,A,A,A,A};
+
+
+/**
+Flag for the ticker
+*/
 volatile int g_timer_flag = 0;
+/**
+Flag for the left inperrupt
+*/
 volatile int g_left = 0;
+/**
+Flag for the right inperrupt
+*/
 volatile int g_right = 0;
+/**
+Flag for the spin inperrupt
+*/
 volatile int g_spin = 0;
+/**
+Flag for the down inperrupt
+*/
 volatile int g_down = 0;
 
+/**Flag for the music ticker
+*/
 volatile int g_music = 0;
 
+/**
+Flag used to stop the left interrupt being called twice unintentionally
+*/
 volatile int g_lefttimeout = 1;
+/**
+Flag used to stop the right interrupt being called twice unintentionally
+*/
 volatile int g_righttimeout = 1;
+/**
+Flag used to stop the spin interrupt being called twice unintentionally
+*/
 volatile int g_spintimeout = 1;
+/**
+Flag used to stop the drop interrupt being called twice unintentionally
+*/
 volatile int g_downtimeout = 1;
 
-//misc game flags
+/**
+Flag used when a new peice needs placing at the top of the screen
+*/
 volatile int g_newpiece = 1;
+/**
+Flag used when a piece is being hard dropped
+*/
 volatile int harddropping = 0;
 
 
 
-//shapes I,J,L,O,T,S,Z all stored as Hex values
-int shapes[7][4] = {{0x00F0,0x4444,0x0F00,0x2222},{0x0071,0x0226,0x0470,0x0322},{0x0074,0x0622,0x0170,0x0223},{0x0033,0x0033,0x0033,0x0033},{0x0072,0x0262,0x0270,0x0232},{0x0036,0x0462,0x0360,0x0231},{0x0063,0x0264,0x0630,0x0132}};
-int gamearea[12][16]; //stores the current states of the game area and is used to check for collisions ***add sides
+
 
-int musisnotes[64] = {E,E,E,GSharp,B,B,G,E,A,A,A,C,HE,HE,HD,C,B,B,B,C,HD,HD,HE,HE,C,C,A,A,A,A,A,A,
-                        HF,HF,HF,HG,HA,HA,HG,HF,HE,HE,HE,HF,HE,HE,HD,C,B,B,B,C,HD,HD,HE,HE,C,C,A,A,A,A,A,A};
\ No newline at end of file
+                        
+#endif                        
\ No newline at end of file