Final Submission. I have read and agreed with Statement of Academic Integrity.

Dependencies:   mbed

Revision:
1:86f96ceaf593
Parent:
0:7423345f87c5
Child:
2:586409836de7
--- a/main.cpp	Fri Jan 31 12:32:38 2020 +0000
+++ b/main.cpp	Fri May 29 12:07:22 2020 +0000
@@ -2,95 +2,120 @@
 #include "mbed.h"
 #include "Gamepad.h"
 #include "N5110.h"
-#include "PongEngine.h"
 
-#ifdef WITH_TESTING
-# include "tests.h"
-#endif
-
-#define PADDLE_WIDTH 2
-#define PADDLE_HEIGHT 8
-#define BALL_SIZE 2
-#define BALL_SPEED 3
+//Objects
+Gamepad pad;
+N5110 lcd;
 
-/////////////// structs /////////////////
-struct UserInput {
-    Direction d;
-    float mag;
-};
-/////////////// objects ///////////////
-N5110 lcd;
-Gamepad pad;
-PongEngine pong;
-
-///////////// prototypes ///////////////
-void init();
-void update_game(UserInput input);
-void render();
-void welcome();
-
-///////////// functions ////////////////
+char player_char = 'x';
+int player_xpos = 1;
+int player_ypos = 45;
+char array[84][48];
+int move = 0;
+ 
+//Prototypes
+void pad_init();
+void update_display();
+void draw_array();
+void player_object();
+void Copy_array();
+void player_movements();
+void update_array();
+void apply_move();
+void array_init();
+void add_surface_array();
+void add_player_array();
+void get_move(int);
+void print_screen();
+//Main function
 int main()
 {
-#ifdef WITH_TESTING
-    int number_of_failures = run_all_tests();
-
-    if(number_of_failures > 0) return number_of_failures;
-#endif
-
-    int fps = 6;  // frames per second
-
-    init();     // initialise and then display welcome screen...
-    welcome();  // waiting for the user to start
-    
-    render();  // first draw the initial frame 
-    wait(1.0f/fps);  // and wait for one frame period
-
-
-    // game loop - read input, update the game state and render the display
-    while (1) {
-        pong.read_input(pad);
-        pong.update(pad);
-        render();
-        wait(1.0f/fps);
+    pad_init();
+    array_init();
+    add_surface_array();
+    add_player_array();
+    print_screen();
+    update_display();
+    //Loop runs forever
+    while(1){
+        get_move(move);
+        apply_move();
+        add_player_array();
+        print_screen();
+        
+        update_display();
     }
 }
 
-// initialies all classes and libraries
-void init()
-{
-    // need to initialise LCD and Gamepad 
+void array_init(){
+    for(int j = 0; j < 47; j++){
+        for(int i = 0; i < 83; i++){
+         array[i][j] = '0';
+         }}}    
+
+void apply_move(){
+    int old_player_xpos = player_xpos;
+    player_xpos += move;
+    array[old_player_xpos][player_ypos] = '0';
+}
+    
+
+void print_screen(){
+ for(int j = 0; j < 47; j++){
+    for(int i = 0; i < 83; i++){
+     
+         if (array[i][j] == '0'){
+             lcd.setPixel(i,j,false);
+             }
+         else if(array[i][j] == '1'){
+             lcd.setPixel(i,j, true);
+             }
+         else if(array[i][j] == 'x'){
+             lcd.setPixel(i,j, true);
+             
+             }
+            }
+            }}
+         
+ 
+ 
+
+//Prototype functions
+void pad_init(){   
     lcd.init();
+    lcd.setContrast(0.5);
+    lcd.clear();
     pad.init();
-     
-    // initialise the game with correct ball and paddle sizes
-    pong.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_SIZE,BALL_SPEED);
-
 }
 
-// this function draws each frame on the LCD
-void render()
+void add_surface_array()
 {
-    // clear screen, re-draw and refresh
-    lcd.clear();  
-    pong.draw(lcd);
-    lcd.refresh();
+ for(int i = 0; i < 84; i++){
+     array[i][46] = '1';
+     }
+}
+
+void add_player_array()
+{
+     array[player_xpos][player_ypos] = player_char;
 }
 
-// simple splash screen displayed on start-up
-void welcome() {
+
+
+void get_move(int)
+{   while(pad.A_pressed() == 0 && pad.B_pressed() == 0){
+        if(pad.A_pressed() == 1){
+            move = 1;
+            }
+        else if(pad.B_pressed() == 1){
+            move = -1;
+    }
+    }
+    }
+
     
-    lcd.printString("     Pong!    ",0,1);  
-    lcd.printString("  Press Start ",0,4);
-    lcd.refresh();
-     
-    // wait flashing LEDs until start button is pressed 
-    while ( pad.start_pressed() == false) {
-        lcd.setContrast( pad.read_pot1());
-        pad.leds_on();
-        wait(0.1);
-        pad.leds_off();
-        wait(0.1);
-    }
- 
+void update_display()
+{
+    lcd.refresh(); //Refreshes the lcd so the pixels appear
+    wait_ms(200);  //Frame rate of game
 }
\ No newline at end of file