Пример #1
0
        /**
         * Draws all objects in the physics world
         */
        public virtual void Draw()
        {
            float     w           = GameEngine.Instance.GraphicsDevice.ScissorRectangle.Width;
            float     h           = GameEngine.Instance.GraphicsDevice.ScissorRectangle.Height;
            float     scale       = Math.Min(w / 650, h / 650);
            int       shiftw      = (int)(w / 2 - Math.Min(w, h) / 2);
            int       shifth      = (int)(h / 2 - Math.Min(w, h) / 2);
            float     cloudscale  = Level.SCALE * Level.WIDTH / cloud.Width;
            var       spriteBatch = Reflexio.GameEngine.Instance.SpriteBatch;
            Texture2D bkg         = Reflexio.GameEngine.Instance.bkg;

            if (is_scrolling_bkg)
            {
                Vector2 bkg_pos = new Vector2(0, current_bkg_pos);
                current_bkg_pos -= scrolling_bkg_speed;
                if (current_bkg_pos < -bkg.Height + WIDTH * SCALE)
                {
                    current_bkg_pos = (int)bkg_pos.Y;
                }
                spriteBatch.Begin();
                spriteBatch.Draw(bkg, bkg_pos * scale + GameEngine.shiftAmount, null, Color.White, 0.0f, Vector2.Zero,
                                 scale, SpriteEffects.None, 1.0f);
                spriteBatch.End();
            }
            else
            {
                spriteBatch.Begin();



                Vector2 backgroundScale = new Vector2(
                    Level.SCALE * Level.WIDTH / bkg.Width,
                    Level.SCALE * Level.HEIGHT / bkg.Height);


                spriteBatch.Draw(bkg, new Rectangle(shiftw, shifth, (int)Math.Min(w, h), (int)Math.Min(w, h)), Color.White);
                spriteBatch.End();
            }

            #region Playing
            foreach (PhysicsObject obj in objects)
            {
                if (!(obj is Player) || (gamestate != GameState.DoorEat && gamestate != GameState.Zip))
                {
                    obj.Draw();
                }
            }

            Texture2D lineTexture = Reflexio.GameEngine.Instance.GetTexture("lineTexture");
            var       origin      = new Vector2(lineTexture.Width, lineTexture.Height) / 2;

            spriteBatch.Begin();
            // Draw the line of reflection
            Color ref_c = new Color(reflection_current_red, reflection_current_green, reflection_current_blue);

            if (ref_orientation == ReflectionOrientation.HORIZONTAL)
            {
                spriteBatch.Draw(lineTexture, GameEngine.shiftAmount + new Vector2(SCALE * WIDTH / 2, SCALE * reflection_line_position * COL_SCALE) * scale, null, ref_c, 0.0f, origin, new Vector2(WIDTH * SCALE, 3) * scale, SpriteEffects.None, 0);
            }
            else if (ref_orientation == ReflectionOrientation.VERTICAL)
            {
                spriteBatch.Draw(lineTexture, GameEngine.shiftAmount + new Vector2(SCALE * reflection_line_position * ROW_SCALE, SCALE * HEIGHT / 2) * scale, null, ref_c, 0.0f, origin, new Vector2(3, HEIGHT * SCALE) * scale, SpriteEffects.None, 0);
            }
            else if (ref_orientation == ReflectionOrientation.DIAGONAL)
            {
                int min = GameEngine.Instance.Window.ClientBounds.Width < GameEngine.Instance.Window.ClientBounds.Height ? GameEngine.Instance.Window.ClientBounds.Width : GameEngine.Instance.Window.ClientBounds.Height;
                if (reflection_line_position == 1)
                {
                    for (int i = 0; i < min; i++)
                    {
                        spriteBatch.Draw(lineTexture, GameEngine.shiftAmount + new Vector2(i, i) * scale, null, ref_c, 0.0f, origin, new Vector2(3, 1) * scale, SpriteEffects.None, 0);
                    }
                }
                else if (reflection_line_position == -1)
                {
                    for (int i = 0; i < min; i++)
                    {
                        spriteBatch.Draw(lineTexture, GameEngine.shiftAmount + new Vector2(min - i, i) * scale, null, ref_c, 0.0f, origin, new Vector2(3, 1) * scale, SpriteEffects.None, 0);
                    }
                }
            }

            //Draw all positions of the line of reflections
            Texture2D circle = Reflexio.GameEngine.Instance.GetTexture("reflectionCircle");;
            float     xscale = (COL_SCALE * SCALE) / circle.Width;
            float     yscale = (ROW_SCALE * SCALE) / circle.Height;
            float     deltaX = (COL_SCALE * SCALE) / 2;
            float     deltaY = (ROW_SCALE * SCALE) / 2;
            origin = new Vector2(circle.Width, circle.Height) / 2;
            int[] arr = horizontal_lines.ToArray();
            foreach (int i in horizontal_lines)
            {
                circle = Reflexio.GameEngine.Instance.GetTexture("reflectionCircle");
                if (h_switch_lines.Contains(i))
                {
                    circle = Reflexio.GameEngine.Instance.GetTexture("reflectionCircleSwitch");
                }
                spriteBatch.Draw(circle, GameEngine.shiftAmount + new Vector2(deltaX, SCALE * (i) * COL_SCALE) * scale, null,
                                 Color.White, (float)Math.PI / 2, origin, new Vector2(xscale, yscale) * scale, SpriteEffects.None, 0);
            }
            arr = vertical_lines.ToArray();
            foreach (int i in vertical_lines)
            {
                circle = Reflexio.GameEngine.Instance.GetTexture("reflectionCircle");
                if (v_switch_lines.Contains(i))
                {
                    circle = Reflexio.GameEngine.Instance.GetTexture("reflectionCircleSwitch");
                }
                spriteBatch.Draw(circle, GameEngine.shiftAmount + new Vector2(SCALE * (i) * ROW_SCALE, (HEIGHT - ROW_SCALE) * SCALE + deltaY) * scale, null,
                                 Color.White, 0.0f, origin, new Vector2(xscale, yscale) * scale, SpriteEffects.None, 0);
            }
            arr = diagonal_lines.ToArray();
            foreach (int i in diagonal_lines)
            {
                circle = Reflexio.GameEngine.Instance.GetTexture("reflectionCircle");
                if (d_switch_lines.Contains(i))
                {
                    circle = Reflexio.GameEngine.Instance.GetTexture("reflectionCircleSwitch");
                }
                if (i == 1)
                {
                    spriteBatch.Draw(circle, GameEngine.shiftAmount + new Vector2(deltaX, deltaY) * scale, null,
                                     Color.White, (float)(3 * Math.PI / 4), origin, new Vector2(xscale, yscale) * scale, SpriteEffects.None, 0);
                }
                else if (i == -1)
                {
                    spriteBatch.Draw(circle, GameEngine.shiftAmount + new Vector2(deltaX, (HEIGHT - ROW_SCALE) * SCALE + deltaY) * scale, null,
                                     Color.White, (float)Math.PI / 4, origin, new Vector2(xscale, yscale) * scale, SpriteEffects.None, 0);
                }
            }
            if (achievestring != null && achieve && achievewatch.ElapsedMilliseconds <= ACHIEVE_TIME)
            {
                spriteBatch.Draw(cloud, GameEngine.shiftAmount + new Vector2(10, 10) * scale, null, Color.White, 0.0f, Vector2.Zero, 1 * scale, SpriteEffects.None, 0);
                spriteBatch.DrawString(Font1, achievestring, GameEngine.shiftAmount + new Vector2(SCALE * WIDTH / 2, ACHIEVE_TEXT_Y) * scale, Color.White, 0, Font1.MeasureString(achievestring) / 2, 1f * scale, SpriteEffects.None, 0);
                spriteBatch.DrawString(Font1, achievestring, GameEngine.shiftAmount + new Vector2(SCALE * WIDTH / 2 + 2, ACHIEVE_TEXT_Y + 2) * scale, Color.Black, 0, Font1.MeasureString(achievestring) / 2, 1f * scale, SpriteEffects.None, 0);
            }

            if (bkg_text != null && !player.pressed_enter)
            {
                spriteBatch.Draw(dialog, GameEngine.shiftAmount + new Vector2(0, 10) * scale, null, Color.White, 0.0f, Vector2.Zero, cloudscale * scale, SpriteEffects.None, 1.0f);
                spriteBatch.DrawString(Font1, bkg_text, GameEngine.shiftAmount + new Vector2(SCALE * WIDTH / 2, ACHIEVE_TEXT_Y) * scale, Color.White, 0, Font1.MeasureString(bkg_text) / 2, 1f * scale, SpriteEffects.None, 0);
                spriteBatch.DrawString(Font1, bkg_text, GameEngine.shiftAmount + new Vector2(SCALE * WIDTH / 2 + 2, ACHIEVE_TEXT_Y + 2) * scale, Color.Black, 0, Font1.MeasureString(bkg_text) / 2, 1f * scale, SpriteEffects.None, 0);
            }

            spriteBatch.End();

            // Draw the dialogs
            if (dialog_displayer != null)
            {
                dialog_displayer.Draw(spriteBatch);
            }
            #endregion

            #region REST
            if (gamestate == GameState.Paused || is_peeking)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(haze, new Rectangle(shiftw, shifth, (int)Math.Min(w, h), (int)Math.Min(w, h)), new Color(255, 255, 255, 100));
                spriteBatch.End();
                pauseMenu.Draw();
            }
            else if (gamestate == GameState.Unzip)
            {
                unzipTexture.DrawWholeScreen(spriteBatch);
                spriteBatch.Begin();
                if (achievestring != null && achieve && achievewatch.ElapsedMilliseconds <= ACHIEVE_TIME)
                {
                    spriteBatch.Draw(cloud, GameEngine.shiftAmount + new Vector2(10, 10) * scale, null, Color.White, 0.0f, Vector2.Zero, 1 * scale, SpriteEffects.None, 0);
                    spriteBatch.DrawString(Font1, achievestring, GameEngine.shiftAmount + new Vector2(SCALE * WIDTH / 2, 30) * scale, Color.White, 0, Font1.MeasureString(achievestring) / 2, 1f * scale, SpriteEffects.None, 0);
                    spriteBatch.DrawString(Font1, achievestring, GameEngine.shiftAmount + new Vector2(SCALE * WIDTH / 2 + 2, 32) * scale, Color.Black, 0, Font1.MeasureString(achievestring) / 2, 1f * scale, SpriteEffects.None, 0);
                }
                spriteBatch.End();
            }
            else if (gamestate == GameState.Zip)
            {
                zipTexture.DrawWholeScreen(spriteBatch);
                spriteBatch.Begin();
                if (achievestring != null && achieve && achievewatch.ElapsedMilliseconds <= ACHIEVE_TIME)
                {
                    spriteBatch.Draw(cloud, GameEngine.shiftAmount + new Vector2(10, 10) * scale, null, Color.White, 0.0f, Vector2.Zero, 1 * scale, SpriteEffects.None, 0);
                    spriteBatch.DrawString(Font1, achievestring, GameEngine.shiftAmount + new Vector2(SCALE * WIDTH / 2, 30) * scale, Color.White, 0, Font1.MeasureString(achievestring) / 2, 1f * scale, SpriteEffects.None, 0);
                    spriteBatch.DrawString(Font1, achievestring, GameEngine.shiftAmount + new Vector2(SCALE * WIDTH / 2 + 2, 32) * scale, Color.Black, 0, Font1.MeasureString(achievestring) / 2, 1f * scale, SpriteEffects.None, 0);
                }
                spriteBatch.End();
            }
            if (gamestate == GameState.Over)
            {
                if (succeeded)
                {
                    Vector2 scale2 = new Vector2(Level.SCALE * Level.WIDTH / zippedTexture.Width, Level.SCALE * Level.HEIGHT / zippedTexture.Height);
                    spriteBatch.Begin();
                    spriteBatch.Draw(zippedTexture, GameEngine.shiftAmount, null, Color.White, 0.0f, Vector2.Zero, scale2 * scale, SpriteEffects.None, 0);
                    if (achievestring != null && achieve && achievewatch.ElapsedMilliseconds <= ACHIEVE_TIME)
                    {
                        spriteBatch.Draw(cloud, GameEngine.shiftAmount + new Vector2(10, 10) * scale, null, Color.White, 0.0f, Vector2.Zero, 1 * scale, SpriteEffects.None, 0);
                        spriteBatch.DrawString(Font1, achievestring, GameEngine.shiftAmount + new Vector2(SCALE * WIDTH / 2, 30) * scale, Color.White, 0, Font1.MeasureString(achievestring) / 2, 1f * scale, SpriteEffects.None, 0);
                        spriteBatch.DrawString(Font1, achievestring, GameEngine.shiftAmount + new Vector2(SCALE * WIDTH / 2 + 2, 32) * scale, Color.Black, 0, Font1.MeasureString(achievestring) / 2, 1f * scale, SpriteEffects.None, 0);
                    }
                    spriteBatch.End();
                }
                else
                {
                    spriteBatch.Begin();
                    spriteBatch.Draw(haze, new Rectangle(shiftw, shifth, (int)Math.Min(w, h), (int)Math.Min(w, h)), new Color(255, 255, 255, 100));
                    spriteBatch.End();
                    gameOverMenu.Draw();
                }
            }
            #endregion
        }
