⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 animate.c

📁 著名物理引擎Hawk的源代码
💻 C
字号:
/* animate.c, HAWK game engine
 *
 * Copyright 1997-1998 by Phil Frisbie, Jr.
 * for Hawk Software
 *
 */

#include "hawk.h"
#include "internal.h"


ANIMATION	Animations[MAX_OBJECTS];

void animUpdate(int animation)
{
	ANIMATION	*anim = &Animations[animation];
	int	frames = Engine.animframes;/* number of frames to advance */

	if(!frames)
		return;
	if(anim->nstart == -1) /* start next animation NOW! */
	{
		anim->cfirst = anim->cframe = anim->nfirst;
		anim->clast = anim->nlast;
		anim->next = anim->cframe + 1;
		if(anim->next > anim->clast)
			anim->next = anim->cfirst;/* loop back to beginning if only one frame */
		anim->nfirst = anim->nlast = NO_FRAME;
		anim->nstart = 0;
		return;
	}
	if(anim->nstart >= Engine.gameframes)/*start next animation */
	{
		if((anim->cframe + frames) > anim->clast)
		{
			anim->cfirst = anim->cframe = anim->nfirst;
			anim->clast = anim->nlast;
			anim->next = anim->cframe + 1;
			if(anim->next > anim->clast)
				anim->next = anim->cfirst;/* loop back to beginning if only one frame */
			anim->nfirst = anim->nlast = NO_FRAME;
			anim->nstart = 0;
			return;
		}
	}
	if(anim->loop)
	{
		if(anim->cfirst == anim->clast)
			return;
		anim->cframe += frames;
		while(anim->cframe > anim->clast)
		{
			anim->cframe += anim->cfirst;
			anim->cframe -= anim->clast;
		}
		anim->next = anim->cframe + 1;
		if(anim->next > anim->clast)
			anim->next = anim->cfirst;/* loop back to beginning */
	}
	else
	{
		anim->cframe += frames;
		if(anim->cframe > anim->clast)/* switch to default animation */
		{
			anim->cfirst = anim->cframe = anim->dfirst;
			anim->clast = anim->dlast;
			anim->loop = TRUE;
			anim->next = anim->cframe + 1;
			if(anim->next > anim->clast)
				anim->next = anim->cfirst;/* loop back to beginning if only one frame */
		}
	}
}

void animInit(void)
{
	memset(Animations, 0, (sizeof(Animations[0]) * MAX_OBJECTS));
}

int animAdd(void)
{
	int			i;
	static BOOL	init = TRUE;

	if(init)	/* first time through */
	{
		animInit();
		init = FALSE;
	}

	for(i=0;i<MAX_OBJECTS; i++)
	{
		if(!Animations[i].used)
		{
			ANIMATION	*anim = &Animations[i];

			anim->used = TRUE;
			anim->loop = FALSE;
			anim->smooth = FALSE;
			anim->speed = 1.0;
			anim->cfirst = NO_FRAME;
			anim->clast = NO_FRAME;
			anim->nfirst = NO_FRAME;
			anim->nlast = NO_FRAME;

			return i;
		}
	}
	return NO_ANIMATION;
}

void animDelete(int animation)
{
	memset(&Animations[animation], 0, sizeof(Animations[0]));
}

void animSetDefault(int animation, int first, int last)
{
	Animations[animation].dfirst = first;
	Animations[animation].dlast = last;
	Animations[animation].cfirst = first;
	Animations[animation].clast = last;
}

void animSetNext(int animation, int first, int last, int start)
{
	Animations[animation].nfirst = first;
	Animations[animation].nlast = last;
	Animations[animation].nstart = start;
}

void animSetLoop(int animation, BOOL loop)
{
	Animations[animation].loop = loop;
}

int animGetCurrentFrame(int animation)
{
	return Animations[animation].cframe;
}

int animGetNextFrame(int animation)
{
	return Animations[animation].next;
}

void animSetCurrentFrame(int animation, int frame)
{
	Animations[animation].cframe = frame;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -