ELEC2645 (2018/19) / Mbed 2 deprecated el17ebs

Dependencies:   mbed FATFileSystem

Files at this revision

API Documentation at this revision

Comitter:
ellisbhastroud
Date:
Wed Apr 17 10:27:09 2019 +0000
Parent:
4:035448357749
Child:
6:747335f697d6
Commit message:
Levels Added Not functioning

Changed in this revision

Ball/Ball.cpp Show annotated file Show diff for this revision Revisions of this file
Ball/Ball.h Show annotated file Show diff for this revision Revisions of this file
FXOS8700CQ/FXOS8700CQ.cpp Show diff for this revision Revisions of this file
FXOS8700CQ/FXOS8700CQ.h Show diff for this revision Revisions of this file
GolfEngine/GolfEngine.cpp Show annotated file Show diff for this revision Revisions of this file
GolfEngine/GolfEngine.h Show annotated file Show diff for this revision Revisions of this file
Menu/Menu.cpp Show annotated file Show diff for this revision Revisions of this file
Menu/Menu.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/Ball/Ball.cpp	Mon Apr 08 15:10:28 2019 +0000
+++ b/Ball/Ball.cpp	Wed Apr 17 10:27:09 2019 +0000
@@ -26,38 +26,33 @@
 
 }
 
-void Ball::draw_ball(N5110 &lcd)
+void Ball::drawBall(N5110 &lcd)
 {
-    lcd.drawRect(_x_pos,_y_pos,3,3,FILL_BLACK); //draws ball 
+    lcd.drawRect(_x_pos,_y_pos,2,2,FILL_BLACK); //draws ball 
 }
 
-void Ball::draw_aim(N5110 &lcd, Gamepad &pad)
+void Ball::printShotCount(N5110 &lcd) 
 {
-    read_joy(pad);
-    lcd.drawLine((_x_pos+1.0f),(_y_pos+1.0f),(_x_pos+1.0f)+(_joystick.x*16.0f),(_y_pos+1.0f)-(_joystick.y*16.0f),1); //draws ball 
+    char buffer[14];
+    sprintf(buffer,"Shot %i",_shot_count);
+    lcd.printString(buffer,40,0);      
 }
 
-void Ball::draw_course(N5110 &lcd) 
-{
-    lcd.drawRect(0,16,83,32,FILL_TRANSPARENT);    
+void Ball::drawPower(N5110 &lcd, Gamepad &pad)
+{     
+
+    _mag = pad.get_mag();
+    lcd.drawRect(0,0,36,6,FILL_TRANSPARENT);
+    lcd.drawRect(0,0,36*_mag,6,FILL_BLACK);
 }
 
-void Ball::draw_screen(N5110 &lcd, Gamepad &pad) {
-    
-    draw_course(lcd);
-    draw_ball(lcd);
-    draw_aim(lcd, pad);
-    print_shot_count(lcd); 
-}
 
-void Ball::move_ball(int frame_rate, N5110 &lcd)
+void Ball::move_ball(int frame_rate)
 {
-    check_bounce(lcd);
     _x_pos = _x_pos + _x_vel*10.0f/frame_rate; //frame_rate used to scale ball movement so that it is the same for any fps  
     _y_pos = _y_pos + _y_vel*10.0f/frame_rate;   
     _x_vel = _x_vel*(1.0f-(0.8f/frame_rate)); //ball slows down 10% each loop (scaled by time between frames)
     _y_vel = _y_vel*(1.0f-(0.8f/frame_rate));
-    check_bounce(lcd);
   
 }
 
@@ -68,13 +63,13 @@
 }
 
 void Ball::shoot_ball(Gamepad &pad)
-{
+{    
+    _joystick = pad.get_mapped_coord();
     
     if(pad.check_event(Gamepad::A_PRESSED) == true && abs(_x_vel) < 0.05f && abs(_y_vel) < 0.05f){ //if ball stationary and a pressed then shoot
-    _x_vel = 8.0f * _joystick.x; //scale x velocity by joystick direction and magnitude
-    _y_vel = 8.0f * -_joystick.y; //scale y velocity by joystick direction and magnitude
-    _shot_count ++; //increment shot count
-    
+        _x_vel = 8.0f * _joystick.x; //scale x velocity by joystick direction and magnitude
+        _y_vel = 8.0f * -_joystick.y; //scale y velocity by joystick direction and magnitude
+        _shot_count ++; //increment shot count
     }
 
 }
@@ -85,42 +80,12 @@
     return shot_count;
 }
 
