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

📄 fight.cpp

📁 圣剑二完整的游戏代码。附作者写的三篇文章。游戏的开发过程
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//   ******************************
//   *      战斗系统类函数
//   *     创建于 5月29日
//   ******************************
//  ************************************
//  *     战斗系统的主循环函数文件 
//  *   创建于  5月29日   
//  ************************************

#include "stdio.h"
#include "..\gamelib\goldpoint2.h"
#include "..\interface\interface2.h"
#include "..\menu\menu_inc.h"
#include "..\main.h"
#include "FightGoods.h"
#include "Fight.h"

//主循环体
int CFight::Loop(int mouse,POINT point)
{
	static ret=0;			//战斗的返回值
	static POINT old_point; //上次鼠标的位置
	int i;
	static int old;			//上次选择的按纽
	static int oldjoy=0;		//上次joy选的按钮
	static bool bUseMagic = false;  //是否使用魔法
	static bool bShowMagicPic = false;//是否显示魔法图片
	bool bButton[5]={0,0,0,0,0};	//当前选择的按纽标志数组

	RECT Rstatus_pic={0,0,170,120};	//人物状态图的矩形
	RECT Rtemp={0,0,50,50};			//头像图矩形

	//背景图象显示
	Blt(lpDDSBack,0,0,background[Number-1],RectScreen,false);

	//--------------------以上为公共代码--------------------

	//-------------------------------------------------------------------
	// 控制部分
	//-------------------------------------------------------------------
	switch( main_count )
	{
	/////////////////////////////////////////////////////////////////////
	// 进行游戏菜单选择-------------------------------------------------
	/////////////////////////////////////////////////////////////////////
	case MAIN:
		{
			// 显示战场人物
			Show_Role_Enemy();
			if(mouse == RB_UP || B_UP )		// 取消操作
			{
				if(command_count > 0)
					command_count --;		//减少命令记数
			}

			// 选人光标的显示
			cursor_role.ShowAni(lpDDSBack, FightRole[command_count].x+30, FightRole[command_count].y-30);

			// 键盘控制 ----------------------------------------
			switch(key)
			{
			case DIK_A:				// 攻击
				{
					bButton[1] = 1;
				}
				break;
			case DIK_E:				// 魔法
				{
					bButton[2] = 1;
				}
				break;
			case DIK_G:				// 道具
				{
					bButton[3] = 1;
				}
				break;
			case DIK_Q:				// 逃跑
				{
					bButton[4] = 1;
				}
				break;
			case DIK_R:				// 重复
				{
					bButton[0] = 1;
				}
				break;

			case DIK_F11:		// test exit
				main_count=OVER;
				temp_swap=1;
				key = 0;
				break;

			case DIK_H:			// hidden key
				{
					for(int i=0; i<RoleNum;i++)
					{
						role[i].Propertiy.Hp = role[i].Propertiy.MaxHp;
						role[i].Propertiy.Mp = role[i].Propertiy.MaxMp;
					}
				}
				break;

			default:
				break;
			}
			//手柄,3号键确定
			if(joystick == DIJ_3)
				bButton[oldjoy] = 1;
			if(joystick == DIJ_4)	//4号键选择
			{
				oldjoy++;
				if(oldjoy==5)
					oldjoy = 0;
			}
			// ----------------------------------------------
		}
		break;

	/////////////////////////////////////////////////////////////////////
	// 使用物品的选择角色
	/////////////////////////////////////////////////////////////////////
	case USER_WHO:
		{
			if(mouse == RB_UP || B_UP )		// 取消操作
				main_count = MAIN;			// 回到主循环状态

			nNonce = Test_Role(nNonce);

			if(old_point.x == point.x && old_point.y == point.y)	//鼠标位置没有变化
			{
			}
			else
			{
				old_point.x = point.x;		//保存鼠标位置
				old_point.y = point.y;
				//得到鼠标所指向的主角
				//范围:向上15向下70向做右15,向右65的矩形
				for(i=0;i<3;i++)			
					if(point.x>FightRole[i].x+15&&point.x<FightRole[i].x+65
						&& point.y>FightRole[i].y+15&&point.y<FightRole[i].y+70 
						&& FightRole[i].use==1)
					{
						nNonce = i;				//保存该主角
						break;
					}
			}

			// 键盘控制
			if(DOWN_DOWN)					//向下,直到找到主角为止
			{
				if(nNonce < 3)
				{
					if(FightRole[nNonce+1].use == 1)
						nNonce ++;
					else if(FightRole[nNonce+2].use == 1)
						nNonce += 2;
					else if(FightRole[nNonce+3].use == 1)
						nNonce += 3;
				}
				else
					nNonce = 3;
			}
			if(UP_DOWN)							//向上,直到找到主角为止
			{
				if(nNonce > 0)
				{
					if(FightRole[nNonce-1].use == 1)
						nNonce --;
					else if(FightRole[nNonce-2].use == 1)
						nNonce -= 2;
					else if(FightRole[nNonce-3].use == 1)
						nNonce -= 3;
				}
				else
					nNonce = 0;
			}
			
			//显示主角和敌人
			//会有轮廓
			Show_Role_Enemy();
			//选人鼠标
			cursor_enemy.ShowAni(lpDDSBack, FightRole[nNonce].x+30, FightRole[nNonce].y-15);

			if( mouse == LB_UP || A_UP )	//选定主角
			{
				i = nNonce;
				{
					Sound_Click.Play();	//音效
					if(!bUseMagic)
					{
						Command[command_count].lCommand = TOOLS;	//该次是使用物品
						Command[command_count].lAccessory = m_fightgoods.GetGoodsID();//物品类型
						Command[command_count].kill_who=i;			//使用对象
						Command[command_count].Class=1;				//对自己的
						main_count=MAIN;	//进入主循环
						command_count++;	//加入该条指令
					}
					else
					{
						Command[command_count].lCommand = MAGIC;	//该次是使用魔法
						Command[command_count].lAccessory = m_fightmagic.GetMagicID();//魔法类型
						Command[command_count].kill_who=i;			//使用对象
						Command[command_count].Class=1;
						main_count=MAIN;	//进入主循环
						command_count++;	//加入该条指令
						bUseMagic = false;
					}
					if(command_count>GetLastRoleNum())	//所有的主角都已经使用了
					{
						command_count=0;				//归0
						main_count = ROLE_KILL_ENEMY;	//命令发布完毕,开始攻击
						for(i=0; i<3; i++)
							if(FightRole[i].use==1  )
							{
								_FREE(Role_Temp);
								//下一个数据
								if(Command[i].lCommand == TOOLS)
									Role_Temp=Role_Tool[i].ReadText("设置","continue");
								else if(Command[i].lCommand == MAGIC)	 //用对自己人的魔法,
								{
									Role_Temp=Role_Magic[Command[i].lAccessory].ReadText("设置","continue");
									//设置图片的起始坐标
									if(Role_Magic[Command[i].lAccessory].ReadInt("设置","相对"))
									{
										fightmagic.x = Role_Magic[Command[i].lAccessory].ReadInt("设置","startx")+FightRole[i].x;
										fightmagic.y = Role_Magic[Command[i].lAccessory].ReadInt("设置","starty")+FightRole[i].y;
									}
									else
									{
										fightmagic.x = Role_Magic[Command[i].lAccessory].ReadInt("设置","startx")+FightRole[Command[i].kill_who].x;
										fightmagic.y = Role_Magic[Command[i].lAccessory].ReadInt("设置","starty")+FightRole[Command[i].kill_who].y;
									}
									//加载魔法声音
									sound_Magic.LoadSoundFX(hWnd,CMagic::MAGIC[Command[i].lAccessory].SoundFileName);
								}
								else		//攻击
									Role_Temp=Role_Move[i].ReadText("设置","continue");
								kill_count=0;			//从第一个主角开始
								break;
							}
						Account_Attack();	//计算攻击力
					}
					else if(FightRole[command_count].use==0)		//轮到下一个主角
					{
						command_count++;
						if(FightRole[command_count].use==0)
							command_count=0;
						main_count = MAIN;		//主循环
					}
					break;
				}
			}
		}
		break;

	/////////////////////////////////////////////////////////////////////
	// 选择要攻击的对象--------------------------------------------
	/////////////////////////////////////////////////////////////////////
	case KILL_WHO:
		{
			if(mouse == RB_UP || B_UP )		// 取消操作
				main_count = MAIN;
			
			nNonce = Test_Enemy(nNonce);
			// 用来显示光标的判断
			//和USER_WHO差不多
			if(old_point.x == point.x && old_point.y == point.y)
			{
			}
			else
			{
				old_point.x = point.x;
				old_point.y = point.y;
				for(i=0;i<4;i++)
				if(point.x>EnemyRole[i].x+15
					&&point.x<EnemyRole[i].x+65 && point.y>EnemyRole[i].y+15
					&&point.y<EnemyRole[i].y+70 && EnemyRole[i].use==1)
				{
					nNonce = i;
					break;
				}
			}

			// 键盘的控制
			if(DOWN_DOWN)
			{
				if(nNonce < 3)
				{
					if(EnemyRole[nNonce+1].use == 1)
						nNonce ++;
					else if(EnemyRole[nNonce+2].use == 1)
						nNonce += 2;
					else if(EnemyRole[nNonce+3].use == 1)
						nNonce += 3;
				}
				else
					nNonce = 3;
			}
			if(UP_DOWN)
			{
				if(nNonce > 0)
				{
					if(EnemyRole[nNonce-1].use == 1)
						nNonce --;
					else if(EnemyRole[nNonce-2].use == 1)
						nNonce -= 2;
					else if(EnemyRole[nNonce-3].use == 1)
						nNonce -= 3;
				}
				else
					nNonce = 0;
			}
			
			//显示敌人和我方的人
			Show_Role_Enemy();		
			cursor_enemy.ShowAni(lpDDSBack, EnemyRole[nNonce].x+24, EnemyRole[nNonce].y-15);

			//选定
			if( mouse == LB_UP || A_UP )
			{
				i = nNonce;
				{
					Sound_Click.Play();	//音效
					if(!bUseMagic)
					{
						Command[command_count].lCommand = ATTACK;
						Command[command_count].kill_who=i;
						main_count=MAIN;
						command_count++;
					}
					else
					{
						Command[command_count].lCommand = MAGIC;	//该次是使用魔法
						Command[command_count].lAccessory = m_fightmagic.GetMagicID();//魔法类型
						Command[command_count].kill_who=i;			//使用对象
						Command[command_count].Class=0;
						main_count=MAIN;	//进入主循环
						command_count++;	//加入该条指令
						bUseMagic = false;
					}
					if(command_count>GetLastRoleNum())
					{
						command_count=0;
						main_count = ROLE_KILL_ENEMY;	//命令发布完毕,开始攻击
						for(i=0; i<3; i++)
							if(FightRole[i].use==1 )
							{
								_FREE(Role_Temp);
								if(Command[i].lCommand == TOOLS)
									Role_Temp=Role_Tool[i].ReadText("设置","continue");
								else if(Command[i].lCommand == MAGIC)		//对敌人的魔法
								{
									Role_Temp=Role_Magic[Command[i].lAccessory].ReadText("设置","continue");
									if(Role_Magic[Command[i].lAccessory].ReadInt("设置","相对"))
									{
										fightmagic.x = Role_Magic[Command[i].lAccessory].ReadInt("设置","startx")+FightRole[i].x;
										fightmagic.y = Role_Magic[Command[i].lAccessory].ReadInt("设置","starty")+FightRole[i].y;
									}
									else
									{
										fightmagic.x = Role_Magic[Command[i].lAccessory].ReadInt("设置","startx")+EnemyRole[Command[i].kill_who].x;
										fightmagic.y = Role_Magic[Command[i].lAccessory].ReadInt("设置","starty")+EnemyRole[Command[i].kill_who].y;

⌨️ 快捷键说明

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