Mert Us Matthew Hannay Logan Starr

Dependencies:   mbed 4DGL-uLCD-SE

Revision:
10:8f73a917b239
Parent:
9:1f33c0f299ae
Child:
12:7ef20deb9d5e
--- a/main.cpp	Fri Nov 18 19:06:03 2022 +0000
+++ b/main.cpp	Mon Nov 28 21:08:59 2022 +0000
@@ -241,9 +241,22 @@
     static const int HOVER_COLOR = 0x0000ff;
     static const int SELECTED_COLOR = 0xff8800;
     static const int MOVE_COLOR = 0xff00ff;
+    
+    // gets the pixel coordinates of the top left of the square
+    static pixelCoord getTopLeftOfSquare(boardPos pos)
+    {
+        return getTopLeftOfSquare(pos.row, pos.column);
+    }
+    static pixelCoord getTopLeftOfSquare(int row, int column)
+    {
+        pixelCoord topLeft;
+        topLeft.x = 16 * column;
+        topLeft.y = 112 - 16 * row;
+        return topLeft;
+    }
 
     // piece sprites (12 x 12)
-    static void spritePawn(bool white, bool light, int* spriteArray)
+    static void drawPawn(int row, int column, bool white, bool light)
     {
         int X = white ? 0xffffff : 0x000000;
         int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR;
@@ -260,10 +273,11 @@
                            _, _, X, X, X, X, X, X, X, X, _, _,
                            _, _, X, X, X, X, X, X, X, X, _, _
                           };
-        memcpy(sprite, spriteArray, sizeof(sprite));
+        pixelCoord tl = getTopLeftOfSquare(row, column);
+        uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite);
     }
 
-    static void spriteRook(bool white, bool light, int* spriteArray)
+    static void drawRook(int row, int column, bool white, bool light)
     {
         int X = white ? 0xffffff : 0x000000;
         int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR;
@@ -280,10 +294,11 @@
                            X, X, X, X, X, X, X, X, X, X, X, X,
                            X, X, X, X, X, X, X, X, X, X, X, X
                           };
-        memcpy(sprite, spriteArray, sizeof(sprite));
+        pixelCoord tl = getTopLeftOfSquare(row, column);
+        uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite);
     }
 
-    static void spriteKnight(bool white, bool light, int* spriteArray)
+    static void drawKnight(int row, int column, bool white, bool light)
     {
         int X = white ? 0xffffff : 0x000000;
         int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR;
@@ -300,10 +315,11 @@
                            _, X, X, X, X, X, X, X, X, X, X, _,
                            _, X, X, X, X, X, X, X, X, X, X, _
                           };
-        memcpy(sprite, spriteArray, sizeof(sprite));
+        pixelCoord tl = getTopLeftOfSquare(row, column);
+        uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite);
     }
 
-    static void spriteBishop(bool white, bool light, int* spriteArray)
+    static void drawBishop(int row, int column, bool white, bool light)
     {
         int X = white ? 0xffffff : 0x000000;
         int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR;
@@ -320,10 +336,11 @@
                            _, _, X, X, X, X, X, X, X, X, _, _,
                            _, _, X, X, X, X, X, X, X, X, _, _
                           };
-        memcpy(sprite, spriteArray, sizeof(sprite));
+        pixelCoord tl = getTopLeftOfSquare(row, column);
+        uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite);
     }
 
-    static void spriteQueen(bool white, bool light, int* spriteArray)
+    static void drawQueen(int row, int column, bool white, bool light)
     {
         int X = white ? 0xffffff : 0x000000;
         int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR;
@@ -340,10 +357,11 @@
                            _, _, X, X, X, X, X, X, X, X, _, _,
                            _, X, X, X, X, X, X, X, X, X, X, _
                           };
-        memcpy(sprite, spriteArray, sizeof(sprite));
+        pixelCoord tl = getTopLeftOfSquare(row, column);
+        uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite);
     }
 
-    static void spriteKing(bool white, bool light, int* spriteArray)
+    static void drawKing(int row, int column, bool white, bool light)
     {
         int X = white ? 0xffffff : 0x000000;
         int _ = light ? BOARD_LIGHT_COLOR : BOARD_DARK_COLOR;
@@ -360,7 +378,8 @@
                            _, _, X, X, X, _, _, X, X, X, _, _,
                            _, X, X, X, X, X, X, X, X, X, X, _
                           };
-        memcpy(sprite, spriteArray, sizeof(sprite));
+        pixelCoord tl = getTopLeftOfSquare(row, column);
+        uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite);
     }
 
 public:
@@ -413,19 +432,6 @@
         }
     }
 
-    // gets the pixel coordinates of the top left of the square
-    pixelCoord getTopLeftOfSquare(boardPos pos)
-    {
-        return getTopLeftOfSquare(pos.row, pos.column);
-    }
-    pixelCoord getTopLeftOfSquare(int row, int column)
-    {
-        pixelCoord topLeft;
-        topLeft.x = 16 * column;
-        topLeft.y = 112 - 16 * row;
-        return topLeft;
-    }
-
     // PIECE MOVEMENT AND GRAPHICS FUNCTIONS
 
     // returns the piece at a given location
@@ -449,34 +455,32 @@
     {
         boardState.placePiece(piece, row, column);
         pixelCoord tl = getTopLeftOfSquare(row, column);
-        int sprite[144];
         switch(piece) {
             case wK:
             case bK:
-                spriteKing(piece==wK, (row+column)%2, sprite);
+                drawKing(row, column, piece==wK, (row+column)%2);
                 break;
             case wQ:
             case bQ:
-                spriteQueen(piece==wQ, (row+column)%2, sprite);
+                drawQueen(row, column, piece==wQ, (row+column)%2);
                 break;
             case wB:
             case bB:
-                spriteBishop(piece==wB, (row+column)%2, sprite);
+                drawBishop(row, column, piece==wB, (row+column)%2);
                 break;
             case wN:
             case bN:
-                spriteKing(piece==wN, (row+column)%2, sprite);
+                drawKnight(row, column, piece==wN, (row+column)%2);
                 break;
             case wR:
             case bR:
-                spriteKing(piece==wR, (row+column)%2, sprite);
+                drawRook(row, column, piece==wR, (row+column)%2);
                 break;
             case w:
             case b:
-                spriteKing(piece==w, (row+column)%2, sprite);
+                drawPawn(row, column, piece==w, (row+column)%2);
                 break;
         }
-        uLCD.BLIT(tl.x + 2, tl.y + 2, 12, 12, sprite);
     }
 
     /*  removes a piece from the set position of the board
@@ -683,7 +687,7 @@
 
 int main()
 {
-    gameBoard = GameBoard();
+    //gameBoard = GameBoard();
     whitePieces.push_back(wK);
     whitePieces.push_back(wQ);
     whitePieces.push_back(wB);