Exemple #1
0
        public Enemy(Game game, Vector3 position, Entity entityToChase)
            : base(game)
        {
            addComponent(new Spatial(game, this, position));
            getComponent<Spatial>().focus = Vector3.Forward + position;
            addComponent(new Drawable3D(game, this, Game.Content.Load<Model>(@"models\Plane3")));
            addComponent(new Collidable(game, this, CollisionType.enemy, onHit, 50, 250,getComponent<Drawable3D>().modelBoundingBox));
            addComponent(new Spatial2D(game, this, Vector2.Zero, new Vector2(1.0f, 1.0f)));
            addComponent(new Drawable2D(game, this, Game.Content.Load<Texture2D>(@"Textures\TrackingTriangle"),Color.Lime));
            weapon = new Missiles(game, this);
            path = new PathingWander(Game, this, entityToChase, speed);
            addComponent(weapon);
            logic = joust;

            int type = ((Game1)Game).rnd.Next(0, 2);
            //int type = 0;
            switch (type)
            {
                case 0:
                    logic = joust;
                    break;
                case 1:
                    logic = stayInFrontAndEvade;
                    break;
                case 2:
                    logic = wanderInFront;
                    break;
                case 3:
                    logic = kamiKaze;
                    break;
                case 4:
                    logic = chaseDown;
                    break;
                default:
                    break;
            }
            addComponent(path);
            targetToChase = entityToChase;
            enemyManager.add(this);
        }
Exemple #2
0
 private void wanderInFront(GameTime gameTime)
 {
     if (path == null)
     {
         removeComponent<Pathing>();
         path = new PathingWander(Game, this, targetToChase, speed);
         addComponent(path);
     }
     if (path.GetType() != typeof(PathingWander))
     {
         removeComponent(path);
         path = new PathingWander(Game, this, targetToChase, speed);
         addComponent(path);
     }
     Spatial sp = getComponent<Spatial>();
     if (Vector3.Dot(sp.focus - sp.position, Vector3.Normalize(targetToChase.getComponent<Spatial>().position - sp.position))> 0.9f)
     {
         weapon.fire();
     }
 }
Exemple #3
0
 private void stayInFrontAndEvade(GameTime gameTime)
 {
     if (path == null)
     {
         removeComponent<Pathing>();
         path = new PathingWander(Game, this, targetToChase, speed);
         addComponent(path);
     }
     if (recentlyHit > 0.0f)
     {
         if (path.GetType() != typeof(PathingEvade))
         {
             removeComponent(path);
             path = new PathingEvade(Game, this, targetToChase, speed);
             addComponent(path);
         }
         recentlyHit -= (float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
     }
     else if (path.GetType() != typeof(PathingWander))
     {
         removeComponent(path);
         path = new PathingWander(Game, this, targetToChase, speed);
         addComponent(path);
     }
 }
Exemple #4
0
 private void kamiKaze(GameTime gameTime)
 {
     if (path == null)
     {
         removeComponent<Pathing>();
         path = new PathingWander(Game, this, targetToChase, speed);
         addComponent(path);
     }
     if (path.GetType() != typeof(PathingChase))
     {
         removeComponent<Pathing>();
         path = new PathingChase(Game, this, targetToChase, speed * chaseSpeedAdjustment);
         addComponent(path);
     }
 }
Exemple #5
0
 private void joust(GameTime gameTime)
 {
     if (path == null)
     {
         removeComponent<Pathing>();
         path = new PathingWander(Game, this, targetToChase, speed);
         addComponent(path);
     }
     Spatial sp = getComponent<Spatial>();
     Spatial enemySp = targetToChase.getComponent<Spatial>();
     bool isWandering = path.GetType() == typeof(PathingWander);
     Vector3 vectorBetween = Vector3.Normalize(enemySp.position - sp.position);
     float dot = Vector3.Dot(enemySp.focus - enemySp.position,-vectorBetween);
     if (isWandering)
     {
             if (dot > 0.93f)
             {
                 removeComponent(path);
                 path = new PathingChase(Game, this, targetToChase, speed * chaseSpeedAdjustment);
                 addComponent(path);
             }
     }
     else if (!isWandering && dot < 0.0f)
     {
         removeComponent(path);
         path = new PathingWander(Game, this, targetToChase, speed);
         addComponent(path);
     }
     if (Vector3.Dot(sp.focus - sp.position, vectorBetween) > 0.9f)
     {
         weapon.fire();
     }
 }
Exemple #6
0
        private void chaseDown(GameTime gameTime)
        {
            Spatial sp = getComponent<Spatial>();
            Vector3 vectorBetween = Vector3.Normalize(targetToChase.getComponent<Spatial>().position - sp.position);
            if (path == null)
            {
                removeComponent<Pathing>();
                path = new PathingChase(Game, this, targetToChase, speed * chaseSpeedAdjustment);
                addComponent(path);
            }

            if (Vector3.Dot(sp.focus - sp.position, vectorBetween) > 0.9f && ((Game1)Game).rnd.NextDouble() > 0.99)
            {
                weapon.fire();
            }
        }
Exemple #7
0
        public override void Update(GameTime gameTime)
        {
            if (targetToChase != null)
            {
                logic(gameTime);
                switchWeapons();
            }
            lifeTime += gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
            if (lifeTime > 30.0f)
            {
                path = null;
                logic = joust;
                lifeTime = float.MinValue;
            }
            Vector3 screenPos = getScreenPosition();
            getComponent<Spatial2D>().position = new Vector2(screenPos.X, screenPos.Y);
            float zscale = 1.0f - (float)Math.Pow(screenPos.Z, 300);
            getComponent<Spatial2D>().scale = new Vector2(zscale);

            base.Update(gameTime);
        }