private void TrackSpawnedBlocks() { if (activeBlock == null && !isRepairing) { isRepairing = true; if (northBlock == null) { northBlock = randomBlockGenerator.createRandomBlock(northSpawn.transform, blocksSpeed, jumpLength, Vector3.back); } else if (southBlock == null) { southBlock = randomBlockGenerator.createRandomBlock(southSpawn.transform, blocksSpeed, jumpLength, Vector3.forward); } else if (eastBlock == null) { eastBlock = randomBlockGenerator.createRandomBlock(eastSpawn.transform, blocksSpeed, jumpLength, Vector3.left); } else if (westBlock == null) { westBlock = randomBlockGenerator.createRandomBlock(westSpawn.transform, blocksSpeed, jumpLength, Vector3.right); } isRepairing = false; } }
//sets up link between attacker and blocker private void makeAttackBlockLink() { //check if can block if (!DuelFunctions.CanBlock(Library.GetCard(atb.name), Library.GetCard(blockwith.name))) { blockwith.GetComponent <Image>().color = Color.white; blockwith.GetComponent <Draggable>().isBlocking = false; blockwith = null; return; } for (int i = 0; i < attackers.Count; i++) { if (attackers[i].attacker.GetHashCode().Equals(atb.GetHashCode())) { AttackBlock ab = attackers[i]; ab.blocker = blockwith; attackers[i] = ab; Debug.Log("Link made"); break; } } atb = null; blockwith = null; Debug.Log("links: " + attackers.Count); }
public void RespawnEmptyBlocks(object source, EventArgs args) { if (activeBlock == null) { return; } if (activeBlock.MoveDirection.Equals(Vector3.back)) { northBlock = randomBlockGenerator.createRandomBlock(activeBlock.transform.parent, blocksSpeed, jumpLength, activeBlock.MoveDirection); } else if (activeBlock.MoveDirection == Vector3.forward) { southBlock = randomBlockGenerator.createRandomBlock(activeBlock.transform.parent, blocksSpeed, jumpLength, activeBlock.MoveDirection); } else if (activeBlock.MoveDirection == Vector3.left) { eastBlock = randomBlockGenerator.createRandomBlock(activeBlock.transform.parent, blocksSpeed, jumpLength, activeBlock.MoveDirection); } else if (activeBlock.MoveDirection == Vector3.right) { westBlock = randomBlockGenerator.createRandomBlock(activeBlock.transform.parent, blocksSpeed, jumpLength, activeBlock.MoveDirection); } this.activeBlock.transform.parent = null; this.activeBlock = null; }
void CreateInitialAttackBlocks() { northBlock = randomBlockGenerator.createRandomBlock(northSpawn, blocksSpeed, jumpLength, Vector3.back); southBlock = randomBlockGenerator.createRandomBlock(southSpawn, blocksSpeed, jumpLength, Vector3.forward); eastBlock = randomBlockGenerator.createRandomBlock(eastSpawn, blocksSpeed, jumpLength, Vector3.left); westBlock = randomBlockGenerator.createRandomBlock(westSpawn, blocksSpeed, jumpLength, Vector3.right); }
void ActivateBlock(AttackBlock block) { this.activeBlock = block; this.activeBlock.Activate(); Color color = Player2Controller.isDestroyBlockActivated ? Color.yellow : Color.red; tempMaterial = new Material(block.GetComponentInChildren <Renderer>().material); if (Player2Controller.isDestroyBlockActivated) { block.isDestroyBlock = true; } if (block.isDestroyBlock == false) { block.PlatformHit += OnActiveBlockPlatformHit; } else { block.PlatformHit += OnDestroyBlockPlatformHit; } block.DestroyAttackBlock += RespawnEmptyBlocks; blockShadow.CreateShadow(this.activeBlock.gameObject); SetAttackBlockColor(color, activeBlock); }
public void CreateShadow(GameObject attackBlock) { GameObject[,] platformBlocks = platformBoard.blocks; AttackBlock attackBlockComponent = attackBlock.GetComponent <AttackBlock>(); GameObject[] platformBlocksOneD = ConvertToGameObjectArray(platformBlocks); GameObject[] attackBlockChildren = GetChildren(attackBlock); GameObject[] closestPair = FindOneClosestPair(platformBlocksOneD, attackBlockChildren, GetAxis(attackBlockComponent)); if (closestPair == null) { return; } System.Random random = new System.Random(); Color randomColor = new Color((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()); Vector3 position = closestPair[0].transform.position - attackBlockComponent.MoveDirection; position = position - (attackBlock.transform.rotation * closestPair[1].transform.localPosition); this.activeBlockShadow = Instantiate(attackBlock, position, attackBlock.transform.rotation); activeBlockShadow.transform.tag = "shadow"; for (int i = 0; i < activeBlockShadow.transform.childCount; i++) { activeBlockShadow.transform.GetChild(i).tag = "shadow"; } DestroyColliders(); ImmobilizeShadow(); ColorizeShadow(); }
public void addBlock(AttackBlock activeBlock, Material mat) { Transform[] gameObjects = activeBlock.GetComponentsInChildren <Transform>(); foreach (Transform item in gameObjects) { if (item != activeBlock.transform) { int x = Convert.ToInt32(item.position.x + transposeBy); int y = Convert.ToInt32(item.position.z + transposeBy); Vector3 vector = new Vector3(this.transform.position.x + x + widthOfAGap * x, this.transform.position.y, this.transform.position.z + y + widthOfAGap * y); if (x >= transform.position.x + transposeBy && x < rowLength && y >= transform.position.z + transposeBy && y < rowLength) { Destroy(item.gameObject); if (this.blocks[x, y] == null) { this.blocks[x, y] = Instantiate(block, vector, Quaternion.identity); // GUILTY! this.blocks[x, y].tag = "platform"; this.blocks[x, y].GetComponent <Renderer>().material = mat; } checkIfThereAreMaxBlocksInRow(); } else { Destroy(item.gameObject); } } } }
void SetAttackBlockColor(Color color, AttackBlock activeBlock) { var childrenMaterials = activeBlock.gameObject.GetComponentsInChildren <Renderer>(); foreach (var item in childrenMaterials) { item.material.color = color; } }
private Axis GetAxis(AttackBlock attackBlock) { if (attackBlock.MoveDirection == Vector3.forward || attackBlock.MoveDirection == Vector3.back) { return(Axis.Vertical); } else { return(Axis.Horizontal); } }
bool IsVertical(AttackBlock attackBlock) { if (northBlock == null || southBlock == null) { return(true); } else { return(false); } }
public AttackBlock createRandomBlock(Transform parent, float blockSpeed, float jumpLength, Vector3 moveDirection) { int randomIndex = lotto.Next(0, possibleBlocks.Count - 1); AttackBlock atkBlock = Instantiate(possibleBlocks[randomIndex], parent).GetComponent <AttackBlock>(); atkBlock.MoveSpeed = blockSpeed; atkBlock.JumpLength = jumpLength; atkBlock.MoveDirection = moveDirection; atkBlock.Initialize(); return(atkBlock); }
void Start() { missle = GetComponent <Rigidbody>(); /* foreach (var item in GameObject.FindObjectsOfType<AttackBlock>()) * { * if(item.IfInMovement()) * { * target = item; * } * }*/ target = GameObject.FindObjectOfType <Player2Controller>().GetActiveBlock(); }
private void HandleSwordCollisionEnter(Collision i_other) { if (!m_attackLaunched) { return; } AttackBlock attackBlock = i_other.gameObject.GetComponent <AttackBlock>(); if (attackBlock) { Debug.Log("Attack Recoil Hit"); attackController.BlockCurrentAttack(); } }
//remove placeholder for attacker public void RemoveToBlock(GameObject attacker) { for (int i = 0; i < attackers.Count; i++) { if (attackers[i].attacker.GetHashCode().Equals(attacker.GetHashCode())) { AttackBlock ab = attackers[i]; attackers[i].blocker.GetComponent <Draggable>().isBlocking = false; attackers[i].blocker.GetComponent <Image>().color = Color.white; ab.blocker = null; attackers[i] = ab; attackers[i].attacker.GetComponent <Draggable>().isBlocking = false; attackers[i].attacker.GetComponent <Image>().color = Color.red; break; } } }
private void addOppBlocker(string blocker) { string[] abpair = blocker.Split('-'); for (int a = 0; a < attackers.Count; a++) { AttackBlock ab = attackers[a]; if (ab.attacker.name.Equals(abpair[0]) && ab.blocker == null) { //find ui card for (int i = 0; i < oppPlayAreaPanel.transform.childCount; i++) { if (oppPlayAreaPanel.transform.GetChild(i).gameObject.name.Equals(abpair[1]) && !oppPlayAreaPanel.transform.GetChild(i).gameObject.GetComponent <Draggable>().isBlocking) { oppPlayAreaPanel.transform.GetChild(i).gameObject.GetComponent <Draggable>().isBlocking = true; oppPlayAreaPanel.transform.GetChild(i).gameObject.GetComponent <Image>().color = Color.gray; ab.blocker = oppPlayAreaPanel.transform.GetChild(i).gameObject; attackers[a] = ab; return; } } } } }
public IEnumerator Trap(TriggerType trigger, List <Card> cards, EventBlock block) { yield return(null); Card openTrap = null; switch (trigger) { case TriggerType.TakeAttack: AttackBlock atkBlock = block as AttackBlock; if (atkBlock == null) { yield break; } int damage = block.GetCaster().AttackPower; int needValue = 0; //必要な最低値 if (atkBlock.GetTarget().GetComponent <Player>()) { damage -= player.Defence; if (damage >= player.Life) { needValue = damage - player.Life; } else if (damage > 0) { needValue = 1; } } else { damage -= atkBlock.GetTarget().GetComponent <Card>().State.defence; needValue = damage + 1; } foreach (Card c in cards) { foreach (CardEffect ce in c.State.Effect) { foreach (EffectState es in ce.effectState) { if (es.effectType == EffectType.AttackAdd && es.value >= -needValue) { if (openTrap == null || openTrap.State.Cost > c.State.Cost) { openTrap = c; } } } } } break; case TriggerType.TakeSkill: openTrap = cards[0]; break; case TriggerType.TakeDispCard: CardDispBlock disp = block as CardDispBlock; if (disp.GetCards()[0].State.cardAligment == player.cardAligment) { openTrap = cards[0]; } break; default: openTrap = cards[0]; break; } if (openTrap) { yield return(new WaitForSeconds(0.5f)); Constants.BATTLE.CardOpen(openTrap); } }
void Update() { //Debug.Log ("DestroyBlock" + activeBlock.isDestroyBlock); blocksSpeed = gameAccelerator.player2Speed; TrackSpawnedBlocks(); if (p2GamePad) { horizontalAxisPlayer2 = Input.GetAxisRaw("HorizontalJoyPlayer2"); verticalAxisPlayer2 = Input.GetAxisRaw("VerticalJoyPlayer2"); bool canFire = activeBlock == null; if (canFire) { /*if (Input.GetKey("joystick 2 button 7") && isDestroyBlockAvailable) * { * isDestroyBlockAvailable = false; * isDestroyBlockActivated = true; * }*/ if (Input.GetKeyDown("joystick 2 button 0")) { ActivateBlock(northBlock); northBlock = null; } else if (Input.GetKeyDown("joystick 2 button 2")) { ActivateBlock(southBlock); southBlock = null; } else if (Input.GetKeyDown("joystick 2 button 3")) { ActivateBlock(westBlock); westBlock = null; } else if (Input.GetKeyDown("joystick 2 button 1")) { ActivateBlock(eastBlock); eastBlock = null; } if (Player2Controller.isDestroyBlockActivated && activeBlock != null) { Player2Controller.isDestroyBlockActivated = false; Player2Controller.isDestroyBlockAvailable = false; activeBlock.isDestroyBlock = true; } } bool canTurn = !canFire; if (canTurn) { if ((activeBlock.MoveDirection.Equals(Vector3.back) && verticalAxisPlayer2 == 1) || (activeBlock.MoveDirection.Equals(Vector3.forward) && verticalAxisPlayer2 == -1) || (activeBlock.MoveDirection.Equals(Vector3.left) && horizontalAxisPlayer2 == -1) || (activeBlock.MoveDirection.Equals(Vector3.right) && horizontalAxisPlayer2 == 1)) { activeBlock.ChangeSpeed(boostSpeed); } else { activeBlock.MoveSpeed = blocksSpeed; } // if (Input.GetKey("joystick 2 button 4")) // { // activeBlock.ChangeSpeed(boostSpeed); // } // else // { // activeBlock.MoveSpeed = blocksSpeed; // } if (IsVertical(activeBlock)) { if (isAxisHorizontalInUse == false) { if (horizontalAxisPlayer2 == -1) { activeBlock.GoToYourLeft(); isAxisHorizontalInUse = true; UpdateShadow(); } else if (horizontalAxisPlayer2 == 1) { activeBlock.GoToYourRight(); isAxisHorizontalInUse = true; UpdateShadow(); } } } else { if (isAxisVerticalInUse == false) { if (verticalAxisPlayer2 == 1) { activeBlock.GoToYourRight(); isAxisVerticalInUse = true; UpdateShadow(); } else if (verticalAxisPlayer2 == -1) { activeBlock.GoToYourLeft(); isAxisVerticalInUse = true; UpdateShadow(); } } } if (horizontalAxisPlayer2 == 0) { isAxisHorizontalInUse = false; } if (verticalAxisPlayer2 == 0) { isAxisVerticalInUse = false; } if (Input.GetKeyDown(KeyCode.Joystick2Button5) || Input.GetKeyDown(KeyCode.Joystick2Button7)) { activeBlock.TurnNinetyDegreesAndUpdateTriggers(); UpdateShadow(); } } } else if (!p2GamePad) { bool canFire = activeBlock == null; if (canFire) { /*if (Input.GetKeyDown(KeyCode.Alpha0) && isDestroyBlockAvailable) * { * isDestroyBlockAvailable = false; * isDestroyBlockActivated = true; * }*/ if (Input.GetKeyDown(KeyCode.Alpha8) && movementSwitchCounter > 0) { timeOfswitchMovementOfPlayer1 = 3.0f; movementSwitchAlert.text = "Automovement switch starts in 1s! ";// + + "s !"; Invoke("switchAutomovement", 1); } if (Player1Controller.isAutomovementOn == false) { if (movementSwitchAlert != null) { movementSwitchAlert.text = "Automovement switch ends in " + (int)timeOfswitchMovementOfPlayer1 + "s !"; } timeOfswitchMovementOfPlayer1 -= Time.deltaTime; if (timeOfswitchMovementOfPlayer1 < 0) { if (movementSwitchAlert != null) { movementSwitchAlert.text = ""; } Player1Controller.isAutomovementOn = false; // timeOfswitchMovementOfPlayer1 = 3.0f; } } if (Input.GetKeyDown("i")) { ActivateBlock(northBlock); northBlock = null; } else if (Input.GetKeyDown("k")) { ActivateBlock(southBlock); southBlock = null; } else if (Input.GetKeyDown("j")) { ActivateBlock(westBlock); westBlock = null; } else if (Input.GetKeyDown("l")) { ActivateBlock(eastBlock); eastBlock = null; } if (Player2Controller.isDestroyBlockActivated && activeBlock != null) { Player2Controller.isDestroyBlockActivated = false; Player2Controller.isDestroyBlockAvailable = false; activeBlock.isDestroyBlock = true; } } bool canTurn = !canFire; if (canTurn) { if ((activeBlock.MoveDirection.Equals(Vector3.back) && Input.GetKeyDown(KeyCode.K)) || (activeBlock.MoveDirection.Equals(Vector3.forward) && Input.GetKeyDown(KeyCode.I)) || (activeBlock.MoveDirection.Equals(Vector3.left) && Input.GetKeyDown(KeyCode.J)) || (activeBlock.MoveDirection.Equals(Vector3.right) && Input.GetKeyDown(KeyCode.L))) { activeBlock.ChangeSpeed(boostSpeed); } else { activeBlock.MoveSpeed = blocksSpeed; } // if (Input.GetKeyDown(KeyCode.Q)) // { // activeBlock.ChangeSpeed(boostSpeed); // } // else // { // activeBlock.MoveSpeed = blocksSpeed; // } if (IsVertical(activeBlock)) { if (Input.GetKeyDown(KeyCode.J)) { activeBlock.GoToYourLeft(); UpdateShadow(); } else if (Input.GetKeyDown(KeyCode.L)) { activeBlock.GoToYourRight(); UpdateShadow(); } } else { if (Input.GetKeyDown(KeyCode.I)) { if (activeBlock == westBlock) { activeBlock.GoToYourRight(); UpdateShadow(); } else { activeBlock.GoToYourLeft(); UpdateShadow(); } } else if (Input.GetKeyDown(KeyCode.K)) { if (activeBlock == westBlock) { activeBlock.GoToYourLeft(); UpdateShadow(); } else { activeBlock.GoToYourRight(); UpdateShadow(); } } } if (Input.GetKeyDown(KeyCode.LeftControl)) { activeBlock.TurnNinetyDegreesAndUpdateTriggers(); UpdateShadow(); } } } if (!GameObject.FindGameObjectWithTag("Player")) { movementSwitchCounter = 3; Player1Controller.hommingMissleCounter = 3; movementSwitchAlert.text = ""; } }
/// <summary> /// 罠カードの発動待機 /// </summary> /// <param name="trigger">発動できる罠カードの発動条件</param> /// <param name="caster">カードの発動権を持つプレイヤー</param> /// <returns></returns> public IEnumerator TrapPlayTime(TriggerType trigger, Player caster, EventBlock block) { //Debug.Log("Trap wait... as " + trigger); List <Card> cards = caster.GetCanPlayTrapCards(trigger); string text = ""; switch (trigger) { case TriggerType.TakeAttack: AttackBlock atkBlock = block as AttackBlock; string targetName = ""; GameObject target = atkBlock.GetTarget(); if (target.GetComponent <Player>()) { targetName = "あなた"; } else { targetName = target.GetComponent <Card>().State.cardName; } text = "相手が" + targetName + "に攻撃しました"; break; case TriggerType.TakeSkill: CardPlayBlock playBlock = block as CardPlayBlock; string skillName = playBlock.GetCards()[0].State.cardName; string skillTargetName = ""; if (playBlock.GetTarget()) { if (playBlock.GetTarget().GetComponent <Player>()) { skillTargetName = "あなた"; } else { skillTargetName = playBlock.GetTarget().GetComponent <Card>().State.cardName; } skillTargetName += "に"; } text = "相手が" + skillTargetName + skillName + "を発動しました"; break; case TriggerType.DraftStart: text = "相手ターン開始時です"; break; case TriggerType.TakeDispCard: CardDispBlock dispBlock = block as CardDispBlock; Card targetCard = dispBlock.GetCards()[0]; foreach (Card c in cards) { foreach (CardEffect ce in c.State.Effect) { foreach (EffectState es in ce.effectState) { es.SetTarget(targetCard.gameObject); } } } string dispCardName = dispBlock.GetCards()[0].State.cardName; text = "相手が" + dispCardName + "を捨てました"; break; } text += "\n罠カードを発動しますか?"; //発動可能なカードがあれば発動確認ウィンドウを出す if (cards.Count > 0) { if (!caster.isAI) { yield return(StartCoroutine(CardPlayWindow.CPW.CallWindow(text, cards, OnSelectedTrapCard))); } else { yield return(StartCoroutine(caster.GetComponent <Scond_AIScript>().Trap(trigger, cards, block))); } } }