-void Ball::print_shot_count(N5110 &lcd) 
-{
-    char buffer[14];
-    sprintf(buffer,"Shot Count = %i",_shot_count);
-    lcd.printString(buffer,0,0);      
-}
-
 void Ball::set_vel(float x_vel, float y_vel) 
 {
     _x_vel = x_vel;
     _y_vel = y_vel;
 }
 
-void Ball::check_bounce(N5110 &lcd) 
-{
-    
-    if(_x_pos - 1 < 0 ) { //
-        _x_pos = 1;
-        _x_vel = -_x_vel;
-    } 
-    else if(_y_pos + 3 > 48) {
-        _y_pos = 45;
-        _y_vel = -_y_vel;
-    }
-    else if(_x_pos + 3 > 83 ) { 
-        _x_pos = 80;
-        _x_vel = -_x_vel;
-    } 
-    else if(_y_pos - 1 < 16) {
-        _y_pos = 17;
-        _y_vel = -_y_vel;
-    }
-    
-    
-}
-
 void Ball::read_joy(Gamepad &pad)
 {
                                     
@@ -128,5 +93,33 @@
 
     
 }
+
+void Ball::check_wall_bounce() //check before and after move_ball called
+{
+    if(_x_pos - 1 < 9 && _y_pos >= 26 && _y_pos <= 40 && _x_vel < 0){ // left wall (x=9 ,26<=y<=40)
+        _x_pos = 10;
+        _x_vel = -0.95f*_x_vel; //5% velocity lost on impact and bounce
+    }     
+    if(_x_pos + 1 > 74 && _y_pos <= 40 && _y_pos >= 9 && _x_vel > 0){ //right wall x + 1
+        _x_pos = 72;
+        _x_vel = -0.95f*_x_vel;
+    }
+    if(_y_pos - 1 < 9 && _x_pos <= 74 && _x_pos >= 50 && _y_vel < 0){ //top wall y -1
+        _y_pos = 10;
+        _y_vel = -0.95f*_y_vel;
+    }
+    if(_y_pos + 1 > 40 && _x_pos >= 9 && _x_pos <= 74 && _y_vel > 0){ //bottom wall y  + 2
+        _y_pos = 39;
+        _y_vel = -0.95f*_y_vel;
+    }
+    if(_x_pos - 1 < 50 && _y_pos >= 9 && _y_pos <= 26 && _x_vel < 0){ // left wall x -1
+        _x_pos = 51;
+        _x_vel = -0.95f*_x_vel; //5% velocity lost on impact and bounce
+    }     
+    if(_y_pos - 1 < 26 && _x_pos <= 50 && _x_pos >= 9 && _y_vel < 0 ){ //top wall y -1
+        _y_pos = 27;
+        _y_vel = -0.95f*_y_vel;
+    }
+}
 //private methods
 
--- a/Ball/Ball.h	Mon Apr 08 15:10:28 2019 +0000
+++ b/Ball/Ball.h	Wed Apr 17 10:27:09 2019 +0000
@@ -5,14 +5,14 @@
 #include "N5110.h"
 #include "Gamepad.h"
 
-
 /** Ball Class
 * @brief Class for controlling the golf ball
 * @author Ellis Blackford Stroud
 * @date May, 2018
 */
 
