struct animate {
int drawable;
int animationFrames;
char *frames[TOTAL_FRAMES+1];
int charWidth;
int charHeight;
int xCoord;
int yCoord;
int xMove;
int yMove;
int currentFrame;
};
struct animate reaper[] =
{
{
1,
3,
{
"PIX\\Reaper\\reaper_right_r.gif",
"PIX\\Reaper\\reaper_right_still.gif",
"PIX\\Reaper\\reaper_right_l.gif",
"PIX\\Reaper\\reaper_right_still.gif",
},
50,
50,
enemyx,
enemyy,
10,
0,
0,
},
{
0,
3,
{
"PIX\\Reaper\\reaper_left_r.gif",
"PIX\\Reaper\\reaper_left_still.gif",
"PIX\\Reaper\\reaper_left_l.gif",
"PIX\\Reaper\\reaper_left_still.gif",
},
50,
50,
enemyx,
enemyy,
-10,
0,
0,
},
{
0,
3,
{
"PIX\\Reaper\\reaper_up_r.gif",
"PIX\\Reaper\\reaper_up_still.gif",
"PIX\\Reaper\\reaper_up_l.gif",
"PIX\\Reaper\\reaper_up_still.gif",
},
50,
50,
enemyx,
enemyy,
0,
-10,
0,
},
{
0,
3,
{
"PIX\\Reaper\\reaper_down_r.gif",
"PIX\\Reaper\\reaper_down_still.gif",
"PIX\\Reaper\\reaper_down_l.gif",
"PIX\\Reaper\\reaper_down_still.gif",
},
50,
50,
enemyx,
enemyy,
0,
10,
0,
},
};
void reaper_animation()
{
srand(time(NULL));
sprintf(charHealthBuff, "Health: %d", charHealth);
outtextxy(30, 30, charHealthBuff);
//randomly determines starting coordinates
enemyx = rand() % 100 + 600;
enemyy = rand() % 100 + 600;
for (int i = 0; i < 4; i++){
if( ! reaper[i].drawable)
continue;
//defines values of collisionBox struct
reaperHit.boundx = reaper[i].xCoord;
reaperHit.boundy = reaper[i].yCoord;
reaperHit.boundheight = reaper[i].charHeight;
reaperHit.boundwidth = reaper[i].charWidth;
//Puts image of reaper on screen based on inputs from struct
readimagefile(reaper[i].frames[reaper[i].currentFrame],
reaper[i].xCoord,
reaper[i].yCoord,
reaper[i].xCoord + reaper[i].charWidth,
reaper[i].yCoord + reaper[i].charHeight );
reaper[i].currentFrame++; //increments the "frame" by one, thus only animating one image at a time
if(reaper[i].currentFrame == reaper[i].animationFrames){
reaper[i].currentFrame = 0;} //When frame 3 is reached, it resorts back to first frame and restarts
//character[i].drawable = 0;}
//increments reaper position based on xMove or yMove value
reaper[i].xCoord += reaper[i].xMove;
reaper[i].yCoord += reaper[i].yMove;
//harms character if this collision is true
if(collisionTest(reaperHit, charHit) == true){
printf("reaper char COLLISION\n");
charHealth = charHealth - 5;}
//harms reaper if this collision is true
if(collisionTest(thunderHit, reaperHit) == true){
reaperHealth = reaperHealth - 10;}
}
}
void playReaper(){
int olddirection = 0, newdirection = 0; //starting values
int reaperDirection;
int moveLoop;
int activate = 0;
reaperHealth = 30;
do {
srand(time(NULL));
moveLoop = 10;
reaperDirection = rand() % 4;
//This loop keeps reaper going in same direction for more than one iteration
for(int k = 0; k < moveLoop; k++){
if(reaperDirection == 0)
newdirection = 0;
if(reaperDirection == 1)
newdirection = 1;
if(reaperDirection == 2)
newdirection = 2;
if(reaperDirection == 3)
newdirection = 3;
if(olddirection != newdirection){
reaper[newdirection].xCoord = reaper[olddirection].xCoord; //keeps xCoord and yCoord the same when changing directions
reaper[newdirection].yCoord = reaper[olddirection].yCoord; //allowing sprite to stay where they were
reaper[olddirection].drawable = 0; //the previous direction is no longer drawable
reaper[newdirection].drawable = 1; //new direction becomes drawable and animated
reaper[newdirection].currentFrame = 0; //resets frame to 0 so complete animation can begin
if(newdirection == 0 || newdirection == 1 || newdirection == 2 || newdirection == 3){
olddirection = newdirection;} //turns newdirection into olddirection for next run through of do-while() loop
}
checkReaperSectors(); //checks for sector collision and allows sector refresh
reaper_animation(); //animates the reaper
Sleep(40); //Slows reaper movement down
check_reaper(); //checks for collisions with wall or obstacles
}
}
while(reaperHealth > 0);
if(reaperHealth <= 0){
level++;}
}
好的,这是相当长的...大声笑,但这是我处理我的敌人动画,收割机的整个代码。有4个定义的结构可以调用每个方向的reaper值,playReaper()函数确定要绘制哪个结构,然后动画收割者实际将它放在屏幕上。
问题是......我一次只能得到一个收割机......我正在试图弄清楚如何用这个来上班,但我担心如果我把收割机改为上课,我将不得不改变角色,老板也上课? (它们使用相同的样式处理,使用animate结构)。
或者如何创建一个结构数组的数组。就像100个结构animate reaper []的数组。这将创建100个准备去个人收割者,然后我可以在每个级别调用一定数量的收割者,然后它们将随机出现并随机移动到屏幕上。
它只是......我不知道如何真正上课......所以我绝对不知道如何去做这个。我尝试在线研究,但它只是到目前为止......没有一个例子看起来像我想要的那样,所以很难将它们应用到我的代码中(特别是从未做过类...)。 / p>
我也不确定如何创建一个reaper []的数组。 :(
有人能指导我做我必须做的事吗?或者至少给我一个很好的起点?
非常感谢!!
P.S。这是简单的自上而下,2D游戏,我在graphics.h:/