您的位置:首页 > 其它

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;

}

}

这个是攻击组件。下面几个组件我就不粘贴了,我直接上传代码就行了,这样粘贴太长了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: