RPG类型游戏—2
2015-12-18 15:36
726 查看
前面介绍到了整个游戏的整体的设计,现在就每个类的具体实现给出相应核心的代码:
public class MoveCpt : MonoBehaviour
{
public float MoveSpeed;
private bool _originRight;
private int _modulus;
public void Intilized()
{
if (this.transform.position.x < BaseData.MiddleDividine)
{
_originRight = true;
}
else
{
_originRight = false;
}
_modulus = _originRight ? 1 : -1;
}
public void MoveByDirection(float dt)
{
transform.Translate(_modulus * Vector3.right * dt * MoveSpeed);
}
}
当然·这里写的只是简单的移动,你也可以写的很复杂,比如人物也可以通过飞行,潜水,坐车来实现位置移动的行为,所以我的建议是让这个组件继承IMove接口,接口里面的方法应该写成void Move()。至于move里面形参根据游戏而定。
public class CanExportCpt:MonoBehaviour,ICanExport,IAtkEffectByProperty
{
private AttackData _attackData;
public SoliderType Type { set; get; }
private float _origingongjisudu;
private float _addSpeed=1f;
private float _muSpeed=1f;
private bool _isFirstInlize=true;
private int _delta=0;
public void Intilized(int level, SoliderType curType)
{
List<float> attack=new List<float>();
Type = curType;
if (curType == SoliderType.Player)
{
attack = BaseData.PlayerAttackList;
}
if (curType == SoliderType.Enemy)
{
attack = BaseData.EnemyAttackList;
}
if (_isFirstInlize)
{
_attackData = new AttackData();
_attackData.GongjiLiNum = ComputerClass.GetFinalGongjiByLevel(level, attack[0], curType);
_attackData.CriStrFrequencyNum = attack[3];
_attackData.CriStrDamageNum = attack[2];
_isFirstInlize = false;
}
else
{
var d = _attackData.GongjiLiNum;
_attackData.GongjiLiNum = ComputerClass.GetFinalGongjiByLevel(level, d, curType);
var maxValue = ComputerClass.GetFinalMaxGongjiByLevel(level);
if (_attackData.GongjiLiNum >= maxValue)
{
_attackData.GongjiLiNum = maxValue;
}
}
_attackData.GongjiSuduNum= attack[1];
_attackData.Level = level;
_origingongjisudu = _attackData.GongjiSuduNum;
var cd = _attackData.CriStrDamageNum;
if (cd >= 5)
_attackData.CriStrDamageNum = 5;
}
public void Attack(PropertyCpt hurtPropertyCpt,IHurt targets,Vector3 posVector3,PropertyData atkPropertyData)
{
targets.GetHurt(hurtPropertyCpt, atkPropertyData, _attackData, posVector3, Type);
}
public AttackData GetAttackData()
{
return _attackData;
}
public float GetAtkSpeed()
{
return _attackData.GongjiSuduNum;
}
public void AtkEffectBySelfPro(PropertyCpt _propertyCpt)
{
if (_propertyCpt.AllpropertiesList[2])//当人物拥有火属性,攻击速度加倍
{
_addSpeed = (1 + _propertyCpt.FireNum * 0.4f);
}
else//否则速度变成原来的攻击速度
{
_addSpeed = 1;
}
_attackData.GongjiSuduNum = _addSpeed*_muSpeed * _origingongjisudu;
if (_propertyCpt.AllpropertiesList[3])
{
_attackData.GongjiLiNum += _propertyCpt.ProperNum * 2.0f;
_propertyCpt.AllpropertiesList[3] = false;
}
if (_propertyCpt.AllpropertiesList[4])
{
_attackData.CriStrFrequencyNum += 0.01f * _propertyCpt.ProperNum;
_attackData.GongjiLiNum += _propertyCpt.ProperNum * 1.0f;
_propertyCpt.AllpropertiesList[4] = false;
}
if (_propertyCpt.AllpropertiesList[5])
{
_attackData.CriStrDamageNum += 0.01f * _propertyCpt.ProperNum;
_attackData.GongjiLiNum += _propertyCpt.ProperNum * 1.0f;
_propertyCpt.AllpropertiesList[5] = false;
}
var maxValue = ComputerClass.GetFinalMaxGongjiByLevel(_attackData.Level);
if (_attackData.GongjiLiNum >= maxValue)
{
_delta += 1;
_delta %= 1000;
_attackData.GongjiLiNum = maxValue;
}
}
public void AtkEffectByEnemyPro(PropertyCpt enemyPropertyCpt)
{
if (enemyPropertyCpt.AllpropertiesList[1])
_muSpeed =0.5f;
else
_muSpeed = 1f;
}
}
这个是攻击组件。下面几个组件我就不粘贴了,我直接上传代码就行了,这样粘贴太长了。
public class MoveCpt : MonoBehaviour
{
public float MoveSpeed;
private bool _originRight;
private int _modulus;
public void Intilized()
{
if (this.transform.position.x < BaseData.MiddleDividine)
{
_originRight = true;
}
else
{
_originRight = false;
}
_modulus = _originRight ? 1 : -1;
}
public void MoveByDirection(float dt)
{
transform.Translate(_modulus * Vector3.right * dt * MoveSpeed);
}
}
当然·这里写的只是简单的移动,你也可以写的很复杂,比如人物也可以通过飞行,潜水,坐车来实现位置移动的行为,所以我的建议是让这个组件继承IMove接口,接口里面的方法应该写成void Move()。至于move里面形参根据游戏而定。
public class CanExportCpt:MonoBehaviour,ICanExport,IAtkEffectByProperty
{
private AttackData _attackData;
public SoliderType Type { set; get; }
private float _origingongjisudu;
private float _addSpeed=1f;
private float _muSpeed=1f;
private bool _isFirstInlize=true;
private int _delta=0;
public void Intilized(int level, SoliderType curType)
{
List<float> attack=new List<float>();
Type = curType;
if (curType == SoliderType.Player)
{
attack = BaseData.PlayerAttackList;
}
if (curType == SoliderType.Enemy)
{
attack = BaseData.EnemyAttackList;
}
if (_isFirstInlize)
{
_attackData = new AttackData();
_attackData.GongjiLiNum = ComputerClass.GetFinalGongjiByLevel(level, attack[0], curType);
_attackData.CriStrFrequencyNum = attack[3];
_attackData.CriStrDamageNum = attack[2];
_isFirstInlize = false;
}
else
{
var d = _attackData.GongjiLiNum;
_attackData.GongjiLiNum = ComputerClass.GetFinalGongjiByLevel(level, d, curType);
var maxValue = ComputerClass.GetFinalMaxGongjiByLevel(level);
if (_attackData.GongjiLiNum >= maxValue)
{
_attackData.GongjiLiNum = maxValue;
}
}
_attackData.GongjiSuduNum= attack[1];
_attackData.Level = level;
_origingongjisudu = _attackData.GongjiSuduNum;
var cd = _attackData.CriStrDamageNum;
if (cd >= 5)
_attackData.CriStrDamageNum = 5;
}
public void Attack(PropertyCpt hurtPropertyCpt,IHurt targets,Vector3 posVector3,PropertyData atkPropertyData)
{
targets.GetHurt(hurtPropertyCpt, atkPropertyData, _attackData, posVector3, Type);
}
public AttackData GetAttackData()
{
return _attackData;
}
public float GetAtkSpeed()
{
return _attackData.GongjiSuduNum;
}
public void AtkEffectBySelfPro(PropertyCpt _propertyCpt)
{
if (_propertyCpt.AllpropertiesList[2])//当人物拥有火属性,攻击速度加倍
{
_addSpeed = (1 + _propertyCpt.FireNum * 0.4f);
}
else//否则速度变成原来的攻击速度
{
_addSpeed = 1;
}
_attackData.GongjiSuduNum = _addSpeed*_muSpeed * _origingongjisudu;
if (_propertyCpt.AllpropertiesList[3])
{
_attackData.GongjiLiNum += _propertyCpt.ProperNum * 2.0f;
_propertyCpt.AllpropertiesList[3] = false;
}
if (_propertyCpt.AllpropertiesList[4])
{
_attackData.CriStrFrequencyNum += 0.01f * _propertyCpt.ProperNum;
_attackData.GongjiLiNum += _propertyCpt.ProperNum * 1.0f;
_propertyCpt.AllpropertiesList[4] = false;
}
if (_propertyCpt.AllpropertiesList[5])
{
_attackData.CriStrDamageNum += 0.01f * _propertyCpt.ProperNum;
_attackData.GongjiLiNum += _propertyCpt.ProperNum * 1.0f;
_propertyCpt.AllpropertiesList[5] = false;
}
var maxValue = ComputerClass.GetFinalMaxGongjiByLevel(_attackData.Level);
if (_attackData.GongjiLiNum >= maxValue)
{
_delta += 1;
_delta %= 1000;
_attackData.GongjiLiNum = maxValue;
}
}
public void AtkEffectByEnemyPro(PropertyCpt enemyPropertyCpt)
{
if (enemyPropertyCpt.AllpropertiesList[1])
_muSpeed =0.5f;
else
_muSpeed = 1f;
}
}
这个是攻击组件。下面几个组件我就不粘贴了,我直接上传代码就行了,这样粘贴太长了。
相关文章推荐
- IntelliJ Idea :Cannot load project: java.lang.RuntimeException: java.io.IOException: java.lang.Asser
- JS导出gridview到excel
- Surviving Generations and Memory Leaks
- 实现统计每个栏目下的文章总数的调用
- jQuery中trigger()与bind()用法分析
- 关于ThinkPHP中$this->redirect的疑问。
- Android onMeasure and onLayout
- 笔记三:Centos 7 64bit 下JDK的安装与配置
- Android使用Fragment来实现TabHost的功能(解决切换Fragment状态不保存)以及各个Fragment之间的通信
- FileItem类
- android bitmap compress(图片压缩)
- 剑指offer系列之五十七:二叉树的下一个节点
- 关于SearchView的一些小细节
- oauth2.0认证和授权原理
- Git简易入门教程
- 如何使用 Idea 远程调试 Java 代码
- 移动webapp页面适配方案
- spring mvc+shiro +cas +spring-session 的通用权限管理系统
- LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- 程序集重新定向与指定加载程序集时公共语言运行时搜索的子目录。