示例#1
0
        public bool moveBotToPos(EnemiesAndPlayer b, Vector3 newPos)
        {
            Vector3 newVel = newPos - b.Position;

            newVel.Normalize();

            float error = 4;

            if (Vector3.Distance(newPos, b.Position) > error) // prevent jitter
            {
                if (switchedToBoss || switchedToMiniBoss)
                {
                    b.Velocity = newVel * 8;
                }
                else
                {
                    b.Velocity = newVel;
                }
            }
            else
            {
                b.Velocity = Vector3.Zero;
                b.Position = newPos;
                return(true);
            }
            return(false);
        }
示例#2
0
 public override void Collision(GameEntity target)
 {
     if (target is EnemiesAndPlayer && !(target is Player)) //your own explosions cannot hurt you
     {
         EnemiesAndPlayer ep = target as EnemiesAndPlayer;
         ep.takeDamage(damage);
     }
 }
 public override void Collision(GameEntity target)
 {
     if (target is EnemiesAndPlayer)
     {
         EnemiesAndPlayer ep = target as EnemiesAndPlayer;
         ep.takeDamage(damage);
         Die();
     }
 }
示例#4
0
        public void UpdatePreMiniBoss(GameTime gameTime)
        {
            Player p = entities[0] as Player;

            p.controls.Locked = true;
            Vector3 newPos = new Vector3(0, 0, -30);

            if (!movePreInfector) // prevent jitter
            {
                movePreInfector = movePlayerToPos(p, newPos);
            }

            velocity = velocity * 0.99f;
            if (velocity.Z > -0.01f) //slow the level down to a halt
            {
                velocity = Vector3.Zero;
            }

            if (velocity == Vector3.Zero)
            {
                if (!enemiesReenabled)
                {
                    for (int i = 0; i < entities.Count; i++)
                    {
                        if (entities[i] is MeleeBot || entities[i] is MissileBot)
                        {
                            EnemiesAndPlayer ep = entities[i] as EnemiesAndPlayer;
                            ep.Enabled = true;
                        }
                    }
                    enemiesReenabled = true;
                }
                //have the infector come in
                if (!infectorAdded)
                {
                    Add(miniBoss);
                    infectorAdded = true;
                }
                else
                {
                    if (miniBoss.Activated)
                    {
                        p.controls.Locked = false;
                    }
                }
                if (infectorAdded && miniBoss.isDead)
                {
                    infectorDestroyed = true;
                    velocity          = -Vector3.UnitZ;
                }
            }
        }
示例#5
0
 public override void Collision(GameEntity target)
 {
     if (target is EnemiesAndPlayer)
     {
         EnemiesAndPlayer ep = target as EnemiesAndPlayer;
         ep.takeDamage(damage);
         Die();
     }
     else if (target is BotMissile)
     {
         BotMissile bm = target as BotMissile;
         bm.Die(); //should missiles be shot down in one hit?
     }
 }
