2021-05-25 13:24:48 +02:00
|
|
|
/*
|
2021-06-02 22:13:39 +02:00
|
|
|
Project name ......: Plague
|
2021-06-05 13:38:03 +02:00
|
|
|
Version ...........: 1.3.3
|
2021-06-04 10:02:03 +02:00
|
|
|
Last modification .: 4 June 2021
|
2021-06-02 22:13:39 +02:00
|
|
|
|
|
|
|
code and assets provided with licence :
|
|
|
|
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>
|
2021-06-02 22:13:39 +02:00
|
|
|
#include <gint/defs/types.h>
|
|
|
|
#include <gint/std/stdlib.h>
|
2021-05-25 13:24:48 +02:00
|
|
|
|
|
|
|
#include "core.h"
|
|
|
|
#include "display_engine.h"
|
2021-06-02 22:13:39 +02:00
|
|
|
#include "mutation_engine.h"
|
2021-06-04 09:47:31 +02:00
|
|
|
#include "save.h"
|
2021-05-25 13:24:48 +02:00
|
|
|
|
2021-06-05 13:38:03 +02:00
|
|
|
const char *VERSION = "1.3.3";
|
|
|
|
|
2021-05-25 13:24:48 +02:00
|
|
|
// title_screen : display the title screen
|
|
|
|
static void title_screen(void);
|
|
|
|
|
2021-06-03 09:46:56 +02:00
|
|
|
|
2021-05-25 13:24:48 +02:00
|
|
|
// main_loop : display background, foreground and manage inputs
|
2021-06-04 23:25:14 +02:00
|
|
|
int main_loop(struct game *current_game);
|
2021-05-25 13:24:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
extern font_t font_plague;
|
|
|
|
dfont(&font_plague);
|
|
|
|
|
|
|
|
title_screen();
|
|
|
|
|
2021-06-02 22:13:39 +02:00
|
|
|
// Game statistics
|
2021-06-04 15:13:48 +02:00
|
|
|
struct plane plane_1 = {22, 20, 2, 84, 20, 22, 20, 0};
|
|
|
|
struct plane plane_2 = {34, 20, 3, 34, 44, 34, 20, 0};
|
|
|
|
struct plane plane_3 = {68, 44, 1, 68, 20, 68, 44, 0};
|
|
|
|
struct plane plane_4 = {104, 20, 3, 104, 50, 104, 20, 0};
|
|
|
|
struct plane plane_5 = {68, 44, 4, 34, 44, 68, 44, 0};
|
2021-05-25 13:24:48 +02:00
|
|
|
|
2021-06-04 09:47:31 +02:00
|
|
|
|
2021-06-02 22:13:39 +02:00
|
|
|
struct game current_game =
|
2021-05-25 13:24:48 +02:00
|
|
|
{
|
|
|
|
.contagion = 0,
|
|
|
|
.severity = 0,
|
|
|
|
.lethality = 0,
|
|
|
|
|
2021-06-03 09:46:56 +02:00
|
|
|
.dna = 0,
|
2021-05-25 13:24:48 +02:00
|
|
|
|
2021-06-02 22:13:39 +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-06-02 22:13:39 +02:00
|
|
|
.limit = RESEARCH_LIMIT,
|
|
|
|
.priority = 0,
|
|
|
|
.humans = {0, 1, 0, 0},
|
2021-05-25 13:24:48 +02:00
|
|
|
|
2021-06-05 13:15:27 +02:00
|
|
|
.time = 0, .total_time = 0, .boost = 0,
|
2021-05-25 13:24:48 +02:00
|
|
|
|
2021-06-02 22:13:39 +02:00
|
|
|
.planes = {&plane_1, &plane_2, &plane_3, &plane_4, &plane_5, NULL},
|
|
|
|
|
|
|
|
.grid = {64, 128, NULL},
|
2021-05-25 13:24:48 +02:00
|
|
|
};
|
|
|
|
|
2021-06-04 09:47:31 +02:00
|
|
|
// Allocate memory
|
2021-06-02 22:13:39 +02:00
|
|
|
current_game.grid.data = calloc(current_game.grid.width * current_game.grid.height, sizeof(uint8_t));
|
|
|
|
|
|
|
|
current_game.grid.data[95 + 20 * current_game.grid.width] = 1;
|
2021-06-04 16:32:37 +02:00
|
|
|
current_game.humans[0] = (current_game.grid.width * current_game.grid.height) - 1 - BLANK_CASES;
|
2021-06-02 22:13:39 +02:00
|
|
|
|
2021-06-04 09:47:31 +02:00
|
|
|
read_save(¤t_game);
|
|
|
|
|
2021-06-04 23:25:14 +02:00
|
|
|
int to_save = main_loop(¤t_game);
|
2021-05-25 13:24:48 +02:00
|
|
|
|
2021-06-04 23:25:14 +02:00
|
|
|
if (to_save) write_save(¤t_game);
|
|
|
|
else delete_save();
|
2021-06-04 09:47:31 +02:00
|
|
|
|
|
|
|
// Free memory
|
2021-06-02 22:13:39 +02:00
|
|
|
free(current_game.grid.data);
|
|
|
|
|
2021-05-25 13:24:48 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void title_screen(void)
|
|
|
|
{
|
|
|
|
extern bopti_image_t img_title;
|
2021-06-02 22:13:39 +02:00
|
|
|
extern bopti_image_t img_explosion;
|
|
|
|
|
|
|
|
dclear(C_BLACK);
|
|
|
|
dupdate();
|
2021-06-03 09:21:41 +02:00
|
|
|
sleep_ms(250);
|
2021-06-02 22:13:39 +02:00
|
|
|
|
2021-06-05 13:38:03 +02:00
|
|
|
for (int i = 64; i > 32; i --)
|
|
|
|
{
|
|
|
|
dclear(C_BLACK);
|
|
|
|
dsubimage(0, 0, &img_title, 0, 0, 128, 64, DIMAGE_NONE);
|
|
|
|
dprint_opt(16, i, C_WHITE, C_BLACK, 0, 0, "VERSION %s", VERSION, -1);
|
|
|
|
dupdate();
|
|
|
|
sleep_ms(75);
|
|
|
|
}
|
|
|
|
sleep_ms(1000);
|
|
|
|
|
2021-06-02 22:13:39 +02:00
|
|
|
|
|
|
|
for (int frame = 0; frame < 5; frame ++)
|
|
|
|
{
|
|
|
|
dclear(C_BLACK);
|
|
|
|
dsubimage(0, 0, &img_title, 0, 0, 128, 64, DIMAGE_NONE);
|
|
|
|
dsubimage(76, 9, &img_explosion, 41 * frame, 0, 40, 40, DIMAGE_NONE);
|
|
|
|
dupdate();
|
2021-06-03 09:21:41 +02:00
|
|
|
sleep_ms(100);
|
2021-06-02 22:13:39 +02:00
|
|
|
}
|
2021-05-25 13:24:48 +02:00
|
|
|
|
2021-06-02 22:13:39 +02:00
|
|
|
dclear(C_BLACK);
|
|
|
|
dsubimage(0, 0, &img_title, 0, 65, 128, 64, DIMAGE_NONE);
|
2021-05-25 13:24:48 +02:00
|
|
|
dupdate();
|
2021-06-05 13:38:03 +02:00
|
|
|
sleep_ms(1000);
|
2021-06-02 22:13:39 +02:00
|
|
|
|
|
|
|
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();
|
2021-06-03 09:21:41 +02:00
|
|
|
sleep_ms(250);
|
2021-06-02 22:13:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
dclear(C_BLACK);
|
|
|
|
dsubimage(0, 0, &img_title, 0, 130, 128, 64, DIMAGE_NONE);
|
|
|
|
dupdate();
|
|
|
|
|
2021-05-25 13:24:48 +02:00
|
|
|
getkey();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-04 23:25:14 +02:00
|
|
|
int main_loop(struct game *current_game)
|
2021-05-25 13:24:48 +02:00
|
|
|
{
|
2021-06-04 16:32:37 +02:00
|
|
|
int background = 1, mutation_menu = 4;
|
2021-06-04 23:25:14 +02:00
|
|
|
int end = 0, to_save = 1;
|
2021-05-25 13:24:48 +02:00
|
|
|
|
|
|
|
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);
|
2021-06-04 14:23:45 +02:00
|
|
|
display_foreground(background, current_game, mutation_menu);
|
2021-05-25 13:24:48 +02:00
|
|
|
dupdate();
|
|
|
|
|
2021-06-02 22:13:39 +02:00
|
|
|
// Compute the motion of planes, DNA points and infectious model
|
2021-06-04 23:25:14 +02:00
|
|
|
to_save = next_frame(current_game);
|
2021-06-05 13:15:27 +02:00
|
|
|
if (!to_save) end = 1;
|
2021-05-25 13:24:48 +02:00
|
|
|
|
|
|
|
// Get inputs from the keyboard and manage it
|
2021-06-05 13:15:27 +02:00
|
|
|
background = get_inputs(background, &mutation_menu, ¤t_game->boost);
|
2021-05-25 13:24:48 +02:00
|
|
|
|
|
|
|
// Special actions : quit and manage mutations
|
|
|
|
if (background == -1) end = 1;
|
|
|
|
if (background == 5)
|
|
|
|
{
|
2021-06-02 22:13:39 +02:00
|
|
|
mutation_select(current_game, mutation_menu);
|
2021-05-25 13:24:48 +02:00
|
|
|
background = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t >= 0) timer_stop(t);
|
2021-06-04 23:25:14 +02:00
|
|
|
return to_save;
|
2021-05-25 13:24:48 +02:00
|
|
|
}
|
|
|
|
|