Odyssee/project/src/main.c

109 lines
2.2 KiB
C

/*
Projet name .......: Odyssée
Version ...........: - dev -
Last modification .: 11 june 2021
code and assets provided with licence :
GNU General Public Licence v3.0
*/
#include <gint/display.h>
#include <gint/gray.h>
#include <gint/keyboard.h>
#include <gint/timer.h>
#include <gint/clock.h>
#include <gint/std/stdlib.h>
#include "core.h"
#include "display_engine.h"
// title_screen : display the title screen with particule effect
void title_screen(void);
void main_loop(void);
int main(void)
{
extern font_t font_odyssee;
dfont(&font_odyssee);
dgray(DGRAY_ON);
title_screen();
main_loop();
dgray(DGRAY_OFF);
dupdate();
return 1;
}
void title_screen(void)
{
extern const bopti_image_t img_title;
int key = 0;
// Initialise particule effect
srand(1551001551);
int coord_x[PARTICULE_NB];
int coord_y[PARTICULE_NB];
for (int i = 0; i < PARTICULE_NB; i ++)
{
coord_x[i] = rand() % 128;
coord_y[i] = rand() % 64;
}
static volatile int tick = 0;
int t = timer_configure(TIMER_ANY, ENGINE_TICK*1000, GINT_CALL(callback_tick, &tick));
if (t >= 0) timer_start(t);
while (!key)
{
while (!tick) sleep();
tick = 0;
dclear(C_WHITE);
dimage(0, 0, &img_title);
// Update particules positions
for (int i = 0; i < PARTICULE_NB; i ++)
{
dpixel(coord_x[i], coord_y[i], C_BLACK);
coord_x[i] += (rand() % 3) - 1;
coord_y[i] += (rand() % 3) - 1;
if (coord_x[i] < 0 || coord_x[i] > 128) coord_x[i] = rand() % 128;
if (coord_y[i] < 0 || coord_y[i] > 64) coord_y[i] = rand() % 64;
}
dupdate();
key = rtc_key();
}
if (t >= 0) timer_stop(t);
}
void main_loop(void)
{
extern const struct map map_world;
int key = 0;
struct player player = {DOWN};
struct game game = {map_world, 0, 0, player, 0};
while (key != KEY_EXIT)
{
dclear(C_WHITE);
draw_map(game);
draw_player(game);
dupdate();
key = getkey().key;
analyze_input(&game, key);
}
}