flipping.c v flipping.cyTEXTCWIEAvw#include #include #include #include "flipping.h" #include "card.h" // Data structure for a card that has to be or is being flipped. typedef struct flipitem { long x,y; // Current position of card (1 pixel = 256). long xstep,ystep; // Amount card should move by each frame. short angle; /* Current angle card is rotated about it's y-axis: * 0 = Full front of card can be seen. * 2048 = Full back of card can be seen. */ short anglechange; // Amount angle should change by each frame. card c; // Card being flipped. card *oldptr, *ptr; // Pointers to original and target card destinations. u_char on; // Whether the card is currently being flipped. u_char timer; // How many more frames should the card be animated by. struct flipitem *next; // Next item in list. } flip; static int delaytonext; // Delay until next card should start to flip. // Pointer to beginning of linked list containing all flips. static flip *flips = NULL; // Delay between each card being flipped (in frames). #define delaybetween 8 // Number of frames a flipped card is in the air for. #define flipsteps 24 void FlipCard(short x0, short y0, short x1, short y1, card cin, card *cout, u_char type) { flip *newflip; // Create memory for new flip item. newflip = (flip*)malloc(sizeof(flip)); newflip->x = x0<<8; newflip->y = y0<<8; /* Calculate how far card should move by each frame in order to reach it's * target destination. */ newflip->xstep = ((x1<<8) - (x0<<8))/flipsteps; newflip->ystep = ((y1<<8) - (y0<<8))/flipsteps; newflip->c = cin; newflip->oldptr = NULL; newflip->ptr = cout; newflip->on = 0; newflip->timer = flipsteps; switch (type) { case 0: // Back to front. newflip->angle = 2048; newflip->anglechange = 2048/flipsteps; break; case 1: // Front to front. newflip->angle = 0; newflip->anglechange = 4096/flipsteps; break; } if (flips==NULL) delaytonext = 0; // If this is first card the flip it immediately. // Bung new card onto the linked list. newflip->next = flips; flips = newflip; } void FlipCard2(short x0, short y0, short x1, short y1, card *cin, card *cout, u_char type) { // As above but cout gets copied into oldptr. flip *newflip; newflip = (flip*)malloc(sizeof(flip)); newflip->x = x0<<8; newflip->y = y0<<8; newflip->xstep = ((x1<<8) - (x0<<8))/flipsteps; newflip->ystep = ((y1<<8) - (y0<<8))/flipsteps; newflip->c = *cin; newflip->oldptr = cin; newflip->ptr = cout; newflip->on = 0; newflip->timer = flipsteps; switch (type) { case 0: newflip->angle = 2048; newflip->anglechange = 2048/flipsteps; break; case 1: newflip->angle = 0; newflip->anglechange = 4096/flipsteps; break; } if (flips==NULL) delaytonext = 0; newflip->next = flips; flips = newflip; } u_char Flipping() {return (flips!=NULL);} void FlipCards(GsOT *OT) { flip *flipptr, *flipptr2; if (flips!=NULL) { // flipptr2 points to flip item before flipptr. flipptr = flips; flipptr2 = NULL; while (flipptr!=NULL) { if (flipptr->on) { // Move flipptr->x+=flipptr->xstep; flipptr->y+=flipptr->ystep; flipptr->angle+=flipptr->anglechange; // Plot PlotAngledCard(OT, &flipptr->c, flipptr->x>>8, flipptr->y>>8, flipptr->angle); /* If timer runs out then move card into it's target location and remove * the flip item from the list. */ if ((--flipptr->timer)==0) { *(flipptr->ptr) = flipptr->c; if (flipptr2==NULL) flips = NULL; else flipptr2->next = flipptr->next; free(flipptr); flipptr = flipptr2; } } flipptr2 = flipptr; if (flipptr!=NULL) flipptr = flipptr->next; } if ((delaytonext--) == 0 && flips!=NULL) { // Start flipping a new card. delaytonext = delaybetween; // Find last item in list that hasn't yet been switched on. flipptr = flips; flipptr2 = NULL; while (flipptr!=NULL) { if (!flipptr->on) flipptr2 = flipptr; flipptr = flipptr->next; } if (flipptr2!=NULL) { flipptr2->on = 1; if (flipptr2->oldptr!=NULL) flipptr2->oldptr->valid = 0; } } } } ZZR $0@ X X  <Ե! flipping.cr IDE 2.0.3atantallerTEXTCWIEvAHP  <Եk!!Pj> I0@ P H <Ե!!P I(!H0H @*P <Ե)!!@* I!% 0H Monaco5 e5 e99 ZZRNX1RMPSRMWBB*LR