Esempio n. 1
0
static void GetCharacterPics(
	ActorPics *pics, Character *c, const direction_e dir, const int frame,
	const NamedSprites *gunPics, const gunstate_e gunState,
	const bool isTransparent, HSV *tint, color_t *mask,
	const int deadPic)
{
	memset(pics, 0, sizeof *pics);
	pics->DrawOrder[0] = pics->DrawOrder[1] = pics->DrawOrder[2] = -1;
	pics->Colors = &c->Colors;

	// If the actor is dead, simply draw a dying animation
	pics->IsDead = deadPic > 0;
	if (pics->IsDead)
	{
		if (deadPic < DEATH_MAX)
		{
			pics->IsDying = true;
			pics->Body = GetDeathPic(&gPicManager, deadPic - 1);
			pics->DrawOrder[0] = BODY_PART_BODY;
		}
		return;
	}

	pics->IsTransparent = isTransparent;
	if (pics->IsTransparent)
	{
		pics->Tint = &tintDarker;
	}
	else if (tint != NULL)
	{
		pics->Tint = tint;
		pics->Mask = mask;
	}

	// Head
	direction_e headDir = dir;
	int headFrame = frame;
	// If firing, draw the firing head pic
	if (gunState == GUNSTATE_FIRING || gunState == GUNSTATE_RECOIL)
	{
		headFrame = STATE_COUNT + gunState - GUNSTATE_FIRING;
	}
	// If idle, turn head left/right on occasion
	if (headFrame == STATE_IDLELEFT) headDir = (dir + 7) % 8;
	else if (headFrame == STATE_IDLERIGHT) headDir = (dir + 1) % 8;

	pics->Head = GetHeadPic(c->Class, headDir, headFrame);

	// Body
	const bool isArmed = gunPics != NULL;
	pics->Body = GetBodyPic(&gPicManager, dir, frame, isArmed);

	// Gun
	pics->Gun = NULL;
	if (isArmed)
	{
		pics->Gun = GetGunPic(gunPics, dir, gunState);
	}

	// Determine draw order based on the direction the player is facing
	// Order is: 0: head, 1: body, 2: gun
	switch (dir)
	{
	case DIRECTION_UP:
	case DIRECTION_UPRIGHT:
		pics->DrawOrder[0] = BODY_PART_GUN;
		pics->DrawOrder[1] = BODY_PART_HEAD;
		pics->DrawOrder[2] = BODY_PART_BODY;
		break;

	case DIRECTION_RIGHT:
	case DIRECTION_DOWNRIGHT:
	case DIRECTION_DOWN:
	case DIRECTION_DOWNLEFT:
		pics->DrawOrder[0] = BODY_PART_BODY;
		pics->DrawOrder[1] = BODY_PART_HEAD;
		pics->DrawOrder[2] = BODY_PART_GUN;
		break;

	case DIRECTION_LEFT:
	case DIRECTION_UPLEFT:
		pics->DrawOrder[0] = BODY_PART_GUN;
		pics->DrawOrder[1] = BODY_PART_BODY;
		pics->DrawOrder[2] = BODY_PART_HEAD;
		break;
	default:
		CASSERT(false, "invalid direction");
		return;
	}
}
Esempio n. 2
0
ActorPics GetCharacterPics(
	Character *c, const direction_e dir,
	const ActorAnimation anim, const int frame,
	const NamedSprites *gunPics, const gunstate_e gunState,
	const bool isTransparent, HSV *tint, color_t *mask,
	const int deadPic)
{
	ActorPics pics;
	memset(&pics, 0, sizeof pics);
	pics.Colors = &c->Colors;

	// If the actor is dead, simply draw a dying animation
	pics.IsDead = deadPic > 0;
	if (pics.IsDead)
	{
		if (deadPic < DEATH_MAX)
		{
			pics.IsDying = true;
			pics.Body = GetDeathPic(&gPicManager, deadPic - 1);
			pics.OrderedPics[0] = pics.Body;
		}
		return pics;
	}

	pics.IsTransparent = isTransparent;
	if (pics.IsTransparent)
	{
		pics.Tint = &tintDarker;
	}
	else if (tint != NULL)
	{
		pics.Tint = tint;
		pics.Mask = mask;
	}

	// Head
	direction_e headDir = dir;
	// If idle, turn head left/right on occasion
	if (anim == ACTORANIMATION_IDLE)
	{
		if (frame == IDLEHEAD_LEFT) headDir = (dir + 7) % 8;
		else if (frame == IDLEHEAD_RIGHT) headDir = (dir + 1) % 8;
	}
	pics.Head = GetHeadPic(c->Class, headDir, gunState);
	pics.HeadOffset = GetActorDrawOffset(
		pics.Head, BODY_PART_HEAD, c->Class->Sprites, anim, frame, dir);

	// Body
	const bool isArmed = gunPics != NULL;
	pics.Body = GetBodyPic(
		&gPicManager, c->Class->Sprites, dir, anim, frame, isArmed);
	pics.BodyOffset = GetActorDrawOffset(
		pics.Body, BODY_PART_BODY, c->Class->Sprites, anim, frame, dir);

	// Legs
	pics.Legs = GetLegsPic(
		&gPicManager, c->Class->Sprites, dir, anim, frame);
	pics.LegsOffset = GetActorDrawOffset(
		pics.Legs, BODY_PART_LEGS, c->Class->Sprites, anim, frame, dir);

	// Gun
	pics.Gun = NULL;
	if (isArmed)
	{
		pics.Gun = GetGunPic(gunPics, dir, gunState);
		pics.GunOffset = GetActorDrawOffset(
			pics.Gun, BODY_PART_GUN, c->Class->Sprites, anim, frame, dir);
	}

	// Determine draw order based on the direction the player is facing
	for (BodyPart bp = BODY_PART_HEAD; bp < BODY_PART_COUNT; bp++)
	{
		const BodyPart drawOrder = c->Class->Sprites->Order[dir][bp];
		switch (drawOrder)
		{
		case BODY_PART_HEAD:
			pics.OrderedPics[bp] = pics.Head;
			pics.OrderedOffsets[bp] = pics.HeadOffset;
			break;
		case BODY_PART_BODY:
			pics.OrderedPics[bp] = pics.Body;
			pics.OrderedOffsets[bp] = pics.BodyOffset;
			break;
		case BODY_PART_LEGS:
			pics.OrderedPics[bp] = pics.Legs;
			pics.OrderedOffsets[bp] = pics.LegsOffset;
			break;
		case BODY_PART_GUN:
			pics.OrderedPics[bp] = pics.Gun;
			pics.OrderedOffsets[bp] = pics.GunOffset;
			break;
		default:
			break;
		}
	}

	pics.Sprites = c->Class->Sprites;

	return pics;
}