1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
//struct template for animating character movement
struct animate {
int draws;
int animationFrames;
char *frames[TOTAL_FRAMES];
int charWidth;
int charHeight;
int xCoord;
int yCoord;
int xMove;
int yMove;
int currentFrame;
};
//Actual struct for character movement
struct animate character[TOTAL_FRAMES] =
{
{
//Character moving left
1,
3,
{
"PIX\\Character\\left_r.gif",
"PIX\\Character\\left_still.gif",
"PIX\\Character\\left_l.gif",
"PIX\\Character\\left_still.gif",
},
50,
50,
x9,
y9,
x9 = x9 + 5,
0,
0,
},
{
//Character moving right
2,
3,
{
"PIX\\Character\\right_r.gif",
"PIX\\Character\\right_still.gif",
"PIX\\Character\\right_l.gif",
"PIX\\Character\\right_still.gif",
},
50,
50,
x9,
y9,
x9 = x9 + 5,
0,
0,
},
{
//Character moving up
3,
3,
{
"PIX\\Character\\up_r.gif",
"PIX\\Character\\up_still.gif",
"PIX\\Character\\up_l.gif",
"PIX\\Character\\up_still.gif",
},
50,
50,
x9,
y9,
0,
y9 = y9 - 5,
0,
},
{
//Character moving down
4,
3, //number of frames for array to consider
{
"PIX\\Character\\down_r.gif",
"PIX\\Character\\down_still.gif",
"PIX\\Character\\down_l.gif",
"PIX\\Character\\down_still.gif",
},
50, //width of character
50, //Height of character
x9, //starting position
y9,
0,
y9 = y9 + 5, //Character movement
0,
},
};
void character_animation()
{
for (int i = 0; i < MAX_LOOPS; i++){
if( ! character[i].draws)
continue;
//Puts image of character on screen based on inputs from struct
readimagefile(character[i].frames[character[i].currentFrame],
character[i].xCoord,
character[i].yCoord,
character[i].xCoord + character[i].charWidth,
character[i].yCoord + character[i].charHeight );
character[i].currentFrame++; //increments the "frame" by one, thus only animating one image at a time
if(character[i].currentFrame == character[i].animationFrames){
character[i].currentFrame = 0; //When frame 4 is reached, it resorts back to first frame and restarts
character[i].draws = 0;}
//These next two lines of code dictate the movement of the character
character[i].xCoord += character[i].xMove;
character[i].yCoord += character[i].yMove;
}
//putimage(0, 0, bkimage, COPY_PUT);
Sleep(10);
}
|