about summary refs log tree commit diff
path: root/src/simulator
diff options
context:
space:
mode:
Diffstat (limited to 'src/simulator')
-rw-r--r--src/simulator/main.c17
-rw-r--r--src/simulator/rendering.c20
2 files changed, 20 insertions, 17 deletions
diff --git a/src/simulator/main.c b/src/simulator/main.c
index 5c875fe..45b2420 100644
--- a/src/simulator/main.c
+++ b/src/simulator/main.c
@@ -3,7 +3,6 @@
 #include <assert.h>
 #include <SDL2/SDL.h>
 
-#include "SDL_events.h"
 #include "./rendering.h"
 #include "../game.h"
 
@@ -37,10 +36,6 @@ int main(int argc, char *argv[]) {
     load_game(input_filepath, &games[current]);
   }
 
-
-
-
-
   //print_chromo(stdout, game.chromos);
 
   scc(SDL_Init(SDL_INIT_VIDEO));
@@ -118,6 +113,18 @@ int main(int argc, char *argv[]) {
     // Render Agents
     render_game(renderer, &games[current]);
 
+    //TODO: Zoom
+
+    //SDL_Rect rect_a = {
+    //  0, 0,
+    //  SCREEN_WIDTH, SCREEN_HEIGHT
+    //};
+
+
+    //char a[10];
+    //a[10] = 0;
+
+    //SDL_RenderCopy(renderer, NULL, &rect_a, &rect_b);
     // Render
     SDL_RenderPresent(renderer);
 
diff --git a/src/simulator/rendering.c b/src/simulator/rendering.c
index 05a93f4..f94700b 100644
--- a/src/simulator/rendering.c
+++ b/src/simulator/rendering.c
@@ -1,5 +1,4 @@
 #include "rendering.h"
-#include "SDL_stdinc.h"
 #include "../game.h"
 
 #include <SDL2/SDL.h>
@@ -161,34 +160,31 @@ void render_agent(SDL_Renderer *renderer, Agent agent) {
 }
 
 void render_game(SDL_Renderer *renderer, const Game *game) {
-  for (size_t i = 0; i < AGENTS_COUNT; ++i) {
-    render_agent(renderer, game->agents[i]);
-  }
 
   // Render Foods
   const int indices[] = {0, 1, 2, 0, 3, 2};
   for(int y = 0; y < BOARD_HEIGHT; ++y) {
     for (int x = 0; x < BOARD_WIDTH; ++x) {
-      if (game->foods_map[y][x]) {
+      int env = game->env_map[y][x];
+      if (env == ENV_MAP_FOOD) {
         SDL_Vertex *vertices = sdl_draw_food_diamond(y, x);
         scc(SDL_RenderGeometry(renderer, NULL, vertices, 4, indices, 6));
         free(vertices); // sdl_draw_food_diamond's malloc
       }
 
-      if (game->walls_map[y][x]) {
+      if (game->env_map[y][x] == ENV_MAP_WALL) {
         SDL_Rect rect = {// Check why int floorf
                          (int)floorf(x * CELL_WIDTH),
                          (int)floorf(y * CELL_HEIGHT),
                          (int)floorf(CELL_WIDTH), (int)floorf(CELL_HEIGHT)};
         SDL_SetRenderDrawColor(renderer, HEX_COLOR(WALL_COLOR));
         SDL_RenderFillRect(renderer, &rect);
+      } else if(env >= ENV_MAP_AGENTS) {
+        int agent_index = env - ENV_MAP_AGENTS;
+        if (game->agents[agent_index].health > 0) {
+          render_agent(renderer, game->agents[agent_index]);
+        }
       }
     }
   }
-
-  // Render Walls
-  for (size_t i = 0; i < WALLS_COUNT; ++i) {
-
-  }
-
 }