-class Ball {
+class Ball 
+{
 
 public:
 
@@ -24,39 +24,38 @@
     
     void init(float x_pos, float y_pos);
     
-    void draw_ball(N5110 &lcd);
+    void drawBall(N5110 &lcd);
     
-    void draw_aim(N5110 &lcd, Gamepad &pad);
+    void printShotCount(N5110 &lcd);
     
-    void draw_course(N5110 &lcd);
-    
-    void draw_screen(N5110 &lcd, Gamepad &pad);
-    
-    void move_ball(int frame_rate, N5110 &lcd);
+    void drawPower(N5110 &lcd, Gamepad &pad);
+                    
+    void move_ball(int frame_rate);
     
     Vector2D get_ball_pos();
     
     void shoot_ball(Gamepad &pad);
     
     int get_shot_count();
-    
-    void print_shot_count(N5110 &lcd);
-    
+        
     void set_vel(float x_vel, float y_vel);
-    
-    void check_bounce(N5110 &lcd);
 
     void read_joy(Gamepad &pad);
     
+    void check_wall_bounce();
+    
+    
 private:
 
     
     Vector2D _joystick;
+    float _mag;
     float _x_pos; 
     float _y_pos;
     float _x_vel;
     float _y_vel;
     int _shot_count;
+    Direction _direction;
 };  
 
 #endif
\ No newline at end of file
--- a/FXOS8700CQ/FXOS8700CQ.cpp	Mon Apr 08 15:10:28 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,185 +0,0 @@
-/* FXOS8700CQ Library
-
-Sample code from ELEC2645 - demonstrates how to create a library
-for the K64F on-board accelerometer and magnetometer
-
-(c) Craig A. Evans, University of Leeds, Jan 2017
-
-*/ 
-
-#include "FXOS8700CQ.h"
-
-// constructor is called when the object is created - use it to set pins and frequency
-FXOS8700CQ::FXOS8700CQ(PinName sda, PinName scl)
-{
-    i2c = new I2C(sda,scl);        // create new I2C instance and initialise
-}
-
-// destructor is called when the object goes out of scope
-FXOS8700CQ::~FXOS8700CQ()
-{
-    delete i2c;        // free memory
-}
-
-// based on 13.4 in datasheet - 200 Hz hybrid mode (both acc and mag)
-void FXOS8700CQ::init()
-{
-    // i2c fast-mode - 10.1.1 data sheet
-    i2c->frequency(400000);       // I2C Fast Mode - 400kHz
-
-    // the device has an ID number so we check the value to ensure the correct
-    // drive is on the i2c bus
-    char data = read_byte_from_reg(FXOS8700CQ_WHO_AM_I);
-    if (data != FXOS8700CQ_WHO_AM_I_VAL) { // if correct ID not found, hang and flash error message
-        error("Incorrect ID!");
-    }
-
-    // write 0000 0000 = 0x00 to accelerometer control register 1 to place
-    // FXOS8700CQ into standby
-    // [7-1] = 0000 000
-    // [0]: active=0
-    data = 0x00;
-    send_byte_to_reg(data,FXOS8700CQ_CTRL_REG1);
-
-    // write 0001 1111 = 0x1F to magnetometer control register 1
-    // [7]: m_acal=0: auto calibration disabled
-    // [6]: m_rst=0: no one-shot magnetic reset
-    // [5]: m_ost=0: no one-shot magnetic measurement
-    // [4-2]: m_os=111=7: 8x oversampling (for 200Hz) to reduce magnetometer noise
-    // [1-0]: m_hms=11=3: select hybrid mode with accel and magnetometer active
-    data = 0x1F;
-    send_byte_to_reg(data,FXOS8700CQ_M_CTRL_REG1);
-
-    // write 0010 0000 = 0x20 to magnetometer control register 2
-    // [7]: reserved
-    // [6]: reserved
-    // [5]: hyb_autoinc_mode=1 to map the magnetometer registers to follow
-    // the accelerometer registers
-    // [4]: m_maxmin_dis=0 to retain default min/max latching even though not used
-    // [3]: m_maxmin_dis_ths=0
-    // [2]: m_maxmin_rst=0
-    // [1-0]: m_rst_cnt=00 to enable magnetic reset each cycle
-    data = 0x20;
-    send_byte_to_reg(data,FXOS8700CQ_M_CTRL_REG2);
-
-    // write 0000 0001= 0x01 to XYZ_DATA_CFG register
-    // [7]: reserved
-    // [6]: reserved
-    // [5]: reserved
-    // [4]: hpf_out=0
-    // [3]: reserved
-    // [2]: reserved
-    // [1-0]: fs=01 for accelerometer range of +/-4g range with 0.488mg/LSB
-    data = 0x01;
-    send_byte_to_reg(data,FXOS8700CQ_XYZ_DATA_CFG);
-
-    // write 0000 1101 = 0x0D to accelerometer control register 1
-    // [7-6]: aslp_rate=00
-    // [5-3]: dr=001 for 200Hz data rate (when in hybrid mode)
-    // [2]: lnoise=1 for low noise mode
-    // [1]: f_read=0 for normal 16 bit reads
-    // [0]: active=1 to take the part out of standby and enable sampling
-    data = 0x0D;
-    send_byte_to_reg(data,FXOS8700CQ_CTRL_REG1);
-
-}
-
-Data FXOS8700CQ::get_values()
-{
-    // 13 bytes - status plus 6 channels (2 bytes each)
-    // x,y,z for accelerometer and magnetometer
-    char data[FXOS8700CQ_READ_LEN];
-    read_bytes_from_reg(FXOS8700CQ_STATUS,FXOS8700CQ_READ_LEN,data);
-
-    // copy the 14 bit accelerometer byte data into 16 bit words
-    int acc_x = (int16_t)(((data[1] << 8) | data[2]))>> 2;
-    int acc_y = (int16_t)(((data[3] << 8) | data[4]))>> 2;
-    int acc_z = (int16_t)(((data[5] << 8) | data[6]))>> 2;
-
-    // copy the magnetometer byte data into 16 bit words
-    int mag_x = (int16_t) (data[7] << 8) | data[8];
-    int mag_y = (int16_t) (data[9] << 8) | data[10];
-    int mag_z = (int16_t) (data[11] << 8) | data[12];
-
-    Data values;  // struct to hold values
-
-    // 0.488 mg/LSB in 4 g mode (8.1 data sheet)
-    values.ax = 0.488e-3*acc_x;
-    values.ay = 0.488e-3*acc_y;
-    values.az = 0.488e-3*acc_z;
-
-    // the magnetometer sensitivity is fixed at 0.1 μT/LSB
-    values.mx = 0.1e-6*mag_x;
-    values.my = 0.1e-6*mag_y;
-    values.mz = 0.1e-6*mag_z;
-
-    return values;
-}
-
-float FXOS8700CQ::get_pitch_angle() {
-    
-    float pitch;
-    Data values = get_values();
-    // calculate pitch
-    float y = -1.0*values.ax;
-    float x = sqrt(pow(values.ay,2)+pow(values.az,2));
-    pitch = atan2(y,x)*(180.0/3.141592653589793238463);
-    
-    return pitch;
-
-    }
-
-float FXOS8700CQ::get_roll_angle() {
-    
-    float roll;
-    Data values = get_values();
-    // calculate roll angle and convert to deg
-    roll = atan2(values.ay,values.az)*(180.0/3.141592653589793238463);
-
-    return roll;
-    }
-
-void FXOS8700CQ::send_byte_to_reg(char byte,char reg)
-{
-    char data[2];
-    data[0] = reg;
-    data[1] = byte;
-    // send the register address, followed by the data
-    int nack = i2c->write(FXOS8700CQ_ADDR,data,2);
-    if (nack)
-        error("No acknowledgement received!");  // if we don't receive acknowledgement, send error message
-
-}
-
-// reads a byte from a specific register
-char FXOS8700CQ::read_byte_from_reg(char reg)
-{
-    int nack = i2c->write(FXOS8700CQ_ADDR,&reg,1,true);  // send the register address to the slave
-    // true as need to send repeated start condition (5.10.1 datasheet)
-    // http://www.i2c-bus.org/repeated-start-condition/
-    if (nack)
-        error("No acknowledgement received!");  // if we don't receive acknowledgement, send error message
-
-    char rx;
-    nack = i2c->read(FXOS8700CQ_ADDR,&rx,1);  // read a byte from the register and store in buffer
-    if (nack)
-        error("No acknowledgement received!");  // if we don't receive acknowledgement, send error message
-
-    return rx;
-}
-
-// reads a series of bytes, starting from a specific register
-void FXOS8700CQ::read_bytes_from_reg(char reg,int number_of_bytes,char bytes[])
-{
-    int nack = i2c->write(FXOS8700CQ_ADDR,&reg,1,true);  // send the slave write address and the configuration register address
-    // true as need to send repeated start condition (5.10.1 datasheet)
-    // http://www.i2c-bus.org/repeated-start-condition/
-
-    if (nack)
-        error("No acknowledgement received!");  // if we don't receive acknowledgement, send error message
-
-    nack = i2c->read(FXOS8700CQ_ADDR,bytes,number_of_bytes);  // read bytes
-    if (nack)
-        error("No acknowledgement received!");  // if we don't receive acknowledgement, send error message
-
-}
\ No newline at end of file
--- a/FXOS8700CQ/FXOS8700CQ.h	Mon Apr 08 15:10:28 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-/** @file FXOS8700CQ.h
-
-@ brief FXOS8700CQ Library
-
-@author Dr Craig A. Evans
-@brief (c) University of Leeds, Jan 2017
-
-@code
-
-#include "mbed.h"
-#include "FXOS8700CQ.h"
-
-// create object and specifiy pins
-FXOS8700CQ device(I2C_SDA,I2C_SCL);
-
-int main()
-{
-    // call initialisation method
-    device.init();
-
-    while (1) {
-        
-        // poll the sensor and get the values, storing in a struct
-        Data values = device.get_values();
-        
-        // print each struct member over serial
-        printf("ax = %f ay = %f az = %f | mx = %f my = %f mz = %f\n"
-               ,values.ax, values.ay, values.az
-               ,values.mx, values.my, values.mz);
-        
-        wait(0.5);
-    }
-}
-
-@endcode
-
-*/
-
-#ifndef FXOS8700CQ_H
-#define FXOS8700CQ_H
-
-#include "mbed.h"
-
-// mbed API uses 8-bit addresses so need to left-shift 7-bit addresses by 1
-#define FXOS8700CQ_ADDR   (0x1D << 1)    // for K64F board
-// values from 13.2 datasheet
-#define FXOS8700CQ_STATUS 0x00
-#define FXOS8700CQ_WHO_AM_I 0x0D
-#define FXOS8700CQ_XYZ_DATA_CFG 0x0E
-#define FXOS8700CQ_CTRL_REG1 0x2A
-#define FXOS8700CQ_M_CTRL_REG1 0x5B
-#define FXOS8700CQ_M_CTRL_REG2 0x5C
-#define FXOS8700CQ_WHO_AM_I_VAL 0xC7
-#define FXOS8700CQ_READ_LEN 13
-
-#define PI 3.14159265359f
-#define RAD2DEG 57.2957795131f
-
-struct Data {
-    float ax;
-    float ay;
-    float az;
-    float mx;
-    float my;
-    float mz;
-};
-
-class FXOS8700CQ
-{
-
-public:
-    FXOS8700CQ(PinName sda, PinName scl);
-    ~FXOS8700CQ();
-    void init();
-    Data get_values();
-    float get_pitch_angle();
-    float get_roll_angle();
-
-private:
-    I2C* i2c;
-
-    void send_byte_to_reg(char byte,char reg);
-    char read_byte_from_reg(char reg);
-    void read_bytes_from_reg(char reg,int number_of_bytes,char bytes[]);
-};
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GolfEngine/GolfEngine.cpp	Wed Apr 17 10:27:09 2019 +0000
@@ -0,0 +1,41 @@
+#include "GolfEngine.h"
+
+void GolfEngine::init()
+{
+    _x_pos = 24;
+    _y_pos = 32;
+    _ball.init(_x_pos, _y_pos);
+    
+    Course _level_1[6] = { //first coord start second end
+    {LEFT,{9,26},{9,40}},  //top to bottom
+    {BOTTOM,{9,40},{74,40}},  //left to right
+    {RIGHT,{74,9},{9,40}}, //top to bottom
+    {TOP,{50,9},{74,9}}, //left to right
+    {LEFT,{50,9},{50,26}},  //top to bottom
+    {TOP,{9,26},{50,26}}  //left to right
+    };
+}
+
+void GolfEngine::drawGame(N5110 &lcd)
+{
+    _ball.drawBall(lcd);
+    _ball.printShotCount(lcd);
+    drawCourseWalls(lcd);
+}
+
+void GolfEngine::update_ball(Gamepad &pad, int frame_rate)
+{
+    
+    _ball.shoot_ball(pad);
+    _ball.check_wall_bounce();
+    _ball.move_ball(frame_rate);
+    _ball.check_wall_bounce();
+}
+
+void GolfEngine::drawCourseWalls(N5110 &lcd)
+{
+    for(int i = 0; i > 5; i++) {
+        lcd.drawLine(_level_1[i].start.x,_level_1[i].start.y,_level_1[i].end.x,_level_1[i].end.y,1); //draws line for each wall in course
+    }
+}   
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GolfEngine/GolfEngine.h	Wed Apr 17 10:27:09 2019 +0000
@@ -0,0 +1,64 @@
+#ifndef GOLFENGINE_H
+#define GOLFENGINE_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+#include "Ball.h"
+
+/** Golf Engine Class
+* @brief Library to run golf game
+* @author Ellis Blackford Stroud
+* @date May, 2018
+*/
+
+/** Enum for wall types */
+enum Wall {
+    
+    LEFT,  /**< left wall */
+    RIGHT,       /**< right wall */
+    TOP,      /**< top wall */
+    BOTTOM,       /**< bottom wall */
+};
+
+/** Course Information struct */
+struct Course {
+    Wall wall;  /**< wall type */
+    Vector2D start; /**< coordinate of line start */
+    Vector2D end; /**< coordinate of line end */
+};
+
+class GolfEngine 
+{
+
+public:
+
+    /** Constructor */
+    GolfEngine();
+
+    /** Destructor */
+    ~GolfEngine();
+    
+    void init();
+    
+    void drawGame(N5110 &lcd);
+    
+    void update_ball(Gamepad &pad, int frame_rate);
+    
+    void drawCourseWalls(N5110 &lcd);
+    
+    void check_wall_bounce();
+
+private:
+
+    int _x_pos;
+    int _y_pos;
+
+    Ball _ball;
+    
+    //Srtuct array to store coords of lines to plot for first level, this data also used in bounce algorithm
+
+    Course _level_1[6];
+};
+
+#endif
\ No newline at end of file
--- a/Menu/Menu.cpp	Mon Apr 08 15:10:28 2019 +0000
+++ b/Menu/Menu.cpp	Wed Apr 17 10:27:09 2019 +0000
@@ -41,16 +41,22 @@
     lcd.refresh();
     wait(1);
 }
