2021-05-25 13:24:48 +02:00
|
|
|
/*
|
2021-05-29 23:02:51 +02:00
|
|
|
Project name ......: Plague
|
2021-05-28 22:37:04 +02:00
|
|
|
Version ...........: - dev -
|
2021-05-29 23:02:51 +02:00
|
|
|
Last modification .: 29 May 2021
|
2021-05-28 22:37:04 +02:00
|
|
|
|
2021-05-29 23:02:51 +02:00
|
|
|
code provided with licence :
|
2021-05-28 22:37:04 +02:00
|
|
|
GNU General Public Licence v3.0
|
2021-05-25 13:24:48 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gint/display.h>
|
|
|
|
#include <gint/keyboard.h>
|
|
|
|
#include <gint/timer.h>
|
|
|
|
#include <gint/clock.h>
|
|
|
|
|
|
|
|
#include "core.h"
|
|
|
|
#include "display_engine.h"
|
2021-05-29 23:02:51 +02:00
|
|
|
#include "mutation_engine.h"
|
2021-05-30 21:33:32 +02:00
|
|
|
#include "epidemic_engine.h"
|
2021-05-25 13:24:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
extern font_t font_plague;
|
|
|
|
dfont(&font_plague);
|
|
|
|
|
|
|
|
title_screen();
|
|
|
|
|
2021-05-29 16:44:46 +02:00
|
|
|
// Game statistics
|
2021-05-25 13:24:48 +02:00
|
|
|
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};
|
|
|
|
|
2021-05-29 16:44:46 +02:00
|
|
|
struct game current_game =
|
2021-05-25 13:24:48 +02:00
|
|
|
{
|
|
|
|
.contagion = 0,
|
|
|
|
.severity = 0,
|
|
|
|
.lethality = 0,
|
|
|
|
|
2021-05-29 23:10:09 +02:00
|
|
|
.dna = 0,
|
2021-05-25 13:24:48 +02:00
|
|
|
|
2021-05-29 23:02:51 +02:00
|
|
|
.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}},
|
2021-05-25 13:24:48 +02:00
|
|
|
|
|
|
|
.research = 0,
|
2021-05-30 21:33:32 +02:00
|
|
|
.limit = RESEARCH_LIMIT,
|
|
|
|
.priority = 0,
|
2021-05-25 13:24:48 +02:00
|
|
|
|
|
|
|
.time = 0,
|
|
|
|
|
2021-05-31 13:36:24 +02:00
|
|
|
.planes = {&plane_1, &plane_2, &plane_3, &plane_4, &plane_5, NULL},
|
|
|
|
|
|
|
|
.grid = {},
|
2021-05-25 13:24:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
main_loop(¤t_game);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void title_screen(void)
|
|
|
|
{
|
|
|
|
extern bopti_image_t img_title;
|
2021-05-31 09:52:58 +02:00
|
|
|
extern bopti_image_t img_explosion;
|
2021-05-25 13:24:48 +02:00
|
|
|
|
2021-05-31 09:52:58 +02:00
|
|
|
static volatile int tick_250 = 1;
|
|
|
|
static volatile int tick_100 = 1;
|
|
|
|
int t_250 = timer_configure(TIMER_ANY, 250000, GINT_CALL(callback_tick, &tick_250));
|
|
|
|
int t_100 = timer_configure(TIMER_ANY, 100000, GINT_CALL(callback_tick, &tick_100));
|
|
|
|
|
|
|
|
if (t_250 >= 0) timer_start(t_250);
|
|
|
|
if (t_100 >= 0) timer_start(t_100);
|
|
|
|
|
|
|
|
dclear(C_BLACK);
|
|
|
|
dupdate();
|
|
|
|
while (!tick_250) sleep();
|
|
|
|
tick_250 = 0;
|
|
|
|
|
|
|
|
dsubimage(0, 0, &img_title, 0, 0, 128, 64, DIMAGE_NONE);
|
|
|
|
dupdate();
|
|
|
|
while (!tick_250) sleep();
|
|
|
|
tick_250 = 0;
|
|
|
|
|
|
|
|
for (int frame = 0; frame < 5; frame ++)
|
|
|
|
{
|
|
|
|
dclear(C_BLACK);
|
|
|
|
dsubimage(0, 0, &img_title, 0, 0, 128, 64, DIMAGE_NONE);
|
|
|
|
dsubimage(72, 5, &img_explosion, 41 * frame, 0, 40, 40, DIMAGE_NONE);
|
|
|
|
dupdate();
|
|
|
|
while (!tick_100) sleep();
|
|
|
|
tick_100 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dclear(C_BLACK);
|
|
|
|
dsubimage(0, 0, &img_title, 0, 65, 128, 64, DIMAGE_NONE);
|
|
|
|
dupdate();
|
|
|
|
while (!tick_250) sleep();
|
|
|
|
tick_250 = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; i ++)
|
|
|
|
{
|
|
|
|
dclear(C_BLACK);
|
|
|
|
dsubimage(0, 0, &img_title, 0, ((i % 2) + 1) * 65, 128, 64, DIMAGE_NONE);
|
|
|
|
dupdate();
|
|
|
|
while (!tick_250) sleep();
|
|
|
|
tick_250 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dclear(C_BLACK);
|
|
|
|
dsubimage(0, 0, &img_title, 0, 130, 128, 64, DIMAGE_NONE);
|
2021-05-25 13:24:48 +02:00
|
|
|
dupdate();
|
2021-05-31 09:52:58 +02:00
|
|
|
|
2021-05-25 13:24:48 +02:00
|
|
|
getkey();
|
2021-05-31 09:52:58 +02:00
|
|
|
|
|
|
|
if (t_250 >= 0) timer_stop(t_250);
|
|
|
|
if (t_100 >= 0) timer_stop(t_100);
|
2021-05-25 13:24:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2021-05-30 18:56:22 +02:00
|
|
|
// Compute the motion of planes, DNA points and infectious model
|
2021-05-25 13:24:48 +02:00
|
|
|
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)
|
|
|
|
{
|
2021-05-29 23:02:51 +02:00
|
|
|
mutation_select(current_game, mutation_menu);
|
2021-05-25 13:24:48 +02:00
|
|
|
background = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t >= 0) timer_stop(t);
|
|
|
|
}
|
|
|
|
|