Example #1
0
        public override 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 (level.gamestate == Level.GameState.Buffer && level.hidePlayer)
            {
                return;
            }
            base.Draw();

            var flip        = FacingRight ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
            var spriteBatch = Reflexio.GameEngine.Instance.SpriteBatch;

            if (Reflexio.GameEngine.Instance.currentLevel.reflection_pause_remaining_time > 0)
            {
                walk_strip.ResetCurrentFrame();
                idle_strip.ResetCurrentFrame();
                reflection_strip.Draw(spriteBatch, Level.SCALE * Body.Position, Color.White, Body.Rotation,
                                      new Vector2(level.ROW_SCALE, level.COL_SCALE) * Level.SCALE, flip);
            }
            else if (diffY > 0.01 && time_since_changed > MINIMUM_AMT_OF_TIME)
            {
                reflection_strip.ResetCurrentFrame();
                idle_strip.ResetCurrentFrame();
                reflection_strip.ResetCurrentFrame();
                Vector2 origin = new Vector2(jumpDown.Width, jumpDown.Height) / 2;
                spriteBatch.Begin();
                spriteBatch.Draw(jumpDown, GameEngine.shiftAmount + Level.SCALE * Body.Position * scale, null, Color.White, Body.Rotation, origin, new Vector2(level.ROW_SCALE / jumpDown.Width, level.COL_SCALE / jumpDown.Height) * Level.SCALE * scale, flip, 0);
                spriteBatch.End();
            }
            else if (diffY < -0.01 && time_since_changed > MINIMUM_AMT_OF_TIME)
            {
                reflection_strip.ResetCurrentFrame();
                idle_strip.ResetCurrentFrame();
                reflection_strip.ResetCurrentFrame();
                Vector2 origin = new Vector2(jumpUp.Width, jumpUp.Height) / 2;
                spriteBatch.Begin();
                spriteBatch.Draw(jumpUp, GameEngine.shiftAmount + Level.SCALE * Body.Position * scale, null, Color.White, Body.Rotation, origin, new Vector2(level.ROW_SCALE / jumpUp.Width, level.COL_SCALE / jumpUp.Height) * Level.SCALE * scale, flip, 0);
                spriteBatch.End();
            }
            else if (is_walking)
            {
                reflection_strip.ResetCurrentFrame();
                idle_strip.ResetCurrentFrame();
                walk_strip.Draw(spriteBatch, Level.SCALE * Body.Position, Color.White, Body.Rotation,
                                new Vector2(level.ROW_SCALE, level.COL_SCALE) * Level.SCALE, flip);
            }
            else
            {
                walk_strip.ResetCurrentFrame();
                reflection_strip.ResetCurrentFrame();
                idle_strip.Draw(spriteBatch, Level.SCALE * Body.Position, Color.White, Body.Rotation,
                                new Vector2(level.ROW_SCALE, level.COL_SCALE) * Level.SCALE, flip);
            }
        }
Example #2
0
        public override 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);

            base.Draw();
            Color color;

            if (is_reflectable)
            {
                color = Color.White;
            }
            else
            {
                color = Color.Gray;
            }

            var origin      = new Vector2(texture.Width, texture.Height) / 2;
            var spriteBatch = Reflexio.GameEngine.Instance.SpriteBatch;

            if (level.reflection_pause_remaining_time <= 0)
            {
                #if SINUSODIAL
                is_being_reflected_straight   = false;
                is_being_reflected_diagonally = false;
                #endif
                is_being_reflected = false;
            }

            // XNA weird thing, can't do a nonuniform negative scale (reflection through ONE axis), but can
            // do a uniform negative scale (reflection through origin)
            // SpriteEffects can reflect through one axis but can't do reflection thorugh origin
            // So if just reflected once use SpriteEffects, if rotated both on both axis use uniform negatove scale.
            SpriteEffects rotation         = SpriteEffects.None;
            int           reflection_scale = 1;
            if (use_sprite_effects)
            {
                if (this.reflected_horizontal && !this.reflected_vertical)
                {
                    rotation = SpriteEffects.FlipVertically;
                }
                else if (!this.reflected_horizontal && this.reflected_vertical)
                {
                    rotation = SpriteEffects.FlipHorizontally;
                }
                else if (this.reflected_horizontal && this.reflected_vertical)
                {
                    reflection_scale = -1;
                }
            }

            if (level.reflection_pause_remaining_time > 0 && is_being_reflected)
            {
                #if SINUSODIAL
                Vector2 position = new Vector2();
                if (is_being_reflected_straight)
                {
                    position = reflectionStartPosition + reflectionVelocity * (Level.REFLECTION_PAUSE_TIME - level.reflection_pause_remaining_time);
                }
                else if (is_being_reflected_diagonally)
                {
                    double angle = ((double)Level.REFLECTION_PAUSE_TIME - level.reflection_pause_remaining_time) / Level.REFLECTION_PAUSE_TIME * Math.PI / 2;
                    position = new Vector2((DiscX - (float)Math.Cos(angle) * (DiscX - startX)) * level.ROW_SCALE, (startY - (float)Math.Sin(angle) * (startY - DiscY)) * level.COL_SCALE) * Level.SCALE;
                }
                #else
                Vector2 position = reflectionStartPosition + reflectionVelocity * (Level.REFLECTION_PAUSE_TIME - level.reflection_pause_remaining_time);
                #endif
                if (use_animation_texture)
                {
                    animTexture.Draw(spriteBatch, position, color, Body.Rotation, origin,
                                     reflection_scale * new Vector2(width * Level.SCALE, height * Level.SCALE),
                                     rotation);
                }
                else
                {
                    spriteBatch.Begin();
                    spriteBatch.Draw(texture, GameEngine.shiftAmount + position * scale, null, color, Body.Rotation, origin,
                                     reflection_scale * new Vector2(width * Level.SCALE / texture.Width, height / texture.Height * Level.SCALE) * scale,
                                     rotation, 0);
                    spriteBatch.End();
                }
            }
            else
            {
                if (Body != null)
                {
                    if (use_animation_texture)
                    {
                        animTexture.Draw(spriteBatch, Reflexio.Level.SCALE * Body.Position, color, Body.Rotation, origin,
                                         reflection_scale * new Vector2(width * Level.SCALE, height * Level.SCALE),
                                         rotation);
                    }
                    else
                    {
                        spriteBatch.Begin();
                        spriteBatch.Draw(texture, GameEngine.shiftAmount + Reflexio.Level.SCALE * Body.Position * scale, null, color, Body.Rotation, origin,
                                         reflection_scale * new Vector2(width * Level.SCALE / texture.Width, height / texture.Height * Level.SCALE) * scale,
                                         rotation, 0);
                        spriteBatch.End();
                    }
                }
            }
        }