Dependencies:   mbed

Revision:
3:ceed6d026b8b
Parent:
2:d08b6a1eaf2b
Child:
4:9f41fc1c2ad1
--- a/main.cpp	Tue Feb 11 12:15:04 2020 +0000
+++ b/main.cpp	Tue Feb 11 13:18:40 2020 +0000
@@ -15,20 +15,86 @@
 #include "Gamepad.h"
 #include "N5110.h"
 #include "Graphics.h"
+#include "Controls.h"
 
 //OBJECTS
 Gamepad Device;
 N5110 LCD;
 Graphics Graphics;
+Controls Controls;
+
+#ifndef STRUCTS
+#define STRUCTS
+
+//STRUCTS
+struct Point_2D {
+    float x;
+    float y;
+};
+struct Line_2D {
+    Point_2D from;
+    Point_2D to;
+};
+
+struct Map_Data {
+    int number_of_track_lines;
+    int number_of_dotted_lines;
+    int number_of_flags;
+};
+
+#endif
 
 //MAP - 1
+Map_Data Map_1 = {36,1,2};
+
 //Lines
-const Line_2D Map_1_Track_Lines[4] = {
+const Line_2D Map_1_Track_Lines[36] = {
     //Inside Line
-    {{16,16},{16,-16}},
-    {{16,-16},{-16,-16}},
-    {{-16,-16},{-16,16}},
-    {{-16,16},{16,16}}
+    {{-20,0},{-20,80}},
+    {{-20,80},{-40,100}},
+    {{-40,100},{-80,100}},
+    {{-80,100},{-100,80}},
+    {{-100,80},{-100,40}},
+    {{-100,40},{-140,0}},
+    {{-140,0},{-220,0}},
+    {{-220,0},{-260,40}},
+    {{-260,40},{-260,80}},
+    {{-260,80},{-280,100}},
+    {{-280,100},{-320,100}},
+    {{-320,100},{-360,60}},
+    {{-360,60},{-360,-100}},
+    {{-360,-100},{-300,-160}},
+    {{-300,-160},{-220,-80}},
+    {{-220,-80},{-100,-80}},
+    {{-100,-80},{-20,0}},
+    //Outside Line
+    {{20,-20},{20,100}},
+    {{20,100},{-20,140}},
+    {{-20,140},{-100,140}},
+    {{-100,140},{-140,100}},
+    {{-140,100},{-140,60}},
+    {{-140,60},{-160,40}},
+    {{-160,40},{-200,40}},
+    {{-200,40},{-220,60}},
+    {{-220,60},{-220,100}},
+    {{-220,100},{-260,140}},
+    {{-260,140},{-340,140}},
+    {{-340,140},{-400,80}},
+    {{-400,80},{-400,-120}},
+    {{-400,-120},{-320,-200}},
+    {{-320,-200},{-280,-200}},
+    {{-280,-200},{-200,-120}},
+    {{-200,-120},{-80,-120}},
+    {{-80,-120},{20,-20}},
+};
+
+const Line_2D Map_1_Track_Dotted_Lines[1] = {
+    {{-20,0},{20,0}},
+};
+
+Point_2D Map_1_Flags[2] = {
+    {-20,0},
+    {24,0}
 };
 
 //GLOBAL VARIABLES
@@ -38,17 +104,23 @@
 Point_2D translation = {0,0};
 float squish = 0.15;
 
+//Vehicle parameters
+float speed = 0;
+float max_speed = 4;
+int handling = 1;
+
 //Game parameters
-int game_fps = 50;
+int game_fps = 30;
 
 int main()
 {
     LCD.init();
     Device.init();
-    Graphics.Change_Contrast(LCD,Device);
     while(1) {
-        Graphics.Draw_Map(game_fps, translation, angle, squish, (Line_2D *) Map_1_Track_Lines, LCD);
-        angle++;
+        angle = Controls.Get_Angle(angle, handling, Device);
+        translation = Controls.Get_Translation(translation, angle, speed, max_speed, Device);
+        Graphics.Change_Contrast(LCD,Device);
+        Graphics.Draw_Map(game_fps, translation, angle, squish, (Line_2D *) Map_1_Track_Lines, (Line_2D *)Map_1_Track_Dotted_Lines, (Point_2D *)Map_1_Flags, Map_1, LCD);
     }