Exemplo n.º 1
0
        internal override void Update(Map map, GameTime gameTime)
        {
            xDistance = (parent.X - map.hero.X);
            yDistance = (parent.Y - map.hero.Y);

            shoot(map, gameTime);
        }
Exemplo n.º 2
0
        internal override void Update(Map map, GameTime gameTime)
        {
            xDistance = (parent.X - map.hero.X);
            yDistance = (parent.Y - map.hero.Y);

            /* Evades from the target */
            parent.move((xDistance <= 0) ? -1 : 1, (yDistance <= 0) ? -1 : 1, parent.velocity);
        }
Exemplo n.º 3
0
        internal override void Update(Map map, GameTime gameTime)
        {
            xDistance = (parent.X - map.hero.X);
            yDistance = (parent.Y - map.hero.Y);

            /* Chases after the target */
            if (Math.Abs(xDistance) <= 2)
                parent.move(0, (yDistance >= 0) ? -1 : 1, parent.velocity);
            else if (Math.Abs(yDistance) <= 2)
                parent.move((xDistance >= 0) ? -1 : 1, 0, parent.velocity);
            else
                parent.move((xDistance >= 0) ? -1 : 1, (yDistance >= 0) ? -1 : 1, parent.velocity);
        }
        internal override void Update(Map map, GameTime gameTime)
        {
            parent.shootStraight(parent.bulletSelection, parent.BulletType[parent.bulletSelection].BulletAmount,
                //MathHelper.Lerp(parent.BulletType[parent.bulletSelection].BulletDensity * 0.75f,
                //parent.BulletType[parent.bulletSelection].BulletDensity * 1.25f,
                //(float)rand.NextDouble()) * 5,
                parent.BulletType[parent.bulletSelection].BulletDensity * 5,
                //MathHelper.Lerp(parent.BulletType[parent.bulletSelection].BulletDensity * 0.9f,
                //parent.BulletType[parent.bulletSelection].BulletDensity * 1.1f,
                //(float)rand.NextDouble() * 3),
                parent.BulletType[parent.bulletSelection].BulletDensity * 3,

                MathHelper.Pi / 2 * 3);
        }
Exemplo n.º 5
0
        internal override void Update(Map map, GameTime gameTime)
        {
            timer.Update(gameTime);
            if (timer.elapsedMilliseconds() > 50)
            {
                distance = Vector2.Distance(parent.position, map.hero.position);
                xDistance = parent.X - map.hero.X;
                yDistance = parent.Y - map.hero.Y;

                controlBehavior(map, gameTime);

                timer.reset();
                lastDistance = distance;
            }
        }
Exemplo n.º 6
0
        internal override void Update(Map map, GameTime gameTime)
        {
            _GLOBAL.InputHandler.keyboardState = Keyboard.GetState();

            if (_GLOBAL.InputHandler.keyboardState.IsKeyDown(Keys.D1) && _GLOBAL.InputHandler.previousKeyboardState.IsKeyUp(Keys.D1))
                bulletSelection = 0;

            else if (_GLOBAL.InputHandler.keyboardState.IsKeyDown(Keys.D2) && _GLOBAL.InputHandler.previousKeyboardState.IsKeyUp(Keys.D2))
                bulletSelection = 1;

            if (_GLOBAL.InputHandler.isKeyUpPressed())
                move(0, -1, velocity);

            if (_GLOBAL.InputHandler.isKeyDownPressed())
                move(0, 1, velocity);

            if (_GLOBAL.InputHandler.isKeyLeftPressed())
                move(-1, 0, velocity);

            if (_GLOBAL.InputHandler.isKeyRightPressed())
                move(1, 0, velocity);

            /* The hero plane object does not use a behavior model, so this has to be hand-coded */
            if (_GLOBAL.InputHandler.isKeyEnterPressed())
            {
                if (Timer.elapsedMilliseconds() > BulletType[bulletSelection].BulletInterval)
                {
                    shootStraight(bulletSelection, BulletType[bulletSelection].BulletAmount, BulletType[bulletSelection].BulletDensity, 3, MathHelper.Pi / 2);
                    Timer.reset();
                }
            }

            if (position.X < _GLOBAL.Viewport.X)
                position.X = 0;

            else if (position.X > _GLOBAL.Viewport.Width - Width)
                position.X = _GLOBAL.Viewport.Width - Width;

            if (position.Y < _GLOBAL.Viewport.Y)
                position.Y = 0;

            else if (position.Y > _GLOBAL.Viewport.Height - Height)
                position.Y = _GLOBAL.Viewport.Height - Height; ;

            _GLOBAL.InputHandler.previousKeyboardState = _GLOBAL.InputHandler.keyboardState;

            base.Update(map, gameTime);
        }
