Пример #1
0
 public Projectile()
 {
     _Speed       = 360;
     collisionBox = new Sprite();
     collisionBox.Activate();
     AddChild(collisionBox);
     TTL = 5;
 }
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            base.Update(gameTime);

            for (int i = 0; i < gamePadStates.Count(); i++)
            {
                gamePadStates[i] = GamePad.GetState((PlayerIndex)i);
                if (gamePadStates[i].IsConnected && !playersReady.ContainsKey((PlayerIndex)i))
                {
                    playersReady.Add((PlayerIndex)i, false);
                    player[i].Alpha = 1.0f;
                    label[i].Text   = "Press A when you're ready";
                }
                else if (!gamePadStates[i].IsConnected && playersReady.ContainsKey((PlayerIndex)i))
                {
                    playersReady.Remove((PlayerIndex)i);
                    player[i].Alpha = 0.2f;
                    label[i].Text   = "Connect a controller";
                }
                else if (!gamePadStates[i].IsConnected)
                {
                    player[i].Alpha = 0.2f;
                    label[i].Text   = "Connect a controller";
                }
            }

            for (int j = 0; j < playersReady.Count; j++)
            {
                if (Controller.Input.JustPressed(playersReady.ElementAt(j).Key, Buttons.A))
                {
                    playersReady[playersReady.ElementAt(j).Key] = !playersReady.ElementAt(j).Value;
                    if (playersReady[playersReady.ElementAt(j).Key])
                    {
                        label[j].Text = "You're Ready";
                    }
                    else
                    {
                        label[j].Text = "Press A when you're ready";
                    }
                }
            }

            if (Controller.Input.JustPressed(PlayerIndex.One, Buttons.Start) || Controller.Input.JustPressed(PlayerIndex.Two, Buttons.Start) ||
                Controller.Input.JustPressed(PlayerIndex.Three, Buttons.Start) || Controller.Input.JustPressed(PlayerIndex.Four, Buttons.Start))
            {
                if (controls.Active)
                {
                    controls.Deactivate();
                }
                else
                {
                    controls.Activate();
                }
            }

            if (playersReady.Where(c => c.Value == true).Count() == playersReady.Count && playersReady.Count > 1)
            {
                Controller.SwitchState(new GameState());
            }
            if (firstHeartBeat)
            {
                scaleTimer -= gameTime.ElapsedGameTime;
                if (scaleTimer.TotalMilliseconds <= 0)
                {
                    firstHeartBeat = false;
                    Heartbeat();
                    scaleTimer = timeBetweenHeartBeat;
                }
            }
            else
            {
                scaleTimer -= gameTime.ElapsedGameTime;
                if (scaleTimer.TotalMilliseconds <= 0)
                {
                    firstHeartBeat = true;
                    Heartbeat();
                    scaleTimer = scaleTime;
                }
            }
        }