//--------------------------------------------------------------------------------------- public void Init() { _gameController = GameController.Instance; //Get the positions in front of the player heroes, that's where the baddie will move to for attacking int len = BaddieAttackPositions.Length; _baddieAttackPositions = new Vector2[len]; int cnt = -1; while (++cnt != len) { _baddieAttackPositions[cnt] = BaddieAttackPositions[cnt].position; BaddieAttackPositions[cnt].gameObject.SetActive(false); //No longer needed } int world = DataManager.Data.World; //Get our Character_SO BaddieCharData = DataManager.Data.BaddieCharacter; //Set the name var baddieNames = DataManager.Data.BaddieNames; BaddieCharData.Name = baddieNames[wrap(world - 1, 0, baddieNames.Length)]; //We don't care about the baddies XP, just it's level, as that affects it's stats BaddieCharData.Level = _gameController.SquadHandler.GetHighestHeroLevel(); //Attack and defence values int attackValue = Random.Range(10, 20); int defenceValue = 35 - attackValue; //We're going to cheat here a little and weaken the baddie on world 1 as we want the player to win the first //time they play if (DataManager.Data.World == 1) { defenceValue -= 10; } BaddieCharData.Attack = attackValue; BaddieCharData.Defence = defenceValue; //Hardcoded 5 baddie types, it *is* a tight deadline int baddieAnims = wrap(world, 0, 5); Animation_SO animData = _gameController.BaddieAnimationDataHolder.CharacterAnimFrames[baddieAnims]; //Finally we can populate our (anti)Hero's data Baddie.SetInitialHealth(200); //They've got to have more health than the player Baddie.ThisHero = Hero.HeroType.Baddie; Baddie.Init(BaddieCharData, animData); }
//--------------------------------------------------------------------------------------- //Here we're going to set up our squad, i.e. pull our data in and place it gently into the Hero instances public void Init() { _gameController = GameController.Instance; //Get the position the player squad will move to to perform an attack (We can turn off the gameObject afterwards, //it's just to make life easier in the Editor) _playerAttackPosition = PlayerAttackPosition.position; PlayerAttackPosition.gameObject.SetActive(false); List <Character_SO> chars = DataManager.Data.GetPlayerSquad(); _numberOfSelectedCharacters = chars.Count; //Populate Hero(s) with our juicy data Hero heroRef; int cnt = -1; while (++cnt != _numberOfSelectedCharacters) { heroRef = Squad[cnt]; heroRef.ThisHero = Hero.HeroType.Player; heroRef.heroID = cnt; heroRef.SetInitialHealth(100); heroRef.AttackPosition = _playerAttackPosition; //Get the correct animation SO for this character Animation_SO animData = _gameController.PlayerAnimationDataHolder.CharacterAnimFrames[chars[cnt].ID]; //Init him, init him good and proper heroRef.Init(chars[cnt], animData); } //Turn off any we're not using cnt--; while (++cnt != 3) { Squad[cnt].gameObject.SetActive(false); } //Get a reference to our baddie _target = _gameController.BaddieHandler.Baddie; }
//--------------------------------------------------------------------------------------- public void Init(Character_SO CharacterData, Animation_SO animData) { _gameController = GameController.Instance; _hud = _gameController.HUD; _characterData = CharacterData; _animFrames = animData; //Flip the sprite if it's a baddie HeroSprite.flipX = ThisHero == HeroType.Baddie; //Set up the default frame _animOffset = Random.Range(0, 3); //So the idle animations aren't in perfect sync HeroSprite.sprite = _animFrames.IdleFrames[_animOffset]; _animIdleLength = _animFrames.IdleFrames.Length; _animWalkingLength = _animFrames.WalkingFrames.Length; AnimationState = AnimationTypes.Idle; _healthBarScale = Vector2.one; _healthBarXScaleTarget = 1; }