Basis of the project : background gestion for all menus, plane's animations and statistics menus

This commit is contained in:
Shadow15510 2021-05-24 16:23:22 +02:00
parent 717e3492fd
commit 489cae1a9a
24 changed files with 370 additions and 394 deletions

View File

@ -11,6 +11,8 @@ 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
@ -18,7 +20,12 @@ set(ASSETS
# ...
)
set(ASSETS_fx
assets-fx/example.png
assets-fx/plague.png
assets-fx/avions.png
assets-fx/fonds.png
assets-fx/muta.png
assets-fx/pieces.png
assets-fx/titre.png
# ...
)
set(ASSETS_cg
@ -33,8 +40,8 @@ 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 "MyAddin.g1a"
NAME "MyAddin" ICON assets-fx/icon.png)
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)

BIN
Sources/Plague.g1a Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 677 B

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

View File

@ -1,3 +1,29 @@
example.png:
plague.png:
type: font
name: font_plague
charset: print
grid.size: 5x5
grid.padding: 1
proportional: True
avions.png:
type: bopti-image
name: img_example
name: img_planes
fonds.png:
type: bopti-image
name: img_bground
muta.png:
type: bopti-image
name: img_mutations
pieces.png:
type: bopti-image
name: img_pieces
titre.png:
type: bopti-image
name: img_title

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

97
Sources/src/core.c Normal file
View File

@ -0,0 +1,97 @@
#include <gint/keyboard.h>
#include "core.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;
}

67
Sources/src/core.h Normal file
View File

@ -0,0 +1,67 @@
#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 levels and sprite selected
int abilities, symptoms, transmission;
int abilities_sel, symptoms_sel, transmission_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;
};
// 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);
#endif /* _PLAGUE_CORE_H */

View File

@ -0,0 +1,79 @@
#include <gint/display.h>
#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 int mutation_menu, const struct game *current_game)
{
extern const bopti_image_t img_mutations;
extern const bopti_image_t img_planes;
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->symptoms_sel) dsubimage(35, 15, &img_mutations, 16, 16 * (current_game->abilities_sel - 1), 15, 15, 0);
if (current_game->symptoms_sel) dsubimage(65, 15, &img_mutations, 32, 16 * (current_game->transmission_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;
}
}

View File

@ -0,0 +1,10 @@
#ifndef _PLAGUE_DISPLAY_ENGINE_H
#define _PLAGUE_DISPLAY_ENGINE_H
// Display the background
void display_background(const int background);
// Display the foreground
void display_foreground(const int background, const int mutation_menu, const struct game *current_game);
#endif /* _PLAGUE_DISPLAY_ENGINE_H */

View File

