2021-05-27 22:09:01 +02:00
|
|
|
#include <gint/timer.h>
|
|
|
|
#include <gint/clock.h>
|
2021-05-25 13:24:48 +02:00
|
|
|
#include <gint/keyboard.h>
|
|
|
|
|
|
|
|
#include "core.h"
|
2021-05-28 22:27:31 +02:00
|
|
|
#include "mutation_engine.h"
|
2021-06-01 11:36:26 +02:00
|
|
|
#include "epidemic_engine.h"
|
2021-05-25 13:24:48 +02:00
|
|
|
#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;
|
2021-05-30 18:56:22 +02:00
|
|
|
if (current_game->time > LIMIT_TICK)
|
2021-05-29 23:10:09 +02:00
|
|
|
{
|
|
|
|
current_game->time = 0;
|
2021-05-31 13:36:24 +02:00
|
|
|
if (current_game->dna <= 100) current_game->dna += 1;
|
2021-05-29 23:10:09 +02:00
|
|
|
|
2021-05-30 21:33:32 +02:00
|
|
|
current_game->research += current_game->priority;
|
2021-06-01 11:36:26 +02:00
|
|
|
if (current_game->research > current_game->limit)
|
|
|
|
{
|
|
|
|
const char *msg[5] = {"Vous avez", "perdu.", "", "", ""};
|
|
|
|
message(msg);
|
|
|
|
current_game->research = 0;
|
|
|
|
}
|
2021-05-30 21:33:32 +02:00
|
|
|
|
2021-06-01 11:36:26 +02:00
|
|
|
epidemic_simulation(current_game);
|
2021-05-29 23:10:09 +02:00
|
|
|
}
|
2021-05-25 13:24:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int get_inputs(const int background, int *mutation_menu)
|
|
|
|
{
|
2021-05-27 22:09:01 +02:00
|
|
|
int key = rtc_key();
|
2021-05-25 13:24:48 +02:00
|
|
|
|
|
|
|
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;
|
2021-05-29 16:44:46 +02:00
|
|
|
if (background == 1 || background == 2) return -1;
|
2021-05-25 13:24:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-27 22:09:01 +02:00
|
|
|
int rtc_key(void)
|
|
|
|
{
|
|
|
|
int opt = GETKEY_DEFAULT & ~GETKEY_REP_ARROWS;
|
|
|
|
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-05-30 18:56:22 +02:00
|
|
|
|
|
|
|
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);
|
2021-05-31 09:52:58 +02:00
|
|
|
}
|