public void EnemyHit(Enemy hit, Enemy reached)
 {
     hit.Velocity = reached.Velocity +new Vector2(0, (float)random.NextDouble());
     reached.Velocity = reached.Velocity - new Vector2(0, (float)random.NextDouble());
     if (hit.Velocity.Y > 0) { hit.Velocity = new Vector2(hit.Velocity.X,0); }
     if (-reached.Velocity.Y > _maxSpeed) { reached.Velocity = new Vector2(0, -(float)_maxSpeed); }
 }
        public void EnemyInterCollision(Enemy enemyA, Enemy enemyB)
        {
            if (enemyA.Bounds.X == enemyB.Bounds.X)
            {
                if (enemyA.Bounds.Y > enemyB.Bounds.Y)
                {
                    EnemyHit(enemyA, enemyB);
                }
                else
                {
                    EnemyHit(enemyB, enemyA);
                }
            }
            else
            {
                if (enemyA.Velocity.Y > enemyB.Velocity.Y)
                {
                    EnemyHit(enemyA, enemyB);
                }
                else
                {
                    EnemyHit(enemyB, enemyA);
                }

                if (enemyA.Bounds.X > enemyB.Bounds.X)
                {
                    if (!enemyB.ChangeLane(-1) && !enemyA.ChangeLane(1))
                    { enemyA.Velocity = Vector2.Zero; }
                }
                else
                {
                    if (!enemyA.ChangeLane(-1) && !enemyB.ChangeLane(1))
                    { enemyA.Velocity = Vector2.Zero; }

                }

            }
        }
Example #3
0
        /// <summary>
        /// Trata a colisão entre o heroi e o carro inimigo
        /// </summary>
        /// <param name="enemy"></param>
        /// <param name="map"></param>
        public void EnemyCollide(Enemy enemy, IMap map)
        {
            if (enemy.Location.Y < Location.Y)
            {
                map.Velocity = -(enemy.Velocity + new Vector2(0, 1));
                enemy.Velocity += new Vector2(0, -(float)random.NextDouble());
            }
            else
            {
                if ((-enemy.Velocity.Y) > map.Velocity.Y)
                {
                   enemy.Velocity = -map.Velocity;
                }
            }

            //heroi bateu na esquerda do carro inimigo
            if ( enemy.Location.X > Location.X )
            {
                targetLane = XtoLane(enemy.Location.X) - 1;
            }
            else if ( enemy.Location.X < Location.X )
            {
                targetLane = XtoLane(enemy.Location.X) + 1;
            }

            if (targetLane > _lanes.LastIndex)
            {
                if (!enemy.ChangeLane(-1))
                {
                    //inimigo esta atras do heroi
                    if (enemy.Location.Y > Location.Y)
                    {
                        enemy.Velocity = new Vector2(enemy.Velocity.X, 0);
                    }
                    else
                    {
                        enemy.Velocity += new Vector2(0, -(float)random.NextDouble());
                        map.Velocity = new Vector2(map.Velocity.X, 0);
                    }
                }

            }
            if (targetLane < _lanes.StartIndex)
            {
                if (!enemy.ChangeLane(1))
                {
                    //inimigo esta atras do heroi
                    if (enemy.Location.Y > Location.Y)
                    {
                        enemy.Velocity = new Vector2(enemy.Velocity.X, 0);
                    }
                    else
                    {
                        enemy.Velocity += new Vector2(0, -(float)random.NextDouble());
                        map.Velocity = new Vector2(map.Velocity.X, 0);
                    }
                }
            }
        }