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

📄 smario.cpp

📁 用VC++及DirectX实现的SuperMario小游戏
💻 CPP
字号:
/*
Author: Bear

This source is free to anybody.
If you have any problem with this or some advice to me, please:
    mailto: heyang22118952.student@sina.com
        or  yang45249.student@sina.com
or you can contact me through my QQ:     261570581

Welcome to discuss game programming techniques with me :)
And I like to play games!
*/
#include ".\smario.h"

SMario::SMario(void)
{
	this->m_screenX = 350;
	this->m_isJumping = false;
	this->m_landed = true;
	this->m_isDead = false;
}

SMario::~SMario(void)
{
	UnInit();
}

void SMario::Anim(void)
{
	if(this->m_speedX != 0) {	//moving
		this->m_posX += this->m_speedX;
		
		if(this->m_speedX > 0) forward = true;
		else forward = false;
		
		if(!this->m_isJumping) {
			static int ncount = 0;
			static int ntemp = 1;
			ncount++;
			if(ncount == 4) {
				ncount = 0;
				ntemp++;
				if(ntemp == 5) {
					ntemp = 1;
				}
				this->m_nCurFrame = this->m_animSeq[ntemp];
			}
		}
	}
	else {
		if(!this->m_isJumping && m_landed) {
			this->m_nCurFrame = this->m_animSeq[0];
		}
	}
	if(this->m_isJumping) {		//jumping
		static int ncount = 0;
		this->m_posY -= this->m_speedY;
		ncount++;
		if(ncount % 4 == 0) {
			this->m_speedY -= 3;
			if(this->m_speedY == 0) {
				ncount = 0;
				this->m_isJumping = false;
				this->m_landed = false;
			}
		}
	}
	else if(!this->m_landed) {	//dropping
		static int ncount = 0;
		this->m_posY -= this->m_speedY;
		ncount++;
		if(ncount == 4) {
			ncount = 0;
			this->m_speedY -= 3;
			if(this->m_speedY <= -15) {
				this->m_speedY = -15;
			}
		}
		if(this->m_posY >= 400) {
			this->m_posY = 400;
			this->m_landed = true;
			this->m_speedY = 0;
		}
	}
}

int SMario::GetScreenX(void)
{
	return this->m_screenX;
}

void SMario::Jump(void)
{
	if(!m_isJumping && m_landed) {
		this->m_isJumping = true;
		this->m_nCurFrame = this->m_animSeq[5];
		this->m_speedY = 15;
		this->m_landed = false;
	}
}

void SMario::StopJump(void)
{
	this->m_isJumping = false;
	this->m_speedY = -this->m_speedY;
	this->m_posY -= this->m_speedY;
	this->m_landed = false;
}

bool SMario::IsJumping(void)
{
	return this->m_isJumping;
}

void SMario::SetSpeedX(int speedX)
{
	this->m_speedX = speedX;
}

void SMario::Land(int height)
{
	this->m_landed = true;
	this->m_posY = height - this->m_height;
	this->m_speedY = 0;
}

bool SMario::IsLanded(void)
{
	return m_landed;
}

void SMario::MoveBack(void)
{
	this->m_posX -= this->m_speedX;
}

void SMario::Drop(void)
{
	this->m_landed = false;
}

void SMario::Move(void)
{
	this->m_posX += this->m_speedX;
}

void SMario::Die(void)
{
	this->m_isDead = true;
}

⌨️ 快捷键说明

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