public void Damage(int value) { if (value == 0) { return; } int lastHP = HP; HP -= value; bool gameover = false; if (HP <= 0) { HP = 0; gameover = true; } GameEntry.Event.Fire(this, PlayerHPChangeEventArgs.Create(lastHP, HP)); if (gameover) { GameOver(); } }
public void Reset() { int lastHP = HP; HP = GameEntry.Config.GetInt(Constant.Config.PlayerHP); //HP = 100; GameEntry.Event.Fire(this, PlayerHPChangeEventArgs.Create(lastHP, HP)); float lastEnergy = Energy; DataLevel dataLevel = GameEntry.Data.GetData <DataLevel>(); if (!dataLevel.IsInLevel) { Log.Error("Is invaild to get player energy outsiede level scene"); Energy = lastEnergy; } else { LevelData levelData = dataLevel.GetLevelData(dataLevel.CurrentLevelIndex); Energy = levelData.InitEnergy; } GameEntry.Event.Fire(this, PlayerEnergyChangeEventArgs.Create(lastEnergy, Energy)); }