Beispiel #1
0
        public static void DrawRectangle(Cv_Renderer r, Rectangle rectangleToDraw, int thickness, Color color)
        {
            // Draw top line
            r.Draw(m_DrawPixel, new Rectangle(rectangleToDraw.X, rectangleToDraw.Y, rectangleToDraw.Width, thickness), color);

            // Draw left line
            r.Draw(m_DrawPixel, new Rectangle(rectangleToDraw.X, rectangleToDraw.Y, thickness, rectangleToDraw.Height), color);

            // Draw right line
            r.Draw(m_DrawPixel, new Rectangle((rectangleToDraw.X + rectangleToDraw.Width - thickness),
                                              rectangleToDraw.Y, thickness, rectangleToDraw.Height), color);
            // Draw bottom line
            r.Draw(m_DrawPixel, new Rectangle(rectangleToDraw.X, rectangleToDraw.Y + rectangleToDraw.Height - thickness,
                                              rectangleToDraw.Width, thickness), color);
        }
Beispiel #2
0
        internal override void VRender(Cv_Renderer renderer)
        {
            if (renderer.DebugDrawRadius && GetRadius(renderer) > 0 && m_DebugCircleTex != null)
            {
                var pos    = CaravelApp.Instance.Scene.Transform.Position;
                var radius = GetRadius(renderer);

                Rectangle r2 = new Rectangle((int)(pos.X - radius),
                                             (int)(pos.Y - radius),
                                             (int)(radius * 2),
                                             (int)(radius * 2));
                renderer.Draw(m_DebugCircleTex, r2, null, Color.Blue, 0, Vector2.Zero, SpriteEffects.None, pos.Z);
            }
        }
Beispiel #3
0
        public static void DrawLine(Cv_Renderer r, Vector2 start, Vector2 end, int thickness, int z, Color color, bool noCamera = false)
        {
            Vector2 edge = end - start;
            // calculate angle to rotate line
            float angle = (float)Math.Atan2(edge.Y, edge.X);
            float layer = (float)z / Cv_Renderer.MaxLayers;

            r.Draw(m_DrawPixel,
                   new Rectangle(             // rectangle defines shape of line and position of start of line
                       (int)start.X,
                       (int)start.Y,
                       (int)edge.Length(), //sb will strech the texture to fill this rectangle
                       thickness),         //width of line, change this to make thicker line
                   null,
                   color,                  //colour of line
                   angle,                  //angle of line (calulated above)
                   Vector2.One,
                   new Vector2(0, 0),      // point in line about which to rotate
                   SpriteEffects.None,
                   layer, noCamera);
        }
        internal override void VRender(Cv_Renderer renderer)
        {
            var particleComponent = (Cv_ParticleEmitterComponent)Component;
            var scene             = CaravelApp.Instance.Scene;

            particleComponent.DrawSelectionHighlight(renderer);

            if (!particleComponent.Visible || particleComponent.Texture == null || particleComponent.Texture == "")
            {
                return;
            }

            Cv_RawTextureResource resource = Cv_ResourceManager.Instance.GetResource <Cv_RawTextureResource>(particleComponent.Texture, particleComponent.Owner.ResourceBundle);
            var tex = resource.GetTexture().Texture;

            foreach (var particle in m_Particles)
            {
                if (!particle.IsAlive)
                {
                    break;
                }

                var layerDepth = (int)particle.Transform.Position.Z;
                layerDepth = (layerDepth % Cv_Renderer.MaxLayers);
                var layer = layerDepth / (float)Cv_Renderer.MaxLayers;

                var newColorVec = EaseValue(new Vector4(particleComponent.Color.R, particleComponent.Color.G, particleComponent.Color.B, particleComponent.Color.A),
                                            new Vector4(particleComponent.FinalColor.R, particleComponent.FinalColor.G, particleComponent.FinalColor.B, particleComponent.FinalColor.A),
                                            particleComponent.ParticleLifeTime,
                                            particleComponent.ParticleLifeTime - particle.TTL,
                                            particleComponent.ColorChangePoint);
                var newColor = new Color((int)newColorVec.X, (int)newColorVec.Y, (int)newColorVec.Z, (int)newColorVec.W);

                var pos   = particle.Transform.Position;
                var scale = particle.Transform.Scale;

                var camTransf = scene.Camera.GetViewTransform(renderer.VirtualWidth, renderer.VirtualHeight, Cv_Transform.Identity);

                if (particleComponent.Parallax != 1 && particleComponent.Parallax != 0)
                {
                    var zoomFactor = ((1 + ((scene.Camera.Zoom - 1) * particleComponent.Parallax)) / scene.Camera.Zoom);
                    scale = scale * zoomFactor; //Magic formula
                    pos  += ((particleComponent.Parallax - 1) * new Vector3(camTransf.Position.X, camTransf.Position.Y, 0));
                    pos  += ((new Vector3(scene.Transform.Position.X, scene.Transform.Position.Y, 0)) * (1 - zoomFactor) * (particleComponent.Parallax - 1));
                }

                var noCamera = particleComponent.Parallax == 0;

                renderer.Draw(tex, new Rectangle((int)(pos.X),
                                                 (int)(pos.Y),
                                                 (int)tex.Width,
                                                 (int)tex.Height),
                              null,
                              newColor,
                              particle.Transform.Rotation,
                              scale,
                              new Vector2(tex.Width * 0.5f, tex.Height * 0.5f),
                              SpriteEffects.None,
                              layer, noCamera);
            }
        }
