diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c2b79c..294350e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ set(ASSETS_fx assets-fx/mutations.png assets-fx/cursor.png assets-fx/title.png + assets-fx/dna.png assets-fx/mutations_table/abilities_1.txt assets-fx/mutations_table/abilities_2.txt assets-fx/mutations_table/abilities_3.txt diff --git a/Plague.g1a b/Plague.g1a index d5aba1d..aaaa1f4 100644 Binary files a/Plague.g1a and b/Plague.g1a differ diff --git a/assets-fx/bground.png b/assets-fx/bground.png index 2a727f5..3df997a 100644 Binary files a/assets-fx/bground.png and b/assets-fx/bground.png differ diff --git a/assets-fx/dna.png b/assets-fx/dna.png new file mode 100644 index 0000000..5d515bd Binary files /dev/null and b/assets-fx/dna.png differ diff --git a/assets-fx/mutations.png b/assets-fx/mutations.png index d6f671b..8ebacb6 100644 Binary files a/assets-fx/mutations.png and b/assets-fx/mutations.png differ diff --git a/src/core.c b/src/core.c index 7338ccb..d7f884c 100644 --- a/src/core.c +++ b/src/core.c @@ -43,9 +43,9 @@ void next_frame(struct game *current_game) } } current_game->time += ENGINE_TICK; - if (current_game->time > 10000) + if (current_game->time > LIMIT_TICK) { - current_game->dna += 1; + if (current_game->dna <= 100) current_game->dna += 1; current_game->time = 0; // Epidemic propagation simulation to add here @@ -120,3 +120,29 @@ int callback_tick(volatile int *tick) return TIMER_CONTINUE; } + +void message(const char *msg[5]) +{ + display_message(msg); + + int key = 0, frame = 1; + + static volatile int tick = 1; + int t = timer_configure(TIMER_ANY, DNA_ANIMATION_TICK*1000, GINT_CALL(callback_tick, &tick)); + if (t >= 0) timer_start(t); + + while (!key) + { + while(!tick) sleep(); + tick = 0; + + key = rtc_key(); + display_dna_animation(frame); + + frame = (frame + 1) % 24; + if (!frame) frame = 24; + } + + if (t >= 0) timer_stop(t); +} + diff --git a/src/core.h b/src/core.h index fdf14e5..d3eca8b 100644 --- a/src/core.h +++ b/src/core.h @@ -1,16 +1,17 @@ #ifndef _PLAGUE_CORE_H #define _PLAGUE_CORE_H -// Duration for internal clock +// Duration for internal clock (ms) #define ENGINE_TICK 50 -#define CURSOR_TICK 100 +#define CURSOR_TICK 150 +#define DNA_ANIMATION_TICK 150 + +// The duration for DNA points and infectious model (ms) +#define LIMIT_TICK 10000 // Number of planes on screen #define NB_PLANES 5 -// Number of humans -#define TOTAL_POP 10000000000 - // game : all statistics of the current game struct game { @@ -28,9 +29,6 @@ struct game // Research data int research, limit; - // Infectious pattern parameters - long long int healthy, infected, dead, cured; - // Time int time; @@ -77,4 +75,7 @@ int rtc_key(void); // callback_timer : basic timer int callback_tick(volatile int *tick); +// message : display a message +void message(const char *msg[5]); + #endif /* _PLAGUE_CORE_H */ \ No newline at end of file diff --git a/src/display_engine.c b/src/display_engine.c index b36070b..93379da 100644 --- a/src/display_engine.c +++ b/src/display_engine.c @@ -58,23 +58,7 @@ void display_foreground(const int background, const struct game *current_game) if (current_game->mutations_selected[2]) dsubimage(65, 15, &img_mutations, 32, 16 * (current_game->mutations_selected[2] - 1), 15, 15, 0); break; - case 6: - length = 63 * current_game->healthy/ TOTAL_POP; - dline(61, 31, 61 + length, 31, C_BLACK); - dline(61, 32, 61 + length, 32, C_BLACK); - - length = 63 * current_game->infected / TOTAL_POP; - dline(61, 39, 61 + length, 39, C_BLACK); - dline(61, 40, 61 + length, 40, C_BLACK); - - length = 63 * current_game->dead / TOTAL_POP; - dline(61, 47, 61 + length, 47, C_BLACK); - dline(61, 48, 61 + length, 48, C_BLACK); - - length = 63 * current_game->cured / TOTAL_POP; - dline(61, 55, 61 + length, 55, C_BLACK); - dline(61, 56, 61 + length, 56, C_BLACK); - break; + // case 6: statistics about humans } } @@ -124,10 +108,19 @@ void display_mutation_buy(const struct cursor c, const int mutation_menu, const } -void output_error(const char *msg) +void display_message(const char *msg[5]) { dclear(C_WHITE); - dprint(0, 0, C_BLACK, msg); + display_background(7); + for (int i = 0; i < 5; i ++) dprint(54, 6 * i + 4, C_BLACK, msg[i]); + dupdate(); +} + +void display_dna_animation(const int frame) +{ + extern bopti_image_t img_dna; + + dsubimage(114, 29, &img_dna, 11 * (frame - 1), 0, 11, 32, DIMAGE_NONE); dupdate(); } diff --git a/src/display_engine.h b/src/display_engine.h index 0ef9459..6942f3c 100644 --- a/src/display_engine.h +++ b/src/display_engine.h @@ -15,6 +15,10 @@ void display_mutation(const int table[4][8], const struct cursor c, const int mu // mutation_selected : display the mutation's informations screen void display_mutation_buy(const struct cursor c, const int mutation_menu, const int table[4][8], const int button_selected); -// output_error : display text -void output_error(const char *msg); +// output_error : display text and message background +void display_message(const char *msg[5]); + +// display_dna_animation : display the DNA according to the frame number +void display_dna_animation(const int frame); + #endif /* _PLAGUE_DISPLAY_ENGINE_H */ \ No newline at end of file diff --git a/src/main.c b/src/main.c index 6e4699b..2f9dbae 100644 --- a/src/main.c +++ b/src/main.c @@ -53,10 +53,6 @@ int main(void) .research = 0, .limit = 100, - .healthy = TOTAL_POP - 1, - .infected = 1, - .dead = 0, - .time = 0, .planes = {&plane_1, &plane_2, &plane_3, &plane_4, &plane_5, NULL} @@ -101,7 +97,7 @@ void main_loop(struct game *current_game) display_foreground(background, current_game); dupdate(); - // Compute the motion of planes + // Compute the motion of planes, DNA points and infectious model next_frame(current_game); // Get inputs from the keyboard and manage it diff --git a/src/mutation_engine.c b/src/mutation_engine.c index c534c93..ed14116 100644 --- a/src/mutation_engine.c +++ b/src/mutation_engine.c @@ -120,8 +120,10 @@ int mutation_buy(struct game *current_game, const struct cursor c, const int mut // Update update_disease(current_game); + const char *msg[5] = {"mutation", "achetee", "", "", ""}; + message(msg); } - else {output_error("Achat impossible"); getkey();} + else {const char *msg[5] = {"achat", "impossible", "", "", ""}; message(msg);} } // if the player has already bought this mutation @@ -129,6 +131,8 @@ int mutation_buy(struct game *current_game, const struct cursor c, const int mut { current_game->mutations_selected[mutation_menu - 1] = id; update_disease(current_game); + const char *msg[5] = {"mutation", "selectionnee"}; + message(msg); } }