]> Shamusworld >> Repos - warehouse-man-deluxe/blobdiff - src/gameboard.cpp
Added/fixed editor, added play level functionality.
[warehouse-man-deluxe] / src / gameboard.cpp
index 0656e74a96425d9577185090bff4c891926ad640..0d1216f1c0bfbd1b16bfbadc2dc1ad0fb9197554 100644 (file)
@@ -15,6 +15,7 @@
 #include <string.h>
 //#include <stdio.h>   // for printf()
 #include "boards.h"
+#include "editorwidget.h"      // for Level
 
 
 GameBoard::GameBoard(int boardNumber)
@@ -31,8 +32,7 @@ GameBoard::GameBoard(int boardNumber)
        boardLength = width * height;
        board = new char[boardLength];
        initialBoard = new char[boardLength];
-//     initialX = boardToUse->x;
-//     initialY = boardToUse->y;
+       name = (const char *)&(boardToUse->state[boardLength]);
 
        for(int i=0; i<boardLength; i++)
        {
@@ -48,11 +48,49 @@ GameBoard::GameBoard(int boardNumber)
                        initialBoard[i] = GTBoxSpot;
                else if (c == '+')
                        initialBoard[i] = GTBox | GTBoxSpot;
-               else if (c == 'o')
+               else if (c == 'o' || c == '*')
                {
-                       initialBoard[i] = GTSpace;
+                       initialBoard[i] = (c == '*' ? GTBoxSpot : GTSpace);
                        initialX = i % width, initialY = i / width;
                }
+               else
+                       initialBoard[i] = GTNull;
+       }
+
+       ResetGame();
+}
+
+
+GameBoard::GameBoard(Level * level)
+{
+       Point size, corner;
+
+       EditorWidget::GetSizeAndCorner(level, size, corner);
+
+       width = size.x;
+       height = size.y;
+       boardLength = width * height;
+       board = new char[boardLength];
+       initialBoard = new char[boardLength];
+       name = level->name;
+
+       int current = 0;
+
+       for(int y=0; y<size.y; y++)
+       {
+               for(int x=0; x<size.x; x++)
+               {
+                       uint8_t tile = level->board[corner.x + x][corner.y + y];
+
+                       if (tile & GTMan)
+                       {
+                               initialX = x;
+                               initialY = y;
+                               tile &= ~GTMan;
+                       }
+
+                       initialBoard[current++] = tile;
+               }
        }
 
        ResetGame();
@@ -149,7 +187,6 @@ int GameBoard::Move(int dx, int dy, char cell1, char cell2)
        // Player is moving into an unoccupied space...
        if (cell1 == GTSpace)
        {
-//             var += direction;
                playerX += dx, playerY += dy;
                undo[numMoves].dx = dx, undo[numMoves].dy = dy, undo[numMoves].type = PMWalk;
                numMoves++;
@@ -158,13 +195,10 @@ int GameBoard::Move(int dx, int dy, char cell1, char cell2)
        // Player is pushing a box into an unoccupied space...
        else if ((cell1 == GTBox) && (cell2 == GTSpace))
        {
-//             var += direction;
                playerX += dx, playerY += dy;
                board[playerX + (playerY * width)] &= GTBoxSpot;
-//             var += direction;
                playerX += dx, playerY += dy;
                board[playerX + (playerY * width)] |= GTBox;
-//             var -= direction;
                playerX -= dx, playerY -= dy;
                undo[numMoves].dx = dx, undo[numMoves].dy = dy, undo[numMoves].type = PMPush;
                numMoves++;