156 lines
4.2 KiB
C
Executable File
156 lines
4.2 KiB
C
Executable File
#include <gint/display.h>
|
|
#include <gint/keyboard.h>
|
|
#include <gint/clock.h>
|
|
#define bloc 1
|
|
#define other 2
|
|
|
|
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;
|
|
typedef int type;
|
|
struct object {
|
|
bopti_image_t *img;
|
|
int x;
|
|
int y;
|
|
type typeObj = bloc;
|
|
struct object *next;
|
|
};
|
|
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, 3 , &anim_walk[1] },
|
|
{ &img_personnage, 3, &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, 3, &anim_walk_left[1] },
|
|
{ &img_personnageleft, 3, &anim_walk_left[0] },
|
|
};
|
|
int main(void)
|
|
{
|
|
struct anim *current_anim = &anim_idle[0];
|
|
int current_anim_time_left = 0;
|
|
int y = 31;
|
|
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;
|
|
extern bopti_image_t img_bloc;
|
|
int a = 0;
|
|
int x = 64;
|
|
int xref = 0;
|
|
int timeout = 1;
|
|
|
|
/* État du personnage : 0=arrêté, 1=marche */
|
|
int state = 0;
|
|
/* État du personnage au frame précé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);
|
|
dupdate();
|
|
|
|
/* Lecture des entré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écution des animations */
|
|
|
|
if((previous_state == 0 && state == 1) || (previous_state == -1 && state == 1))
|
|
{
|
|
/* On vient de commencer à 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ê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écé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+160)
|
|
{
|
|
xref = xref-1;
|
|
}
|
|
|
|
}
|
|
else if(state == -1)
|
|
{
|
|
xref = xref+1;
|
|
|
|
}
|
|
|
|
/* Délai */
|
|
sleep_us(25000);
|
|
|
|
/* Préparation des invariants du frame suivant */
|
|
previous_state = state;
|
|
}
|
|
|
|
getkey();
|
|
return 1;
|
|
}
|