Пример #2
0
        public virtual void Draw()
        {
            float w      = GameEngine.Instance.GraphicsDevice.ScissorRectangle.Width;
            float h      = GameEngine.Instance.GraphicsDevice.ScissorRectangle.Height;
            float scale  = Math.Min(w / 650, h / 650);
            int   shiftw = (int)(w / 2 - Math.Min(w, h) / 2);
            int   shifth = (int)(h / 2 - Math.Min(w, h) / 2);

            if (animBkg != null)
            {
                animBkg.DrawWholeScreen(spriteBatch);
            }
            spriteBatch.Begin();

            float y   = deltaY;
            int   cnt = 0;

            foreach (MenuItem mi in menu_items_off)
            {
                Texture2D texture;
                string    message = menu_items_on.ToArray <MenuItem>()[current].message;;
                if (cnt == current)
                {
                    texture = menu_items_on.ToArray <MenuItem>()[current].texture;
                }
                else
                {
                    texture = mi.texture;
                }
                if (texture == null)
                {
                    Vector2 FontPos    = new Vector2(deltaX, y);
                    string  output     = menu_items_off.ToArray <MenuItem>()[cnt].name;
                    Vector2 FontOrigin = Font1.MeasureString(output) / 2;
                    Color   c          = Color.DarkCyan;
                    if (cnt == current)
                    {
                        c = Color.Blue;
                        if (message != null)
                        {
                            spriteBatch.DrawString(Font1, message, new Vector2(deltaX, 20), Color.Black, 0, Font1.MeasureString(message) / 2, 0.7f, SpriteEffects.None, 0);
                        }
                    }
                    spriteBatch.DrawString(Font1, output, new Vector2(FontPos.X + 2, FontPos.Y + 2), Color.GhostWhite, 0, FontOrigin, 1.5f, SpriteEffects.None, 0);
                    spriteBatch.DrawString(Font1, output, FontPos, c, 0, FontOrigin, 1.5f, SpriteEffects.None, 0);

                    y += padding + Font1.LineSpacing;
                    cnt++;
                }
                else
                {
                    var origin = new Vector2(texture.Width, texture.Height) / 2;
                    spriteBatch.Draw(texture, new Vector2(deltaX, y) * scale + GameEngine.shiftAmount, null, Color.White, 0, origin, 1 * scale, SpriteEffects.None, 0);
                    if (cnt == current && message != null)
                    {
                        Vector2 FontOrigin = Font1.MeasureString(message) / 2;
                        spriteBatch.DrawString(Font1, message, new Vector2(deltaX, 20) * scale + GameEngine.shiftAmount, Color.Black, 0, FontOrigin, 0.7f * scale, SpriteEffects.None, 0);
                    }
                    y += padding + texture.Height;
                    cnt++;
                }
            }
            spriteBatch.End();
        }