Dependencies:   mbed

Revision:
3:ceed6d026b8b
Parent:
2:d08b6a1eaf2b
Child:
4:9f41fc1c2ad1
--- a/Graphics/Graphics.cpp	Tue Feb 11 12:15:04 2020 +0000
+++ b/Graphics/Graphics.cpp	Tue Feb 11 13:18:40 2020 +0000
@@ -1,14 +1,33 @@
 #include "Graphics.h"
 
+//***********
+//  Sprites
+//***********
+
+int flag[8][8] = {
+    {4,1,1,1,1,1,1,1},
+    {4,1,1,0,1,0,1,1},
+    {4,1,0,1,0,1,1,1},
+    {4,1,1,0,1,0,1,1},
+    {4,1,1,1,1,1,1,1},
+    {4,4,4,4,4,4,1,1},
+    {4,4,4,4,4,4,1,1},
+    {4,4,4,4,4,4,1,1},
+    };
+
+
 //**************************
 //  MAIN GRAPHICS FUNCTION
 //**************************
 
-void Graphics::Draw_Map(int game_fps, Point_2D translation, int angle, float squish, Line_2D *Track_Lines, N5110 &LCD)
+void Graphics::Draw_Map(int game_fps, Point_2D translation, int angle, float squish, Line_2D *Track_Lines, Line_2D *Track_Dotted_Lines, Point_2D *Track_Flags, Map_Data map_info, N5110 &LCD)
 {
-    Line_2D Track_Lines_Transformed[4];
 
-    for(int i = 0; i < 4; i++) {
+    Line_2D Track_Lines_Transformed[map_info.number_of_track_lines];
+    Line_2D Track_Dotted_Lines_Transformed[map_info.number_of_dotted_lines];
+    Point_2D Transformed_Flags[map_info.number_of_flags];
+
+    for(int i = 0; i < map_info.number_of_track_lines; i++) {
         Track_Lines_Transformed[i] = Track_Lines[i];
         //Translation
         Track_Lines_Transformed[i].from = Translate_Point(Track_Lines_Transformed[i].from, Round(translation.x), Round(translation.y));
@@ -21,12 +40,44 @@
         Track_Lines_Transformed[i].to = Squish_Point(Track_Lines_Transformed[i].to, squish);
     }
 
+    for(int i = 0; i < map_info.number_of_dotted_lines; i++) {
+        Track_Dotted_Lines_Transformed[i] = Track_Dotted_Lines[i];
+        //Translation
+        Track_Dotted_Lines_Transformed[i].from = Translate_Point(Track_Dotted_Lines_Transformed[i].from, Round(translation.x), Round(translation.y));
+        Track_Dotted_Lines_Transformed[i].to = Translate_Point(Track_Dotted_Lines_Transformed[i].to, Round(translation.x), Round(translation.y));
+        //Rotation
+        Track_Dotted_Lines_Transformed[i].from = Rotate_Point(Track_Dotted_Lines_Transformed[i].from, angle);
+        Track_Dotted_Lines_Transformed[i].to = Rotate_Point(Track_Dotted_Lines_Transformed[i].to, angle);
+        //Squish
+        Track_Dotted_Lines_Transformed[i].from = Squish_Point(Track_Dotted_Lines_Transformed[i].from, squish);
+        Track_Dotted_Lines_Transformed[i].to = Squish_Point(Track_Dotted_Lines_Transformed[i].to, squish);
+    }
+
+    for(int i = 0; i < map_info.number_of_flags; i++) {
+        Transformed_Flags[i] = Track_Flags[i];
+        //Translation
+        Transformed_Flags[i] = Translate_Point(Transformed_Flags[i], Round(translation.x), Round(translation.y));
+        //Rotation
+        Transformed_Flags[i] = Rotate_Point(Transformed_Flags[i], angle);
+        //Squish
+        Transformed_Flags[i] = Squish_Point(Transformed_Flags[i], squish);
+    }
+
     LCD.clear();
-    for(int i = 0; i < 4; i++) {
+    for(int i = 0; i < map_info.number_of_track_lines; i++) {
         Graphics_Draw_Line(Track_Lines_Transformed[i].from, Track_Lines_Transformed[i].to, true, LCD);
     }
+
+    for(int i = 0; i < map_info.number_of_dotted_lines; i++) {
+        Graphics_Draw_Line(Track_Dotted_Lines_Transformed[i].from, Track_Dotted_Lines_Transformed[i].to,false, LCD);
+    }
+
+    for(int i = 0; i < map_info.number_of_flags; i++) {
+        Graphics_Draw_Sprite(Transformed_Flags[i], 8, 8, (int *)flag, LCD);
+    }
+
     LCD.refresh();
-    wait(0.02);
+    wait((1 / game_fps));
 }
 
 
@@ -104,9 +155,9 @@
     }
 }
 
-//********
-//  DRAW
-//********
+//*************
+//  DRAW LINE
+//*************
 
 void Graphics::Graphics_Draw_Line(Point_2D from, Point_2D to, bool solid, N5110 &LCD) //Draw a line between two points on only the portion of the screen
 {
@@ -198,4 +249,24 @@
             }
         }
     }
+}
+
+//***************
+//  DRAW SPRITE
+//***************
+
+void Graphics::Graphics_Draw_Sprite(Point_2D point, int x_size, int y_size, int *sprite, N5110 &LCD)
+{
+    Point_2D zeroed_point = {Round(point.x) + 42 - x_size, Round(-point.y) + 36 - y_size};
+    if(zeroed_point.x <= 84 && zeroed_point.x >= 0 && zeroed_point.y <= 48 && zeroed_point.y >= 0) {
+        for(int y = 0; y < y_size; y++) {
+            for(int x = 0; x < x_size; x++) {
+                if(*((sprite + y*y_size)+x) == 1) {
+                    LCD.setPixel((zeroed_point.x + x), (zeroed_point.y + y), true);
+                } else if(*((sprite + y*y_size)+x) == 0) {
+                    LCD.setPixel((zeroed_point.x + x), (zeroed_point.y + y), false);
+                }
+            }
+        }
+    }
 }
\ No newline at end of file