ELEC2645 (2015/16) / Mbed 2 deprecated Game

Dependencies:   N5110 mbed

Fork of Game_StarCraft_III by Chenyu Li

Committer:
el15cl
Date:
Wed May 04 19:22:58 2016 +0000
Revision:
1:97ef4864d6fb
Game: Starcraft III(Chenyu Li SID: 200985958)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el15cl 1:97ef4864d6fb 1 /**
el15cl 1:97ef4864d6fb 2 @file main.h
el15cl 1:97ef4864d6fb 3 @brief Header file containing functions prototypes, defines and and global variables.
el15cl 1:97ef4864d6fb 4 @brief Shows examples of creating Doxygen documentation.
el15cl 1:97ef4864d6fb 5 @brief Revision 1.0.
el15cl 1:97ef4864d6fb 6 @author Chenyu Li(John Lee) SID: 200985958.
el15cl 1:97ef4864d6fb 7 @data May 2016
el15cl 1:97ef4864d6fb 8 */
el15cl 1:97ef4864d6fb 9
el15cl 1:97ef4864d6fb 10 #ifndef MAIN_H
el15cl 1:97ef4864d6fb 11 #define MAIN_H
el15cl 1:97ef4864d6fb 12
el15cl 1:97ef4864d6fb 13 #include "mbed.h"
el15cl 1:97ef4864d6fb 14
el15cl 1:97ef4864d6fb 15 #include "N5110.h" ///head file for N5110 in order to use the code set in N5110.
el15cl 1:97ef4864d6fb 16 #include <stdio.h> ///head file for random number.
el15cl 1:97ef4864d6fb 17 #include <stdlib.h> ///head file for random number.
el15cl 1:97ef4864d6fb 18 #define DIRECTION_TOLERANCE 0.05 /// change this to alter tolerance of joystick direction
el15cl 1:97ef4864d6fb 19
el15cl 1:97ef4864d6fb 20
el15cl 1:97ef4864d6fb 21 ///VCC,SCE,RST,D/C,MOSI,SCLK,LED
el15cl 1:97ef4864d6fb 22 N5110 lcd(PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3);
el15cl 1:97ef4864d6fb 23 /// Can also power (VCC) directly from VOUT (3.3 V) -
el15cl 1:97ef4864d6fb 24 /// Can give better performance due to current limitation from GPIO pin
el15cl 1:97ef4864d6fb 25 PwmOut buzzer(PTA2); ///set PwmOut out as the buzzer
el15cl 1:97ef4864d6fb 26 InterruptIn button(PTB18);/// set button as an interrupt in
el15cl 1:97ef4864d6fb 27 DigitalIn buttonjoystick(PTB11);/// connections for joystick
el15cl 1:97ef4864d6fb 28 AnalogIn xPot(PTB3);/// connections for joystick
el15cl 1:97ef4864d6fb 29 AnalogIn yPot(PTB2);/// connections for joystick
el15cl 1:97ef4864d6fb 30 Ticker pollJoystick;/// timer to regularly read the joystick
el15cl 1:97ef4864d6fb 31 Ticker bullet;/// set 'bullet' as a ticker (not used currently)
el15cl 1:97ef4864d6fb 32 Ticker enermy;/// set 'enermy' as a ticker (not used currently)
el15cl 1:97ef4864d6fb 33
el15cl 1:97ef4864d6fb 34 Serial serial(USBTX,USBRX);/// Serial for debug
el15cl 1:97ef4864d6fb 35
el15cl 1:97ef4864d6fb 36 /// create enumerated type (0,1,2,3 etc. for direction)
el15cl 1:97ef4864d6fb 37 /// could be extended for diagonals etc.
el15cl 1:97ef4864d6fb 38 enum DirectionName {
el15cl 1:97ef4864d6fb 39 UP,
el15cl 1:97ef4864d6fb 40 DOWN,
el15cl 1:97ef4864d6fb 41 LEFT,
el15cl 1:97ef4864d6fb 42 RIGHT,
el15cl 1:97ef4864d6fb 43 CENTRE,
el15cl 1:97ef4864d6fb 44 UNKNOWN
el15cl 1:97ef4864d6fb 45 };
el15cl 1:97ef4864d6fb 46
el15cl 1:97ef4864d6fb 47 typedef struct JoyStick Joystick;/// struct for Joystick
el15cl 1:97ef4864d6fb 48 struct JoyStick {
el15cl 1:97ef4864d6fb 49 float x; /// current x value
el15cl 1:97ef4864d6fb 50 float x0; /// 'centred' x value
el15cl 1:97ef4864d6fb 51 float y; /// current y value
el15cl 1:97ef4864d6fb 52 float y0; /// 'centred' y value
el15cl 1:97ef4864d6fb 53 int buttonjoystick; /// button state (assume pull-down used, so 1 = pressed, 0 = unpressed)
el15cl 1:97ef4864d6fb 54 DirectionName direction; /// current direction
el15cl 1:97ef4864d6fb 55 };
el15cl 1:97ef4864d6fb 56
el15cl 1:97ef4864d6fb 57 Joystick joystick;/// create struct variable
el15cl 1:97ef4864d6fb 58 int printFlag = 0;/// create struct variable
el15cl 1:97ef4864d6fb 59
el15cl 1:97ef4864d6fb 60 int enermyFlag = 0;
el15cl 1:97ef4864d6fb 61 int bulletFlag = 0;
el15cl 1:97ef4864d6fb 62
el15cl 1:97ef4864d6fb 63 // function prototypes
el15cl 1:97ef4864d6fb 64 void calibrateJoystick();
el15cl 1:97ef4864d6fb 65 void updateJoystick();
el15cl 1:97ef4864d6fb 66 void createbullet();
el15cl 1:97ef4864d6fb 67 void createenermy();
el15cl 1:97ef4864d6fb 68 void button_isr();
el15cl 1:97ef4864d6fb 69
el15cl 1:97ef4864d6fb 70 int status =1;
el15cl 1:97ef4864d6fb 71
el15cl 1:97ef4864d6fb 72 volatile int g_button_flag = 0;/// set the original value of "g_button_flag" equals to 0.
el15cl 1:97ef4864d6fb 73
el15cl 1:97ef4864d6fb 74 ///set "wall", "hit", "bullethit" as a boolean value.
el15cl 1:97ef4864d6fb 75 bool wall = false;
el15cl 1:97ef4864d6fb 76 bool hit = false;
el15cl 1:97ef4864d6fb 77 bool bullethit = false;
el15cl 1:97ef4864d6fb 78
el15cl 1:97ef4864d6fb 79 #endif