示例#6
0
        public override void Update(GameTime gameTime)
        {
            Player p = entities[0] as Player;

            #region Intro Handling
            if (!firstStart)                  // Intro sequence
            {
                if (position.Z <= startGameZ) //unlock the player's controls at a certain point
                {
                    //Camera.Instance.translateCameraToTarget3(Camera.Instance.TopDownPosition, 0.5f);
                    p.controls.Locked = false;
                    firstStart        = true;
                    velocity          = -Vector3.UnitZ; //level speeds up as soon as player gains control at start
                    //velocity = Vector3.Zero;
                    //position.Z = 3999;
                }
                else //still in intro to level - do some interesting things with the camera here
                {
                    if (!p.InitialLock)
                    {
                        velocity = -Vector3.UnitZ;
                        if (!introRot1 && position.Z <= 7820)
                        {
                            introRot1 = Camera.Instance.translateCameraToTarget3(new Vector3(p.Position.X - 10, p.Position.Y, p.Position.Z), 0.20f);
                        }
                        if (introRot1 && !introRot2)
                        {
                            introRot2 = Camera.Instance.translateCameraToTarget3(new Vector3(p.Position.X, p.Position.Y + 20, p.Position.Z - 30), 0.25f);
                        }
                        if (introRot2)
                        {
                            returnedToTopDown = Camera.Instance.translateCameraToTarget3(Camera.Instance.TopDownPosition, 0.20f);
                        }
                    }
                }
            }
            else
            {
                if (!returnedToTopDown)
                {
                    returnedToTopDown = Camera.Instance.translateCameraToTarget3(Camera.Instance.TopDownPosition, 0.5f);
                }
            }
            #endregion
            #region Shortcuts
            if (Game1.debug)
            {
                KeyboardState k = Keyboard.GetState();
                if (k.IsKeyDown(Keys.W) && !switchedToBoss && position.Z > preBossZ)
                {
                    destroyAllEnemies();
                    setRot         = false;
                    setTrans       = false;
                    position       = new Vector3(-45, -700, preBossZ);
                    switchedToBoss = true;
                }
                if (k.IsKeyDown(Keys.E) && !switchedToMiniBoss && position.Z > infectorZ)
                {
                    //destroyAllEnemies();
                    setRot             = false;
                    setTrans           = false;
                    position           = new Vector3(-45, -700, infectorZ);
                    switchedToMiniBoss = true;
                }
                if (k.IsKeyDown(Keys.C) && !switchedToClot && position.Z > clotZ)
                {
                    if (!miniBoss.isDead)
                    {
                        miniBoss.Die();
                    }
                    infectorDestroyed = true;
                    setRot            = false;
                    setTrans          = false;
                    position          = new Vector3(-45, -700, clotZ);
                    switchedToClot    = true;
                }
                if (k.IsKeyDown(Keys.D) && !switchedToStart && position.Z > 7600)
                {
                    setRot          = false;
                    setTrans        = false;
                    position        = new Vector3(-45, -700, startGameZ);
                    switchedToStart = true;
                }
            }
            #endregion
            if (!bossAdded)
            {
                Add(new Boss(content, new Vector3(285, -1200, -400)));
                bossAdded = true;
            }
            if (reachedBoss)
            {
                UpdateBoss(gameTime);
                return;
            }
            if (!reachedInfectorZ)
            {
                if (position.Z < infectorZ)
                {
                    reachedInfectorZ = true;
                    for (int i = 0; i < entities.Count; i++)
                    {
                        if (entities[i] is MeleeBot || entities[i] is MissileBot)
                        {
                            EnemiesAndPlayer ep = entities[i] as EnemiesAndPlayer;
                            ep.Enabled  = false;
                            ep.Velocity = Vector3.UnitZ;
                        }
                    }
                }
            }
            else
            {
                if (!reachedPreBossZ && !infectorDestroyed)
                {
                    UpdatePreMiniBoss(gameTime);
                }
            }
            if (!reachedClotZ)
            {
                if (position.Z < clotZ)
                {
                    reachedClotZ = true;
                }
            }
            else
            {
                if (!reachedPreBossZ && infectorDestroyed && !clotsDestroyed)
                {
                    UpdateClot(gameTime);
                }
            }
            if (!reachedPreBossZ)
            {
                if (position.Z < preBossZ)
                {
                    reachedPreBossZ = true;
                }
            }
            else
            {
                UpdatePreBoss(gameTime);
            }

            position += velocity;
            CheckCollision();

            bool fightingInfector = position.Z < infectorZ && !infectorDestroyed && miniBoss.Activated;
            bool inClotSection    = position.Z < clotZ && infectorDestroyed;

            if (!reachedPreBossZ && (position.Z > infectorZ || infectorDestroyed))
            {
                if (position.Z > clotZ)
                {
                    enemySpawner.Update(gameTime, entities[0].Position, getZ(), true, false); //add enemies along with cells
                }
                else
                {
                    enemySpawner.Update(gameTime, entities[0].Position, getZ(), false, false); //add cells only
                }
            }
            else if (!reachedPreBossZ && (fightingInfector || inClotSection))
            {
                enemySpawner.Update(gameTime, entities[0].Position, getZ(), false, false); //add cells only
            }

            levelWorldMat = Matrix.CreateScale(10) * Matrix.CreateRotationY(0) * Matrix.CreateTranslation(position);
            base.Update(gameTime);
        }
