Extract the planes from the structure game

This commit is contained in:
Shadow15510 2021-06-03 17:20:32 +02:00
parent 2e869371c7
commit a807356317
8 changed files with 54 additions and 57 deletions

Binary file not shown.

View File

@ -9,39 +9,39 @@
#include "display_engine.h"
void next_frame(struct game *current_game)
void next_frame(struct game *current_game, struct plane *planes[NB_PLANES + 1])
{
for (int i = 0; current_game->planes[i]; i++)
for (int i = 0; planes[i]; i++)
{
switch(current_game->planes[i]->direction)
switch(planes[i]->direction)
{
case 1:
current_game->planes[i]->y -= 1;
planes[i]->y -= 1;
break;
case 2:
current_game->planes[i]->x += 1;
planes[i]->x += 1;
break;
case 3:
current_game->planes[i]->y += 1;
planes[i]->y += 1;
break;
case 4:
current_game->planes[i]->x -= 1;
planes[i]->x -= 1;
break;
}
if (current_game->planes[i]->x == current_game->planes[i]->dest_x && current_game->planes[i]->y == current_game->planes[i]->dest_y)
if (planes[i]->x == planes[i]->dest_x && planes[i]->y == planes[i]->dest_y)
{
// Set the new destination
current_game->planes[i]->dest_x = current_game->planes[i]->depa_x;
current_game->planes[i]->dest_y = current_game->planes[i]->depa_y;
planes[i]->dest_x = planes[i]->depa_x;
planes[i]->dest_y = planes[i]->depa_y;
// Set the new departure
current_game->planes[i]->depa_x = current_game->planes[i]->x;
current_game->planes[i]->depa_y = current_game->planes[i]->y;
planes[i]->depa_x = planes[i]->x;
planes[i]->depa_y = planes[i]->y;
// Set the new direction
int new_dir = (current_game->planes[i]->direction + 2) % 4;
int new_dir = (planes[i]->direction + 2) % 4;
if (!new_dir) new_dir = 4;
current_game->planes[i]->direction = new_dir;
planes[i]->direction = new_dir;
}
}

View File

@ -46,9 +46,6 @@ struct game
// Time
int time, total_time;
// Planes
struct plane *planes[NB_PLANES + 1];
// Grid for epidemologic model
struct grid grid;
};
@ -83,8 +80,8 @@ struct cursor
// get_inputs : detect and manage inputs
int get_inputs(const int background, int *mutation_menu);
// next_frame : compute the plane's positions
void next_frame(struct game *current_game);
// next_frame : update all the game
void next_frame(struct game *current_game, struct plane *planes[NB_PLANES + 1]);
// rtc_key : get the key with RTC system
int rtc_key(void);

View File

@ -4,17 +4,17 @@
// (contation, severity, lethality, DNA cost, change to cure requirement)
const struct mutation symptoms_data[14] =
{
{15, 10, 0, 2, 0, "NAUSEE"},
{25, 10, 0, 4, 0, "VOMISSEMENT"},
{10, 10, 0, 2, 0, "NAUSEE"},
{25, 10, 0, 10, 0, "VOMISSEMENT"},
{20, 10, 0, 3, 0, "TOUX"},
{15, 20, 0, 4, 0, "PNEUMONIE"},
{15, 20, 0, 10, 0, "PNEUMONIE"},
{10, 30, 20, 15, 25, "TUMEUR"},
{25, 10, 0, 4, 0, "PLAIES"},
{10, 10, 0, 10, 0, "LESIONS"},
{30, 20, 20, 20, 30, "HEMORRAGIE"},
{25, 15, 10, 17, 0, "INFECTION"},
{15, 10, 10, 5, 0, "INFLAMMATION"},
{10, 15, 20, 12, 0, "IMMUNITE"},
{25, 10, 20, 20, 0, "INFLAMMATION"},
{10, 15, 20, 15, 0, "IMMUNITE"},
{ 0, 20, 0, 15, 120, "PARANOIA"},
{ 0, 15, 0, 20, 100, "FOLIE"},
{ 0, 30, 30, 30, 250, "ARRET TOTAL"},
@ -25,8 +25,8 @@ const struct mutation abilities_data[6] =
{
{15, 0, 0, 10, 0, "FROID"},
{15, 0, 0, 15, 0, "CHAUD"},
{ 0, 20, 4, 25, 20, "GENETIQUE"},
{10, 40, 8, 30, 50, "MUTATION+"},
{ 0, 10, 4, 25, 20, "GENETIQUE"},
{10, 40, 20, 30, 50, "MUTATION+"},
{30, 0, 0, 30, 0, "ENVIRON"},
{ 0, 15, 30, 15, 30, "MEDICAMENT"},
};

View File

@ -12,7 +12,7 @@ void display_background(const int background)
}
void display_foreground(const int background, const struct game *current_game)
void display_foreground(const int background, const struct game *current_game, struct plane *planes[NB_PLANES + 1])
{
extern const bopti_image_t img_mutations;
extern const bopti_image_t img_planes;
@ -34,9 +34,9 @@ void display_foreground(const int background, const struct game *current_game)
}
// Planes animations
for (int i = 0; current_game->planes[i]; i++)
for (int i = 0; planes[i]; i++)
{
dsubimage(current_game->planes[i]->x - 4, current_game->planes[i]->y - 4, &img_planes, 0, 8 * (current_game->planes[i]->direction - 1), 8, 8, DIMAGE_NONE);
dsubimage(planes[i]->x - 4, planes[i]->y - 4, &img_planes, 0, 8 * (planes[i]->direction - 1), 8, 8, DIMAGE_NONE);
}
break;
@ -52,9 +52,9 @@ void display_foreground(const int background, const struct game *current_game)
}
// Planes animations
for (int i = 0; current_game->planes[i]; i++)
for (int i = 0; planes[i]; i++)
{
if (current_game->planes[i]->y + 8 < 57) dsubimage(current_game->planes[i]->x - 4, current_game->planes[i]->y - 4, &img_planes, 0, 8 * (current_game->planes[i]->direction - 1), 8, 8, DIMAGE_NONE);
if (planes[i]->y + 8 < 57) dsubimage(planes[i]->x - 4, planes[i]->y - 4, &img_planes, 0, 8 * (planes[i]->direction - 1), 8, 8, DIMAGE_NONE);
}
// Status bottom bar

