/// <summary> /// Converts an enum type of <see cref="EnemyMoves"/> to an <see cref="SpecialMove"/> instance /// </summary> /// <returns>A special move instance</returns> /// <param name="moveType">The type of special move to create.</param> /// <param name="text">The text to show when the move is used</param> /// <param name="magic">The magic it will consume</param> /// <param name="value">A number value, used for the calculation of that specific special move</param> private SpecialMove createSpecialMove(EnemyMoves moveType, string text, int magic, float value) { SpecialMove specialMove; switch (moveType) { case EnemyMoves.MagicAttack: specialMove = new MagicAttack(text, "", magic, (int)value); break; case EnemyMoves.RaiseAttack: specialMove = new RaiseAttack(text, "", magic, value); break; case EnemyMoves.RaiseDefence: specialMove = new RaiseDefence(text, "", magic, value); break; case EnemyMoves.LowerDefence: specialMove = new LowerDefence(text, "", magic, value); break; case EnemyMoves.LowerSpeed: specialMove = new LowerSpeed(text, "", magic, value); break; default: specialMove = null; break; } return(specialMove); }
public MatrixPlayer(int playerNumber, int boardSize, Config playerConfig) : base(playerNumber, boardSize, playerConfig) { Size = boardSize; PlayerNumber = playerNumber; Me = PlayerNumber == 1 ? Players.PlayerType.Blue : Players.PlayerType.Red; MaxLevels = GetDefault(playerConfig, "maxLevels", 20); Name = playerConfig.name; Board = new MatrixHex[Size, Size]; for (int row = 0; row < Size; row++) { for (int col = 0; col < Size; col++) { Board[row, col] = new MatrixHex(Size); } } MyMoves = Matrix <int> .Build.Dense(Size, Size); MyMoves.Clear(); EnemyMoves = Matrix <int> .Build.Dense(Size, Size); EnemyMoves.Clear(); //Startup(); }
void Awake() { weapons = GetComponentsInChildren <WeaponManager>(); moves = GetComponent <EnemyMoves>(); coliderComponent = GetComponent <Collider2D>(); rendererComponent = GetComponent <SpriteRenderer>(); }
private IEnumerator PlayEnemyMoves() { foreach (KeyValuePair <Rigidbody2D, Vector2> pair in EnemyMoves) { const float MoveDuration = 0.1f; pair.Key.DOMove(pair.Value, MoveDuration); } yield return(null); EnemyMoves.Clear(); CurrentPhase.Value = Phase.PlayerMove; }
public override Tuple <int, int> SelectHex(Tuple <int, int> opponentMove) { UpdateEnemyMoves(opponentMove); // Now that we've updated the player information, time to look for a move. var matrixToExamine = MyMoves .Add(EmptyMatrix.Multiply(2)) .Add(EnemyMoves.Multiply(3)); var bestScore = Minimax(matrixToExamine, MaxLevels, AbsoluteWorstScore, AbsoluteBestScore, true); return(null); }
/// <summary> /// The main game loop thats allow the player to attack the enemy. /// </summary> /// <param name="random">Random number value that we are using for the player and enemy actions.</param> /// <param name="enemy">The current enemy.</param> /// <param name="player">The player that we are playing as.</param> /// <param name="tools">Player restriction area - counters for the hheal and three strike attack usages.</param> private static void GameLoop(Random random, Enemy enemy, Player player, Tools tools) { Print.PrintMessage(Messages.EnemyEncounter, player.Name, enemy.Name); try { while (!enemy.IsDead && !player.IsDead) { PlayerMoves.PlayerAction(random, enemy, player, tools); EnemyMoves.EnemyAction(random, enemy, player); ConsoleMessageColor.ResetMessageColor(); } } catch (Exception e) { Print.PrintMessage(Messages.GameLoopError, e); } }
void Start() { theTrack = FindObjectOfType <trackMove>(); coin = FindObjectOfType <CoinsMaker>(); sign = FindObjectOfType <SignPool>(); Enemy = FindObjectOfType <EnemyMoves>(); //Plane = FindObjectOfType<AirPlanes>(); timer = 4.2f; timeCoin = 5f; /// walls Rand = Random.Range(2.45f, 3f); timer = Rand; if (scoreChange > 300) { timer = Rand / 1.2f; } if (scoreChange > 550) { timer = Rand / 1.4f; } if (scoreChange > 800) { timer = Rand / 1.5f; } if (scoreChange > 1040) { timer = Rand / 1.6f; } if (scoreChange > 1220) { timer = Rand / 1.7f; } /// InvokeRepeating("CallWalls", timer, timer); timer2 = Random.Range(8f, 15f); InvokeRepeating("CallBullon", timer2, timer2); }
public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = shootingRate; var shotTransform = Instantiate(shotPrefab) as Transform; shotTransform.position = transform.position; ShotManager shot = shotTransform.gameObject.GetComponent <ShotManager>(); if (shot != null) { shot.hitted = isEnemy; } EnemyMoves move = shotTransform.gameObject.GetComponent <EnemyMoves>(); if (move != null) { move.direction = this.transform.right; } } }
public override void update() { #region player controlled if (isInputAllowed) //if Game1 allows input { if (this.keys.rightPressed() && this.Position.X < 1740 && isMovementAllowedRight) //if the right key is pressed and Game1 doesnt block the movement and the character is not at the right edge of the screen { if (!isJumping && !isHitting && !isDucking) // if the character is not in the middle of another motion { //change the state to a walking state if (this.state != State.walk) { base.state = State.walk; base.frame = 0; base.count = 0; } } if (!isHitting && !isDucking) //if the character isnt ducking or hitting (jumping is allowed) { this.Position += new Vector2(4, 0); //move it to the right } } //same as the right key but for the other direction if (this.keys.leftPressed() && this.Position.X > 60 && isMovementAllowedLeft) { if (!isJumping && !isHitting && !isDucking) { if (this.state != State.walk) { base.state = State.walk; base.frame = 0; base.count = 0; } } if (!isHitting && !isDucking) { this.Position += new Vector2(-4, 0); } } //if up key is pressed if (this.keys.upPressed()) { if (!isJumping) //if the character wasnt jumping already { velocity = new Vector2(0, -17); // give the character a starting velocity of 17 pixels upwards isJumping = true; // mark the character to be jumping positionBeforeJump = Position; // save the position the character needs to reach backwards do if (this.state != State.jump) //put the character in a jumping state { base.state = State.jump; base.frame = 0; base.count = 0; } } } //if the hit button is pressed if (this.keys.hitButtonPressed()) { if (!isHitting && this.state != State.walk && !isDucking) // if the character is not hitting walking or ducking { isHitting = true; // mark the charcter to be hitting randomizeAnimation = animationRandomizer.Next(1, 4); // randomize an attack animation // initiate the attack animation if (this.state != State.kick && randomizeAnimation == 1) { base.state = State.kick; base.frame = 0; base.count = 0; } if (this.state != State.punch1 && randomizeAnimation == 2) { base.state = State.punch1; base.frame = 0; base.count = 0; } if (this.state != State.punch2 && randomizeAnimation == 3) { base.state = State.punch2; base.frame = 0; base.count = 0; } } } //if the duck button is pressed if (this.keys.duckButtonPressed()) { if (!isHitting && !isJumping) // if the character isnt hitting or jumping { isDucking = true; // mark the character to be ducking if (this.state != State.duck) //intiate the ducking animation { this.state = State.duck; base.frame = 0; base.count = 0; } } } else { isDucking = false; // if the ducking key isnt pressed mark the character to not be ducking } } // if no key is being pressed, the character is not in the middle of an animation and the game is not over, reset the character to be in a standing state if (!isJumping && !isHitting && !this.keys.duckButtonPressed() && !this.keys.rightPressed() && !this.keys.leftPressed() && !this.keys.upPressed() && !this.keys.hitButtonPressed() && this.state != State.stand && !isGameOver) { this.state = State.stand; base.frame = 0; base.count = 0; } //this part of the code adds velocity to the character //usually the velocity is supposed to be empty, but if the charcter jumped it will have a starting value of 17 in the y axis and 0 in the x axis this.Position += velocity; if (isJumping) { velocity.Y += 0.5f; // if the charcter is jumping, deduce 0.5 from the velocity so that eventually the character will stop going up, start going down and reach the floor. } if (Position.Y == positionBeforeJump.Y && isJumping) //if the character had reached the floor { velocity.Y = 0; // reset the velocity to be empty isJumping = false; // mark the end of the jump } if (isHitting && base.frame == base.spriteAnalyzer.Orgs.Count - 1 && base.count == base.spriteAnalyzer.Rate - 1 && !isGameOver) // if the game is in play, the character is hitting, and the hitting animation ended { isHitting = false; // mark the end of the hit this.state = State.stand; //reset the character state to be standing base.frame = 0; base.count = 0; this.shouldAddHit = true;//mark that a new hit can be added } if (this.state == State.kick && base.frame == 5 && this.shouldAddHit) // if the character is kicking and reached the 5th frame, add an internal hit { this.HitCount++; this.shouldAddHit = false; // we use the shouldAddHit boolean to make sure that the game doesnt register a hit for every tick where the character is in the right frame, but only once } if (this.state == State.punch1 && base.frame == 2 && this.shouldAddHit) // if the character is punching and reached the 2nd frame, add an internal hit { this.HitCount++; this.shouldAddHit = false; } if (this.state == State.punch2 && base.frame == 2 && this.shouldAddHit) // if the character is punching (different animation) and reached the 2nd frame, add an internal hit { this.HitCount++; this.shouldAddHit = false; } #endregion #region Update Enemy Movements moveUpdateTimer += (float)Global.gameTime.ElapsedGameTime.TotalSeconds; //update the move update timer if (moveUpdateTimer > moveUpdateRate && Math.Abs((int)this.Position.X - (int)enemy.Position.X) < changeStateTolerance) // if the timer had reached the desired time between each update { //updating the list according to the move that the enemy is preforming if (enemy.isHitting) { lastEnemyMoves.Add(EnemyMoves.Hit); moveUpdateRate = 1.1f; } else if (enemy.isDucking) { lastEnemyMoves.Add(EnemyMoves.Duck); moveUpdateRate = 0.5f; } else if (enemy.isJumping) { lastEnemyMoves.Add(EnemyMoves.Jump); moveUpdateRate = 1.2f; } else { lastEnemyMoves.Add(EnemyMoves.Move); } moveUpdateTimer = 0; //resetting the timer } #endregion //if the ai is on random mode or the enemy is yet to perform enough move or the players arent in close combat if (isRandomAi || lastEnemyMoves.Count < 10 || Math.Abs((int)this.Position.X - (int)enemy.Position.X) < changeStateTolerance) { AIHandlerRandom(); //calling for the ai handler DuckingRandom(Global.gameTime); JumpingRandom(Global.gameTime); } else // if conditions are right for the ai to try to guess the enemy's next move { for (int i = 0; i < lastEnemyMoves.Count; i++) { //calculating the amount of times each move appears in the list if (lastEnemyMoves[i] == EnemyMoves.Hit) { enemyHitCount++; } else if (lastEnemyMoves[i] == EnemyMoves.Duck) { enemyDuckCount++; } else if (lastEnemyMoves[i] == EnemyMoves.Jump) { enemyJumpCount++; } else if (lastEnemyMoves[i] == EnemyMoves.Move) { enemyMoveCount++; } if (lastEnemyMoves.Count - 1 - i <= 10) //calculating the amount of times each moves appears in the last ten spots of the list { if (lastEnemyMoves[i] == EnemyMoves.Hit) { enemyHitLast10++; } else if (lastEnemyMoves[i] == EnemyMoves.Duck) { enemyDuckLast10++; } else if (lastEnemyMoves[i] == EnemyMoves.Jump) { enemyJumpLast10++; } else if (lastEnemyMoves[i] == EnemyMoves.Move) { enemyMoveLast10++; } } } //calculating the total for both the last 10 moves and the entire game totalHit = (float)enemyHitLast10 * (5 / lastEnemyMoves.Count) + (float)enemyHitCount * (lastEnemyMoves.Count - 5 / lastEnemyMoves.Count); totalDuck = (float)enemyDuckLast10 * (5 / lastEnemyMoves.Count) + (float)enemyDuckCount * (lastEnemyMoves.Count - 5 / lastEnemyMoves.Count); totalJump = (float)enemyJumpLast10 * (5 / lastEnemyMoves.Count) + (float)enemyJumpCount * (lastEnemyMoves.Count - 5 / lastEnemyMoves.Count); totalMove = (float)enemyMoveLast10 * (5 / lastEnemyMoves.Count) + (float)enemyMoveCount * (lastEnemyMoves.Count - 5 / lastEnemyMoves.Count); mostChanceMove = MaxChance(totalHit, totalDuck, totalJump, totalMove); //calling the function to calculate which move has the highest chance of appearing if (mostChanceMove == EnemyMoves.Hit) { DuckOrHit(); //if the enemy is likely to hit, either duck or hit buck } else if (mostChanceMove == EnemyMoves.Duck) { RandomMovement(Global.gameTime); //if the enemy is likely to duck, move to allow him to stop ducking } else if (mostChanceMove == EnemyMoves.Jump) { Jump(); // if the enemy is likely to jump, jump along with him } else if (mostChanceMove == EnemyMoves.Move) { AttackRandom(Global.gameTime); // if the enemy is likely to move, attack him } } base.update(); }
void Start() { instance = this; }