Exemplo n.º 7
0
        internal override void Update(Map map, GameTime gameTime)
        {
            Vector2 difference;

            if (parent.Path.Count == 0)
                return;

            /* Moves linearly toward a destination */
            if (parent.Path.Peek().withinRange(parent.position,
                (parent.sprite.Height + parent.sprite.Width) / 4)) // reach the point
                parent.Path.Dequeue();
            else
            {
                difference = parent.Path.Peek().Point - parent.position;
                difference.Normalize();
                parent.move(difference.X, difference.Y, parent.velocity);
            }
        }
        internal override void Update(Map map, GameTime gameTime)
        {
            x = map.hero.position.X - parent.position.X;
            y = map.hero.position.Y - parent.position.Y;

            targetAngle = (float)(Math.PI * 2 - Math.Atan2(y, x));
            parent.shootStraight(parent.bulletSelection, parent.BulletType[parent.bulletSelection].BulletAmount,

            /* Lerp adds unpredictability to the bullet */
            MathHelper.Lerp(parent.BulletType[parent.bulletSelection].BulletDensity * 0.9f,
            parent.BulletType[parent.bulletSelection].BulletDensity * 1.1f,
            (float)rand.NextDouble()) * 5,

            /* Lerp adds unpredictability to the bullet */
            MathHelper.Lerp(parent.BulletType[parent.bulletSelection].BulletDensity * 0.9f,
            parent.BulletType[parent.bulletSelection].BulletDensity * 1.1f,
            (float)rand.NextDouble()) * 3, targetAngle);
        }
Exemplo n.º 9
0
        internal override void Update(Map map, GameTime gameTime)
        {
            x = map.hero.position.X - parent.position.X;
            y = map.hero.position.Y - parent.position.Y;

            targetAngle = (float)(Math.PI * 2 - Math.Atan2(y, x));

            if (_GLOBAL.Debug)
            {
                double degree = (((targetAngle) / (Math.PI * 2)) * 360 + 360) % 360;
                map.TargetShooting = "Hero: (" + map.hero.position.X + ", " + map.hero.position.Y +
                    ")\nEnemy: (" + parent.position.X + ", " + parent.position.Y +
                    ")\nDegree: " + degree +
                    "\ntargetAngle: " + targetAngle;
            }

            /* Lerp adds unpredictability to the bullet */
            parent.shootMulti(parent.bulletSelection, parent.BulletType[parent.bulletSelection].BulletAmount,
            MathHelper.Pi / 180 * MathHelper.Lerp(parent.BulletType[parent.bulletSelection].BulletDensity * 0.9f,
                parent.BulletType[parent.bulletSelection].BulletDensity * 1.1f,
                (float)rand.NextDouble()), targetAngle);
        }
Exemplo n.º 10
0
 internal abstract void Update(Map map, GameTime gameTime);
Exemplo n.º 11
0
 internal override void Update(Map map, GameTime gameTime)
 {
     parent.shootCircle(parent.bulletSelection, MathHelper.Pi / 180 * parent.BulletType[parent.bulletSelection].BulletDensity);
 }
Exemplo n.º 12
0
        internal override void Update(Map map, GameTime gameTime)
        {
            if (collision(map.hero) && map.hero.visibility)
            {
                map.hero.hp -= 5;
                hp -= 5;
            }

            /* If the object is out of visible or allowed viewport, it is removed */
            if ((position.Y > _GLOBAL.Viewport.Height + 200 || position.Y < _GLOBAL.Viewport.Y - 200
                || position.X > _GLOBAL.Viewport.Width + 200 || position.X < _GLOBAL.Viewport.X - 200))
                visibility = false;

            currentBehavior.Update(map, gameTime);

            base.Update(map, gameTime);
        }
Exemplo n.º 13
0
 internal override void Update(Map map, GameTime gameTime)
 {
     behavior.Update(map, gameTime);
 }