View File

@ -7,7 +7,7 @@
void display_background(const int background);
// display_foreground : display the foreground, planes, statistics
void display_foreground(const int background, const struct game *current_game);
void display_foreground(const int background, const struct game *current_game, struct plane *planes[NB_PLANES + 1]);
// display_mutation : display the mutation selection screen
void display_mutation(const int table[4][8], const struct cursor c, const int mutation_menu);

View File

@ -24,7 +24,7 @@ static void title_screen(void);
// main_loop : display background, foreground and manage inputs
void main_loop(struct game *current_game);
void main_loop(struct game *current_game, struct plane *planes[NB_PLANES + 1]);
int main(void)
@ -35,13 +35,6 @@ int main(void)
title_screen();
// Game statistics
struct plane plane_1 = {22, 20, 2, 84, 20, 22, 20};
struct plane plane_2 = {34, 20, 3, 34, 44, 34, 20};
struct plane plane_3 = {68, 44, 1, 68, 20, 68, 44};
struct plane plane_4 = {104, 20, 3, 104, 50, 104, 20};
struct plane plane_5 = {68, 44, 4, 34, 44, 68, 44};
struct game current_game =
{
.contagion = 0,
@ -61,24 +54,31 @@ int main(void)
.time = 0, .total_time = 0,
.planes = {&plane_1, &plane_2, &plane_3, &plane_4, &plane_5, NULL},
.grid = {64, 128, NULL},
};
/* allocate memory */
// Allocate memory
current_game.grid.data = calloc(current_game.grid.width * current_game.grid.height, sizeof(uint8_t));
read_save(&current_game);
current_game.grid.data[95 + 20 * current_game.grid.width] = 1;
current_game.humans[0] = (current_game.grid.width * current_game.grid.height) - 1;
main_loop(&current_game);
// Planes generation
struct plane plane_1 = {22, 20, 2, 84, 20, 22, 20};
struct plane plane_2 = {34, 20, 3, 34, 44, 34, 20};
struct plane plane_3 = {68, 44, 1, 68, 20, 68, 44};
struct plane plane_4 = {104, 20, 3, 104, 50, 104, 20};
struct plane plane_5 = {68, 44, 4, 34, 44, 68, 44};
struct plane *planes[NB_PLANES + 1] = {&plane_1, &plane_2, &plane_3, &plane_4, &plane_5, NULL};
read_save(&current_game);
main_loop(&current_game, planes);
write_save(&current_game);
/* free memory */
// Free memory
free(current_game.grid.data);
return 1;
@ -128,7 +128,7 @@ static void title_screen(void)
}
void main_loop(struct game *current_game)
void main_loop(struct game *current_game, struct plane *planes[NB_PLANES + 1])
{
int background = 1, mutation_menu = 0;
int end = 0;
@ -146,11 +146,11 @@ void main_loop(struct game *current_game)
// Update the screen
dclear(C_WHITE);
display_background(background);
display_foreground(background, current_game);
display_foreground(background, current_game, planes);
dupdate();
// Compute the motion of planes, DNA points and infectious model
next_frame(current_game);
next_frame(current_game, planes);
// Get inputs from the keyboard and manage it
background = get_inputs(background, &mutation_menu);

View File

@ -15,7 +15,7 @@ void read_save(struct game *current_game)
uint16_t foundpath[30];
// Sizes of data
const int data_size = current_game->grid.width * current_game->grid.height;
const int data_size = sizeof(*current_game->grid.data);
uint8_t *data = current_game->grid.data;
// Check if the savefile exists
@ -25,15 +25,15 @@ void read_save(struct game *current_game)
// If file doesn't exists
if (checkfile == -1)
{
int size = sizeof(current_game) + data_size;
int size = sizeof(*current_game) + data_size;
BFile_Create(filename, BFile_File, &size);
}
// Loading of the game data
else
{
fd = BFile_Open(filename, BFile_ReadOnly);
BFile_Read(fd, current_game, sizeof(current_game), 0);
BFile_Read(fd, current_game, sizeof(*current_game), 0);
BFile_Read(fd, data, data_size, -1);
BFile_Close(fd);
current_game->grid.data = data;
@ -47,14 +47,14 @@ void write_save(const struct game *current_game)
int fd = BFile_Open(filename, BFile_WriteOnly);
// Create a new savefile
const int data_size = current_game->grid.width * current_game->grid.height;
int size = sizeof(current_game) + data_size;
const int data_size = sizeof(*current_game->grid.data);
int size = sizeof(*current_game) + data_size;
BFile_Remove(filename);
BFile_Create(filename, BFile_File, &size);
// Write data
BFile_Write(fd, current_game, sizeof(current_game));
BFile_Write(fd, current_game, sizeof(*current_game));
BFile_Write(fd, current_game->grid.data, data_size);
// Close file