Fully fonctionnal game (thanks Sensei~ ♥)
This commit is contained in:
parent
c57a6f97ae
commit
329743fb32
BIN
Plague.g1a
BIN
Plague.g1a
Binary file not shown.
|
@ -58,7 +58,7 @@ const struct mutation default_value = {0, 0, 0, 0, 0, "NONE"};
|
|||
2: temperate
|
||||
3: hot
|
||||
*/
|
||||
const unsigned int world[64][128] =
|
||||
const uint8_t world[64][128] =
|
||||
{
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
void display_background(const int background)
|
||||
{
|
||||
extern const bopti_image_t img_bground;
|
||||
if (background != 6) dsubimage(0, 0, &img_bground, 0, 65 * (background - 1), 128, 64, DIMAGE_NONE);
|
||||
dsubimage(0, 0, &img_bground, 0, 65 * (background - 1), 128, 64, DIMAGE_NONE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,7 +16,7 @@ void display_foreground(const int background, const struct game *current_game)
|
|||
{
|
||||
extern const bopti_image_t img_mutations;
|
||||
extern const bopti_image_t img_planes;
|
||||
extern const unsigned int world[64][128];
|
||||
extern const uint8_t world[64][128];
|
||||
|
||||
GUNUSED int length;
|
||||
|
||||
|
@ -29,7 +29,7 @@ void display_foreground(const int background, const struct game *current_game)
|
|||
{
|
||||
for (int j = 0; j < current_game->grid.height; j ++)
|
||||
{
|
||||
if (current_game->grid.data[i + j * current_game->grid.width] == 1 && world[i][j] != 0) dpixel(i, j, C_BLACK);
|
||||
if (current_game->grid.data[i + j * current_game->grid.width] == 1 && world[j][i] != 0) dpixel(i, j, C_BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,9 +45,9 @@ void display_foreground(const int background, const struct game *current_game)
|
|||
// Disease propagation
|
||||
for (int i = 0; i < current_game->grid.width; i ++)
|
||||
{
|
||||
for (int j = 0; j < 50; j ++)
|
||||
for (int j = 0; j < 48; j ++)
|
||||
{
|
||||
if (current_game->grid.data[i + j * current_game->grid.width] == 1 && world[i][j] != 0) dpixel(i, j, C_BLACK);
|
||||
if (current_game->grid.data[i + j * current_game->grid.width] == 1 && world[j][i] != 0) dpixel(i, j, C_BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,11 +88,9 @@ void display_foreground(const int background, const struct game *current_game)
|
|||
case 6:
|
||||
for (int i = 0; i < 4; i ++)
|
||||
{
|
||||
// length = 63 * current_game->humans[i] / (current_game->grid.width * current_game->grid.height);
|
||||
// dline(61, i*8 + 31, 61 + length, i*8 + 31, C_BLACK);
|
||||
// dline(61, i*8 + 32, 61 + length, i*8 + 32, C_BLACK);
|
||||
dprint(61, i*8 + 31, C_BLACK, "%d", current_game->humans[i]);
|
||||
|
||||
length = 63 * current_game->humans[i] / (current_game->grid.width * current_game->grid.height);
|
||||
dline(61, i*8 + 31, 61 + length, i*8 + 31, C_BLACK);
|
||||
dline(61, i*8 + 32, 61 + length, i*8 + 32, C_BLACK);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <gint/std/stdlib.h>
|
||||
|
||||
#include "epidemic_engine.h"
|
||||
|
||||
|
||||
|
@ -11,12 +12,12 @@ int grid_get(const struct grid epidemic_grid, const int i, const int j)
|
|||
|
||||
bool can_become_infected(const struct grid epidemic_grid, const int mutations_selected[3], const int i, const int j)
|
||||
{
|
||||
extern const unsigned int world[64][128];
|
||||
extern const uint8_t world[64][128];
|
||||
|
||||
// In case of water, low or high temperature
|
||||
/*if (world[j][i] == 0 && mutations_selected[2] != 3) return false;
|
||||
if (world[j][i] == 0 && mutations_selected[2] != 3) return false;
|
||||
if (world[j][i] == 1 && mutations_selected[1] != 0 && mutations_selected[1] != 4) return false;
|
||||
if (world[j][i] == 3 && mutations_selected[1] != 1 && mutations_selected[1] != 4) return false;*/
|
||||
if (world[j][i] == 3 && mutations_selected[1] != 1 && mutations_selected[1] != 4) return false;
|
||||
|
||||
// Test cases around
|
||||
return grid_get(epidemic_grid, i - 1, j) == 1 || grid_get(epidemic_grid, i + 1, j) == 1 || grid_get(epidemic_grid, i, j - 1) == 1 || grid_get(epidemic_grid, i, j + 1) == 1;
|
||||
|
@ -25,7 +26,7 @@ bool can_become_infected(const struct grid epidemic_grid, const int mutations_se
|
|||
|
||||
bool bernoulli(const int p)
|
||||
{
|
||||
return (rand() % 101) <= p;
|
||||
return (rand() % 101) < p;
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,15 +34,17 @@ void epidemic_simulation(struct game *current_game)
|
|||
{
|
||||
srand(15510);
|
||||
|
||||
// Create a copy of the epidemic grid
|
||||
uint8_t *current_grid = calloc(current_game->grid.width * current_game->grid.height, sizeof(uint8_t));
|
||||
init_tab(current_game->grid.width * current_game->grid.height, current_grid, current_game->grid.data);
|
||||
|
||||
int healed_rate = 100 * (current_game->research / current_game->limit);
|
||||
|
||||
// Make the epidemic grid evolove
|
||||
for (int i = 0; i < current_game->grid.width; i ++)
|
||||
{
|
||||
for (int j = 0; j < current_game->grid.height; j ++)
|
||||
{
|
||||
current_game->grid.data[i + j * current_game->grid.width] = 1;
|
||||
|
||||
/*
|
||||
switch (current_game->grid.data[i + j * current_game->grid.width])
|
||||
{
|
||||
// Healthy
|
||||
|
@ -50,7 +53,7 @@ void epidemic_simulation(struct game *current_game)
|
|||
// Become infected
|
||||
if (can_become_infected(current_game->grid, current_game->mutations_selected, i, j) && bernoulli(current_game->contagion))
|
||||
{
|
||||
current_game->grid.data[i + j * current_game->grid.width] = 1;
|
||||
current_grid[i + j * current_game->grid.width] = 1;
|
||||
current_game->humans[0] --;
|
||||
current_game->humans[1] ++;
|
||||
}
|
||||
|
@ -62,7 +65,7 @@ void epidemic_simulation(struct game *current_game)
|
|||
// Become healed
|
||||
if (bernoulli(healed_rate))
|
||||
{
|
||||
current_game->grid.data[i + j * current_game->grid.width] = 2;
|
||||
current_grid[i + j * current_game->grid.width] = 2;
|
||||
current_game->humans[1] --;
|
||||
current_game->humans[2] ++;
|
||||
}
|
||||
|
@ -70,13 +73,24 @@ void epidemic_simulation(struct game *current_game)
|
|||
// Become dead
|
||||
else if (bernoulli(current_game->lethality))
|
||||
{
|
||||
current_game->grid.data[i + j * current_game->grid.width] = 3;
|
||||
current_grid[i + j * current_game->grid.width] = 3;
|
||||
current_game->humans[1] --;
|
||||
current_game->humans[3] ++;
|
||||
}
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
init_tab(current_game->grid.width * current_game->grid.height, current_game->grid.data, current_grid);
|
||||
free(current_grid);
|
||||
}
|
||||
|
||||
|
||||
void init_tab(int x, uint8_t dest[x], uint8_t src[x])
|
||||
{
|
||||
for (int i = 0; i < x; i++)
|
||||
{
|
||||
dest[i] = src[i];
|
||||
}
|
||||
}
|
|
@ -15,4 +15,7 @@ bool bernoulli(const int p);
|
|||
// epidemic_simulation : simulate the propagation of the virus
|
||||
void epidemic_simulation(struct game *current_game);
|
||||
|
||||
// init_tab : copy src into dest (for int)
|
||||
void init_tab(int x, uint8_t dest[x], uint8_t src[x]);
|
||||
|
||||
#endif /* _EPIDEMIC_ENGINE_H */
|
Loading…
Reference in New Issue