Exemplo n.º 14
0
        private void shoot(Map map, GameTime gameTime)
        {
            PlaneObj target = map.hero;
            Behavior behavior = null;

            /* h = hero; 1 = parent is at this location and uses first the if statement, 2  the second
             * -------------
             * | h | h | h |
             * +---+---+---+
             * | 1 | 2 | 1 |
             * +---+---+---+
             * | 1 | 2 | 1 |
             * -------------
             */
            if (yDistance > _GLOBAL.Viewport.Height / 6) // hero is in the back
            {
                if (xDistance > _GLOBAL.Viewport.Width / 6 || xDistance < -_GLOBAL.Viewport.Width / 3) // hero is left or right
                {
                    behavior = firstBehaviorfirstGet(parent.Behaviors,
                        BehaviorState.ShootCircle,
                        BehaviorState.ShootTarget,
                        BehaviorState.ShootStraightAngle,
                        BehaviorState.ShootStraight);
                    if (_GLOBAL.Debug) Console.WriteLine("top left/right");
                }
                else // hero is in range
                {
                    behavior = firstBehaviorfirstGet(parent.Behaviors,
                        BehaviorState.ShootStraightAngle,
                        BehaviorState.ShootCircle,
                        BehaviorState.ShootTarget,
                        BehaviorState.ShootStraight);
                    if (_GLOBAL.Debug) Console.WriteLine("top mid");
                }
            }

            /* h = hero; 1 = parent is at this location and uses first the if statement, 2  the second
             * -------------
             * |   |   |   |
             * +---+---+---+
             * |h1 |h2 |h1 |
             * +---+---+---+
             * |   |   |   |
             * -------------
             */
            else if (yDistance <= _GLOBAL.Viewport.Height / 3 && yDistance >= -_GLOBAL.Viewport.Height / 6) // hero is within range
            {
                if (xDistance > _GLOBAL.Viewport.Width / 6 || xDistance < -_GLOBAL.Viewport.Width / 6) // hero is left or right
                {
                    behavior = firstBehaviorfirstGet(parent.Behaviors,
                        BehaviorState.ShootTarget,
                        BehaviorState.ShootStraightAngle,
                        BehaviorState.ShootCircle,
                        BehaviorState.ShootStraight);
                    if (_GLOBAL.Debug) Console.WriteLine("mid left/right");
                }
                else
                {
                    behavior = firstBehaviorfirstGet(parent.Behaviors,
                        BehaviorState.ShootCircle,
                        BehaviorState.ShootStraight,
                        BehaviorState.ShootStraightAngle,
                        BehaviorState.ShootTarget);
                    if (_GLOBAL.Debug) Console.WriteLine("mid mid");
                }
            }

            /* h = hero; 1 = parent is at this location and uses first the if statement, 2  the second
             * -------------
             * | 1 | 2 | 1 |
             * +---+---+---+
             * | 1 | 2 | 1 |
             * +---+---+---+
             * | h | h | h |
             * -------------
             */

            else if (yDistance < -_GLOBAL.Viewport.Height / 6) // hero is in the front
            {
                if (xDistance > _GLOBAL.Viewport.Width / 6 || xDistance < -_GLOBAL.Viewport.Width / 6) // hero is left or right
                {
                    behavior = firstBehaviorfirstGet(parent.Behaviors,
                        BehaviorState.ShootTarget,
                        BehaviorState.ShootStraightAngle,
                        BehaviorState.ShootCircle,
                        BehaviorState.ShootStraight);
                    if (_GLOBAL.Debug) Console.WriteLine("bot left/right");
                }
                else
                {
                    behavior = firstBehaviorfirstGet(parent.Behaviors,
                        BehaviorState.ShootStraight,
                        BehaviorState.ShootCircle,
                        BehaviorState.ShootStraightAngle,
                        BehaviorState.ShootTarget);
                    if (_GLOBAL.Debug) Console.WriteLine("bot mid");
                }
            }

            if (behavior != null)
            {
                behavior.Update(map, gameTime);
                lastShooting = behavior.behaviorState;
            }
        }
Exemplo n.º 15
0
        internal virtual void Update(Map map, GameTime gameTime)
        {
            Timer.Update(gameTime);
            if (!visibility)
            {
                //map.toBeRemoved.Add(ID); // remove the plane if it's invisible
                map.enemiessToBeUpdated.Remove(this);
                map.bulletPool.AddRange(BulletPool); // this adds all the BulletObjs in BulletPool to the map.bulletPool
            }

            if (hp <= 0)
                visibility = false;

            /* Calling update on all of it's bullets, foreach will cause a problem if the item is removed */
            for (int i = BulletPool.Count - 1; i >= 0; --i)
                BulletPool[i].Update(BulletPool, map, gameTime);

            map.MSG2 += "\n" + ID + ".Bulelts: " + BulletPool.Count;

            base.Update(gameTime);
        }
Exemplo n.º 16
0
        private void controlBehavior(Map map, GameTime gameTime)
        {
            PlaneObj target = map.hero;
            Behavior behavior = null;

            foreach (Behavior b in parent.Behaviors)
            {
                /* If the object has waypoints to go, ignore other behaviors; waypoints are prioritized */
                if (b.behaviorState == BehaviorState.LinearBehavior)
                {
                    if (parent.Path.Count > 0)
                        behavior = b;
                }
            }

            if (behavior == null)
            {
                /* These if-statements can be reduced, but this is more readable. At lease, for me it is. */
                if (yDistance > _GLOBAL.Viewport.Height / 6) // hero is in the back
                {
                    if (xDistance > _GLOBAL.Viewport.Width / 6 || xDistance < -_GLOBAL.Viewport.Width / 6) // hero is left or right of parent
                        behavior = routineB();
                    else // hero is nearby
                        behavior = routineA();
                }
                else if (yDistance <= _GLOBAL.Viewport.Height / 6 && yDistance >= -_GLOBAL.Viewport.Height / 6) // hero is nearby
                    behavior = routineA();
                else if (yDistance < -_GLOBAL.Viewport.Height / 6) // hero is in the front
                    behavior = routineB();
            }
            else
            {
                /* if the hero has waypoints to move, but it can shoot as well. Shooting is prioritized */
                if (parent.Timer.elapsedMilliseconds() > parent.BulletType[parent.bulletSelection].BulletInterval)
                {
                    foreach (Behavior b in parent.Behaviors)
                        if (b.behaviorState == BehaviorState.Shoot && canShoot(parent.Behaviors))
                            behavior = b;

                    parent.Timer.reset();
                }
            }

            if (behavior != null)
            {
                if (_GLOBAL.Debug)
                    Console.WriteLine(behavior.ToString());

                behavior.Update(map, gameTime);
                lastBehavior = behavior.behaviorState;
            }
        }