diff --git a/Plague.g1a b/Plague.g1a index 7c5eeb7..88654ad 100644 Binary files a/Plague.g1a and b/Plague.g1a differ diff --git a/src/core.c b/src/core.c index b9554cb..d0496e3 100644 --- a/src/core.c +++ b/src/core.c @@ -113,62 +113,3 @@ int callback_tick(volatile int *tick) return TIMER_CONTINUE; } - -void manage_mutation(struct game *current_game, const int mutation_menu) -{ - int key = 0, end = 0; - struct cursor c = {0, 0, 0}; - - static volatile int tick = 1; - int t = timer_configure(TIMER_ANY, CURSOR_TICK*1000, GINT_CALL(callback_tick, &tick)); - if (t >= 0) timer_start(t); - - - while (!end) - { - // Cursor blinking gestion - while (!tick) sleep(); - tick = 0; - c.display = (c.display + 1) % 2; - - // Get and display the mutation menu - int table[4][8]; - get_mutation(current_game, mutation_menu, table); - display_mutation(table, c, mutation_menu); - - // Get the key - key = rtc_key(); - - // Manage input - if (key == KEY_EXIT) end = 1; - if (key == KEY_EXE && table[c.y][c.x] != 15 && table[c.y][c.x] != 0) mutation_buy(current_game, c, mutation_menu, table); - - if (key == KEY_LEFT && c.x > 0) c.x--; - if (key == KEY_RIGHT && c.x < 7) c.x++; - if (key == KEY_UP && c.y > 0) c.y--; - if (key == KEY_DOWN && c.y < 3) c.y++; - } - if (t >= 0) timer_stop(t); -} - - -void mutation_buy(struct game *current_game, const struct cursor c, const int mutation_menu, const int table[4][8]) -{ - int button_selected = 1, end = 0; - int key = 0; - - while (!end) - { - mutation_selected(c, mutation_menu, table, button_selected); - key = getkey().key; - - if (key == KEY_DOWN || key == KEY_UP) button_selected = (button_selected + 1) % 2; - if (key == KEY_EXIT) end = 1; - if (key == KEY_EXE) - { - if (!button_selected) end = 1; - // else evolution - } - - } -} diff --git a/src/core.h b/src/core.h index dc16d39..fdf14e5 100644 --- a/src/core.h +++ b/src/core.h @@ -20,9 +20,10 @@ struct game // DNA points int dna; - // Mutations counts and sprite selected - int abilities, symptoms, transmissions; - int abilities_sel, symptoms_sel, transmissions_sel; + // Mutations counts, mutations selected, mutations bought (symptoms; abilities; transmissions) + int mutations_count[3]; + int mutations_selected[3]; + int mutations_bought[3][14]; // Research data int research, limit; @@ -76,10 +77,4 @@ int rtc_key(void); // callback_timer : basic timer int callback_tick(volatile int *tick); -// manage_mutation : an independant sub-programm which allow to select and see the mutations. -void mutation_select(struct game *current_game, const int mutation_menu); - -// mutation_buy : UI interface to buy mutations and see informations on them -void mutation_buy(struct game *current_game, const struct cursor c, const int mutation_menu, const int table[4][8]); - #endif /* _PLAGUE_CORE_H */ \ No newline at end of file diff --git a/src/display_engine.c b/src/display_engine.c index 7280944..0e36e00 100644 --- a/src/display_engine.c +++ b/src/display_engine.c @@ -39,6 +39,9 @@ void display_foreground(const int background, const struct game *current_game) break; case 3: + + dprint(1, 35, C_BLACK, "C:%d S:%d L:%d", current_game->contagion, current_game->severity, current_game->lethality); + dprint(102, 37, C_BLACK, "%d", current_game->dna); length = 67 * current_game->contagion / 26; @@ -53,9 +56,9 @@ void display_foreground(const int background, const struct game *current_game) dline(57, 60, 57 + length, 60, C_BLACK); dline(57, 61, 57 + length, 61, C_BLACK); - if (current_game->symptoms_sel) dsubimage(5, 15, &img_mutations, 0, 16 * (current_game->symptoms_sel - 1), 15, 15, 0); - if (current_game->abilities_sel) dsubimage(35, 15, &img_mutations, 16, 16 * (current_game->abilities_sel - 1), 15, 15, 0); - if (current_game->transmissions_sel) dsubimage(65, 15, &img_mutations, 32, 16 * (current_game->transmissions_sel - 1), 15, 15, 0); + if (current_game->mutations_selected[0]) dsubimage(5, 15, &img_mutations, 0, 16 * (current_game->mutations_selected[0] - 1), 15, 15, 0); + if (current_game->mutations_selected[1]) dsubimage(35, 15, &img_mutations, 16, 16 * (current_game->mutations_selected[1] - 1), 15, 15, 0); + 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: @@ -99,31 +102,12 @@ void display_mutation(const int table[4][8], const struct cursor c, const int mu } -void mutation_selected(const struct cursor c, const int mutation_menu, const int table[4][8], const int button_selected) +void display_mutation_buy(const struct cursor c, const int mutation_menu, const int table[4][8], const int button_selected) { extern const bopti_image_t img_mutations; const int id = table[c.y][c.x]; - extern struct mutation symptoms_data[14]; - extern struct mutation abilities_data[6]; - extern struct mutation transmissions_data[13]; - - struct mutation *mutation_data; - - switch (mutation_menu) - { - case 1: - mutation_data = &symptoms_data[id - 1]; - break; - - case 2: - mutation_data = &abilities_data[id - 1]; - break; - - case 3: - mutation_data = &transmissions_data[id - 1]; - break; - } + struct mutation *mutation_data = get_mutation_data(mutation_menu, id); dclear(C_WHITE); @@ -140,8 +124,14 @@ void mutation_selected(const struct cursor c, const int mutation_menu, const int else drect(81, 12, 123, 18, C_INVERT); dupdate(); - - +} + + +void output_error(const char *msg) +{ + dclear(C_WHITE); + dprint(0, 0, C_BLACK, msg); + dupdate(); } diff --git a/src/display_engine.h b/src/display_engine.h index 21670df..0ef9459 100644 --- a/src/display_engine.h +++ b/src/display_engine.h @@ -13,6 +13,8 @@ void display_foreground(const int background, const struct game *current_game); void display_mutation(const int table[4][8], const struct cursor c, const int mutation_menu); // mutation_selected : display the mutation's informations screen -void mutation_selected(const struct cursor c, const int mutation_menu, const int table[4][8], const int button_selected); +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); #endif /* _PLAGUE_DISPLAY_ENGINE_H */ \ No newline at end of file diff --git a/src/main.c b/src/main.c index a161c31..2396119 100644 --- a/src/main.c +++ b/src/main.c @@ -1,9 +1,9 @@ /* - Name ..............: Plague + Project name ......: Plague Version ...........: - dev - - Last modification .: 24 May 2021 + Last modification .: 29 May 2021 - Code provided with licence : + code provided with licence : GNU General Public Licence v3.0 */ @@ -14,6 +14,7 @@ #include "core.h" #include "display_engine.h" +#include "mutation_engine.h" // title_screen : display the title screen @@ -43,11 +44,11 @@ int main(void) .severity = 0, .lethality = 0, - .dna = 0, + .dna = 100, - .abilities = 1, .abilities_sel = 0, - .symptoms = 1, .symptoms_sel = 0, - .transmissions = 1, .transmissions_sel = 0, + .mutations_count = {0, 0, 0}, + .mutations_selected = {0, 0, 0}, + .mutations_bought = {{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}}, .research = 0, .limit = 100, @@ -110,7 +111,7 @@ void main_loop(struct game *current_game) if (background == -1) end = 1; if (background == 5) { - manage_mutation(current_game, mutation_menu); + mutation_select(current_game, mutation_menu); background = 3; } } diff --git a/src/mutation_data.c b/src/mutation_data.c index f298398..28410b1 100644 --- a/src/mutation_data.c +++ b/src/mutation_data.c @@ -1,5 +1,25 @@ #include "mutation_engine.h" + +const struct mutation symptoms_data[14] = +{ + {1, 1, 0, 2, 0, "NAUSEE"}, + {3, 2, 0, 4, 0, "VOMISSEMENT"}, + {2, 1, 0, 3, 0, "TOUX"}, + {2, 2, 0, 4, 0, "PNEUMONIE"}, + {4, 2, 5, 15, 1, "TUMEUR"}, + {2, 1, 0, 3, 0, "PLAIES"}, + {5, 4, 0, 10, 0, "LESIONS"}, + {5, 15, 15, 20, 0, "HEMORRAGIE"}, + {6, 7, 6, 17, 0, "INFECTION"}, + {2, 2, 2, 5, 0, "INFLAMMATION"}, + {2, 6, 4, 12, 1, "IMMUNITE"}, + {0, 4, 0, 5, 1, "PARANOIA"}, + {6, 15, 0, 20, 2, "FOLIE"}, + {0, 20, 25, 30, 2, "ARRET TOTAL"}, +}; + + const struct mutation abilities_data[6] = { {4, 0, 0, 10, 0, "FROID"}, @@ -10,23 +30,6 @@ const struct mutation abilities_data[6] = {0, 2, 2, 15, 1, "MEDICAMENT"}, }; -const struct mutation symptoms_data[14] = -{ - {1, 1, 0, 2, 0.5, "NAUSEE"}, - {3, 2, 0, 4, 0.5, "VOMISSEMENT"}, - {2, 1, 0, 3, 0.5, "TOUX"}, - {2, 2, 0, 4, 0.5, "PNEUMONIE"}, - {4, 2, 5, 15, 1, "TUMEUR"}, - {2, 1, 0, 3, 0.5, "PLAIES"}, - {5, 4, 0, 10, 0.5, "LESIONS"}, - {5, 15, 15, 20, 0.5, "HEMORRAGIE"}, - {6, 7, 6, 17, 0.5, "INFECTION"}, - {2, 2, 2, 5, 0.5, "INFLAMMATION"}, - {2, 6, 4, 12, 1, "IMMUNODEFICIENCE"}, - {0, 4, 0, 5, 1, "PARANOIA"}, - {6, 15, 0, 20, 2, "FOLIE"}, - {0, 20, 25, 30, 2, "ARRET TOTAL"}, -}; const struct mutation transmissions_data[13] = { @@ -42,5 +45,8 @@ const struct mutation transmissions_data[13] = { 6, 0, 0, 16, 0, "OISEAU 2"}, { 1, 0, 0, 8, 0, "SANG 1"}, { 4, 0, 0, 14, 0, "SANG 2"}, - { 9, 0, 0, 20, 0, "SANG 3"}, -}; \ No newline at end of file + { 9, 1, 1, 20, 0, "SANG 3"}, +}; + + +const struct mutation default_value = {0, 0, 0, 1, 0, "VIDE"}; \ No newline at end of file diff --git a/src/mutation_engine.c b/src/mutation_engine.c index a4dc60b..c33297a 100644 --- a/src/mutation_engine.c +++ b/src/mutation_engine.c @@ -1,3 +1,9 @@ +#include +#include +#include + +#include + #include "mutation_engine.h" void get_mutation(const struct game *current_game, const int mutation_menu, int table[4][8]) @@ -19,27 +25,168 @@ void get_mutation(const struct game *current_game, const int mutation_menu, int if (mutation_menu == 1) { - if (current_game->symptoms < 4) init_mat(8, 4, table, mt_symptoms_1.data); - else if (current_game->symptoms < 8) init_mat(8, 4, table, mt_symptoms_2.data); + if (current_game->mutations_count[0] < 4) init_mat(8, 4, table, mt_symptoms_1.data); + else if (current_game->mutations_count[0] < 8) init_mat(8, 4, table, mt_symptoms_2.data); else init_mat(8, 4, table, mt_symptoms_3.data); } if (mutation_menu == 2) { - if (current_game->abilities < 2) init_mat(8, 4, table, mt_abilities_1.data); - else if (current_game->abilities < 4) init_mat(8, 4, table, mt_abilities_2.data); + if (current_game->mutations_count[1] < 2) init_mat(8, 4, table, mt_abilities_1.data); + else if (current_game->mutations_count[1] < 4) init_mat(8, 4, table, mt_abilities_2.data); else init_mat(8, 4, table, mt_abilities_3.data); } if (mutation_menu == 3) { - if (current_game->transmissions < 5) init_mat(8, 4, table, mt_transmissions_1.data); - else if (current_game->transmissions < 10) init_mat(8, 4, table, mt_transmissions_2.data); + if (current_game->mutations_count[2] < 5) init_mat(8, 4, table, mt_transmissions_1.data); + else if (current_game->mutations_count[2] < 10) init_mat(8, 4, table, mt_transmissions_2.data); else init_mat(8, 4, table, mt_transmissions_3.data); } } +void mutation_select(struct game *current_game, const int mutation_menu) +{ + int key = 0, end = 0; + struct cursor c = {0, 0, 0}; + + static volatile int tick = 1; + int t = timer_configure(TIMER_ANY, CURSOR_TICK*1000, GINT_CALL(callback_tick, &tick)); + if (t >= 0) timer_start(t); + + + while (!end) + { + // Cursor blinking gestion + while (!tick) sleep(); + tick = 0; + c.display = (c.display + 1) % 2; + + // Get and display the mutation menu + int table[4][8]; + get_mutation(current_game, mutation_menu, table); + display_mutation(table, c, mutation_menu); + + // Get the key + key = rtc_key(); + + // Manage input + if (key == KEY_EXIT) end = 1; + if (key == KEY_EXE && table[c.y][c.x] != 15 && table[c.y][c.x] != 0) + { + end = mutation_buy(current_game, c, mutation_menu, table); + } + + if (key == KEY_LEFT && c.x > 0) c.x --; + if (key == KEY_RIGHT && c.x < 7) c.x ++; + if (key == KEY_UP && c.y > 0) c.y --; + if (key == KEY_DOWN && c.y < 3) c.y ++; + } + if (t >= 0) timer_stop(t); +} + + +int mutation_buy(struct game *current_game, const struct cursor c, const int mutation_menu, const int table[4][8]) +{ + int button_selected = 1; + int key = 0, id = table[c.y][c.x]; + + struct mutation *mutation_data = get_mutation_data(mutation_menu, table[c.y][c.x]); + + while (1) + { + display_mutation_buy(c, mutation_menu, table, button_selected); + key = getkey().key; + + if (key == KEY_DOWN || key == KEY_UP) button_selected = (button_selected + 1) % 2; + if (key == KEY_EXIT) return 1; + if (key == KEY_EXE) + { + if (!button_selected) return 0; + else + { + // if the player has'nt bought this mutation yet + if (!current_game->mutations_bought[mutation_menu - 1][id - 1]) + { + // if the player has enought DNA points + if (current_game->dna >= mutation_data->dna) + { + // Take DNA points and save the purchase + current_game->dna = current_game->dna - mutation_data->dna; + current_game->mutations_bought[mutation_menu - 1][id - 1] = 1; + current_game->mutations_count[mutation_menu - 1] ++; + current_game->mutations_selected[mutation_menu - 1] = id; + + // Update + update_disease(current_game); + } + else {output_error("Achat impossible"); getkey();} + } + + // if the player has already bought this mutation + else + { + current_game->mutations_selected[mutation_menu - 1] = id; + update_disease(current_game); + } + + } + return 1; + } + } + return 0; +} + + +void update_disease(struct game *current_game) +{ + struct mutation *symptom = get_mutation_data(1, current_game->mutations_selected[0]); + struct mutation *ability = get_mutation_data(2, current_game->mutations_selected[1]); + struct mutation *transmission = get_mutation_data(3, current_game->mutations_selected[2]); + + dclear(C_WHITE); + dprint(0, 0, C_BLACK, "SY C:%d S:%d L:%d", symptom->contagion, symptom->severity, symptom->lethality); + dprint(0, 8, C_BLACK, "AB C:%d S:%d L:%d", ability->contagion, ability->severity, ability->lethality); + dprint(0, 16, C_BLACK, "TR C:%d S:%d L:%d", transmission->contagion, transmission->severity, transmission->lethality); + dupdate(); + getkey(); + + current_game->contagion = symptom->contagion + ability->contagion + transmission->contagion; + current_game->severity = symptom->severity + ability->severity + transmission->severity; + current_game->lethality = symptom->lethality + ability->lethality + transmission->lethality; +} + + +struct mutation *get_mutation_data(const int mutation_menu, const int id) +{ + extern struct mutation symptoms_data[14]; + extern struct mutation abilities_data[6]; + extern struct mutation transmissions_data[13]; + extern struct mutation default_value; + + if (!id) return &default_value; + + struct mutation *mutation_data = &default_value; + + switch (mutation_menu) + { + case 1: + mutation_data = &symptoms_data[id - 1]; + break; + + case 2: + mutation_data = &abilities_data[id - 1]; + break; + + case 3: + mutation_data = &transmissions_data[id - 1]; + break; + } + return mutation_data; +} + + void init_mat(int x, int y, int dest[][x], int src[][x]) { for (int i = 0; i < x; i++) diff --git a/src/mutation_engine.h b/src/mutation_engine.h index a132110..206ba50 100644 --- a/src/mutation_engine.h +++ b/src/mutation_engine.h @@ -2,6 +2,7 @@ #define _MUTATION_ENGINE_H #include "core.h" +#include "display_engine.h" // mutation_table : contain the map of the mutation available struct mutation_table @@ -23,10 +24,20 @@ struct mutation // get_mutation : return the mutation table to display void get_mutation(const struct game *current_game, const int mutation_menu, int table[4][8]); +// manage_mutation : an independant sub-programm which allow to select and see the mutations. +void mutation_select(struct game *current_game, const int mutation_menu); + +// mutation_buy : UI interface to buy mutations and see informations on them +int mutation_buy(struct game *current_game, const struct cursor c, const int mutation_menu, const int table[4][8]); + +// update_disease : update the disease parameters +void update_disease(struct game *current_game); + +// get_mutation_data : get the information from a mutation +struct mutation * get_mutation_data(const int mutation_menu, const int id); + // init_mat : copy src into dest (for int) void init_mat(int x, int y, int dest[][x], int src[][x]); -// char_init_mat : copy src into dest (for char) -void char_init_mat(int x, char dest[x], char srx[x]); #endif /* _MUTATION_ENGINE_H */ \ No newline at end of file