Beispiel #5
0
        internal override void VRender(Cv_Renderer renderer)
        {
            var spriteComponent = (Cv_SpriteComponent)Component;
            var scene           = CaravelApp.Instance.Scene;

            var pos   = scene.Transform.Position;
            var rot   = scene.Transform.Rotation;
            var scale = scene.Transform.Scale;


            var camTransf = scene.Camera.GetViewTransform(renderer.VirtualWidth, renderer.VirtualHeight, Cv_Transform.Identity);

            if (spriteComponent.Parallax != 1 && spriteComponent.Parallax != 0)
            {
                var zoomFactor = ((1 + ((scene.Camera.Zoom - 1) * spriteComponent.Parallax)) / scene.Camera.Zoom);
                scale = scale * zoomFactor; //Magic formula
                pos  += ((spriteComponent.Parallax - 1) * new Vector3(camTransf.Position.X, camTransf.Position.Y, 0));
                pos  += ((new Vector3(scene.Transform.Position.X, scene.Transform.Position.Y, 0)) * (1 - zoomFactor) * (spriteComponent.Parallax - 1));
            }

            var noCamera = spriteComponent.Parallax == 0;

            spriteComponent.DrawSelectionHighlight(renderer);

            if (!spriteComponent.Visible || spriteComponent.Texture == null || spriteComponent.Texture == "")
            {
                return;
            }

            Cv_RawTextureResource resource = Cv_ResourceManager.Instance.GetResource <Cv_RawTextureResource>(spriteComponent.Texture, spriteComponent.Owner.ResourceBundle);

            var tex = resource.GetTexture().Texture;

            var frameW = tex.Width / spriteComponent.FrameX;
            var frameH = tex.Height / spriteComponent.FrameY;
            var x      = (spriteComponent.CurrentFrame % spriteComponent.FrameX) * frameW;
            var y      = (spriteComponent.CurrentFrame / spriteComponent.FrameX) * frameH;

            var layerDepth = (int)Parent.Position.Z;

            layerDepth = layerDepth % Cv_Renderer.MaxLayers;

            var spriteEffect = SpriteEffects.None;

            if (spriteComponent.Mirrored)
            {
                spriteEffect = SpriteEffects.FlipHorizontally;
            }

            renderer.Draw(tex, new Rectangle((int)pos.X,
                                             (int)pos.Y,
                                             (int)(spriteComponent.Width),
                                             (int)(spriteComponent.Height)),
                          new Rectangle(x, y, frameW, frameH),
                          spriteComponent.Color,
                          rot,
                          scale,
                          new Vector2(frameW * scene.Transform.Origin.X, frameH * scene.Transform.Origin.Y),
                          spriteEffect,
                          layerDepth / (float)Cv_Renderer.MaxLayers, noCamera);
        }