diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/lettergame.iml b/.idea/lettergame.iml
new file mode 100644
index 0000000..f08604b
--- /dev/null
+++ b/.idea/lettergame.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..79b3c94
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..64eb958
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/include/grid.h b/include/grid.h
index e7e1584..1fdd53d 100644
--- a/include/grid.h
+++ b/include/grid.h
@@ -35,11 +35,11 @@
#include
#include
-
+#include "sdlhelpers.h"
#include "utils.h"
-#define GRID_MAX_X_CELLS (20)
-#define GRID_MAX_Y_CELLS (20)
+#define GRID_MAX_X_CELLS (15)
+#define GRID_MAX_Y_CELLS (15)
struct Cell
{
diff --git a/include/letter.h b/include/letter.h
new file mode 100644
index 0000000..e3bdde8
--- /dev/null
+++ b/include/letter.h
@@ -0,0 +1,28 @@
+#ifndef LETTER_H
+#define LETTER_H
+
+#include
+#include
+
+#include
+#include "sdlhelpers.h"
+#include "utils.h"
+
+struct Letter
+{
+ SDL_Rect rect;
+
+ // Grid background color
+ SDL_Color backgroundColor;
+
+ // Grid border thickness and color
+ unsigned int border;
+ SDL_Color borderColor;
+
+ int isFromPreviousMove;
+
+ int letterIndex;
+
+};
+
+#endif // LETTER_H
diff --git a/include/sdlhelpers.h b/include/sdlhelpers.h
new file mode 100644
index 0000000..f8c84ae
--- /dev/null
+++ b/include/sdlhelpers.h
@@ -0,0 +1,13 @@
+//
+// Created by hamo on 11/25/22.
+//
+#include
+
+#ifndef LETTERGAME_SDLHELPERS_H
+#define LETTERGAME_SDLHELPERS_H
+int
+SDH_fill_rounded_box_b( SDL_Surface* dst, int xo, int yo,
+ int w, int h, int r, Uint32 color );
+Uint32 ColourToUint(int R, int G, int B);
+SDL_Colour UintToColour(Uint32 colour);
+#endif //LETTERGAME_SDLHELPERS_H
diff --git a/src/game.c b/src/game.c
index fbdefcd..cbade6f 100644
--- a/src/game.c
+++ b/src/game.c
@@ -1,33 +1,3 @@
-/*
- * Copyright (c) 2018, 2019 Amine Ben Hassouna
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any
- * person obtaining a copy of this software and associated
- * documentation files (the "Software"), to deal in the
- * Software without restriction, including without
- * limitation the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of
- * the Software, and to permit persons to whom the Software
- * is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice
- * shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
- * ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
- * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
- * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
#include "game.h"
bool Game_start(SDL_Renderer *renderer, int w, int h)
@@ -41,15 +11,15 @@ bool Game_start(SDL_Renderer *renderer, int w, int h)
grid.rect.h = grid.rect.w;
// Set grid backgroud
- grid.backgroundColor = COLOR_DARK_GRAY;
+ grid.backgroundColor = COLOR_LIGHT_GRAY;
// Set grid border thickness and color
- grid.border = 3;
- grid.borderColor = COLOR_GRAY;
+ grid.border = 1;
+ grid.borderColor = COLOR_BLACK;
// Set number of cells
- grid.xCells = 10;
- grid.yCells = 10;
+ grid.xCells = 15;
+ grid.yCells = 15;
// Set cells border thickness and color
grid.cellsBorder = grid.border;
@@ -71,12 +41,8 @@ bool Game_start(SDL_Renderer *renderer, int w, int h)
SDL_setFramerate(&fpsmanager, 30);
// Initialize start time (in ms)
- long long last = Utils_time();
+ // long long last = Utils_time();
- // Falling brick coordinates
- int fallingBrickX = grid.xCells / 2;
- int fallingBrickY = -1;
- int fallingBrickSpeed = 4;
// Event loop exit flag
@@ -103,63 +69,12 @@ bool Game_start(SDL_Renderer *renderer, int w, int h)
case SDLK_ESCAPE:
quit = true;
break;
-
- case SDLK_RIGHT:
- if(fallingBrickY != -1 && fallingBrickX < grid.xCells - 1)
- {
- // Un-color last position
- grid.cells[fallingBrickX][fallingBrickY].rectColor = grid.backgroundColor;
-
- // Color new position
- fallingBrickX++;
- grid.cells[fallingBrickX][fallingBrickY].rectColor = COLOR_RED;
- }
- break;
-
- case SDLK_LEFT:
- if(fallingBrickY != -1 && fallingBrickX > 0)
- {
- // Un-color last position
- grid.cells[fallingBrickX][fallingBrickY].rectColor = grid.backgroundColor;
-
- // Color new position
- fallingBrickX--;
- grid.cells[fallingBrickX][fallingBrickY].rectColor = COLOR_RED;
- }
- break;
}
}
}
// Move the falling brick
- if(Utils_time() - last >= 1000 / fallingBrickSpeed)
- {
- if(fallingBrickY >= 0)
- {
- // Un-color the falling brick last position
- grid.cells[fallingBrickX][fallingBrickY].rectColor = grid.backgroundColor;
- }
-
- if(fallingBrickY < grid.yCells - 1)
- {
- // Go to next position
- fallingBrickY++;
-
- // Color the falling brick new position
- grid.cells[fallingBrickX][fallingBrickY].rectColor = COLOR_RED;
- }
- else
- {
- // Reset position
- fallingBrickY = -1;
- }
-
- last = Utils_time();
- }
-
- // Set background color
- Utils_setBackgroundColor(renderer, COLOR_DARK_GRAY);
-
+ // if(Utils_time() - last >= 1000 / fallingBrickSpeed)
// Render grid
Grid_render(&grid, renderer);
diff --git a/src/grid.c b/src/grid.c
index 13bdd2e..8d3f1d4 100644
--- a/src/grid.c
+++ b/src/grid.c
@@ -112,6 +112,7 @@ void Grid_initCell(Grid *grid, Cell *cell, int i, int j, SDL_Color color, SDL_Co
cell->borderColor = borderColor;
}
+
void Grid_render(Grid *grid, SDL_Renderer *renderer)
{
if(grid->border != 0) // Grid border thickness different from 0
@@ -123,6 +124,13 @@ void Grid_render(Grid *grid, SDL_Renderer *renderer)
grid->borderColor.b,
grid->borderColor.a);
+ /* (renderer,
+ grid->rect.x,
+ grid->rect.y,
+ grid->rect.w,
+ grid->rect.h,
+ grid->borderRadius,
+ grid->border); */
// Render grid border
SDL_RenderFillRect(renderer, &(grid->rect));
}
@@ -149,7 +157,9 @@ void Grid_renderCell(Cell *cell, SDL_Renderer *renderer)
cell->borderColor.a);
// Render filled cell
- SDL_RenderFillRect(renderer, &(cell->border));
+ // SDL_RenderFillRect(renderer, &(cell->border));
+ SDH_fill_rounded_box_b(renderer->surface, cell->border.x, cell->border.y, cell->border.w, cell->border.h, 10.,
+ ColourToUint(cell->borderColor.r, cell->borderColor.g, cell->borderColor.b) );
}
// Set renderer color to cell color
@@ -161,4 +171,5 @@ void Grid_renderCell(Cell *cell, SDL_Renderer *renderer)
// Render filled cell
SDL_RenderFillRect(renderer, &(cell->rect));
+
}
diff --git a/src/letter.c b/src/letter.c
new file mode 100644
index 0000000..259345c
--- /dev/null
+++ b/src/letter.c
@@ -0,0 +1,3 @@
+#include "letter.h"
+
+
diff --git a/src/main.c b/src/main.c
index 3d87a6b..b2c28af 100644
--- a/src/main.c
+++ b/src/main.c
@@ -36,8 +36,8 @@
#include "game.h"
// Define screen dimensions
-#define SCREEN_WIDTH 800
-#define SCREEN_HEIGHT 600
+#define SCREEN_WIDTH 1024
+#define SCREEN_HEIGHT 768
int main(int argc, char* argv[])
{
diff --git a/src/sdlhelpers.c b/src/sdlhelpers.c
new file mode 100644
index 0000000..f5e7b14
--- /dev/null
+++ b/src/sdlhelpers.c
@@ -0,0 +1,82 @@
+//
+// Created by hamo on 11/25/22.
+//
+
+#include "sdlhelpers.h"
+
+
+int
+SDH_fill_rounded_box_b( SDL_Surface* dst, int xo, int yo,
+ int w, int h, int r, Uint32 color ) {
+ int yd = dst->pitch / dst->format->BytesPerPixel;
+ Uint32* pixels = NULL;
+
+ int x,y,i,j;
+ int rpsqrt2 = (int) (r / sqrt( 2 ) );
+ double r2 = r*r;
+
+ w /= 2;
+ h /= 2;
+
+ xo += w;
+ yo += h;
+
+ w -= r;
+ h -= r;
+
+ if( w < 0 || h < 0 )
+ return 0;
+
+ SDL_LockSurface( dst );
+ pixels = (Uint32*)( dst->pixels );
+
+ int sy = (yo-h)*yd;
+ int ey = (yo+h)*yd;
+ int sx = (xo-w);
+ int ex = (xo+w);
+ for( i = sy; i<=ey; i+=yd )
+ for( j = sx-r; j<=ex+r; j++ )
+ pixels[i+j] = color;
+
+ int d = -r;
+ int x2m1 = -1;
+ y = r;
+ for( x=0; x <= rpsqrt2; x++ ) {
+ x2m1 += 2;
+ d+= x2m1;
+ if( d >= 0 ) {
+ y–;
+ d -= (y*2);
+ }
+
+ for( i=sx-x; i<=ex+x; i++ )
+ pixels[sy-y*yd + i] = color;
+
+ for( i=sx-y; i<=ex+y; i++ )
+ pixels[sy-x*yd + i] = color;
+
+ for( i=sx-y; i<=ex+y; i++ )
+ pixels[ey+x*yd + i] = color;
+
+ for( i=sx-x; i<=ex+x; i++ )
+ pixels[ey+y*yd + i] = color;
+
+ }
+ SDL_UnlockSurface( dst );
+ return 1;
+}
+
+Uint32 ColourToUint(int R, int G, int B)
+{
+ return (Uint32)((R << 16) + (G << 8) + (B << 0));
+}
+
+SDL_Colour UintToColour(Uint32 colour)
+{
+ SDL_Colour tempcol;
+ tempcol.a = 255;
+ tempcol.r = (colour >> 16) & 0xFF;
+ tempcol.g = (colour >> 8) & 0xFF;
+ tempcol.b = colour & 0xFF;
+ return tempcol;
+}
\ No newline at end of file