Skip to content

Commit b8a4e6f

Browse files
committed
Can now place bricks and clear them again
1 parent 3727857 commit b8a4e6f

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

source/code/puzzle_editor/PuzzleEditorState.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@ static void DrawBrick(int brick, int x, int y, int width, int height) {
9393
ImGuiWritePartOfTexture(sprite.GetTextureHandler().get(), sprite.GetImageCord().x, sprite.GetImageCord().y, sprite.GetWidth(), sprite.GetHeight(), width, height);
9494
}
9595

96+
97+
void PuzzleEditorState::BrickClicked(int x, int y) {
98+
if (read_only) {
99+
return;
100+
}
101+
if (x < 0 || x >= 6) {
102+
return;
103+
}
104+
if (y <0 || y >= 12) {
105+
return;
106+
}
107+
if (selected_action >= 0 && selected_action < 7) {
108+
PuzzleSetBrick(this->selected_puzzle, x, y, this->selected_action);
109+
}
110+
if (selected_action == selection_clear) {
111+
PuzzleSetBrick(this->selected_puzzle, x, y, -1);
112+
}
113+
114+
}
115+
96116
void PuzzleEditorState::Draw(SDL_Renderer* target) {
97117
DrawBackground(target);
98118

@@ -154,9 +174,10 @@ void PuzzleEditorState::Draw(SDL_Renderer* target) {
154174
//std::cout << "Clicked at: " << pos.x << "," << pos.y << "\n";
155175
//std::cout << "Logical Pos: " << logical_pos_x << "," << logical_pos_y << "\n";
156176
int board_x = logical_pos_x / 50;
157-
int board_y = logical_pos_y / 50;
177+
int board_y = 11-(logical_pos_y / 50);
158178
if (board_x >=0 && board_x < 6 && board_y >= 0 && board_y < 12) {
159179
std::cout << "Board Pos: " << board_x << "," << board_y << "\n";
180+
BrickClicked(board_x, board_y);
160181
}
161182

162183
}

source/code/puzzle_editor/PuzzleEditorState.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class PuzzleEditorState : public sago::GameStateInterface {
5252
private:
5353
void SelectFile(const std::string& file);
5454

55+
void BrickClicked(int x, int y);
56+
5557
int selected_action = 0;
5658

5759
bool isActive = true;

source/code/puzzlehandler.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ int PuzzleGetBrick(size_t level, int x, int y) {
5656
return puzzleLevels[level][x][y];
5757
}
5858

59+
void PuzzleSetBrick(size_t level, int x, int y, int brick) {
60+
if (level >= maxNrOfPuzzleStages || x >= 6 || y >= 12 || x < 0 || y < 0) {
61+
return;
62+
}
63+
if (brick >= 7) {
64+
return;
65+
}
66+
puzzleLevels[level][x][y] = brick;
67+
}
68+
5969
int PuzzleGetNumberOfPuzzles() {
6070
return nrOfPuzzles;
6171
}

source/code/puzzlehandler.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Source information and contacts persons can be found at
2929

3030
int PuzzleNumberOfMovesAllowed(size_t level);
3131
int PuzzleGetBrick(size_t level, int x, int y);
32+
void PuzzleSetBrick(size_t level, int x, int y, int brick); // used only for editor
3233
bool PuzzleIsCleared(size_t level);
3334
int LoadPuzzleStages();
3435
int SavePuzzleStages();

0 commit comments

Comments
 (0)