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

📄 sprite.cpp

📁 source code for mini mario
💻 CPP
字号:
#include "StdAfx.h"
#include "Sprite.h"

Sprite::Sprite(void)
{
}

Sprite::~Sprite(void)
{
}


Sprite::Sprite(int srcX, int srcY, int width, int height, int frameDirection, int frameCount, int frameDelay, MyBitmap *image)
{
	m_srcX = srcX;
	m_srcY = srcY;
	Width = width;
	Height = height;
	m_frameDirection = frameDirection;
	m_frameCount = frameCount;
	m_frameDelay = frameDelay;
	m_image = image;
	m_currentFrame = 0;
	m_loopType = 0;
	m_curDelay = 0;
	m_loopDirection = 1;
}

void Sprite::SetLoopType(int loopType)
{
	if((0 <= loopType) && (loopType <= 1))
		m_loopType = loopType;
}

void Sprite::NextFrame()
{
	if(m_curDelay >= m_frameDelay)
	{
		m_curDelay = 0;
		m_currentFrame += m_loopDirection;
		if(m_currentFrame >= m_frameCount && m_loopType == 0)
			m_currentFrame = 0;
		if(m_currentFrame >= m_frameCount && m_loopType == 1) {
			m_loopDirection *= -1;
			m_currentFrame = m_frameCount-1;
		}
		if(m_currentFrame < 0 && m_loopType == 1) {
			m_loopDirection *= -1;
			m_currentFrame = 1;
		}
	}
	else
		m_curDelay++;


}

void Sprite::PreviousFrame()
{
	m_currentFrame -= m_loopDirection;
	if(m_currentFrame < 0 && m_loopType == 0)
		m_currentFrame = m_frameCount-1;
	if(m_currentFrame >= m_frameCount && m_loopType == 1) {
		m_loopDirection *= -1;
		m_currentFrame = m_frameCount-1;
	}
	if(m_currentFrame < 0 && m_loopType == 1) {
		m_loopDirection *= -1;
		m_currentFrame = 1;
	}
}

void Sprite::SetDelay(int Delay)
{
	m_frameDelay = Delay;
}

void Sprite::Render(int X, int Y, CDC *pDC)
{
	int imageX, imageY;
	imageX = m_srcX;
	imageY = m_srcY;
	if(m_frameDirection == 0)
		imageY += (m_currentFrame*Height);
	else
		imageX += (m_currentFrame*Width);
	
	m_image->DrawTransparent(pDC,X,Y,imageX,imageY,imageX+Width,Height,RGB(255,255,255));
}

⌨️ 快捷键说明

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