Elphorina/src/main.c

146 lines
4.0 KiB
C
Raw Normal View History

2020-12-30 11:55:34 +01:00
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/clock.h>
extern bopti_image_t img_personnage;
extern bopti_image_t img_personnagemarche;
extern bopti_image_t img_personnagemarcheleft;
extern bopti_image_t img_personnageleft;
extern bopti_image_t img_personnage2;
extern bopti_image_t img_personnage2left;
struct anim {
bopti_image_t *img;
int duration;
struct anim *next;
};
struct anim anim_idle[2] = {
{ &img_personnage, 40, &anim_idle[1] },
{ &img_personnage2, 40, &anim_idle[0] },
};
struct anim anim_walk[2] = {
{ &img_personnagemarche, 5, &anim_walk[1] },
{ &img_personnage, 5, &anim_walk[0] },
};
struct anim anim_idle_left[2] = {
{ &img_personnageleft, 40, &anim_idle_left[1] },
{ &img_personnage2left, 40, &anim_idle_left[0] },
};
struct anim anim_walk_left[2] = {
{ &img_personnagemarcheleft, 5, &anim_walk_left[1] },
{ &img_personnageleft, 5, &anim_walk_left[0] },
};
int main(void)
{
struct anim *current_anim = &anim_idle[0];
int current_anim_time_left = 0;
int y = 31;
2020-12-30 11:55:34 +01:00
extern bopti_image_t img_personnage2left;
extern bopti_image_t img_personnageleft;
extern bopti_image_t img_personnagemarcheleft;
extern bopti_image_t img_personnage;
extern bopti_image_t img_personnagemarche;
extern bopti_image_t img_personnage2;
2020-12-31 17:13:47 +01:00
extern bopti_image_t img_bloc;
2020-12-30 11:55:34 +01:00
int a = 0;
int x = 16;
int xref = 0;
2020-12-30 11:55:34 +01:00
int timeout = 1;
/* <20>tat du personnage : 0=arr<72>t<EFBFBD>, 1=marche */
int state = 0;
/* <20>tat du personnage au frame pr<70>c<EFBFBD>dent */
int previous_state = 0;
while(a != 1)
{
/* Affichage */
dclear(C_WHITE);
dimage(x, y, current_anim->img);
dimage(xref+16,55,&img_bloc);
dimage(xref+32,55,&img_bloc);
dimage(xref+48,55,&img_bloc);
dimage(xref+64,55,&img_bloc);
dimage(xref+80,55,&img_bloc);
dimage(xref+96,55,&img_bloc);
dimage(xref+112,55,&img_bloc);
dimage(xref+128,55,&img_bloc);
dimage(xref+144,55,&img_bloc);
dimage(xref+160,55,&img_bloc);
2020-12-30 11:55:34 +01:00
dupdate();
/* Lecture des entr<74>es ; si on n'appuie sur rien, state=0 */
clearevents();
state = 0;
if(keydown(KEY_EXE))
a = 1;
if(keydown(KEY_RIGHT))
state = 1;
if(keydown(KEY_LEFT))
state = -1;
/* Ex<45>cution des animations */
if((previous_state == 0 && state == 1) || (previous_state == -1 && state == 1))
{
/* On vient de commencer <20> marcher */
current_anim = &anim_walk[0];
current_anim_time_left = current_anim->duration;
}
else if((previous_state == 1 && state == 0) || (previous_state == 1 && state == -1))
{
/* On vient de s'arr<72>ter */
current_anim = &anim_idle[0];
current_anim_time_left = current_anim->duration;
}
else if((previous_state == 0 && state == -1) || (previous_state == 1 && state == -1))
{
current_anim = &anim_walk_left[0];
current_anim_time_left = current_anim->duration;
}
else if((previous_state == -1 && state == 0) || (previous_state == -1 && state == 1))
{
current_anim = &anim_idle_left[0];
current_anim_time_left = current_anim->duration;
}
else
{
/* On continue l'anim pr<70>c<EFBFBD>dente */
current_anim_time_left--;
if(current_anim_time_left <= 0)
{
current_anim = current_anim->next;
current_anim_time_left = current_anim->duration;
}
}
/* Simulation du monde */
if(state == 1)
{
if(x <= xref+141)
x = x + 1;
xref = xref-1;
2020-12-30 11:55:34 +01:00
}
else if(state == -1)
{
x = x-1;
xref = xref+1;
2020-12-30 11:55:34 +01:00
}
/* D<>lai */
sleep_us(25000);
/* Pr<50>paration des invariants du frame suivant */
previous_state = state;
}
getkey();
return 1;
}