2021-06-02 22:13:39 +02:00
|
|
|
#include <gint/timer.h>
|
|
|
|
#include <gint/clock.h>
|
2021-05-25 13:24:48 +02:00
|
|
|
#include <gint/keyboard.h>
|
2021-06-04 09:47:31 +02:00
|
|
|
#include <math.h>
|
2021-05-25 13:24:48 +02:00
|
|
|
|
|
|
|
#include "core.h"
|
2021-06-02 22:13:39 +02:00
|
|
|
#include "mutation_engine.h"
|
|
|
|
#include "epidemic_engine.h"
|
2021-05-25 13:24:48 +02:00
|
|
|
#include "display_engine.h"
|
|
|
|
|
|
|
|
|
2021-06-06 18:05:30 +02:00
|
|
|
int next_frame(struct game *current_game, int *dna_animation, int *vaccine)
|
2021-05-25 13:24:48 +02:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2021-06-04 15:13:48 +02:00
|
|
|
// Infect the airport
|
|
|
|
if (current_game->planes[i]->is_infected) current_game->grid.data[current_game->planes[i]->x + current_game->planes[i]->y * current_game->grid.width] = 1;
|
|
|
|
|
2021-05-25 13:24:48 +02:00
|
|
|
// 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;
|
2021-06-04 15:13:48 +02:00
|
|
|
|
|
|
|
// Infect the plane
|
2021-06-04 15:36:10 +02:00
|
|
|
if (current_game->grid.data[current_game->planes[i]->x + current_game->planes[i]->y * current_game->grid.width] == 1 && current_game->mutations_selected[2] == 4) current_game->planes[i]->is_infected = 1;
|
2021-05-25 13:24:48 +02:00
|
|
|
}
|
|
|
|
}
|
2021-06-03 09:21:41 +02:00
|
|
|
|
2021-06-05 13:15:27 +02:00
|
|
|
int limit_tick = LIMIT_TICK;
|
|
|
|
if (current_game->boost) limit_tick = floor(LIMIT_TICK / 10);
|
|
|
|
|
2021-06-05 14:39:48 +02:00
|
|
|
|
2021-05-25 13:24:48 +02:00
|
|
|
current_game->time += ENGINE_TICK;
|
2021-06-03 09:21:41 +02:00
|
|
|
current_game->total_time += ENGINE_TICK;
|
2021-06-03 09:45:24 +02:00
|
|
|
|
2021-06-05 14:39:48 +02:00
|
|
|
if (!(current_game->time % 150)) *dna_animation = (*dna_animation + 1) % 16;
|
|
|
|
|
2021-06-05 13:15:27 +02:00
|
|
|
if (current_game->time > limit_tick)
|
2021-06-02 22:13:39 +02:00
|
|
|
{
|
2021-06-03 09:21:41 +02:00
|
|
|
// Reset internal clock
|
2021-06-02 22:13:39 +02:00
|
|
|
current_game->time = 0;
|
|
|
|
|
2021-06-06 18:05:30 +02:00
|
|
|
// Display message on research
|
2021-06-06 17:03:29 +02:00
|
|
|
if (!current_game->research && current_game->priority) message("LA RECHERHCE CONTRE VOTRE VIRUS COMMENCE !");
|
2021-06-06 18:05:30 +02:00
|
|
|
else if (!*vaccine && (current_game->research == current_game->limit)) {*vaccine = 1; message("LE VACCIN EST TERMINE."); }
|
2021-06-06 17:03:29 +02:00
|
|
|
|
2021-06-03 09:21:41 +02:00
|
|
|
// Update the game
|
2021-06-04 23:25:14 +02:00
|
|
|
current_game->dna = current_game->dna + 1 + floor(current_game->severity / 10);
|
2021-06-04 15:13:48 +02:00
|
|
|
if (current_game->dna > 30) current_game->dna = 30;
|
2021-06-05 20:18:32 +02:00
|
|
|
|
2021-06-04 16:32:37 +02:00
|
|
|
current_game->research += current_game->priority;
|
|
|
|
if (current_game->research > current_game->limit) current_game->research = current_game->limit;
|
2021-06-05 20:18:32 +02:00
|
|
|
|
2021-06-03 09:21:41 +02:00
|
|
|
epidemic_simulation(current_game);
|
|
|
|
|
|
|
|
// Check the end of the game
|
2021-06-03 09:45:24 +02:00
|
|
|
if (!current_game->humans[1])
|
2021-06-03 09:21:41 +02:00
|
|
|
{
|
2021-06-05 13:15:27 +02:00
|
|
|
|
2021-06-07 21:26:52 +02:00
|
|
|
if (current_game->humans[3] < 4 * (current_game->humans[0] + current_game->humans[2])) message("VOUS AVEZ PERDU.");
|
2021-06-04 22:26:31 +02:00
|
|
|
else message("VOUS AVEZ GAGNE !");
|
2021-06-04 23:25:14 +02:00
|
|
|
return 0;
|
2021-06-03 09:21:41 +02:00
|
|
|
}
|
2021-06-02 22:13:39 +02:00
|
|
|
}
|
2021-06-04 23:25:14 +02:00
|
|
|
return 1;
|
2021-05-25 13:24:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-05 13:15:27 +02:00
|
|
|
int get_inputs(const int background, int *mutation_menu, int *boost)
|
2021-05-25 13:24:48 +02:00
|
|
|
{
|
2021-06-02 22:13:39 +02:00
|
|
|
int key = rtc_key();
|
2021-05-25 13:24:48 +02:00
|
|
|
|
2021-06-05 13:15:27 +02:00
|
|
|
if (key == KEY_ARROW) *boost = (*boost + 1) % 2;
|
2021-05-25 13:24:48 +02:00
|
|
|
if (key == KEY_OPTN && (background == 1 || background == 2)) return (background % 2) + 1;
|
2021-06-04 14:23:45 +02:00
|
|
|
if (key == KEY_VARS)
|
|
|
|
{
|
2021-06-04 18:21:01 +02:00
|
|
|
*mutation_menu = 4;
|
2021-06-04 14:23:45 +02:00
|
|
|
return 3;
|
|
|
|
}
|
2021-06-04 23:25:14 +02:00
|
|
|
if (key == KEY_SQUARE)
|
|
|
|
{
|
|
|
|
if (background == 1 || background == 2) return 6;
|
|
|
|
else if (background == 6) return 1;
|
|
|
|
}
|
2021-05-25 13:24:48 +02:00
|
|
|
|
2021-06-04 14:23:45 +02:00
|
|
|
if (key == KEY_ALPHA)
|
2021-05-25 13:24:48 +02:00
|
|
|
{
|
|
|
|
if (background == 5) return 3;
|
2021-06-05 13:15:27 +02:00
|
|
|
else return 1;
|
2021-05-25 13:24:48 +02:00
|
|
|
}
|
2021-06-04 14:23:45 +02:00
|
|
|
if (key == KEY_EXIT && (background == 1 || background == 2)) return -1;
|
2021-05-25 13:24:48 +02:00
|
|
|
|
|
|
|
if (background == 3)
|
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
// Symptoms
|
2021-06-04 14:23:45 +02:00
|
|
|
case KEY_LEFT:
|
|
|
|
*mutation_menu = *mutation_menu - 1;
|
|
|
|
if (*mutation_menu <= 0) *mutation_menu = 4;
|
2021-05-25 13:24:48 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Abilities
|
2021-06-04 14:23:45 +02:00
|
|
|
case KEY_RIGHT:
|
|
|
|
*mutation_menu = *mutation_menu + 1;
|
|
|
|
if (*mutation_menu >= 5) *mutation_menu = 1;
|
2021-05-25 13:24:48 +02:00
|
|
|
break;
|
|
|
|
|
2021-06-04 14:23:45 +02:00
|
|
|
// Validation
|
|
|
|
case KEY_SHIFT:
|
|
|
|
if (*mutation_menu == 4) return 1;
|
|
|
|
else return 5;
|
2021-05-25 13:24:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return background;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-02 22:13:39 +02:00
|
|
|
int rtc_key(void)
|
2021-05-25 13:24:48 +02:00
|
|
|
{
|
2021-06-04 14:23:45 +02:00
|
|
|
int opt = GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & ~GETKEY_MOD_ALPHA & ~GETKEY_REP_ARROWS;
|
2021-06-02 22:13:39 +02:00
|
|
|
int timeout = 1;
|
|
|
|
|
|
|
|
key_event_t ev = getkey_opt(opt, &timeout);
|
|
|
|
if(ev.type == KEYEV_NONE) return 0;
|
|
|
|
|
|
|
|
return ev.key;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int callback_tick(volatile int *tick)
|
|
|
|
{
|
|
|
|
*tick = 1;
|
|
|
|
return TIMER_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-04 22:26:31 +02:00
|
|
|
void message(char *msg)
|
2021-06-02 22:13:39 +02:00
|
|
|
{
|
2021-06-06 17:03:29 +02:00
|
|
|
int opt = GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & ~GETKEY_MOD_ALPHA & ~GETKEY_REP_ARROWS;
|
2021-06-06 18:05:30 +02:00
|
|
|
key_event_t ev = {0};
|
2021-06-02 22:13:39 +02:00
|
|
|
|
|
|
|
display_message(msg);
|
2021-06-06 18:05:30 +02:00
|
|
|
while (ev.key != KEY_ALPHA) ev = getkey_opt(opt, NULL);
|
2021-06-03 09:21:41 +02:00
|
|
|
}
|