Ejemplo n.º 1
0
        public override void Render()
        {
            base.Render();

            Draw.SpriteBatch.Begin(
                SpriteSortMode.Deferred,
                BlendState.AlphaBlend,
                SamplerState.LinearClamp,
                DepthStencilState.None,
                RasterizerState.CullNone,
                null,
                Engine.ScreenMatrix
                );

            Vector2 anchor = new Vector2(96f, 96f);

            // render the spinning cogwheel
            if (!(cogwheel?.Texture?.Texture?.IsDisposed ?? true))
            {
                Vector2 cogPosition = anchor + new Vector2(0f, 0f);
                float   cogScale    = 0.25f;
                float   cogRot      = (cogwheelSpinning ? RawTimeActive : cogwheelStopTime) * 4f;

                // render a 2 pixel-thick cogwheel shadow / outline
                for (int x = -2; x <= 2; x++)
                {
                    for (int y = -2; y <= 2; y++)
                    {
                        if (x != 0 || y != 0)
                        {
                            cogwheel.DrawCentered(cogPosition + new Vector2(x, y), Color.Black, cogScale, cogRot);
                        }
                    }
                }

                // render the cogwheel itself
                cogwheel.DrawCentered(cogPosition, Color.White, cogScale, cogRot);
            }

            if (modUpdatingMessage != null)
            {
                // render sub-text (appears smaller under the text)
                drawText(modUpdatingMessage, anchor + new Vector2(48f, 0f), 0.8f);
            }

            if (modUpdatingSubMessage != null)
            {
                // render sub-text (appears smaller under the text)
                drawText(modUpdatingSubMessage, anchor + new Vector2(53f, 40f), 0.5f);
            }

            if (showCancel)
            {
                string label = Dialog.Clean("AUTOUPDATECHECKER_SKIP");
                ButtonUI.Render(new Vector2(1880f, 1024f), label, Input.MenuCancel, 0.5f, 1f);
            }

            Draw.SpriteBatch.End();
        }
Ejemplo n.º 2
0
        public override void OnUserUpdate(float fElapsedTime)
        {
            Clear(Pixel.Black);

            if (infoScreen)
            {
                DrawString(Middle(), infoMessage, Pixel.White, 2, PositionMode.Center);
                if (Input.KeyReleased(MouseButtons.Left))
                {
                    infoScreen = false;
                }
                return;
            }

            if (Input.KeyPressed(Keys.Tab))
            {
                debugMode = !debugMode;
            }

            if (Input.KeyPressed(Keys.D1))
            {
                speedMultiplier = 1;
            }
            if (Input.KeyPressed(Keys.D2))
            {
                speedMultiplier = 2;
            }
            if (Input.KeyPressed(Keys.D3))
            {
                speedMultiplier = 3;
            }
            if (Input.KeyPressed(Keys.D4))
            {
                speedMultiplier = 4;
            }
            if (Input.KeyPressed(Keys.D5))
            {
                speedMultiplier = 5;
            }
            if (Input.KeyPressed(Keys.D6))
            {
                speedMultiplier = 6;
            }
            if (Input.KeyPressed(Keys.D7))
            {
                speedMultiplier = 7;
            }
            if (Input.KeyPressed(Keys.D8))
            {
                speedMultiplier = 8;
            }
            if (Input.KeyPressed(Keys.D9))
            {
                speedMultiplier = 9;
            }

            if (debugMode)
            {
                if (Input.KeyPressed(MouseButtons.Left))
                {
                    Vector mouse = ScreenMousePos();
                    foreach (Ball ball in balls)
                    {
                        if ((ball.position - mouse).Magnitude() < ball.radius)
                        {
                            grab = ball;
                            break;
                        }
                    }
                }
                if (Input.KeyHeld(MouseButtons.Left))
                {
                    if (grab != null)
                    {
                        if (Input.KeyPressed(Keys.Right))
                        {
                            grab.ballType = (BallType)(((int)grab.ballType + 1) % 3);
                        }
                        if (Input.KeyPressed(Keys.Left))
                        {
                            grab.ballType = (BallType)(((int)grab.ballType - 1 + 3) % 3);
                        }
                        grab.position.x += ChangeInScreenMouse().x;
                        grab.position.y += ChangeInScreenMouse().y;
                    }
                }
                if (Input.KeyReleased(MouseButtons.Left))
                {
                    grab = null;
                }
            }

            for (int i = 0; i < balls.Count; i++)
            {
                Ball ball = balls[i];
                if (!debugMode)
                {
                    ball.Update(fElapsedTime, ScreenSize(), speedMultiplier);

                    for (int j = i + 1; j < balls.Count; j++)
                    {
                        Ball colBall = balls[j];
                        if (j != i)
                        {
                            ball.Collision(colBall);
                        }
                    }
                }

                ball.Render(this);

                if (debugMode)
                {
                    DrawString(ball.position, balls.IndexOf(ball) + ": " + ball.ballType, Pixel.White, 1, PositionMode.Center);
                    string interText = "";
                    foreach (Ball b in ball.interactions)
                    {
                        interText += balls.IndexOf(b) + " ";
                    }
                    DrawString(ball.position + new Vector(0, 25), interText, Pixel.White, 1, PositionMode.Center);
                }

                ball.interactions.RemoveAll(b => b.dead);
            }

            balls.RemoveAll(b => b.dead);

            if (!endGame)
            {
                int repelants = 0;
                int regulars  = 0;
                int monsters  = 0;
                foreach (Ball ball in balls)
                {
                    switch (ball.ballType)
                    {
                    case BallType.RegularBall: regulars++; break;

                    case BallType.MonsterBall: monsters++; break;

                    case BallType.RepelantBall: repelants++; break;
                    }
                }

                if (regulars == 0)
                {
                    endGame    = true;
                    endMessage = "All regular balls are gone.";
                }
                else
                {
                    if (monsters == 0)
                    {
                        endGame    = true;
                        endMessage = "Regular balls have no way of dying.";
                    }
                }
            }
            else
            {
                DrawString(Middle() - new Vector(0, 20), "Game ended", Pixel.White, 3, PositionMode.Center);
                DrawString(Middle() + new Vector(0, 20), endMessage, Pixel.White, 2, PositionMode.Center);
            }

            SetPixelMode(PixelMode.Alpha);
            info.Render(this);
            restart.Render(this);
            SetPixelMode(PixelMode.Normal);

            if (info.clicked)
            {
                infoScreen = true;
            }
            if (restart.clicked)
            {
                OnUserCreate();
            }
        }