Snake and Physics based jumping game with high scores and different difficulties.

Dependencies:   N5110 SDFileSystem mbed

Revision:
0:23a749719479
Child:
1:c4928de1f922
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Sat Mar 12 17:41:11 2016 +0000
@@ -0,0 +1,229 @@
+/**
+@file main.h
+
+@brief Header file containing functions prototypes, defines and global variables.
+@brief Revision 1.0.
+@author Joel W. Webb
+@date   March 2016
+*/
+ 
+#ifndef MAIN_H
+#define MAIN_H
+ 
+#define PI 3.14159265359
+#define DIRECTION_TOLERANCE 0.05
+ 
+#include "mbed.h"
+#include "N5110.h"
+
+
+
+        // GPIO Objects
+/*
+@namespace lcd
+@brief N5110 object for interfacing with Nokia 5110 LCD
+@param VCC - PTE26
+@param SCE - PTA0
+@param RST - PTC4
+@param D/C - PTD0
+@param MOSI - PTD2
+@param SCLK - PTD1
+@param LED - PTC3 
+*/
+N5110 lcd(PTE26, PTA0, PTC4, PTD0, PTD2, PTD1, PTC3);
+
+/**  
+@namespace errorLED
+@brief GPIO output for error LED
+*/
+DigitalOut errorLED(LED1);
+
+/**
+@namespace buzzer
+@brief PWM output for buzzer
+*/
+PwmOut buzzer(PTC10);
+
+/**
+@namespace xpot
+@brief The joystick x axis potentiometer
+*/
+AnalogIn xPot(PTB11);
+
+/**
+@namespace ypot
+@brief The joystick y axis potentiometer
+*/
+AnalogIn yPot(PTB10);
+
+/**
+@namespace buttonjoy
+@brief Interrupt input for Joystick button
+*/
+InterruptIn buttonjoy(PTB9);
+
+/**
+@namespace buttonA
+@brief Interrupt input for Button A
+*/
+InterruptIn buttonA(PTA1);
+
+/**
+@namespace buttonB
+@brief Interrupt input for Button B
+*/
+InterruptIn buttonB(PTB23);
+
+
+
+        //Data Structures
+
+/// stringList struct for dealing with printing strings to LCD easier
+struct stringList {
+    char str[14];
+    int offset;
+};
+typedef stringList stringList;
+
+/// cell struct for dealing with coordinates
+struct cell {
+    int x;
+    int y;
+};
+typedef cell cell;
+
+
+
+        // Global variables
+        
+volatile int g_buttonA_flag; /*!< Button A flag set in ISR */
+volatile int g_buttonB_flag; /*!< Button B flag set in ISR */
+volatile int g_buttonjoy_flag; /*!< Joystick Button flag set in ISR */
+volatile int g_joystick_flag; /*!< Joystick x and y values have been polled in ISR */
+ volatile int g_gametick_flag; /*!< gametick flag is set in gametick_isr by Ticker gametick */
+ 
+volatile const float* noteArray; /*!< Float pointer to next note in array. Used in sound Timeout ISR */
+
+// Menu stringList arrays kept in FLASH
+const stringList menuList[] = {{"Games",20},{"Snake",0},{"Pong",0},{"replace",0},{"replace",0},{"replace",0}};
+const stringList snakeList[] = {{"Snake",20},{"Start",0},{"Difficulty",0},{"Back",0}};
+const stringList difficultyList[] = {{"Difficulty",10},{"Easy",0},{"Medium",0},{"Hard",0}};
+const stringList plinkList[] = {{"Plink",20},{"Start",0},{"Difficulty",0},{"Back",0}};
+
+ 
+ 
+        // Function Prototypes
+        
+    //ISR
+/**
+Interrupt service routine for button A
+@brief Sets g_buttonA_flag
+*/
+void buttonA_isr();
+/**
+Interrupt service routine for button B
+@brief Sets g_buttonB_flag
+*/
+void buttonB_isr();
+/**
+Interrupt service routine for buttonjoy
+@brief Set g_buttonjoy_flag
+*/
+void buttonjoy_isr();
+
+/**
+Interrupt service routine for playing the current note
+@brief Alters the current PWM signal to the current note frequency read from noteArray
+*/
+void sound_isr();
+
+/**
+Interrupt service routine for Ticker gametick
+@brief Used to control the update speed of games
+*/
+void gametick_isr();
+
+
+    // Snake functions
+/**
+Main Snake game function
+@brief The snake function is called from the main loop and contains everything needed to play the snake game
+@param difficulty - The difficulty is easy(0) medium(1) or hard(2) and it alters how fast the game ticker is applied
+*/
+void snake(int difficulty);
+/**
+drawCellArray function
+@brief A function for simplifying the drawing of pixels in an array of cell structs
+@param array[] - The array of cells the user wishes to plot
+@param length - Integer corresponding to how many array[] elements exist
+*/
+void drawCellArray(cell array[], int length);
+/**
+drawBoundary function
+@brief Used for plotting a 2 pixel thick boundary to the edges of the LCD display
+*/
+void drawBoundary();
+
+
+    // Pong functions
+    
+void pong(int difficulty);
+
+
+    // Menu functions
+/**
+Menu screen Controller
+@brief menu is a function that handles the selection of different menu selections
+@param menuList - The pointer to the array of strings handled in the menu (Must be 6 or less)
+@param line - The number of lines in the menu list (Must be 6 or less)
+@returns Selected menu element (0-4)
+*/
+int menu(const stringList* menuList,int lines);
+/**
+The drawString function
+@brief This function is used to simplify the menu function
+@param stringList - a const string array containing the strings needed to be written on each line
+@param lines - Integer representing how many strings should be written
+*/
+void drawStrings(const stringList* list,int lines);
+
+
+    // Sound and error functions
+/**
+Attaches Timeout to play sounds immediately
+@brief playSound is a function to provide ease fo use when calling sound arrays
+@param sound - The pointer to the noteArray
+*/
+void playSound(const float* sound);
+
+/**
+Error function
+@brief Hangs while flashing errorLED
+*/
+void error();
+
+
+    // Initialising and joystick
+/**
+Initializes Inputs
+@brief Used to group code that will run only once at startup
+*/
+void initInputs();
+/**
+Initializes the joystick
+@brief Aquires xpot and ypot default values
+*/
+void calibrateJoystick();
+
+/**
+updateJoystick
+@brief Updates direction the joystick is pointing in on a Ticker event
+*/
+void updateJoystick();
+
+
+
+#include "sounds.h"
+ 
+#endif
+ 
\ No newline at end of file