-//prints main menu screen
-void Menu::print_menu(N5110 &lcd)
+//prints menu creen and controls cursor and choices
+void Menu::menu_screen(Gamepad &pad, N5110 &lcd)
 {
-    lcd.clear();
-    lcd.printString("Start Game",10,1);
-    lcd.printString("Highscores",10,3);
-    lcd.printString("Settings",10,5);
+    while(pad.check_event(Gamepad::START_PRESSED) == false){
+        
+        lcd.clear();
+        lcd.printString("Start Game",10,1);
+        lcd.printString("Highscores",10,3);
+        lcd.printString("Settings",10,5);
+        cursor_select(pad, lcd);
+        lcd.refresh();
+        wait(0.1);
+    }
 }
-//prints start screen and waits to start game
-bool Menu::check_start(N5110 &lcd, Gamepad &pad)
+//prints start screen and returns true when game started
+bool Menu::start_screen(N5110 &lcd, Gamepad &pad)
 {
     lcd.clear();
     lcd.printString("Press A ?",8,2);
@@ -62,20 +68,20 @@
     return true; //when true returned game begins
 }
 //prints highscores screen
-void Menu::print_highscores(N5110 &lcd, Gamepad &pad) 
+void Menu::highscores_screen(N5110 &lcd, Gamepad &pad) 
 {
     
-    while(pad.check_event(Gamepad::BACK_PRESSED) == false) {   
+    while(pad.check_event(Gamepad::BACK_PRESSED) == false) {   //loops until back pressed
     
         lcd.clear();
         lcd.printString("Highscores",0,0);
         lcd.refresh();
         
     }
-    print_menu(lcd);
+    menu_screen(pad, lcd); //when back pressed returns to menu screen
 }
 //prints settings screen
-void Menu::print_settings(N5110 &lcd, Gamepad &pad)
+void Menu::settings_screen(N5110 &lcd, Gamepad &pad)
 {
     
     _cursor_pos = 0;
@@ -84,9 +90,10 @@
     lcd.printString("Use pot",0,1);
     lcd.printString("and joystick",0,2);
     lcd.printString("to modify!",0,3);
+    lcd.printString("settings!",0,3);
     lcd.refresh();
     wait(1);
-    while(pad.check_event(Gamepad::BACK_PRESSED) == false) { 
+    while(pad.check_event(Gamepad::BACK_PRESSED) == false) { //loops until back pressed
       
         _joy_direction = pad.get_direction();
         lcd.clear();
@@ -95,7 +102,7 @@
         lcd.refresh();
         wait(0.2);
     }
-    print_menu(lcd);
+    menu_screen(pad, lcd);  //when back pressed returns to menu screen
 }
 
 
@@ -109,18 +116,15 @@
     lcd.drawRect(8,25,40,6,FILL_TRANSPARENT);
     lcd.drawRect(8,41,40,6,FILL_TRANSPARENT);
     char buffer[14];
-    sprintf(buffer,"%.2f%",_contrast); //print contrast value to 2dp
-    lcd.printString(buffer,52,1);  
-    sprintf(buffer,"%.2f%",_brightness); //print brightness value to 2dp
-    lcd.printString(buffer,52,3);
-    sprintf(buffer,"%ifps",_frame_rate); //prints integer value of frame rate
-    lcd.printString(buffer,52,5);  
     
     switch(_cursor_pos) { 
         case 0:
-            _contrast = _pot;
+        
+            _contrast = (_pot*4.0f/10.0f)+0.4f; //scale from 0-1 to 0.4-0.8 (below 0.4 no colour, above 0.8 no change)
             lcd.setContrast(_contrast);
-            lcd.drawRect(8,9,40*_contrast,6,FILL_BLACK);
+            sprintf(buffer,"%.2f%",_contrast); //print contrast value to 2dp
+            lcd.printString(buffer,52,1);  
+            lcd.drawRect(8,9,40*(_contrast-0.4f)*(10.0f/4.0f),6,FILL_BLACK);
             lcd.drawRect(8,25,40*_brightness,6,FILL_BLACK); 
             lcd.drawRect(8,41,40*(_frame_rate-5.0f)/45.0f,6,FILL_BLACK); 
             
@@ -128,13 +132,17 @@
         case 1:
             _brightness = _pot;
             lcd.setBrightness(_brightness);
-            lcd.drawRect(8,9,40*_contrast,6,FILL_BLACK);
+            sprintf(buffer,"%.2f%",_brightness); //print brightness value to 2dp
+            lcd.printString(buffer,52,3);
+            lcd.drawRect(8,9,40*(_contrast-0.4f)*(10.0f/4.0f),6,FILL_BLACK);
             lcd.drawRect(8,25,40*_brightness,6,FILL_BLACK); 
             lcd.drawRect(8,41,40*(_frame_rate-5.0f)/45.0f,6,FILL_BLACK); 
             break;
         case 2:
             _frame_rate = (_pot*45.0f)+5.0f; //scales 0-1 pot value to 5-50 fps
-            lcd.drawRect(8,9,40*_contrast,6,FILL_BLACK);
+            sprintf(buffer,"%ifps",_frame_rate); //prints integer value of frame rate
+            lcd.printString(buffer,52,5);  
+            lcd.drawRect(8,9,40*(_contrast-0.4f)*(10.0f/4.0f),6,FILL_BLACK);
             lcd.drawRect(8,25,40*_brightness,6,FILL_BLACK); 
             lcd.drawRect(8,41,40*(_frame_rate-5.0f)/45.0f,6,FILL_BLACK);  //scales frame rate from 0-1 to draw box 
             break;
@@ -149,42 +157,27 @@
         case 0:
             //returns true if start game
             { 
-            bool start = check_start(lcd, pad); //waits until game start confirmed
+            bool start = start_screen(lcd, pad); //waits until game start confirmed
             return start; //causes exit of menu loop and game loop begins
             }
         case 1:
-            print_highscores(lcd, pad);
+            highscores_screen(lcd, pad);
             return false;
         case 2:
-            print_settings(lcd, pad);
+            settings_screen(lcd, pad);
             return false;
          default:  // default case
             return false;                
     }
 }
 
-void Menu::menu_return(N5110 &lcd, Gamepad &pad)
-{
-    while(pad.check_event(Gamepad::BACK_PRESSED) == false) {   
-        
-    }
-    print_menu(lcd);
-}
 
 //Uses joystick direction to select menu option and waits until start message
-void Menu::menu_select(Gamepad &pad, N5110 &lcd)
+void Menu::cursor_select(Gamepad &pad, N5110 &lcd)
 {
     
-    while(pad.check_event(Gamepad::START_PRESSED) == false) { //loops until start pressed and choice selected
-    
-        _joy_direction  = pad.get_direction();
-        lcd.clear();
-        print_menu(lcd);
-        move_cursor(lcd);
-        lcd.refresh();
-        wait(0.2);
-    }
-
+    _joy_direction  = pad.get_direction();
+    move_cursor(lcd);
 }
 
 void Menu::set_frame_rate(int frame_rate)
@@ -240,7 +233,7 @@
     }
 }
 
