Esempio n. 1
0
        public virtual void think(GameTime gt)
        {
            double currentTime = gt.TotalGameTime.TotalMilliseconds;
            if (lastFired == 0)
            {
                lastFired = gt.TotalGameTime.TotalMilliseconds;
            }

            // Allows the game to exit
            if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) || Keyboard.GetState().IsKeyDown(Keys.Escape))
                doNextScreen = true;

            if (Keyboard.GetState().IsKeyDown(Keys.W))
                Epc.velocity += Vector3.Transform(Vector3.UnitZ * -0.2f, Epc.Orientation);
            if (Keyboard.GetState().IsKeyDown(Keys.S))
                Epc.velocity += Vector3.Transform(Vector3.UnitZ * 0.2f, Epc.Orientation);
            if (Keyboard.GetState().IsKeyDown(Keys.A))
                Epc.velocity += Vector3.Transform(Vector3.UnitX * -0.2f, Epc.Orientation);
            if (Keyboard.GetState().IsKeyDown(Keys.D))
                Epc.velocity += Vector3.Transform(Vector3.UnitX * 0.2f, Epc.Orientation);

            if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Length() > 0.25f) {
                Vector2 d = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left;
                Epc.velocity += new Vector3(d.X * 0.25f, 0, d.Y * 0.25f);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.I))
                Epc.orientation = Epc.orientation * Quaternion.CreateFromAxisAngle(Vector3.UnitX, 0.02f);

            if (Keyboard.GetState().IsKeyDown(Keys.K))
                Epc.orientation = Epc.orientation * Quaternion.CreateFromAxisAngle(Vector3.UnitX, -0.02f);

            if (Keyboard.GetState().IsKeyDown(Keys.J))
                Epc.orientation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0.02f) * Epc.orientation;

            if (Keyboard.GetState().IsKeyDown(Keys.L))
                Epc.orientation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, -0.02f) * Epc.orientation;

            if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Length() > 0.25f)
            {
                Vector2 d = GamePad.GetState(PlayerIndex.One).ThumbSticks.Right;
                Epc.orientation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, d.X * -0.02f) * Epc.orientation * Quaternion.CreateFromAxisAngle(Vector3.UnitX, -0.02f);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Space) || (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed))
            {
                if ((currentTime - lastFired) > 200 && Epc.CanFire)
                {
                    lastFired = currentTime;
                    // create bullet and fire it;
                    EntBullet Ebullet = new EntBullet(Epc, Epc.orientation);
                    Ebullet.position +=  Vector3.Transform(-Vector3.UnitZ * 2, Epc.orientation);
                    entities.add(Ebullet);
                }
            }

            entities.thinkAll();
            entities.collisionAll();

            entities.cam = Matrix.CreateTranslation(-Epc.position) * Matrix.CreateFromQuaternion(Quaternion.Inverse(Epc.orientation)) * Matrix.CreateTranslation(Vector3.UnitZ * 0);

            int numballoons = 0;
            int numsets = 0;
            int numairballoons = 0;
            foreach (Ent e in entities.Ents)
            {
                if (e is EntBalloon) numballoons++;
                if (e is EntAirBalloon) numairballoons++;
                if (e is EntBalloonSet) numsets++;
            }

            if (!endShown)
            {
                if (numballoons == 0)
                {
                    EntText e = new EntText("YOU WIN", Color.White);
                    entities.add(e);
                    endShown = true;
                }
                if (Epc.lives == 0)
                {
                    EntText e = new EntText("GAME OVER", Color.Red);
                    entities.add(e);
                    endShown = true;
                }
            }

            if (((float)numballoons / (float)startballoons <= 0.9) && hab1)
            {
                hab1 = false;
                EntAirBalloon e = new EntAirBalloon();
                entities.add(e);
            }
            if (((float)numballoons / (float)startballoons <= 0.6) && hab2)
            {
                hab2 = false;
                EntAirBalloon e = new EntAirBalloon();
                entities.add(e);
            }
            if (((float)numballoons / (float)startballoons <= 0.3) && hab3)
            {
                hab3 = false;
                EntAirBalloon e = new EntAirBalloon();
                entities.add(e);
            }
        }
Esempio n. 2
0
        public virtual void think(GameTime gt)
        {
            double currentTime = gt.TotalGameTime.TotalMilliseconds;
            if (lastFired == 0)
            {
                lastFired = gt.TotalGameTime.TotalMilliseconds;
            }

            // Allows the game to exit
            if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) || Keyboard.GetState().IsKeyDown(Keys.Escape))
                doNextScreen = true;

            if (Keyboard.GetState().IsKeyDown(Keys.Up))
                Epc.velocity += new Vector2(0, -2);
            if (Keyboard.GetState().IsKeyDown(Keys.Down))
                Epc.velocity += new Vector2(0, 2);
            if (Keyboard.GetState().IsKeyDown(Keys.Left))
                Epc.velocity += new Vector2(-2, 0);
            if (Keyboard.GetState().IsKeyDown(Keys.Right))
                Epc.velocity += new Vector2(2, 0);

            if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Length() > 0.25f)
                Epc.velocity += GamePad.GetState(PlayerIndex.One).ThumbSticks.Left * 2;

            if ((GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed) || Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                if ((currentTime - lastFired) > 200 && Epc.CanFire)
                {
                    lastFired = currentTime;
                    // create bullet and fire it;
                    EntBullet Ebullet = new EntBullet(Epc, Epc.direction);
                    entities.add(Ebullet);
                }
            }

            entities.thinkAll();
            entities.collisionAll();

            int numballoons = 0;
            int numsets = 0;
            int numairballoons = 0;
            foreach (Ent e in entities.Ents)
            {
                if (e is EntBalloon) numballoons++;
                if (e is EntAirBalloon) numairballoons++;
                if (e is EntBalloonSet) numsets++;
            }

            if (!endShown)
            {
                if (numballoons == 0)
                {
                    EntText e = new EntText("YOU WIN", Color.White);
                    entities.add(e);
                    endShown = true;
                }
                if (Epc.lives == 0)
                {
                    EntText e = new EntText("GAME OVER", Color.Red);
                    entities.add(e);
                    endShown = true;
                }
            }

            if (((float)numballoons / (float)startballoons <= 0.9) && hab1)
            {
                hab1 = false;
                EntAirBalloon e = new EntAirBalloon();
                entities.add(e);
            }
            if (((float)numballoons / (float)startballoons <= 0.6) && hab2)
            {
                hab2 = false;
                EntAirBalloon e = new EntAirBalloon();
                entities.add(e);
            }
            if (((float)numballoons / (float)startballoons <= 0.3) && hab3)
            {
                hab3 = false;
                EntAirBalloon e = new EntAirBalloon();
                entities.add(e);
            }
        }