ELEC2645 Joseph Allison 200860349
Dependencies: N5110 Tetris mbed
Diff: main.h
- Revision:
- 1:2b9ba34131ca
- Child:
- 2:61caca4dd3f0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Thu Apr 07 10:38:32 2016 +0000 @@ -0,0 +1,190 @@ +/** +@file main.h +@breif +@author Joseph Allison +@date 27/3/2016 +*/ + +#include "mbed.h" +#include "N5110.h" +#include "time.h" +#include "Tetris.h" + +#define E 3034 +#define GSharp 2408 +#define G 2551 +#define A 2273 +#define B 2025 +#define C 1911 +#define HD 1703 +#define HE 1517 +#define HF 1431 +#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); + +/** Creates Tertis instance*/ +Tetris tetris(); + +/** Creates Ticker instance*/ +Ticker ticker; + +/** Creates music ticker instace*/ +Ticker musicticker; + +/** Creates Timeout instances that are used to stop button double clicks */ +Timeout lefttimeout; +Timeout righttimeout; +Timeout spintimeout; +Timeout downtimeout; + + +/** +@namespace ain +@breif Analog input that is used for the seed for the randomiser +*/ +AnalogIn ain(A0); + +/** +@namespace buzzer +@brief Buzzer output to play tetris music +*/ +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; +float 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 +*/ +void clearGamePixel(int x, int y); + +/** +Clears the game area +*/ +void clearGame(); + +/** +Sets the information for the user on the left side of the screen +@param score +@param level +@param next +*/ +void gameInfo(int score,int level,int next); + +/** +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 +*/ +void piecePlace(int x,int y,int shape); //places a piece + +/** +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 +*/ +void pieceClear(int x,int y,int shape); //clears a spesific shape + +/** +Randomly generates new bag of 7 +*/ +void newShapeBag(); + + +void movePieceRight();//moves the piece right +void movePieceLeft();//moves the piece left +void spinPiece(); //spins the piece clockwise +void movePieceDown(); //movespiece + +/** +Returns turn if piece placement is valid ********** +*/ +bool movePossible(int xpos, int ypos, int orientation); //returns turn if piece placement is valid +void newpiece(); +void pieceToGameArray(); +void checkCompleteLine(); +void setGameArea(); //sets the game area from the game area array +void removeCompleteLines(int rowscomplete[4]); +void setTicker(float time); + + +/** +Fucntions called by the button interupts to set the flags ****** +*/ +void moveDownTicker(); +void left_isr(); +void right_isr(); +void spin_isr(); +void down_isr(); + +void music_isr(); + +void lefttimeout_isr(); +void righttimeout_isr(); +void spintimeout_isr(); +void downtimeout_isr(); + +//interupt and ticker flags +volatile int g_timer_flag = 0; +volatile int g_left = 0; +volatile int g_right = 0; +volatile int g_spin = 0; +volatile int g_down = 0; + +volatile int g_music = 0; + +volatile int g_lefttimeout = 1; +volatile int g_righttimeout = 1; +volatile int g_spintimeout = 1; +volatile int g_downtimeout = 1; + +//misc game flags +volatile int g_newpiece = 1; +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