Animated DNA in main screen

This commit is contained in:
Shadow15510 2021-06-05 14:39:48 +02:00
parent c13439cd6b
commit 6e2fae8649
9 changed files with 29 additions and 21 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 808 B

View File

@ -9,7 +9,7 @@
#include "display_engine.h"
int next_frame(struct game *current_game)
int next_frame(struct game *current_game, int *dna_animation)
{
for (int i = 0; current_game->planes[i]; i++)
{
@ -54,9 +54,12 @@ int next_frame(struct game *current_game)
int limit_tick = LIMIT_TICK;
if (current_game->boost) limit_tick = floor(LIMIT_TICK / 10);
current_game->time += ENGINE_TICK;
current_game->total_time += ENGINE_TICK;
if (!(current_game->time % 150)) *dna_animation = (*dna_animation + 1) % 16;
if (current_game->time > limit_tick)
{
// Reset internal clock
@ -158,7 +161,7 @@ void message(char *msg)
{
display_message(msg);
int key = 0, frame = 1;
int key = 0, frame = 0;
static volatile int tick = 1;
int t = timer_configure(TIMER_ANY, DNA_ANIMATION_TICK*1000, GINT_CALL(callback_tick, &tick));
@ -172,8 +175,7 @@ void message(char *msg)
key = rtc_key();
display_dna_animation(frame);
frame = (frame + 1) % 24;
if (!frame) frame = 24;
frame = (frame + 1) % 16;
}
if (t >= 0) timer_stop(t);

View File

@ -90,7 +90,7 @@ struct cursor
int get_inputs(const int background, int *mutation_menu, int *boost);
// next_frame : compute the plane's positions
int next_frame(struct game *current_game);
int next_frame(struct game *current_game, int *dna_animation);
// rtc_key : get the key with RTC system
int rtc_key(void);

View File

@ -12,10 +12,11 @@ void display_background(const int background)
}
void display_foreground(const int background, const struct game *current_game, const int mutation_menu)
void display_foreground(const int background, const struct game *current_game, const int mutation_menu, const int dna_animation)
{
extern const bopti_image_t img_mutations;
extern const bopti_image_t img_planes;
extern const bopti_image_t img_dna;
extern const uint8_t world[64][128];
GUNUSED int length;
@ -57,6 +58,9 @@ void display_foreground(const int background, const struct game *current_game, c
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);
}
// Animated DNA
dsubimage(1, 51, &img_dna, dna_animation * 8, 0, 7, 12, DIMAGE_NONE);
// Status bottom bar
int length = 73 * current_game->research / current_game->limit;
dprint(9, 58, C_BLACK, "%d", current_game->dna);
@ -196,9 +200,10 @@ void display_message(char *msg)
void display_dna_animation(const int frame)
{
extern bopti_image_t img_dna;
extern const bopti_image_t img_dna;
dsubimage(114, 29, &img_dna, 11 * (frame - 1), 0, 11, 32, DIMAGE_NONE);
dsubimage(2, 3, &img_dna, 8 * frame, 0, 7, 12, DIMAGE_NONE);
dsubimage(42, 3, &img_dna, 8 * ((frame + 2) % 16), 0, 7, 12, DIMAGE_NONE);
dupdate();
}

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, const int mutation_menu);
void display_foreground(const int background, const struct game *current_game, const int mutation_menu, const int dna_animation);
// 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

@ -42,7 +42,7 @@ void epidemic_simulation(struct game *current_game)
init_tab(current_game->grid.width * current_game->grid.height, current_grid, current_game->grid.data);
int healed_rate = 0;
if (current_game->research == current_game->limit) healed_rate = rand() % 26;
if (current_game->research == current_game->limit) healed_rate = rand() % 11;
// Make the epidemic grid evolove
for (int i = 0; i < current_game->grid.width; i ++)
@ -97,6 +97,12 @@ void epidemic_simulation(struct game *current_game)
}
init_tab(current_game->grid.width * current_game->grid.height, current_game->grid.data, current_grid);
free(current_grid);
for (int i = 0; i < 4; i ++)
{
if (current_game->humans[i] < 0) current_game->humans[i] = 0;
else if (current_game->humans[i] > (current_game->grid.width * current_game->grid.height) - BLANK_CASES) current_game->humans[i] = (current_game->grid.width * current_game->grid.height) - BLANK_CASES;
}
}

View File

@ -97,14 +97,9 @@ static void title_screen(void)
dupdate();
sleep_ms(250);
for (int i = 64; i > 32; i --)
{
dclear(C_BLACK);
dsubimage(0, 0, &img_title, 0, 0, 128, 64, DIMAGE_NONE);
dprint_opt(16, i, C_WHITE, C_BLACK, 0, 0, "VERSION %s", VERSION, -1);
dupdate();
sleep_ms(75);
}
dsubimage(0, 0, &img_title, 0, 0, 128, 64, DIMAGE_NONE);
dprint_opt(32, 29, C_WHITE, C_BLACK, 0, 0, "VERSION %s", VERSION, -1);
dupdate();
sleep_ms(1000);
@ -141,7 +136,7 @@ static void title_screen(void)
int main_loop(struct game *current_game)
{
int background = 1, mutation_menu = 4;
int end = 0, to_save = 1;
int end = 0, to_save = 1, dna_animation = 0;
static volatile int tick = 1;
int t = timer_configure(TIMER_ANY, ENGINE_TICK*1000, GINT_CALL(callback_tick, &tick));
@ -156,11 +151,11 @@ int main_loop(struct game *current_game)
// Update the screen
dclear(C_WHITE);
display_background(background);
display_foreground(background, current_game, mutation_menu);
display_foreground(background, current_game, mutation_menu, dna_animation);
dupdate();
// Compute the motion of planes, DNA points and infectious model
to_save = next_frame(current_game);
to_save = next_frame(current_game, &dna_animation);
if (!to_save) end = 1;
// Get inputs from the keyboard and manage it