RPG类型游戏—2

    前面介绍到了整个游戏的整体的设计,现在就每个类的具体实现给出相应核心的代码:

    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;
    }
}

   这个是攻击组件。下面几个组件我就不粘贴了,我直接上传代码就行了,这样粘贴太长了。

  

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值