Cancel precend commit

This commit is contained in:
Shadow15510 2021-06-03 17:25:45 +02:00
parent a807356317
commit 0d06b95554
7 changed files with 38 additions and 39 deletions

Binary file not shown.

View File

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

View File

@ -80,8 +80,8 @@ struct cursor
// get_inputs : detect and manage inputs
int get_inputs(const int background, int *mutation_menu);
// next_frame : update all the game
void next_frame(struct game *current_game, struct plane *planes[NB_PLANES + 1]);
// next_frame : compute the plane's positions
void next_frame(struct game *current_game);
// rtc_key : get the key with RTC system
int rtc_key(void);

View File

@ -12,7 +12,7 @@ void display_background(const int background)
}
void display_foreground(const int background, const struct game *current_game, struct plane *planes[NB_PLANES + 1])
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;
@ -34,9 +34,9 @@ void display_foreground(const int background, const struct game *current_game, s
}
// Planes animations
for (int i = 0; planes[i]; i++)
for (int i = 0; current_game->planes[i]; i++)
{
dsubimage(planes[i]->x - 4, planes[i]->y - 4, &img_planes, 0, 8 * (planes[i]->direction - 1), 8, 8, DIMAGE_NONE);
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);
}
break;
@ -52,9 +52,9 @@ void display_foreground(const int background, const struct game *current_game, s
}
// Planes animations
for (int i = 0; planes[i]; i++)
for (int i = 0; current_game->planes[i]; i++)
{
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);
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);
}
// 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, struct plane *planes[NB_PLANES + 1]);
void display_foreground(const int background, const struct game *current_game);
// 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, struct plane *planes[NB_PLANES + 1]);
void main_loop(struct game *current_game);
int main(void)
@ -35,6 +35,13 @@ 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,
@ -54,6 +61,8 @@ int main(void)
.time = 0, .total_time = 0,
.planes = {&plane_1, &plane_2, &plane_3, &plane_4, &plane_5, NULL},
.grid = {64, 128, NULL},
};
@ -63,18 +72,9 @@ int main(void)
current_game.grid.data[95 + 20 * current_game.grid.width] = 1;
current_game.humans[0] = (current_game.grid.width * current_game.grid.height) - 1;
// 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);
main_loop(&current_game);
write_save(&current_game);
@ -128,7 +128,7 @@ static void title_screen(void)
}
void main_loop(struct game *current_game, struct plane *planes[NB_PLANES + 1])
void main_loop(struct game *current_game)
{
int background = 1, mutation_menu = 0;
int end = 0;
@ -146,11 +146,11 @@ void main_loop(struct game *current_game, struct plane *planes[NB_PLANES + 1])
// Update the screen
dclear(C_WHITE);
display_background(background);
display_foreground(background, current_game, planes);
display_foreground(background, current_game);
dupdate();
// Compute the motion of planes, DNA points and infectious model
next_frame(current_game, planes);
next_frame(current_game);
// Get inputs from the keyboard and manage it
background = get_inputs(background, &mutation_menu);

View File

@ -7,7 +7,6 @@
// Name of the savefile
static const uint16_t *filename = u"\\\\fls0\\Plague.sav";
void read_save(struct game *current_game)
{
struct BFile_FileInfo fileInfo;
@ -15,7 +14,7 @@ void read_save(struct game *current_game)
uint16_t foundpath[30];
// Sizes of data
const int data_size = sizeof(*current_game->grid.data);
const int data_size = current_game->grid.width * current_game->grid.height;
uint8_t *data = current_game->grid.data;
// Check if the savefile exists
@ -47,7 +46,7 @@ void write_save(const struct game *current_game)
int fd = BFile_Open(filename, BFile_WriteOnly);
// Create a new savefile
const int data_size = sizeof(*current_game->grid.data);
const int data_size = current_game->grid.width * current_game->grid.height;
int size = sizeof(*current_game) + data_size;
BFile_Remove(filename);