diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b6f3adf --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,58 @@ +# Configure with [fxsdk build-fx] or [fxsdk build-cg], which provide the +# toolchain file and module path of the fxSDK + +cmake_minimum_required(VERSION 3.18) +project(Plague) + +include(GenerateG1A) +include(GenerateG3A) +include(Fxconv) +find_package(Gint 2.1 REQUIRED) + +set(SOURCES + src/main.c + src/core.c + src/display_engine.c + # ... +) +# Shared assets, fx-9860G-only assets and fx-CG-50-only assets +set(ASSETS + # ... +) +set(ASSETS_fx + assets-fx/plague.png + assets-fx/planes.png + assets-fx/bground.png + assets-fx/mutations.png + assets-fx/piece.png + assets-fx/title.png + assets-fx/mutations_table/abilities_1.txt + assets-fx/mutations_table/abilities_2.txt + assets-fx/mutations_table/abilities_3.txt + assets-fx/mutations_table/symptoms_1.txt + assets-fx/mutations_table/symptoms_2.txt + assets-fx/mutations_table/symptoms_3.txt + assets-fx/mutations_table/transmissions_1.txt + assets-fx/mutations_table/transmissions_2.txt + assets-fx/mutations_table/transmissions_3.txt + # ... +) +set(ASSETS_cg + assets-cg/example.png + # ... +) + +fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA) +fxconv_declare_converters(assets-fx/converters.py) + +add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}}) +target_compile_options(myaddin PRIVATE -Wall -Wextra -Os) +target_link_libraries(myaddin Gint::Gint) + +if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G) + generate_g1a(TARGET myaddin OUTPUT "Plague.g1a" + NAME "Plague" ICON assets-fx/icon.png) +elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) + generate_g3a(TARGET myaddin OUTPUT "MyAddin.g3a" + NAME "MyAddin" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png) +endif() diff --git a/Plague.g1a b/Plague.g1a new file mode 100644 index 0000000..42200be Binary files /dev/null and b/Plague.g1a differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..c3a1686 --- /dev/null +++ b/README.md @@ -0,0 +1,88 @@ +# Plague inc + +## Présentation + +De l'Anglais 'Plague' virus, ou peste et 'inc' diminutif de 'incorporated' peut être traduit par coopérative ou entreprise. Vous voila donc plongé dans 'L'Entreprise du Virus' un nom digne de 1984 : 'Le Ministère des Virus et de la Régulation Démographique' Ça nous fait un superbe acronyme : MVRD. J'aurais pu rajouter 'Et de la Santé Publique' on tape dans du très haut niveau là : MVRDESP aussi… Les Humains sont tellement fragiles, protégeons-les ! La plus grande menace pour l'Homme étant l'Homme, faites une bonne action : jouez à ce jeu ! + +Plague inc est donc un jeu de stratégie où le but est de réduire l'humanité à néant… Simple ? Non ! Il vous faudra manipuler avec dextérité et prudence un virus pour anéantir des humains qui ne sont pas super collaboratifs… Pire, ces petits rigolos veulent sauver leurs peaux et recherchent activement un remède à ce mystérieux virus inconnu… + +## Contrôles + +Lancez le jeu, et pressez n'importe quelle touche pour passer l'écran principal. Une fois sur l'écran représentant la Terre, plusieurs choix s'offrent à vous : + - [OPTN] permet d'afficher / cacher la barre en dessous du monde qui vous affiche vos points ADN et la barre de recherche des humains. + - [VARS] permet de passer au gros du jeu : les mutations. Ce menu vous affiche vos points ADN, mais aussi les mutations sélectionnées ainsi que vos point de contagion, de sévérité, et de létalité. Dans ce menu, vous pouvez modifier tout cela. + - [x^2] permet d'accéder au menu statistique qui vous affiche les stats sur les humains. La barre symbolise la popuation totale : donc la somme de toute les barre doit donné une seule barre entière. + +De manière générale, si vous êtes perdu, [EXIT] vous ramènera toujours sur la mappemonde. + +Dans le menu des mutations, vous pouvez modifier vos caractéristiques via les touches F1 à F6 comme suit : + - [F1] sert à changer les symptômes de votre maladie + - [F3] sert à changer les capacités d'adaptation de votre maladie + - [F5] sert à modifier les moyens de transmission de votre maladie + - [F6] sert à revenir au menu principal avec la mappemonde + +## Mutations + +Dans ce jeu, vous aurez le choix entre plusieurs mutations pour faire le plus de dégât possible parmis les humains ! Comme dans le jeu d'origine, celles-ci sont divisées en 3 catégories : Symptômes, Capacités, et Transmissions. + +Toutes les mutations ont plusieurs spécificités : + - Contagion qui détermine la proportion de personnes infectées + - Sévérité touche la recherche, on peut la comprendre de la manière suivante : si la sévérité est élevée, la maladie est grave, elle entraine par conséquent une recherche active de la part des Humains. Néanmoins, votre compteur de points ADN, augmente plus vite… + - Létalité détermine le taux de mortalité parmi les infectés… Une létalité élevée fera de votre maladie une veritable machine à tuer, mais cela vous dévoile au grand jour et accèlere la recherche ! + - ADN, du nom de la molècule qui compose le code génétique. Ici, rien à voir, les points ADN vous permettent d'acheter des mutations. + - Changement : certaines mutations par leur nature ralentissent la recherche, c'est ce ralentissement qui est symbolysé par changement. Concrétement, plus une maladie a de *changement* plus elle ralentit la recherche… + +### Symptômes + +Comme son nom l'indique, votre maladie aussi puissante soit-elle n'est pas invisible : elle présente certains symptômes qui ont leurs spécificités. Bien entendu, les symptômes présentés dans ce jeu font partie du jeu d'origines et leurs spécificités sont proches. + +|Nom|Coût ADN|Pt de contagion|Pt de sévérité|Pt de létalité|Changement| +|:---:|:---:|:---:|:---:|:---:|:---:| +|nausée|2|1|1|0|0,5 +|vomissement|4|3|2|0|0,5 +|tumeurs|15|4|2|5|1 +|pneumonie|4|2|2|0|0,5 +|toux|3|2|1|0|0,5 +|arrêt total des organes|30|0|20|25|2 +|folie|20|6|15|0|2 +|paranoïa|5|0|4|0|1 +|lésions|10|5|4|0|0,5 +|hémorragie|20|5|15|15|0,5 +|plaies|3|2|1|0|0,5 +|infections|17|6|7|6|0,5 +|immunodéficience|12|2|6|4|1 +|inflammation|5|2|2|2|0,5 + +### Capacités + +En mutant, votre maladie peut acquérir des capacités. Ces capacités lui permettent de mieux apréhender un milieu ou une situation, ainsi la capacité *Résistance au froid* donne un suplément de vigueur à votre virus dans les pays froid. Cela se traduit par une augmentation plus ou moins forte de la contagion dans ces régions du monde… + +|Nom|Pt de contagion|Pt de sévérité|Pt de létalité|Coût ADN| +|:---:|:---:|:---:|:---:|:---:| +|résistance au froid|+4|||10 +|résistance au chand|+7|||15 +|résistance à l'environnement|+10|||30 +|résistance aux médicaments||+2|+0,5|15 +|résistance génétique||+5|+1|25 +|mutation accélérée||+8|+2|30 + +### Moyens de transmissions + +Votre maladie aura tout le loisir de changer ses moyens de transmission ! Plus ou moins efficaces ceux-ci permettent à votre maladie d'accéder à des caractérestiques intéressantes qui lui permettront de coloniser le monde entier ! ;) + +|Nom|Pt de contagion|Coût ADN| +|:---:|:---:|:---:| +|air Nv 1|+2|9 +|air Nv 2|+5|15 +|air Nv 3|+8|20 +|air et eau|+10|30 +|eau Nv 1|+2|9 +|eau Nv 2|+3|12 +|eau Nv 3|+9|25 +|oiseau Nv 1|+3|12 +|oiseau Nv 2|+5|18 +|animaux Nv 1|+2|10 +|animaux Nv 2|+6|16 +|sang Nv 1|+1|8 +|sang Nv 2|+4|14 +|sang Nv 3|+9|20 diff --git a/assets-fx/bground.png b/assets-fx/bground.png new file mode 100644 index 0000000..a50e413 Binary files /dev/null and b/assets-fx/bground.png differ diff --git a/assets-fx/converters.py b/assets-fx/converters.py new file mode 100644 index 0000000..91227c7 --- /dev/null +++ b/assets-fx/converters.py @@ -0,0 +1,24 @@ +import fxconv + + +def convert(input_name, output, params, target): + if params["custom-type"] == "mutation-table": + convert_mt(map, input_name, output, params, target) + return 0 + else: + return 1 + + +def convert_mt(input_name, output, params, target): + with open(input_name, "r") as file: + # Extract informations + lines = file.read().splitlines() + mutation_matrix = [i.split(" | ") for i in lines] + + # Encode information into bytes + data = bytes() + for i in enumerate(mutation_matrix): + for j in enumerate(i): + mutation += fxconv.u32(int(j)) + + fxconv.elf(data, output, "_" + params["name"], **target) diff --git a/assets-fx/fxconv-metadata.txt b/assets-fx/fxconv-metadata.txt new file mode 100644 index 0000000..f5f6e06 --- /dev/null +++ b/assets-fx/fxconv-metadata.txt @@ -0,0 +1,13 @@ +*.png: + type: bopti-image + name_regex: (.*)\.png img_\1 + +plague.png: + type: font + name: font_plague + charset: print + grid.size: 5x5 + grid.padding: 1 + proportional: True + + diff --git a/assets-fx/icon.png b/assets-fx/icon.png new file mode 100644 index 0000000..e323f42 Binary files /dev/null and b/assets-fx/icon.png differ diff --git a/assets-fx/mutations.png b/assets-fx/mutations.png new file mode 100644 index 0000000..6970d18 Binary files /dev/null and b/assets-fx/mutations.png differ diff --git a/assets-fx/mutations_table/abilities_1.txt b/assets-fx/mutations_table/abilities_1.txt new file mode 100644 index 0000000..216307f --- /dev/null +++ b/assets-fx/mutations_table/abilities_1.txt @@ -0,0 +1,4 @@ +1 | 0 | 0 | 0 | 6 | 0 | 0 | 0 +7 | 7 | 0 | 7 | 0 | 0 | 0 | 0 +0 | 0 | 0 | 0 | 7 | 0 | 0 | 0 +0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 diff --git a/assets-fx/mutations_table/abilities_2.txt b/assets-fx/mutations_table/abilities_2.txt new file mode 100644 index 0000000..d2f497b --- /dev/null +++ b/assets-fx/mutations_table/abilities_2.txt @@ -0,0 +1,4 @@ +1 | 0 | 0 | 0 | 6 | 0 | 0 | 0 +2 | 7 | 0 | 3 | 0 | 0 | 0 | 0 +0 | 0 | 0 | 0 | 7 | 0 | 0 | 0 +0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 \ No newline at end of file diff --git a/assets-fx/mutations_table/abilities_3.txt b/assets-fx/mutations_table/abilities_3.txt new file mode 100644 index 0000000..91de132 --- /dev/null +++ b/assets-fx/mutations_table/abilities_3.txt @@ -0,0 +1,4 @@ +1 | 0 | 0 | 0 | 6 | 0 | 0 | 0 +2 | 5 | 0 | 3 | 0 | 0 | 0 | 0 +0 | 0 | 0 | 0 | 4 | 0 | 0 | 0 +0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 \ No newline at end of file diff --git a/assets-fx/mutations_table/fxconv-metadata.txt b/assets-fx/mutations_table/fxconv-metadata.txt new file mode 100644 index 0000000..2cc3c63 --- /dev/null +++ b/assets-fx/mutations_table/fxconv-metadata.txt @@ -0,0 +1,3 @@ +*.txt: + custom-type: mutation-table + name_regex: (.*)\.txt mt_\1 \ No newline at end of file diff --git a/assets-fx/mutations_table/symptoms_1.txt b/assets-fx/mutations_table/symptoms_1.txt new file mode 100644 index 0000000..b906523 --- /dev/null +++ b/assets-fx/mutations_table/symptoms_1.txt @@ -0,0 +1,4 @@ +1 | 15 | 15 | 15 | 3 | 0 | 0 | 0 +0 | 0 | 15 | 15 | 0 | 0 | 0 | 0 +0 | 0 | 15 | 0 | 15 | 0 | 0 | 0 +0 | 10 | 15 | 6 | 15 | 15 | 0 | 0 \ No newline at end of file diff --git a/assets-fx/mutations_table/symptoms_2.txt b/assets-fx/mutations_table/symptoms_2.txt new file mode 100644 index 0000000..09b0da5 --- /dev/null +++ b/assets-fx/mutations_table/symptoms_2.txt @@ -0,0 +1,4 @@ +1 | 2 | 15 | 4 | 3 | 0 | 0 | 0 +0 | 0 | 15 | 15 | 0 | 0 | 0 | 0 +0 | 0 | 15 | 0 | 15 | 0 | 0 | 0 +0 | 10 | 7 | 6 | 9 | 15 | 0 | 0 \ No newline at end of file diff --git a/assets-fx/mutations_table/symptoms_3.txt b/assets-fx/mutations_table/symptoms_3.txt new file mode 100644 index 0000000..b7a0a65 --- /dev/null +++ b/assets-fx/mutations_table/symptoms_3.txt @@ -0,0 +1,4 @@ +1 | 2 | 5 | 4 | 3 | 0 | 0 | 0 +0 | 0 | 14 | 13 | 0 | 0 | 0 | 0 +0 | 0 | 8 | 0 | 12 | 0 | 0 | 0 +0 | 10 | 7 | 6 | 9 | 11 | 0 | 0 \ No newline at end of file diff --git a/assets-fx/mutations_table/transmissions_1.txt b/assets-fx/mutations_table/transmissions_1.txt new file mode 100644 index 0000000..0fde8a8 --- /dev/null +++ b/assets-fx/mutations_table/transmissions_1.txt @@ -0,0 +1,4 @@ +1 | 14 | 14 | 0 | 14 | 5 | 0 | 0 +0 | 0 | 0 | 14 | 0 | 0 | 0 | 11 +9 | 14 | 0 | 0 | 0 | 0 | 0 | 14 +0 | 0 | 0 | 7 | 14 | 0 | 0 | 14 \ No newline at end of file diff --git a/assets-fx/mutations_table/transmissions_2.txt b/assets-fx/mutations_table/transmissions_2.txt new file mode 100644 index 0000000..ed42e81 --- /dev/null +++ b/assets-fx/mutations_table/transmissions_2.txt @@ -0,0 +1,4 @@ +1 | 2 | 14 | 0 | 6 | 5 | 0 | 0 +0 | 0 | 0 | 14 | 0 | 0 | 0 | 11 +9 | 10 | 0 | 0 | 0 | 0 | 0 | 12 +0 | 0 | 0 | 7 | 8 | 0 | 0 | 14 \ No newline at end of file diff --git a/assets-fx/mutations_table/transmissions_3.txt b/assets-fx/mutations_table/transmissions_3.txt new file mode 100644 index 0000000..eee8275 --- /dev/null +++ b/assets-fx/mutations_table/transmissions_3.txt @@ -0,0 +1,4 @@ +1 | 2 | 3 | 0 | 6 | 5 | 0 | 0 +0 | 0 | 0 | 4 | 0 | 0 | 0 | 11 +9 | 10 | 0 | 0 | 0 | 0 | 0 | 12 +0 | 0 | 0 | 7 | 8 | 0 | 0 | 13 \ No newline at end of file diff --git a/assets-fx/piece.png b/assets-fx/piece.png new file mode 100644 index 0000000..d0c2a63 Binary files /dev/null and b/assets-fx/piece.png differ diff --git a/assets-fx/pieces.png b/assets-fx/pieces.png new file mode 100644 index 0000000..985aedf Binary files /dev/null and b/assets-fx/pieces.png differ diff --git a/assets-fx/plague.png b/assets-fx/plague.png new file mode 100644 index 0000000..6c25191 Binary files /dev/null and b/assets-fx/plague.png differ diff --git a/assets-fx/planes.png b/assets-fx/planes.png new file mode 100644 index 0000000..fae3c21 Binary files /dev/null and b/assets-fx/planes.png differ diff --git a/assets-fx/title.png b/assets-fx/title.png new file mode 100644 index 0000000..f0beb69 Binary files /dev/null and b/assets-fx/title.png differ diff --git a/src/core.c b/src/core.c new file mode 100644 index 0000000..e66e00b --- /dev/null +++ b/src/core.c @@ -0,0 +1,112 @@ +#include + +#include "core.h" +#include "display_engine.h" + + +void next_frame(struct game *current_game) +{ + for (int i = 0; current_game->planes[i]; i++) + { + switch(current_game->planes[i]->direction) + { + case 1: + current_game->planes[i]->y -= 1; + break; + case 2: + current_game->planes[i]->x += 1; + break; + case 3: + current_game->planes[i]->y += 1; + break; + case 4: + current_game->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) + { + // 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; + + // 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; + + // Set the new direction + int new_dir = (current_game->planes[i]->direction + 2) % 4; + if (!new_dir) new_dir = 4; + current_game->planes[i]->direction = new_dir; + } + } + current_game->time += ENGINE_TICK; +} + + +int get_inputs(const int background, int *mutation_menu) +{ + int opt = GETKEY_DEFAULT & ~GETKEY_REP_ARROWS; + int timeout = 1; + + key_event_t ev = getkey_opt(opt, &timeout); + if(ev.type == KEYEV_NONE) return background; + + int key = ev.key; + + if (key == KEY_OPTN && (background == 1 || background == 2)) return (background % 2) + 1; + if (key == KEY_VARS) return 3; + if (key == KEY_SQUARE) return 6; + + if (key == KEY_EXIT) + { + if (background == 5) return 3; + if (background != 1 && background != 2) return 1; + if (background == 1) return -1; + } + + if (background == 3) + { + switch (key) + { + // Symptoms + case KEY_F1: + *mutation_menu = 1; + return 5; + break; + + // Abilities + case KEY_F3: + *mutation_menu = 2; + return 5; + break; + + // Transmission + case KEY_F5: + *mutation_menu = 3; + return 5; + break; + + // Return to the main menu + case KEY_F6: + *mutation_menu = 0; + return 1; + break; + } + } + + return background; +} + + +void manage_mutation(struct game *current_game, const int mutation_menu) +{ + int key = 0, end = 0; + int cursor_x = 1, cursor_y = 1; + while (!end) + { + display_mutation(current_game, mutation_menu, cursor_x, cursor_y); + key = getkey().key; + + if (key == KEY_EXIT) end = 1; + } +} diff --git a/src/core.h b/src/core.h new file mode 100644 index 0000000..5e09a34 --- /dev/null +++ b/src/core.h @@ -0,0 +1,79 @@ +#ifndef _PLAGUE_CORE_H +#define _PLAGUE_CORE_H + + +// Duration for internal clock +#define ENGINE_TICK 50 + +// 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 +{ + // Disease parameters + int contagion, severity, lethality; + + // DNA points + int dna; + + // Mutations counts and sprite selected + int abilities, symptoms, transmissions; + int abilities_sel, symptoms_sel, transmissions_sel; + + // Research data + int research, limit; + + // Infectious pattern parameters + long long int healthy, infected, dead, cured; + + // Time + int time; + + // Planes + struct plane *planes[NB_PLANES + 1]; +}; + + +// plane : information about planes +struct plane +{ + // Plane's coordinates + int x, y; + + // Plane's direction + int direction; + + // Coordinates of the plane's destination + int dest_x, dest_y; + + //Coordinates of the plane's departure + int depa_x, depa_y; + +}; + + +// mutation : contain the map of the mutation available +struct mutation_table +{ + // Data of the map + int data[4][8]; +}; + + +// 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); + + +// manage_mutation : an independant sub-programm which allow to select, buy and see the mutations. +void manage_mutation(struct game *current_game, const int mutation_menu); + +#endif /* _PLAGUE_CORE_H */ \ No newline at end of file diff --git a/src/display_engine.c b/src/display_engine.c new file mode 100644 index 0000000..4d4ac48 --- /dev/null +++ b/src/display_engine.c @@ -0,0 +1,147 @@ +#include + +#include "core.h" +#include "display_engine.h" + + +void display_background(const int background) +{ + extern const bopti_image_t img_bground; + dsubimage(0, 0, &img_bground, 0, 65 * (background - 1), 128, 64, DIMAGE_NONE); +} + + +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; + GUNUSED int length; + + switch (background) + { + case 1: + for (int i = 0; current_game->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); + } + break; + case 2: + for (int i = 0; current_game->planes[i]; i++) + { + if (current_game->planes[i]->y + 8 < 53) 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); + } + + int length = 74 * current_game->research / current_game->limit; + dprint(9, 58, C_BLACK, "%d", current_game->dna); + + dline(51, 60, 51 + length, 60, C_BLACK); + dline(51, 59, 51 + length, 59, C_BLACK); + break; + + case 3: + dprint(102, 37, C_BLACK, "%d", current_game->dna); + + length = 67 * current_game->contagion / 26; + dline(57, 48, 57 + length, 48, C_BLACK); + dline(57, 49, 57 + length, 49, C_BLACK); + + length = 67 * current_game->severity / 20; + dline(57, 54, 57 + length, 54, C_BLACK); + dline(57, 55, 57 + length, 55, C_BLACK); + + length = 67 * current_game->lethality / 33; + 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); + 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; + } +} + + +void display_mutation(const struct game *current_game, const int mutation_menu, const int cursor_x, const int cursor_y) +{ + extern const bopti_image_t img_mutations; + extern bopti_image_t img_piece; + + // Load symptoms + extern struct mutation_table mt_symptoms_1; + extern struct mutation_table mt_symptoms_2; + extern struct mutation_table mt_symptoms_3; + + // Load abilities + extern struct mutation_table mt_abilities_1; + extern struct mutation_table mt_abilities_2; + extern struct mutation_table mt_abilities_3; + + // Load transmissions + extern struct mutation_table mt_transmissions_1; + extern struct mutation_table mt_transmissions_2; + extern struct mutation_table mt_transmissions_3; + + int table[4][8]; + 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); + 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); + 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); + else init_mat(8, 4, table, mt_transmissions_3.data); + } + + dclear(C_WHITE); + for (int i = 0 ; i < 4 ; i++) + { + for (int j = 0 ; j < 8; j++) + { + if (table[i][j]) dsubimage(i*16, j*16, &img_mutations, 16 * (mutation_menu - 1), 0, 16 * (table[i][j] - 1), 15, 15); + } + } + dimage(16 * (cursor_x - 1), 16 * (cursor_y - 1), &img_piece); + dupdate(); + +} + + +void init_mat(int x, int y, int dest[][x], int src[][x]) +{ + for (int i = 0 ; i < x ; i++) + { + for (int j = 0 ; j < y ; j++) + { + dest[j][i] = src[j][i]; + } + } +} diff --git a/src/display_engine.h b/src/display_engine.h new file mode 100644 index 0000000..6ab6315 --- /dev/null +++ b/src/display_engine.h @@ -0,0 +1,16 @@ +#ifndef _PLAGUE_DISPLAY_ENGINE_H +#define _PLAGUE_DISPLAY_ENGINE_H + +// display_background : display the background +void display_background(const int background); + +// display_foreground : display the foreground, planes, statistics +void display_foreground(const int background, const struct game *current_game); + +// display_mutation : display the mutation selection screen +void display_mutation(const struct game *current_game, const int mutation_menu, const int cursor_x, const int cursor_y); + +// init_mat : copy src into dest +void init_mat(int x, int y, int dest[][x], int src[][x]); + +#endif /* _PLAGUE_DISPLAY_ENGINE_H */ \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..abb3ba2 --- /dev/null +++ b/src/main.c @@ -0,0 +1,125 @@ +/* + Name : Plague + Version : - dev - + Last modification : 24 May 2021 +*/ + +#include +#include +#include +#include + +#include "core.h" +#include "display_engine.h" + + +// title_screen : display the title screen +static void title_screen(void); + +// main_loop : display background, foreground and manage inputs +void main_loop(struct game *current_game); + +// callback_timer : basic timer +int callback_tick(volatile int *tick); + + +int main(void) +{ + extern font_t font_plague; + dfont(&font_plague); + + title_screen(); + + 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}; + + GUNUSED struct game current_game = + { + .contagion = 0, + .severity = 0, + .lethality = 0, + + .dna = 0, + + .abilities = 1, .abilities_sel = 0, + .symptoms = 1, .symptoms_sel = 0, + .transmissions = 1, .transmissions_sel = 0, + + .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} + }; + + main_loop(¤t_game); + + return 1; +} + + +static void title_screen(void) +{ + extern bopti_image_t img_title; + + dclear(C_WHITE); + dimage(0, 0, &img_title); + + dupdate(); + getkey(); +} + + +void main_loop(struct game *current_game) +{ + int background = 1, mutation_menu = 0; + int end = 0; + + static volatile int tick = 1; + int t = timer_configure(TIMER_ANY, ENGINE_TICK*1000, GINT_CALL(callback_tick, &tick)); + if (t >= 0) timer_start(t); + + while (!end) + { + // Real-time clock system + while (!tick) sleep(); + tick = 0; + + // Update the screen + dclear(C_WHITE); + display_background(background); + display_foreground(background, current_game); + dupdate(); + + // Compute the motion of planes + next_frame(current_game); + + // Get inputs from the keyboard and manage it + background = get_inputs(background, &mutation_menu); + + // Special actions : quit and manage mutations + if (background == -1) end = 1; + if (background == 5) + { + manage_mutation(current_game, mutation_menu); + background = 3; + } + } + + if (t >= 0) timer_stop(t); +} + + +int callback_tick(volatile int *tick) +{ + *tick = 1; + return TIMER_CONTINUE; +}