|
|
@ -36,10 +36,14 @@ struct gui_resource_t display_start() { |
|
|
|
null_die(res.title_img = IMG_LoadBoost("img/title.png"), "cannot load title img"); |
|
|
|
null_die(res.bgnd_img = IMG_LoadBoost("img/background.png"), "cannot load bg img"); |
|
|
|
null_die(res.board_img = IMG_LoadBoost("img/board.png"), "cannot load board img"); |
|
|
|
SDL_Surface *msgboard_srcimg; |
|
|
|
null_die(msgboard_srcimg = IMG_Load("img/msgboard.png"), "cannot load message board img"); |
|
|
|
res.msgboard_img = SDL_DisplayFormat(msgboard_srcimg); |
|
|
|
SDL_FreeSurface(msgboard_srcimg); |
|
|
|
|
|
|
|
/* cas spécial pour la variation de transparence */ |
|
|
|
SDL_Surface *srcimg; |
|
|
|
null_die(srcimg = IMG_Load("img/msgboard.png"), "cannot load message board img"); |
|
|
|
res.msgboard_img = SDL_DisplayFormat(srcimg); |
|
|
|
SDL_FreeSurface(srcimg); |
|
|
|
|
|
|
|
null_die(res.nameboard_img = IMG_LoadBoost("img/nameboard.png"), "cannot load name board img"); |
|
|
|
null_die(res.pawn_img[0] = IMG_LoadBoost("img/pawn0-void.png"), "cannot load void pawn img"); |
|
|
|
null_die(res.pawn_img[1] = IMG_LoadBoost("img/pawn1-yellow.png"), "cannot load yellow pawn img"); |
|
|
|
null_die(res.pawn_img[2] = IMG_LoadBoost("img/pawn2-black.png"), "cannot load black pawn img"); |
|
|
@ -50,11 +54,26 @@ struct gui_resource_t display_start() { |
|
|
|
|
|
|
|
/* chargement police de caractères */ |
|
|
|
null_die(res.font_big = TTF_OpenFont("img/cmunbmr.otf", 34), "cannot load font"); |
|
|
|
null_die(res.font_small = TTF_OpenFont("img/cmunbmr.otf", 18), "cannot load font"); |
|
|
|
null_die(res.font_small = TTF_OpenFont("img/cmunbmr.otf", 19), "cannot load font"); |
|
|
|
|
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
void draw_nameboard(const struct gui_resource_t *res, const char *name, SDL_Surface *destbuffer, double hide) { |
|
|
|
SDL_Surface *nbbuffer = SDL_ConvertSurface(res->nameboard_img, res->nameboard_img->format, res->nameboard_img->flags); |
|
|
|
/* rendu du nom */ |
|
|
|
SDL_Color text_color = {20, 18, 17, 0}; /* R, G, B, unused TODO: use parm color */ |
|
|
|
SDL_Surface *text_img = TTF_RenderUTF8_Blended(res->font_small, name, text_color); |
|
|
|
SDL_Rect textclip = { nbbuffer->w/2 - text_img->w/2, nbbuffer->h/2 - text_img->h/2, 0, 0 }; |
|
|
|
/* copie sur le fond */ |
|
|
|
SDL_BlitSurface(text_img, NULL, nbbuffer, &textclip); /* dessin du texte */ |
|
|
|
SDL_FreeSurface(text_img); |
|
|
|
/* copie du tout dans le buffer de destination */ |
|
|
|
SDL_Rect destclip = { SCREEN_X - nbbuffer->w + (short)(hide*(double)nbbuffer->w), 0, 0, 0 }; |
|
|
|
SDL_BlitSurface(nbbuffer, NULL, destbuffer, &destclip); |
|
|
|
SDL_FreeSurface(nbbuffer); |
|
|
|
} |
|
|
|
|
|
|
|
SDL_Rect coord_rotate(SDL_Rect coord, double sin, double cos) { |
|
|
|
SDL_Rect res; |
|
|
|
res.x = (short)round( cos * ((double)coord.x) + sin * ((double)coord.y) ); |
|
|
@ -143,13 +162,14 @@ void draw_all(const struct gui_resource_t *res, const struct game_state_t *games |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void display_render_board(const struct gui_resource_t *res, const struct game_state_t *gamestate, enum hole_t currentplayer) { |
|
|
|
void display_render_board(const struct gui_resource_t *res, const struct game_state_t *gamestate, enum hole_t currentplayer, const char *playername) { |
|
|
|
null_die(res, "ヌルポ。。。ガ! (gui_resource)"); |
|
|
|
null_die(gamestate, "ヌルポ。。。ガ! (game_state)"); |
|
|
|
draw_all(res, gamestate, NULL, ((((double)currentplayer)-1)*M_PI)/3, 1/*antialias*/, NULL); |
|
|
|
draw_nameboard(res, playername, res->screen, 0); |
|
|
|
} |
|
|
|
|
|
|
|
int display_anirotate_board(const struct gui_resource_t *res, const struct game_state_t *gamestate, enum hole_t currentplayer, enum hole_t nextplayer) { |
|
|
|
int display_anirotate_board(const struct gui_resource_t *res, const struct game_state_t *gamestate, enum hole_t currentplayer, const char *playername, enum hole_t nextplayer, const char *nextplayername) { |
|
|
|
null_die(res, "ヌルポ。。。ガ! (gui_resource)"); |
|
|
|
null_die(gamestate, "ヌルポ。。。ガ! (game_state)"); |
|
|
|
|
|
|
@ -165,11 +185,14 @@ int display_anirotate_board(const struct gui_resource_t *res, const struct game_ |
|
|
|
while(SDL_PollEvent(&event)) |
|
|
|
if(event.type == SDL_QUIT) |
|
|
|
return 1; |
|
|
|
|
|
|
|
double progress = ((double)frame)/((double)(ANIMTIME/ANIFRAMETIME)); |
|
|
|
/* progrès non-linéaire (cosinus au cours du temps) */ |
|
|
|
double anim_progress = ( ((double)nextplayer) - ((double)currentplayer) ) * ( cos(M_PI*((double)frame)/((double)(ANIMTIME/ANIFRAMETIME))+M_PI) + 1 ) / 2; |
|
|
|
double anim_progress = ( ((double)nextplayer) - ((double)currentplayer) ) * ( cos(M_PI*progress + M_PI) + 1 ) / 2; |
|
|
|
double angle = ( anim_progress + (((double)currentplayer)-1) ) * M_PI / 3; |
|
|
|
|
|
|
|
draw_all(res, gamestate, NULL, angle, frame == ANIMTIME/ANIFRAMETIME, NULL); /* antialiasing si dernière frame, sinon pas */ |
|
|
|
draw_nameboard(res, (progress < 0.5)?playername:nextplayername, res->screen, sin(progress*M_PI)); |
|
|
|
SDL_Flip(res->screen); |
|
|
|
|
|
|
|
/* attente du temps restant dans la frame : stabilisation de la vitesse d'exécution */ |
|
|
@ -184,7 +207,7 @@ int display_anirotate_board(const struct gui_resource_t *res, const struct game_ |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int display_animove_pawn(const struct gui_resource_t *res, struct game_state_t gamestate, enum hole_t currentplayer, int startpos, int endpos) { |
|
|
|
int display_animove_pawn(const struct gui_resource_t *res, struct game_state_t gamestate, enum hole_t currentplayer, const char *playername, int startpos, int endpos) { |
|
|
|
null_die(res, "ヌルポ。。。ガ! (gui_resource)"); |
|
|
|
|
|
|
|
#define PANIFRAMETIME 40 /* 40ms → 25fps */ |
|
|
@ -195,6 +218,7 @@ int display_animove_pawn(const struct gui_resource_t *res, struct game_state_t g |
|
|
|
SDL_Surface *buffer = SDL_ConvertSurface(res->bgnd_img, res->bgnd_img->format, res->bgnd_img->flags); |
|
|
|
struct pos_export_t pos_import = { {startpos, endpos}, {{0, 0, 0, 0}, {SCREEN_X, SCREEN_Y, 0, 0}} }; |
|
|
|
draw_all(res, &gamestate, buffer, ((((double)currentplayer)-1)*M_PI)/3, 1/*antialias*/, &pos_import); |
|
|
|
draw_nameboard(res, playername, buffer, 0); |
|
|
|
|
|
|
|
uint32_t time1, time2; /* mesure du temps de rendu de frame */ |
|
|
|
SDL_Event event; |
|
|
@ -242,7 +266,7 @@ int find_pawn_index(Uint16 click_x, Uint16 click_y, const struct pawns_pxcoords_ |
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
int display_usermove_pawn(const struct gui_resource_t *res, const struct game_state_t *gamestate, enum hole_t currentplayer, struct move_t *move, int *moremoves) { |
|
|
|
int display_usermove_pawn(const struct gui_resource_t *res, const struct game_state_t *gamestate, enum hole_t currentplayer, const char *playername, struct move_t *move, int *moremoves) { |
|
|
|
null_die(res, "ヌルポ。。。ガ! (gui_resource)"); |
|
|
|
null_die(gamestate, "ヌルポ。。。ガ! (game_state)"); |
|
|
|
null_die(move, "ヌルポ。。。ガ! (move)"); |
|
|
@ -255,7 +279,7 @@ int display_usermove_pawn(const struct gui_resource_t *res, const struct game_st |
|
|
|
int quit = 0; |
|
|
|
while(!quit) { |
|
|
|
/* (ré)affichage du plateau dans son état d'avant le mouvement */ |
|
|
|
display_render_board(res, gamestate, currentplayer); |
|
|
|
display_render_board(res, gamestate, currentplayer, playername); |
|
|
|
SDL_Flip(res->screen); |
|
|
|
|
|
|
|
/* attente du début de glisser-déposer */ |
|
|
@ -287,6 +311,7 @@ int display_usermove_pawn(const struct gui_resource_t *res, const struct game_st |
|
|
|
struct game_state_t tmp_gamestate = *gamestate; /* copie du plateau */ |
|
|
|
tmp_gamestate.board[move->startPos] = none; /* on enlève le pion en déplacement */ |
|
|
|
draw_all(res, &tmp_gamestate, bgbufferdrag, ((((double)currentplayer)-1)*M_PI)/3, 1/*antialias*/, NULL); /* dessin du plateau sans pion en buffer */ |
|
|
|
draw_nameboard(res, playername, bgbufferdrag, 0); |
|
|
|
|
|
|
|
/* attente de la fin de glisser-déposer */ |
|
|
|
int release = 0; |
|
|
@ -329,7 +354,7 @@ int display_usermove_pawn(const struct gui_resource_t *res, const struct game_st |
|
|
|
return quit; |
|
|
|
} |
|
|
|
|
|
|
|
int display_animsg(const struct gui_resource_t *res, const struct game_state_t *gamestate, enum hole_t currentplayer, const char *msg, uint32_t duration) { |
|
|
|
int display_animsg(const struct gui_resource_t *res, const struct game_state_t *gamestate, enum hole_t currentplayer, const char *playername, const char *msg, uint32_t duration) { |
|
|
|
null_die(res, "ヌルポ。。。ガ! (gui_resource)"); |
|
|
|
null_die(gamestate, "ヌルポ。。。ガ! (game_state)"); |
|
|
|
|
|
|
@ -338,6 +363,7 @@ int display_animsg(const struct gui_resource_t *res, const struct game_state_t * |
|
|
|
/* mise en buffer de l'image de fond */ |
|
|
|
SDL_Surface *bgbuffer = SDL_ConvertSurface(res->bgnd_img, res->bgnd_img->format, res->bgnd_img->flags); |
|
|
|
draw_all(res, gamestate, bgbuffer, ((((double)currentplayer)-1)*M_PI)/3, 1/*antialias*/, NULL); |
|
|
|
draw_nameboard(res, playername, bgbuffer, 0); |
|
|
|
|
|
|
|
/* mise en buffer de l'image du message */ |
|
|
|
SDL_Surface *msgbuffer = SDL_ConvertSurface(res->msgboard_img, res->msgboard_img->format, res->msgboard_img->flags); |
|
|
@ -392,6 +418,7 @@ void display_close(struct gui_resource_t *res) { |
|
|
|
SDL_FreeSurface(res->title_img); |
|
|
|
SDL_FreeSurface(res->board_img); |
|
|
|
SDL_FreeSurface(res->msgboard_img); |
|
|
|
SDL_FreeSurface(res->nameboard_img); |
|
|
|
int i; |
|
|
|
for( i = 0; i < 7; i++) |
|
|
|
SDL_FreeSurface(res->pawn_img[i]); |
|
|
|