-void Menu::move_cursor(N5110 &lcd) 
+void Menu::move_cursor(N5110 &lcd) //changes cursor position dependent on current position and joystick direction
 {
     switch(_cursor_pos) {
         case 0: //cursor on position 0
--- a/Menu/Menu.h	Mon Apr 08 15:10:28 2019 +0000
+++ b/Menu/Menu.h	Wed Apr 17 10:27:09 2019 +0000
@@ -5,7 +5,6 @@
 #include "N5110.h"
 #include "Gamepad.h"
 
-
 /** Menu Class
 * @brief Library for navigating menu options
 * @author Ellis Blackford Stroud
@@ -28,16 +27,16 @@
     void print_welcome(N5110 &lcd);
     
     /** Prints menu screen */
-    void print_menu(N5110 &lcd);
+    void menu_screen(Gamepad &pad, N5110 &lcd);
     
     /** Prints start screen */
-    bool check_start(N5110 &lcd, Gamepad &pad);
+    bool start_screen(N5110 &lcd, Gamepad &pad);
     
      /** Prints highscore screen */
-    void print_highscores(N5110 &lcd, Gamepad &pad);
+    void highscores_screen(N5110 &lcd, Gamepad &pad);
     
      /** Prints settings screen */
-    void print_settings(N5110 &lcd, Gamepad &pad);
+    void settings_screen(N5110 &lcd, Gamepad &pad);
     
     void draw_settings(N5110 &lcd, Gamepad &pad);
     
@@ -45,14 +44,11 @@
     * @returns a bool: true to start game, false to stay in menu
     */
     bool menu_change(N5110 &lcd, Gamepad &pad);
-    
-    /** Returns to menu screen */
-    void menu_return(N5110 &lcd, Gamepad &pad);
 
     /** Updates cursor and returns menu choice
     * @returns an enum: START, HIGHSCORES, SETTINGS
     */
-    void menu_select(Gamepad &pad, N5110 &lcd);    
+    void cursor_select(Gamepad &pad, N5110 &lcd);    
     
     void set_frame_rate(int frame_rate);
     
@@ -85,8 +81,6 @@
     int _frame_rate;
     
     Direction _joy_direction;
-    
-    
 
 };
 
--- a/main.cpp	Mon Apr 08 15:10:28 2019 +0000
+++ b/main.cpp	Wed Apr 17 10:27:09 2019 +0000
@@ -7,19 +7,20 @@
 Student ID Number: 201155309
 Date: 09/05/19
 */
+
 #include "mbed.h"
 #include "Gamepad.h"
 #include "N5110.h"
 #include "Menu.h"
-#include "Ball.h"
-
+#include "GolfEngine.h"
 
 // objects 
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
 Gamepad pad;
 Menu menu;
-Ball ball;
+GolfEngine golf;
 void init();
+
 int frame_rate = 40;
 
 int main()
@@ -27,30 +28,24 @@
     init();
     lcd.clear();
     menu.print_welcome(lcd);
-    menu.print_menu(lcd); 
+    lcd.clear();
     bool start_game = false; 
     
-    while(start_game== false) {   //menu loop navigates menu until game started
-
-        lcd.refresh();
-        menu.menu_select(pad, lcd); //main menu cursor code loops until start pressed
-        start_game = menu.menu_change(lcd, pad); //changes menu screen to choice returns true if game started        
+    while(start_game == false) {   //menu loop navigates menu until game started
+        
+        menu.menu_screen(pad, lcd); 
+        start_game = menu.menu_change(lcd, pad); //changes menu screen to selected screen the returns true when start game 
     }  
     
-    frame_rate = menu.get_frame_rate(); 
+    frame_rate = menu.get_frame_rate(); //can be changed in the settings screen
     
     //game loop to run game
     
-    int x_pos = 24;
-    int y_pos = 24;
-    ball.init(x_pos, y_pos);
-    
     while(1){ 
     
         lcd.clear();    
-        ball.shoot_ball(pad);
-        ball.move_ball(frame_rate, lcd);
-        ball.draw_screen(lcd, pad);
+        golf.update_ball(pad, frame_rate);
+        golf.drawGame(lcd);        
         lcd.refresh();
 
         wait(1.0f/frame_rate); //time between loops/frames
@@ -64,5 +59,6 @@
     lcd.init();
     pad.init();
     menu.init();
+    golf.init();
     lcd.setContrast(0.5f);
 }
--- a/mbed.bld	Mon Apr 08 15:10:28 2019 +0000
+++ b/mbed.bld	Wed Apr 17 10:27:09 2019 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/e7ca05fa8600
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/176b8275d35d
\ No newline at end of file