示例#7
0
        public virtual void Update(GameTime gameTime)
        {
            Player p = entities[0] as Player;

            if (p.SwitchedFromShield)
            {
                for (int j = 0; j < entities.Count; j++)
                {
                    if (entities[j] is Shield)
                    {
                        entities.Remove(entities[j]);
                        j = 0;
                    }
                }
                p.SwitchedFromShield = false;
            }
            for (int i = 0; i < entities.Count; i++)
            {
                if (!entities[i].isDead)
                {
                    if (entities[i] is ChargeBall)
                    {
                        ChargeBall cb = entities[i] as ChargeBall;
                        cb.Update(gameTime, p.Position, p.Rotation);
                    }
                    if (entities[i] is Laser)
                    {
                        Laser l = entities[i] as Laser;
                        l.Update(gameTime, p.Position, p.Rotation);
                    }
                    if (entities[i] is Boss)
                    {
                        Boss b = entities[i] as Boss;
                        b.Update(gameTime, p.Position);
                    }
                    if (entities[i] is ClotSide)
                    {
                        ClotSide cs = entities[i] as ClotSide;
                        cs.Update(gameTime, velocity);
                    }
                    if (entities[i] is Infector)
                    {
                        Infector inf = entities[i] as Infector;
                        inf.Update(gameTime, p.Position);
                    }
                    if (entities[i] is TokenPickup)
                    {
                        TokenPickup tp = entities[i] as TokenPickup;
                        tp.Update(gameTime);
                    }
                    if (entities[i] is PlayerWeapon)
                    {
                        PlayerWeapon w = entities[i] as PlayerWeapon;
                        w.Update(gameTime, p.Position, p.Rotation);
                    }
                    if (entities[i] is BotWeapon)
                    {
                        BotWeapon bw = entities[i] as BotWeapon;
                        bw.Update(gameTime, p.Position, p.Rotation);
                    }
                    if (entities[i] is Shield)
                    {
                        Shield s = entities[i] as Shield;
                        s.Update(gameTime, p.Velocity, p.controls.isPlayerFiring());
                    }
                    if (entities[i] is LatchingCell || entities[i] is MeleeBot || entities[i] is MissileBot)
                    {
                        if (entities[i] is LatchingCell)
                        {
                            LatchingCell lc = entities[i] as LatchingCell;
                            lc.Update(gameTime, p.Position);
                        }
                        else if (entities[i] is MeleeBot)
                        {
                            MeleeBot mb = entities[i] as MeleeBot;
                            mb.Update(gameTime, p.Position);
                        }
                        else
                        {
                            MissileBot missBot = entities[i] as MissileBot;
                            missBot.Update(gameTime, p.Position);
                        }
                    }
                    entities[i].Update(gameTime);
                }
                else
                {
                    if (entities[i] is EnemiesAndPlayer)
                    {
                        EnemiesAndPlayer ep = entities[i] as EnemiesAndPlayer;
                        if (ep.killedBy())
                        {
                            p.addScore(ep.Score);
                            p.AddPowerup(15);
                            if (ep is MeleeBot || ep is MissileBot)
                            {
                                if (random.Next(2) == 0)
                                {
                                    Add(new TokenPickup(content, ep.Position));
                                }
                            }
                        }
                    }
                    entities.Remove(entities[i]);
                }
            }
        }
        public bool moveBotToPos(EnemiesAndPlayer b, Vector3 newPos)
        {
            Vector3 newVel = newPos - b.Position;
            newVel.Normalize();

            float error = 4;
            if (Vector3.Distance(newPos, b.Position) > error) // prevent jitter
            {
                if (switchedToBoss || switchedToMiniBoss)
                    b.Velocity = newVel * 8;
                else
                    b.Velocity = newVel;
            }
            else
            {
                b.Velocity = Vector3.Zero;
                b.Position = newPos;
                return true;
            }
            return false;
        }