@ -1,428 +1,118 @@
/*
Nom : Plague
Version : - dev-
Dernière modification : 28 Décembre 2019
Liste des choses à faire :
- Gestion des sélection dans les mutations et menu info
- Gestion des avions
- Moteurs du jeu (gestion du temps et sauvegarde)
- Gestion des pays à inclure dans le modèle infectieux
*/
Name : Plague
Version : - dev -
Last modification : 24 May 2021
*/
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/std/stdio.h>
#include <gint/std/string.h>
#include <gint/timer.h>
#include <gint/clock.h>
#include "core.h"
#include "display_engine.h"
//display_barre : affiche les infos de la barre en dessous du monde
void display_barre (const int *adn, const int *recherche, const int *limite);
// title_screen : display the title screen
static void title_screen(void);
//display_menu : affiche les données sur l'écran menu du jeu à partir duquel on peut modifier la maladie
void display_menu (const int *adn, const int *contagion, const int *severite, const int *letalite, const int *sel_symp, const int *sel_capa, const int *sel_trans);
// main_loop : display background, foreground and manage inputs
void main_loop(struct game *current_game);
//display_info : affiche les infos sur la maladie selectionnée
void display_info (const char *nom, const int adn, const int conta, const int leta, const int sev);
//display_stats : affiche les statistiques des humains
void display_stats(const double *sains, const double *infectes, const double *morts, const double *gueris, const double *total);
//menu : gère les tableaux des mutations en fonction de la variable 'variable'
int menu (const int menu_muta, const image_t *img_fonds, const int nv_symp, const int nv_capa, const int nv_trans);
//modele_infectieux : calcule la propagation de la maladie
void modele_infectieux (double *sains, double *infectes, double *morts, double *gueris, double *s_avant, double *i_avant, double *m_avant, double *g_avant, int *contagion, int *severite, int *letalite, int *changement);
//floor : renvoie la partie entière d'une variable
double floor (double x);
//init_mat : remplis la matrice dest à partir de src
void init_mat(int x, int y, int dest[][x], int src[][x]);
//strcpy : copie une chaîne de caractère dans une autre
char * strcpy(char * dest, const char * src);
//strtok : recherche les champs en fonction du séparateur
char * strtok(char * src, const char * separateur);
//atof : convertit le texte en double
double atof(const char *nptr);
// callback_timer : basic timer
int callback_tick(volatile int *tick);
int main (void)
int main(void)
{
extern const font_t font_plague; // Déclaration de la police custom
extern const image_t img_titre; // Déclaration de l'image-titre
extern const image_t img_fonds; // Déclaration des différents fonds du jeu
//extern const image_t img_avions; // Déclaration des avions
dfont(&font_plague);// On change la police pour la police custom
int fond = 1, fin = 0, key = 0, menu_muta = 0;//variables diverses pour le jeu
int recherche = 0, limite = 100, adn = 0, contagion = 0, severite = 0, letalite = 0, nv_symp = 1, nv_capa = 1, nv_trans = 1, sel_symp = 1, sel_capa = 1, sel_trans = 1;// Variables pour la maladie
double total = 10000000000, sains = total, infectes = 0, morts = 0, gueris = 0, s_avant, i_avant, m_avant, g_avant;// Variables pour les statistiques des humains
double changement = 0, priorite = 0;// Variables pour le modèle infectieux
dclear(C_WHITE);
dimage(0, 0, &img_titre);
dupdate();
getkey();
// Fin de l'écran d'accueil
while (fin == 0)
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 =
{
dclear(C_WHITE);
dsubimage(0, 0, &img_fonds, 0, 65 * (fond - 1), 128, 64, 0);
switch (fond)// Affichage supplémentaires dépendant des fonds.
{
case 2:
display_barre(&adn, &recherche, &limite);// Monde avec la barre en dessous
break;
case 3:
display_menu(&adn, &contagion, &severite, &letalite, &sel_symp, &sel_capa, &sel_trans);// Menu de modification de la maladie
break;
case 6:
display_stats(&sains, &infectes, &morts, &gueris, &total);// Satistiques des humains
break;
}
dupdate(); // Mise à jour de l'écran
key = getkey().key;
switch (key) // Detection de la touche
{
case KEY_OPTN:
if (fond == 1) fond = 2;
else if (fond == 2) fond = 1;
break;
case KEY_VARS:
fond = 3;
break;
case KEY_SQUARE:
fond = 6;
break;
case KEY_F1:
if (fond == 3) menu_muta = 1;
break;
case KEY_F3:
if (fond == 3) menu_muta = 2;
break;
case KEY_F5:
if (fond == 3) menu_muta = 3;
break;
case KEY_F6:
if (fond == 3) fond = 1;
break;
case KEY_EXIT:
if (fond != 1) fond = 1;
else fin = 1;
break;
}
if (menu_muta != 0) menu_muta = menu(menu_muta, &img_fonds, nv_symp, nv_capa, nv_trans);
}
return 0;
.contagion = 0,
.severity = 0,
.lethality = 0,
.dna = 0,
.abilities = 1, .abilities_sel = 0,
.symptoms = 1, .symptoms_sel = 0,
.transmission = 1, .transmission_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(&current_game);
return 1;
}
void display_barre (const int *adn, const int *recherche, const int *limite)
static void title_screen(void)
{
// Recherche (jauge = 74 pxl) donc : 74 * (recherche / 100) pour le pourcentage
int variable;
char string[100];
variable = 74 * *recherche / *limite;
sprintf(string, "%d", *adn);
dtext(9, 58, string, C_BLACK, C_NONE);
dline(51, 60, 51 + variable, 60, C_BLACK);
dline(51, 59, 51 + variable, 59, C_BLACK);
}
extern bopti_image_t img_title;
void display_menu (const int *adn, const int *contagion, const int *severite, const int *letalite, const int *sel_symp, const int *sel_capa, const int *sel_trans)
{
// toutes les jauges font 67 pxl de long.
extern const image_t img_muta;
int variable;
char string[100];
sprintf(string, "%d", *adn);
dtext(102, 37, string, C_BLACK, C_NONE);
variable = 67 * *contagion / 26;
dline(57, 48, 57 + variable, 48, C_BLACK);
dline(57, 49, 57 + variable, 49, C_BLACK);
variable = 67 * *severite / 20;
dline(57, 54, 57 + variable, 54, C_BLACK);
dline(57, 55, 57 + variable, 55, C_BLACK);
variable = 67 * *letalite / 33;
dline(57, 60, 57 + variable, 60, C_BLACK);
dline(57, 61, 57 + variable, 61, C_BLACK);
dsubimage(5, 15, &img_muta, 0, 16 * (*sel_symp - 1), 15, 15, 0);
dsubimage(35, 15, &img_muta, 16, 16 * (*sel_capa - 1), 15, 15, 0);
dsubimage(65, 15, &img_muta, 32, 16 * (*sel_trans - 1), 15, 15, 0);
}
void display_info (const char *nom, const int adn, const int conta, const int leta, const int sev)
{
char string[100];
extern const image_t img_fonds;
extern const image_t img_muta;
dclear(C_WHITE);
dsubimage(0, 0, &img_fonds, 0, 195, 128, 64, 0);
dtext(47, 25, nom, C_BLACK, C_NONE);
sprintf(string, "%d", adn);
dtext(73, 33, string, C_BLACK, C_NONE);
sprintf(string, "%d", conta);
dtext(81, 41, string, C_BLACK, C_NONE);
sprintf(string, "%d", leta);
dtext(74, 49, string, C_BLACK, C_NONE);
sprintf(string, "%d", sev);
dtext(75, 57, string, C_BLACK, C_NONE);
dimage(0, 0, &img_title);
dupdate();
getkey();
}
void display_stats (const double *sains, const double *infectes, const double *morts, const double *gueris, const double *total)
void main_loop(struct game *current_game)
{
// Toutes les jauges font 63 pxl
int variable;
variable = 63 * *sains / *total;
dline(61, 31, 61 + variable, 31, C_BLACK);
dline(61, 32, 61 + variable, 32, C_BLACK);
variable = 63 * *infectes / *total;
dline(61, 39, 61 + variable, 39, C_BLACK);
dline(61, 40, 61 + variable, 40, C_BLACK);
variable = 63 * *morts / *total;
dline(61, 47, 61 + variable, 47, C_BLACK);
dline(61, 48, 61 + variable, 48, C_BLACK);
variable = 63 * *gueris / *total;
dline(61, 55, 61 + variable, 55, C_BLACK);
dline(61, 56, 61 + variable, 56, C_BLACK);
}
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);
int menu (const int menu_muta, const image_t *img_fonds, const int nv_symp, const int nv_capa, const int nv_trans)
{
extern const image_t img_muta;
extern const image_t img_pieces;
const char * sous_str;
int variable, contagion = 0, letalite = 0, severite = 0, cout_adn = 0;
double changement = 0.0;
int x = 0, y = 0, i, j, fin = 0, key = 0, lim = 0;
int tableau[4][8];
int symp_1[4][8] = {{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, 15, 15, 6, 15, 15, 0, 0}};
int symp_2[4][8] = {{1, 2, 15, 4, 3, 0, 0, 0},{0, 0, 15, 15, 0, 0, 0, 0},{0, 0, 15, 0, 12, 0, 0, 0},{0, 15, 7, 6, 9, 15, 0, 0}};
int symp_3[4][8] = {{1, 2, 5, 4, 3, 0, 0, 0},{0, 0, 15, 15, 0, 0, 0, 0},{0, 0, 15, 0, 12, 0, 0, 0},{0, 10, 7, 6, 9, 11, 0, 0}};
int symp_4[4][8] = {{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}};
int capa_1[4][8] = {{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}};
int capa_2[4][8] = {{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}};
int capa_3[4][8] = {{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}};
int trans_1[4][8] = {{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, 14, 14, 0, 0, 0, 14}};
int trans_2[4][8] = {{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, 14, 14, 0, 0, 14}};
int trans_3[4][8] = {{1, 2, 3, 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, 14, 0, 0, 13}};
int trans_4[4][8] = {{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}};
char element_sel[50], nom[50];
const char *symptome[] = {"NAUSEE,1,1,0,0.5,2", "VOMISSEMENT,3,2,0,0.5,4", "TOUX,2,1,0,0.5,3", "PNEUMONIE,2,2,0,0.5,4", "TUMEURS,4,2,5,0.5,15", "PLAIE,2,1,0,0.5,3", "LESION,5,4,0,0.5,10", "HEMORAGIE,0,15,15,0.5,20", "INFLAMATION,2,2,2,0.5,5", "INFECTION,6,7,6,0.5,17", "SIDA,2,6,4,0.5,12", "PARANOIA,0,4,1,1,5", "FOLIE,6,15,0,2,20", "CYROSE,0,20,25,0,30"};
switch (menu_muta)// Remplissage de la matrice pour afficher les mutations
while (!end)
{
case 1:
lim = 15;
switch (nv_symp)
{
case 1:
init_mat(8, 4, tableau, symp_1);
break;
case 2:
init_mat(8, 4, tableau, symp_2);
break;
case 3:
init_mat(8, 4, tableau, symp_3);
break;
case 4:
init_mat(8, 4, tableau, symp_4);
break;
}
break;
// Real-time clock system
while (!tick) sleep();
tick = 0;
case 2:
lim = 7;
switch (nv_capa)
{
case 1:
init_mat(8, 4, tableau, capa_1);
break;
case 2:
init_mat(8, 4, tableau, capa_2);
break;
case 3:
init_mat(8, 4, tableau, capa_3);
break;
}
break;
case 3:
lim = 14;
switch (nv_trans)
{
case 1:
init_mat(8, 4, tableau, trans_1);
break;
case 2:
init_mat(8, 4, tableau, trans_2);
break;
case 3:
init_mat(8, 4, tableau, trans_3);
break;
case 4:
init_mat(8, 4, tableau, trans_4);
break;
}
break;
}
while (fin == 0)
{
// Update the screen
dclear(C_WHITE);
dsubimage(0, 0, img_fonds, 0, 260, 128, 64, 0);
for (i = 0 ; i <= 7 ; i++)
{
for (j = 0 ; j <= 3; j++)
{
if (tableau[j][i] != 0) dsubimage(16 * i, 16 * j, &img_muta, 16 * (menu_muta - 1), 16 * (tableau[j][i] - 1), 15, 15, 0);
}
}
if (tableau[y][x] == lim) dsubimage(16 * x - 1, 16 * y - 1, &img_pieces, 0, 18, 17, 17, 0);
else dsubimage(16 * x - 1, 16 * y - 1, &img_pieces, 0, 0, 17, 17, 0);
display_background(background);
display_foreground(background, mutation_menu, current_game);
dupdate();
key = getkey().key;
// Compute the motion of planes
next_frame(current_game);
switch (key)
{
case KEY_LEFT:
if (x > 0) x -= 1;
break;
case KEY_RIGHT:
if (x < 7) x += 1;
break;
case KEY_UP:
if (y > 0) y -= 1;
break;
case KEY_DOWN:
if (y < 3) y += 1;
break;
case KEY_EXIT:
fin = 1;
break;
case KEY_EXE:
if (tableau[y][x] != lim && tableau[y][x] != 0) fin = 2;
else fin = 0;
break;
}
// Get inputs from the keyboard and manage it
background = get_inputs(background, &mutation_menu);
if (background == -1) end = 1;
}
if (fin == 2)
{
switch(menu_muta)
{
case 1:
strcpy(element_sel, symptome[tableau[y][x] - 1]);
break;
}
variable = 0;
while(1)
{
if(variable == 0) sous_str = strtok(element_sel, ",");
else sous_str = strtok(NULL, ",");
variable ++;
switch (variable)
{
case 1:
strcpy(nom, sous_str);
break;
case 2:
contagion = floor(atof(sous_str));
break;
case 3:
severite = floor(atof(sous_str));
break;
case 4:
letalite = floor(atof(sous_str));
break;
case 5:
changement = atof(sous_str);
break;
case 6:
cout_adn = floor(atof(sous_str));
break;
}
if(sous_str == NULL) break;
}
display_info (nom, cout_adn, contagion, letalite, severite);
}
return 0;
if (t >= 0) timer_stop(t);
}
void modele_infectieux (double *sains, double *infectes, double *morts, double *gueris, double *s_avant, double *i_avant, double *m_avant, double *g_avant, int *contagion, int *severite, int *letalite, int *changement)
int callback_tick(volatile int *tick)
{
double r = *contagion / 2600, a = *severite / (200 - *changement), b = *letalite / 3300;
*sains = floor(*s_avant - r * *s_avant);
*infectes = floor (*i_avant + r * *s_avant - *i_avant * b - *i_avant * a);
*morts = floor (*m_avant + *infectes * b);
*gueris = floor(*g_avant + *infectes * a);
*s_avant = *sains;
*i_avant = *infectes;
*m_avant = *morts;
*g_avant = *gueris;
}
double floor (double x)
{
return (int)x;
}
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];
}
}
*tick = 1;
return TIMER_CONTINUE;
}