Added a seeding function to generate a 'random' board. There's clearly some logic bugs for cell status but its a start.
This commit is contained in:
+22
@@ -20,6 +20,7 @@ const int CELL_SIZE = 15;
|
|||||||
const int MAX_X = SCREEN_WIDTH / CELL_SIZE - 1;
|
const int MAX_X = SCREEN_WIDTH / CELL_SIZE - 1;
|
||||||
const int MAX_Y = SCREEN_HEIGHT / CELL_SIZE - 1;
|
const int MAX_Y = SCREEN_HEIGHT / CELL_SIZE - 1;
|
||||||
int Start = 0;
|
int Start = 0;
|
||||||
|
int RestartSim = 0;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SDL_Window *window;
|
SDL_Window *window;
|
||||||
@@ -41,6 +42,7 @@ void Cleanup(void);
|
|||||||
void HandleInput(void);
|
void HandleInput(void);
|
||||||
int GetIndex(int x, int y, int columns);
|
int GetIndex(int x, int y, int columns);
|
||||||
int GetNotSoRandomNumber(int);
|
int GetNotSoRandomNumber(int);
|
||||||
|
void Seed(void);
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
memset(&app, 0, sizeof(app));
|
memset(&app, 0, sizeof(app));
|
||||||
@@ -99,6 +101,12 @@ int main(int argc, char** argv) {
|
|||||||
// rect->y = 0;//MAX_Y * CELL_SIZE;
|
// rect->y = 0;//MAX_Y * CELL_SIZE;
|
||||||
// Cell* cell = CreateCell(*rect);
|
// Cell* cell = CreateCell(*rect);
|
||||||
|
|
||||||
|
Restart:
|
||||||
|
|
||||||
|
RestartSim = 0;
|
||||||
|
|
||||||
|
Seed();
|
||||||
|
|
||||||
while(!Start){
|
while(!Start){
|
||||||
HandleInput();
|
HandleInput();
|
||||||
|
|
||||||
@@ -128,6 +136,8 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
HandleInput();
|
HandleInput();
|
||||||
|
|
||||||
|
if (RestartSim) goto Restart;
|
||||||
|
|
||||||
SDL_Delay(128);
|
SDL_Delay(128);
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255);
|
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255);
|
||||||
@@ -196,6 +206,17 @@ int main(int argc, char** argv) {
|
|||||||
//free(cell);
|
//free(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Seed(){
|
||||||
|
for(int i = 0; i < GlobalList->capcity; i++) {
|
||||||
|
if (GlobalList->cells[i] == NULL) continue;
|
||||||
|
|
||||||
|
if (GetNotSoRandomNumber(100) % 3 != 0) continue;
|
||||||
|
|
||||||
|
Cell* cell = GlobalList->cells[i];
|
||||||
|
cell->Status = Alive;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Cleanup(void) {
|
void Cleanup(void) {
|
||||||
SDL_DestroyWindow(app.window);
|
SDL_DestroyWindow(app.window);
|
||||||
SDL_DestroyRenderer(app.renderer);
|
SDL_DestroyRenderer(app.renderer);
|
||||||
@@ -232,6 +253,7 @@ void HandleInput(void) {
|
|||||||
else Thing(event.button.x, event.button.y);
|
else Thing(event.button.x, event.button.y);
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
if (event.key.keysym.sym == SDLK_s) Start = 1;
|
if (event.key.keysym.sym == SDLK_s) Start = 1;
|
||||||
|
if (event.key.keysym.sym == SDLK_r) RestartSim = 1;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user