public void UpdateCharacters(int player) { // Select new character to focus ( upon death of another ) if (CharacterList[player - 1] != null) { SelectedCharacter = CharacterList[player - 1]; } else { if (CharacterList[0] != null) { SelectedCharacter = CharacterList[0]; } else if (CharacterList[1] != null) { SelectedCharacter = CharacterList[1]; } else if (CharacterList[2] != null) { SelectedCharacter = CharacterList[2]; } } // Set camera to focused player UpdateCamera(); }
// Update is called once per frame public void Update() { // Switch players if (Input.GetKeyDown(KeyCode.Alpha1)) { if (CharacterList[0] != null && !CharacterList[0].HasDied) { SelectedCharacter = CharacterList[0]; UpdateCamera(); } } else if (Input.GetKeyDown(KeyCode.Alpha2)) { if (CharacterList[1] != null && !CharacterList[1].HasDied) { SelectedCharacter = CharacterList[1]; UpdateCamera(); } } else if (Input.GetKeyDown(KeyCode.Alpha3)) { if (CharacterList[2] != null && !CharacterList[2].HasDied) { SelectedCharacter = CharacterList[2]; UpdateCamera(); } } }
void CreateCharacters() { // Character 1 = Eddy - Sword var eddy = new Character.PlayerCharacter(); CreateSpecificCharacter(eddy, 120, 2, "Eddy", 1, new Sword(), new Armor(Armor.ArmorType.Chestplate), "Warrior", Color.blue, new Vector3(5, 1.5f, 0)); // Character 2 = Barry - Bow var barry = new Character.PlayerCharacter(); CreateSpecificCharacter(barry, 70, 6, "Barry", 2, new Bow(), new Armor(Armor.ArmorType.Pants), "Ranger", Color.yellow, new Vector3(0, 1.5f, 0)); // Character 1 = Gandalf - Staff var gandalf = new Character.PlayerCharacter(); CreateSpecificCharacter(gandalf, 100, 12, "Gandalf", 3, new Staff(), new Armor(Armor.ArmorType.Boots), "Wizard", Color.magenta, new Vector3(-5, 1.5f, 0)); // Debug foreach (var character in CharManager.CharacterList) { Debug.Log("Characterlist contains " + character.Name + " , he is a " + character.Role + "!"); } // Camera MainCamera.GetComponent <CameraSwitching>().Initialize(); CharManager.MainCamera = MainCamera; }
// Use this for initialization public void Init() { // Player one is focused character SelectedCharacter = CharacterList[0]; // Set camera to focused player UpdateCamera(); }
// 各セル毎のFunctionの処理 private void ApplyCellFunctionToCell( CellGrid OwnerCellGrid, CellGrid AnotherCellGrid, Character.PlayerCharacter OwnerPlayerCharacter, Character.PlayerCharacter AnotherPlayerChracter, CellStatusType[] cellStatusTypes, int x, int y) { switch (cellStatusTypes[OwnerCellGrid.GetCell(true, x, y)].CellFunction) { case CellFunction.Normal: break; case CellFunction.Eater: // セルの破壊 for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (i != 0 || j != 0) { AnotherCellGrid.SetCell(false, x + i, y + j, 0); } } } // // TODO : プレイヤーへの攻撃 // break; case CellFunction.Turret: // TODO : 最もコストの高いセルorプレイヤーを攻撃(関数として分けたほうがいいかな?) if ((AnotherPlayerChracter.GetPosition() - new Vector2(x, y)).magnitude >= CellStatusType.TURRETRANGE) { int minDistance = CellStatusType.TURRETRANGE; int maxCost = -1; (int dx, int dy)position = (0, 0); for (int i = -CellStatusType.TURRETRANGE; i <= CellStatusType.TURRETRANGE; i++) { for (int j = -CellStatusType.TURRETRANGE; j <= CellStatusType.TURRETRANGE; j++) { if (cellStatusTypes[AnotherCellGrid.GetCell(false, x + i, y + j)].Cost >= maxCost) { maxCost = cellStatusTypes[AnotherCellGrid.GetCell(false, x + i, y + j)].Cost; if (i * i + j * j <= minDistance) { minDistance = i * i + j * j; position = (i, j); } } } } AnotherCellGrid.SetCell(false, x + position.dx, y + position.dy, 0); } else { AnotherPlayerChracter.TakeDamage(CellStatusType.TURRETPOWER); } break; } }
// ゲームのエントリーポイント void Start() { Application.targetFrameRate = 30; Physics.gravity = new Vector3(0, 0, 1f); // 重力小さめ prevFrameMousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y); characterModel = new Character.PlayerCharacter(BOARD_SIZE); cellAutomataGA = new CellAutomataGA(BOARD_SIZE); InitUnityGameObjects(); SetButtonEventListeners(); }
// update for selected character ( overload for the sake of overloading, no real difference ) void RefreshPanel(Character.PlayerCharacter currentCharacter) { // Update text NameText.text = "Name: " + currentCharacter.Name; WeaponText.text = "Weapon: " + currentCharacter.CharacterWeapon.Name; HPText.text = "HP: " + currentCharacter.HealthPoints; MPText.text = "MP: " + currentCharacter.ManaPoints; AttackText.text = "ATT: " + currentCharacter.AttackStat; DefenseText.text = "DEF: " + currentCharacter.DefenseStat; RoleText.text = "He is a " + currentCharacter.Role; }
void CreateSpecificCharacter(Character.PlayerCharacter player, int health, int mana, string charName, int uiTag, Weapon weapon, Armor armor, string role, Color color, Vector3 position) { // Player attributes player.Name = charName; player.HealthPoints = health; player.ManaPoints = mana; player.CharacterWeapon = weapon; player.CharacterArmor = armor; player.Tag = uiTag; player.UpdateDefensStat(); player.UpdateAttackStat(); player.Role = role; player.Color = color; player.StartingPosition = position; // Add items of player to inventory pool Inventory.ItemList.Add(weapon); Inventory.ItemList.Add(armor); player.Initialize(); CharManager.CharacterList.Add(player); }