예제 #1
0
 public void Draw(SpriteBatch spriteBatch, Camera camera)
 {
     if (canDraw)
     {
         foreach (Line line in boltList)
         {
             line.Draw(spriteBatch, color, camera);
         }
     }
 }
예제 #2
0
        public void Draw(SpriteBatch spriteBatch, Camera camera)
        {
            Rectangle textureArea = new Rectangle((int)position.X - texture.Width / 2, (int)position.Y - texture.Width / 2, texture.Width, texture.Height);

            if (textureArea.Intersects(camera.visibleArea) || !screenCull)
            {
                positionModifier = 2;
                Draw(spriteBatch);
                positionModifier = 1;
            }

            //if (position.X * 2 - texture.Width > camera.visibleArea.Right || position.X * 2 + texture.Width < camera.visibleArea.Left || position.Y * 2 - texture.Height > camera.visibleArea.Bottom || position.Y * 2 + texture.Height < camera.visibleArea.Top)
            //{
            //    return;
            //}
            //else
            //{
            //    Draw(spriteBatch);
            //}
        }
예제 #3
0
        public void Draw(SpriteBatch spriteBatch, Color color, Camera camera)
        {
            Vector2 cornerTopLeft = Vector2.Zero;
            if (a.X < b.X) cornerTopLeft.X = a.X / 2;
            else cornerTopLeft.X = b.X / 2;
            if (a.Y < b.Y) cornerTopLeft.Y = a.Y / 2;
            else cornerTopLeft.Y = b.Y / 2;

            Vector2 tangent = b - a;

            Rectangle textureArea = new Rectangle((int)cornerTopLeft.X, (int)cornerTopLeft.Y, (int)Math.Abs(tangent.X), (int)Math.Abs(tangent.Y));
            if (textureArea.Intersects(camera.visibleArea))
            {
                Draw(spriteBatch, color);
            }

            //if (traceID == 99)
            //{
            //    Trace.WriteLine("Texture:");
            //    Trace.WriteLine(textureArea.X + ", " + textureArea.Y + ", " + textureArea.Width + ", " + textureArea.Height);
            //    Trace.WriteLine("Camera:");
            //    Trace.WriteLine(camera.visibleArea.X + ", " + camera.visibleArea.Y + ", " + camera.visibleArea.Width + ", " + camera.visibleArea.Height);
            //}
        }
예제 #4
0
        public void DrawWithCamera(SpriteBatch spriteBatch, Camera camera)
        {
            #region Set Regular Showing
            if (playerIndex == PlayerIndex.One)
            {
                player1.showingRegular = true;
                player2.showingRegular = false;
            }
            else
            {
                player1.showingRegular = false;
                player2.showingRegular = true;
            }
            #endregion

            #region Create Alpha Mask
            if (playerIndex == PlayerIndex.One) alphaDot.position = player2.position;
            else alphaDot.position = player1.position;

            //if (playerIndex == PlayerIndex.One)
            gameStateManager.game.GraphicsDevice.SetRenderTarget(alphaMask);
            //else gameStateManager.game.GraphicsDevice.SetRenderTarget(alphaMask2);
            gameStateManager.game.GraphicsDevice.Clear(Color.White);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, camera.transform);
            alphaDot.Draw(spriteBatch, camera);
            spriteBatch.End();
            #endregion

            #region Aura drawing
            gameStateManager.game.GraphicsDevice.SetRenderTarget(auraTarget);
            if (player1.psyHold)
            {
                colorShader.Parameters["DestColor"].SetValue(player1.auraColor.ToVector4());
                gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, colorShader);
                player1.DrawAura(spriteBatch, auraTargetOrigin);
                spriteBatch.End();

                //warpShader.Parameters["resolution"].SetValue(new Vector2(500, 500));
                //warpShader.Parameters["ringSize"].SetValue(1);
                warpShader.Parameters["magnitude"].SetValue(.02f);
                warpShader.Parameters["scale"].SetValue(player1.auraScale);

                player1.auraTexture = gaussianBlur.PerformGaussianBlur(auraTarget, blurX, blurY, spriteBatch);

                gameStateManager.game.GraphicsDevice.SetRenderTarget(warpTarget);
                gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, warpShader);
                spriteBatch.Draw(player1.auraTexture, Vector2.Zero, Color.White);
                spriteBatch.End();

                player1.auraTexture = warpTarget;
                //gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                //colorShader.Parameters["DestColor"].SetValue(player1.auraColor.ToVector4());
                //spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, colorShader);
                //player1.DrawAura(spriteBatch, auraTargetOrigin);
                //spriteBatch.End();
                //player1.auraTexture = gaussianBlur.PerformGaussianBlur(auraTarget, blurX, blurY, spriteBatch);
            }
            else player1.auraTexture = null;

            gameStateManager.game.GraphicsDevice.SetRenderTarget(player2Aura);
            if (player2.psyHold)
            {

                gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                colorShader.Parameters["DestColor"].SetValue(player2.auraColor.ToVector4());
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, colorShader);
                player2.DrawAura(spriteBatch, auraTargetOrigin);
                spriteBatch.End();

                //warpShader.Parameters["resolution"].SetValue(new Vector2(500, 500));
                //warpShader.Parameters["ringSize"].SetValue(1);
                warpShader.Parameters["magnitude"].SetValue(.02f);
                warpShader.Parameters["scale"].SetValue(player2.auraScale);

                player2.auraTexture = gaussianBlur.PerformGaussianBlur(player2Aura, blurX2, blurY2, spriteBatch);

                gameStateManager.game.GraphicsDevice.SetRenderTarget(warpTarget2);
                gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, warpShader);
                spriteBatch.Draw(player2.auraTexture, Vector2.Zero, Color.White);
                spriteBatch.End();

                player2.auraTexture = warpTarget2;
            }
            else player2.auraTexture = null;

            foreach (PickUpObj pickUp in pickUpList)
            {
                if (pickUp.psyHold)
                {
                    GaussianTargets aurTex = pickUpAuras[pickUpList.IndexOf(pickUp)];
                    gameStateManager.game.GraphicsDevice.SetRenderTarget(aurTex.target);
                    gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                    colorShader.Parameters["DestColor"].SetValue(pickUp.auraColor.ToVector4());
                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, colorShader);
                    pickUp.DrawAura(spriteBatch, auraTargetOrigin);
                    spriteBatch.End();

                    //warpShader.Parameters["resolution"].SetValue(new Vector2(500, 500));
                    //warpShader.Parameters["ringSize"].SetValue(1);
                    warpShader.Parameters["magnitude"].SetValue(.02f);
                    warpShader.Parameters["scale"].SetValue(pickUp.auraScale);

                    pickUp.auraTexture = gaussianBlur.PerformGaussianBlur(aurTex.target, aurTex.blurX, aurTex.blurY, spriteBatch);

                    gameStateManager.game.GraphicsDevice.SetRenderTarget(aurTex.warpTarget);
                    gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, warpShader);
                    spriteBatch.Draw(pickUp.auraTexture, Vector2.Zero, Color.White);
                    spriteBatch.End();

                    pickUp.auraTexture = aurTex.warpTarget;
                }
                else pickUp.auraTexture = null;
            }

            foreach (Moveable move in moveList)
            {
                if (move.psyHold)
                {
                    GaussianTargets aurTex = moveAuras[moveList.IndexOf(move)];
                    gameStateManager.game.GraphicsDevice.SetRenderTarget(aurTex.target);
                    gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                    colorShader.Parameters["DestColor"].SetValue(move.auraColor.ToVector4());
                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, colorShader);
                    move.DrawAura(spriteBatch, auraTargetOrigin);
                    spriteBatch.End();

                    //warpShader.Parameters["resolution"].SetValue(new Vector2(500, 500));
                    //warpShader.Parameters["ringSize"].SetValue(1);
                    warpShader.Parameters["magnitude"].SetValue(.02f);
                    warpShader.Parameters["scale"].SetValue(move.auraScale);

                    move.auraTexture = gaussianBlur.PerformGaussianBlur(aurTex.target, aurTex.blurX, aurTex.blurY, spriteBatch);

                    gameStateManager.game.GraphicsDevice.SetRenderTarget(aurTex.warpTarget);
                    gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, warpShader);
                    spriteBatch.Draw(move.auraTexture, Vector2.Zero, Color.White);
                    spriteBatch.End();

                    move.auraTexture = aurTex.warpTarget;

                }
                else move.auraTexture = null;
            }
            #endregion

            #region Create Light pass
            //if (playerIndex == PlayerIndex.One)
            gameStateManager.game.GraphicsDevice.SetRenderTarget(lightMask);
            //else gameStateManager.game.GraphicsDevice.SetRenderTarget(lightMask2);
            gameStateManager.game.GraphicsDevice.Clear(level.atmosphereLight);
            //spriteBatch.Begin();
            ////spriteBatch.Draw(blackSquare, new Vector2(0, 0), new Rectangle(0, 0, Game1.screenWidth, Game1.screenHeight), Color.White);
            //spriteBatch.End();
            colorShader.Parameters["DestColor"].SetValue(Color.White.ToVector4());
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, null, null, colorShader, camera.transform);
            if (player1.selfIlluminating)
            {
                spriteBatch.End();
                colorShader.Parameters["DestColor"].SetValue(Color.White.ToVector4());
                spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, null, null, null, colorShader, camera.transform);
                player1.Draw(spriteBatch, camera);
            }
            else
            {
                spriteBatch.End();
                colorShader.Parameters["DestColor"].SetValue(new Color(50, 50, 50).ToVector4());
                spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, null, null, null, colorShader, camera.transform);
                player1.Draw(spriteBatch, camera);

            }
            if (player2.selfIlluminating)
            {
                spriteBatch.End();
                colorShader.Parameters["DestColor"].SetValue(Color.White.ToVector4());
                spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, null, null, null, colorShader, camera.transform);
                player2.Draw(spriteBatch, camera);
            }
            else
            {
                spriteBatch.End();
                colorShader.Parameters["DestColor"].SetValue(new Color(50, 50, 50).ToVector4());
                spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, null, null, null, colorShader, camera.transform);
                player2.Draw(spriteBatch, camera);

            }
            foreach (PointLight light in lightList) if (light.playerVisible == PlayerObjectMode.None)
            {
                spriteBatch.End();
                colorShader.Parameters["DestColor"].SetValue(light.color.ToVector4());
                spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, null, null, null, colorShader, camera.transform);
                light.Draw(spriteBatch, camera);
            }
            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, null, null, null, colorShader, camera.transform);
            colorShader.Parameters["DestColor"].SetValue(Color.White.ToVector4());
            if (playerIndex == PlayerIndex.One)
            {
                foreach (SpriteIMG tile in backFGList) if (tile.selfIlluminating && (tile.playerVisible == PlayerObjectMode.None || tile.playerVisible == PlayerObjectMode.One)) tile.Draw(spriteBatch, camera);
                foreach (FlipSwitch s in switchList) if (s.selfIlluminating && (s.playerVisible == PlayerObjectMode.None || s.playerVisible == PlayerObjectMode.One)) s.Draw(spriteBatch, camera);
                foreach (Button button in buttonList) if (button.selfIlluminating && (button.playerVisible == PlayerObjectMode.None || button.playerVisible == PlayerObjectMode.One)) button.Draw(spriteBatch, camera);
                foreach (TriggerArea area in areaList) if (area.selfIlluminating && (area.playerVisible == PlayerObjectMode.None || area.playerVisible == PlayerObjectMode.One)) area.Draw(spriteBatch, camera);
                foreach (LightConsole console in consoleList) if (console.selfIlluminating && (console.playerVisible == PlayerObjectMode.None || console.playerVisible == PlayerObjectMode.One)) console.Draw(spriteBatch, camera);
                foreach (Door door in doorList) if (door.selfIlluminating && (door.playerVisible == PlayerObjectMode.None || door.playerVisible == PlayerObjectMode.One)) door.Draw(spriteBatch, camera);
                foreach (MovingPlatform platform in platformList) if (platform.selfIlluminating && (platform.playerVisible == PlayerObjectMode.None || platform.playerVisible == PlayerObjectMode.One)) platform.Draw(spriteBatch, camera);
                foreach (CircularPlatform platform in cPlatformList) if (platform.selfIlluminating && (platform.playerVisible == PlayerObjectMode.None || platform.playerVisible == PlayerObjectMode.One)) platform.Draw(spriteBatch, camera);
                foreach (Moveable move in moveList) if (move.selfIlluminating && (move.playerVisible == PlayerObjectMode.None || move.playerVisible == PlayerObjectMode.One)) move.Draw(spriteBatch, camera);
                foreach (PickUpObj pickUp in pickUpList) if (pickUp.selfIlluminating && (pickUp.playerVisible == PlayerObjectMode.None || pickUp.playerVisible == PlayerObjectMode.One)) pickUp.Draw(spriteBatch, camera);
                foreach (Portal portal in portalList) if (portal.selfIlluminating && (portal.playerVisible == PlayerObjectMode.None || portal.playerVisible == PlayerObjectMode.One)) portal.Draw(spriteBatch, camera);
                foreach (SpriteIMG tile in frontFGList) if (tile.selfIlluminating && (tile.playerVisible == PlayerObjectMode.None || tile.playerVisible == PlayerObjectMode.One)) tile.Draw(spriteBatch, camera);
                foreach (PointLight light in lightList) if (light.playerVisible == PlayerObjectMode.One) light.Draw(spriteBatch, camera);
                spriteBatch.End();

                foreach (Particle particle in particleList) if (particle.selfIlluminating && (particle.playerVisible == PlayerObjectMode.One || particle.playerVisible == PlayerObjectMode.None))
                {
                    colorShader.Parameters["DestColor"].SetValue(particle.color.ToVector4());
                    spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, null, null, null, null, camera.transform);
                    particle.Draw(spriteBatch, camera);
                    spriteBatch.End();
                }

                spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, null, null, null, null, camera.transform);
                foreach (LightningChain lightning in lightningList) if (lightning.playerObjectMode == PlayerObjectMode.One || lightning.playerObjectMode == PlayerObjectMode.None) lightning.Draw(spriteBatch, camera);
                spriteBatch.End();

            }
            else
            {
                foreach (SpriteIMG tile in backFGList) if (tile.selfIlluminating && (tile.playerVisible == PlayerObjectMode.None || tile.playerVisible == PlayerObjectMode.Two)) tile.Draw(spriteBatch, camera);
                foreach (FlipSwitch s in switchList) if (s.selfIlluminating && (s.playerVisible == PlayerObjectMode.None || s.playerVisible == PlayerObjectMode.Two)) s.Draw(spriteBatch, camera);
                foreach (Button button in buttonList) if (button.selfIlluminating && (button.playerVisible == PlayerObjectMode.None && button.playerVisible == PlayerObjectMode.Two)) button.Draw(spriteBatch, camera);
                foreach (TriggerArea area in areaList) if (area.selfIlluminating && (area.playerVisible == PlayerObjectMode.None || area.playerVisible == PlayerObjectMode.Two)) area.Draw(spriteBatch, camera);
                foreach (LightConsole console in consoleList) if (console.selfIlluminating && (console.playerVisible == PlayerObjectMode.None || console.playerVisible == PlayerObjectMode.Two)) console.Draw(spriteBatch, camera);
                foreach (Door door in doorList) if (door.selfIlluminating && (door.playerVisible == PlayerObjectMode.None || door.playerVisible == PlayerObjectMode.Two)) door.Draw(spriteBatch, camera);
                foreach (MovingPlatform platform in platformList) if (platform.selfIlluminating && (platform.playerVisible == PlayerObjectMode.None || platform.playerVisible == PlayerObjectMode.Two)) platform.Draw(spriteBatch, camera);
                foreach (CircularPlatform platform in cPlatformList) if (platform.selfIlluminating && (platform.playerVisible == PlayerObjectMode.None || platform.playerVisible == PlayerObjectMode.Two)) platform.Draw(spriteBatch, camera);
                foreach (Moveable move in moveList) if (move.selfIlluminating && (move.playerVisible == PlayerObjectMode.None || move.playerVisible == PlayerObjectMode.Two)) move.Draw(spriteBatch, camera);
                foreach (PickUpObj pickUp in pickUpList) if (pickUp.selfIlluminating && (pickUp.playerVisible == PlayerObjectMode.None || pickUp.playerVisible == PlayerObjectMode.Two)) pickUp.Draw(spriteBatch, camera);
                foreach (Portal portal in portalList) if (portal.selfIlluminating && (portal.playerVisible == PlayerObjectMode.None || portal.playerVisible == PlayerObjectMode.Two)) portal.Draw(spriteBatch, camera);
                foreach (SpriteIMG tile in frontFGList) if (tile.selfIlluminating && (tile.playerVisible == PlayerObjectMode.None || tile.playerVisible == PlayerObjectMode.Two)) tile.Draw(spriteBatch, camera);
                foreach (PointLight light in lightList) if (light.playerVisible == PlayerObjectMode.Two) light.Draw(spriteBatch, camera);
                spriteBatch.End();

                foreach (Particle particle in particleList) if (particle.selfIlluminating && (particle.playerVisible == PlayerObjectMode.Two || particle.playerVisible == PlayerObjectMode.None))
                {
                    colorShader.Parameters["DestColor"].SetValue(particle.color.ToVector4());
                    spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, null, null, null, null, camera.transform);
                    particle.Draw(spriteBatch, camera);
                    spriteBatch.End();
                }

                spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, null, null, null, null, camera.transform);
                foreach (LightningChain lightning in lightningList) if (lightning.playerObjectMode == PlayerObjectMode.Two || lightning.playerObjectMode == PlayerObjectMode.None) lightning.Draw(spriteBatch, camera);
                spriteBatch.End();
            }

            #endregion

            #region Player 1 Backgrounds

            //if (playerIndex == PlayerIndex.One)
            gameStateManager.game.GraphicsDevice.SetRenderTarget(player1Backgrounds);
            //else gameStateManager.game.GraphicsDevice.SetRenderTarget(player1Objects2);
            gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);
            foreach (SpriteIMG tile in backFGList) if (tile.playerVisible == PlayerObjectMode.One) tile.Draw(spriteBatch, camera);
            spriteBatch.End();

            #endregion

            #region Player 2 Backgrounds

            gameStateManager.game.GraphicsDevice.SetRenderTarget(player2Backgrounds);
            //else gameStateManager.game.GraphicsDevice.SetRenderTarget(player2Objects2);
            gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);
            foreach (SpriteIMG tile in backFGList) if (tile.playerVisible == PlayerObjectMode.Two) tile.Draw(spriteBatch, camera);

            spriteBatch.End();

            #endregion

            #region Player 1 Objects

            //if (playerIndex == PlayerIndex.One)
            gameStateManager.game.GraphicsDevice.SetRenderTarget(player1Objects);
            //else gameStateManager.game.GraphicsDevice.SetRenderTarget(player1Objects2);
            gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);
            //foreach (SpriteIMG tile in backFGList) if (tile.playerVisible == PlayerObjectMode.One) tile.Draw(spriteBatch, camera);
            foreach (Particle particle in bgParticleList) if (particle.playerVisible == PlayerObjectMode.One) particle.Draw(spriteBatch, camera);
            foreach (FlipSwitch s in switchList) if (s.playerVisible == PlayerObjectMode.One) s.Draw(spriteBatch, camera);
            foreach (Button button in buttonList) if (button.playerVisible == PlayerObjectMode.One) button.Draw(spriteBatch, camera);
            foreach (TriggerArea area in areaList) if (area.playerVisible == PlayerObjectMode.One) area.Draw(spriteBatch, camera);
            foreach (LightConsole console in consoleList)
            {
                if (console.playerVisible == PlayerObjectMode.One)
                {
                    if (console.light == null) console.Draw(spriteBatch, camera);
                    else
                    {
                        spriteBatch.End();
                        colorShader.Parameters["DestColor"].SetValue(Color.White.ToVector4());
                        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, colorShader, camera.transform);
                        console.Draw(spriteBatch, camera);
                        spriteBatch.End();
                        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);
                    }
                }
            }
            foreach (Door door in doorList) if (door.playerVisible == PlayerObjectMode.One) door.Draw(spriteBatch, camera);
            foreach (MovingPlatform platform in platformList) if (platform.playerVisible == PlayerObjectMode.One) platform.Draw(spriteBatch, camera);
            foreach (CircularPlatform platform in cPlatformList) if (platform.playerVisible == PlayerObjectMode.One) platform.Draw(spriteBatch, camera);
            foreach (Moveable move in moveList) if (move.playerVisible == PlayerObjectMode.One) move.Draw(spriteBatch, camera);
            foreach (PickUpObj pickUp in pickUpList) if (pickUp.playerVisible == PlayerObjectMode.One) pickUp.Draw(spriteBatch, camera);
            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, camera.transform);
            foreach (SpriteIMG tile in frontFGList) if (tile.playerVisible == PlayerObjectMode.One) tile.Draw(spriteBatch, camera);
            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);
            foreach (Particle particle in particleList) if (particle.playerVisible == PlayerObjectMode.One) particle.Draw(spriteBatch, camera);
            spriteBatch.End();
            #endregion

            #region Player 2 Objects
            //if (playerIndex == PlayerIndex.One)
            gameStateManager.game.GraphicsDevice.SetRenderTarget(player2Objects);
            //else gameStateManager.game.GraphicsDevice.SetRenderTarget(player2Objects2);
            gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);
            //foreach (SpriteIMG tile in backFGList) if (tile.playerVisible == PlayerObjectMode.Two) tile.Draw(spriteBatch, camera);
            foreach (Particle particle in bgParticleList) if (particle.playerVisible == PlayerObjectMode.Two) particle.Draw(spriteBatch, camera);
            foreach (FlipSwitch s in switchList) if (s.playerVisible == PlayerObjectMode.Two) s.Draw(spriteBatch, camera);
            foreach (Button button in buttonList) if (button.playerVisible == PlayerObjectMode.Two) button.Draw(spriteBatch, camera);
            foreach (TriggerArea area in areaList) if (area.playerVisible == PlayerObjectMode.Two) area.Draw(spriteBatch, camera);
            foreach (LightConsole console in consoleList)
            {
                if (console.playerVisible == PlayerObjectMode.Two)
                {
                    if (console.light == null) console.Draw(spriteBatch, camera);
                    else
                    {
                        spriteBatch.End();
                        colorShader.Parameters["DestColor"].SetValue(Color.White.ToVector4());
                        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, colorShader, camera.transform);
                        console.Draw(spriteBatch, camera);
                        spriteBatch.End();
                        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);
                    }
                }
            }
            foreach (Door door in doorList) if (door.playerVisible == PlayerObjectMode.Two) door.Draw(spriteBatch, camera);
            foreach (MovingPlatform platform in platformList) if (platform.playerVisible == PlayerObjectMode.Two) platform.Draw(spriteBatch, camera);
            foreach (CircularPlatform platform in cPlatformList) if (platform.playerVisible == PlayerObjectMode.Two) platform.Draw(spriteBatch, camera);
            foreach (Moveable move in moveList) if (move.playerVisible == PlayerObjectMode.Two) move.Draw(spriteBatch, camera);
            foreach (PickUpObj pickUp in pickUpList) if (pickUp.playerVisible == PlayerObjectMode.Two) pickUp.Draw(spriteBatch, camera);
            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, camera.transform);
            foreach (SpriteIMG tile in frontFGList) if (tile.playerVisible == PlayerObjectMode.Two) tile.Draw(spriteBatch, camera);
            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);
            foreach (Particle particle in particleList) if (particle.playerVisible == PlayerObjectMode.Two) particle.Draw(spriteBatch, camera);
            spriteBatch.End();
            #endregion

            #region AlphaMaskingPlayerObjects
            alphaShader.Parameters["MaskTexture"].SetValue(alphaMask);
            if (playerIndex == PlayerIndex.One)
            {

                gameStateManager.game.GraphicsDevice.SetRenderTarget(alphaPlayer);
                gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, alphaShader);
                spriteBatch.Draw(player2Objects, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
                spriteBatch.End();

                gameStateManager.game.GraphicsDevice.SetRenderTarget(nonAlphaPlayer);
                gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                spriteBatch.Begin();
                spriteBatch.Draw(player1Objects, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
                spriteBatch.End();

                gameStateManager.game.GraphicsDevice.SetRenderTarget(alphaBGPlayer);
                gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, alphaShader);
                spriteBatch.Draw(player2Backgrounds, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
                spriteBatch.End();

                gameStateManager.game.GraphicsDevice.SetRenderTarget(nonAlphaBGPlayer);
                gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                spriteBatch.Begin();
                spriteBatch.Draw(player1Backgrounds, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
                spriteBatch.End();
            }
            else
            {
                gameStateManager.game.GraphicsDevice.SetRenderTarget(alphaPlayer);
                gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, alphaShader);
                spriteBatch.Draw(player1Objects, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
                spriteBatch.End();

                gameStateManager.game.GraphicsDevice.SetRenderTarget(nonAlphaPlayer);
                gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                spriteBatch.Begin();
                spriteBatch.Draw(player2Objects, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
                spriteBatch.End();

                gameStateManager.game.GraphicsDevice.SetRenderTarget(alphaBGPlayer);
                gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, alphaShader);
                spriteBatch.Draw(player1Backgrounds, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
                spriteBatch.End();

                gameStateManager.game.GraphicsDevice.SetRenderTarget(nonAlphaBGPlayer);
                gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
                spriteBatch.Begin();
                spriteBatch.Draw(player2Backgrounds, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
                spriteBatch.End();
            }
            #endregion

            #region Player neutral drawing
            //if (playerIndex == PlayerIndex.One)
            gameStateManager.game.GraphicsDevice.SetRenderTarget(renderTarget);
            //else gameStateManager.game.GraphicsDevice.SetRenderTarget(renderTarget2);
            gameStateManager.game.GraphicsDevice.Clear(Color.SlateBlue); //TODO: change here for background color
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            //if (playerIndex == PlayerIndex.One)
            spriteBatch.Draw(bgTarget, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);

            if (playerIndex == PlayerIndex.One)
                spriteBatch.Draw(bgTarget1, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
            else
                spriteBatch.Draw(bgTarget2, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);

            //else spriteBatch.Draw(bgTarget2, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
            spriteBatch.End();

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            spriteBatch.Draw(nonAlphaBGPlayer, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
            spriteBatch.Draw(alphaBGPlayer, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
            spriteBatch.End();

            //colorShader.Parameters["DestColor"].SetValue(Color.White.ToVector4());
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);
            foreach (SpriteIMG tile in backFGList) if (tile.playerVisible == PlayerObjectMode.None) tile.Draw(spriteBatch, camera);
            foreach (Particle particle in bgParticleList) if (particle.playerVisible == PlayerObjectMode.None) particle.Draw(spriteBatch, camera);
            spriteBatch.End();

            spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, null, null, null, null, camera.transform);
            if (playerIndex == PlayerIndex.One)
            {
                foreach (LightningChain lightning in lightningList)
                    if (lightning.playerObjectMode == PlayerObjectMode.None || lightning.playerObjectMode == PlayerObjectMode.One) lightning.Draw(spriteBatch, camera);
            }
            else
            {
                foreach (LightningChain lightning in lightningList)
                    if (lightning.playerObjectMode == PlayerObjectMode.None || lightning.playerObjectMode == PlayerObjectMode.Two) lightning.Draw(spriteBatch, camera);
            }
            spriteBatch.End();

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);

            foreach (FlipSwitch s in switchList) if (s.playerVisible == PlayerObjectMode.None) s.Draw(spriteBatch, camera);
            foreach (Button button in buttonList) if (button.playerVisible == PlayerObjectMode.None) button.Draw(spriteBatch, camera);
            foreach (TriggerArea area in areaList) if (area.playerVisible == PlayerObjectMode.None) area.Draw(spriteBatch, camera);
            foreach (LightConsole console in consoleList)
            {
                if (console.playerVisible == PlayerObjectMode.None)
                {
                    if (console.light == null) console.Draw(spriteBatch, camera);
                    else
                    {
                        spriteBatch.End();
                        colorShader.Parameters["DestColor"].SetValue(Color.White.ToVector4());
                        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, colorShader, camera.transform);
                        console.Draw(spriteBatch, camera);
                        spriteBatch.End();
                        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);
                    }
                }
            }
            foreach (Door door in doorList) if (door.playerVisible == PlayerObjectMode.None) door.Draw(spriteBatch, camera);
            foreach (MovingPlatform platform in platformList) if (platform.playerVisible == PlayerObjectMode.None) platform.Draw(spriteBatch, camera);
            foreach (CircularPlatform platform in cPlatformList) if (platform.playerVisible == PlayerObjectMode.None) platform.Draw(spriteBatch, camera);
            foreach (Moveable move in moveList) if (move.playerVisible == PlayerObjectMode.None) move.Draw(spriteBatch, camera);
            foreach (Portal portal in portalList) if (portal.playerVisible == PlayerObjectMode.None) portal.Draw(spriteBatch, camera);
            foreach (Particle particle in particleList) if (particle.playerVisible == PlayerObjectMode.None) particle.Draw(spriteBatch, camera);

            if (playerIndex == PlayerIndex.One)
            {
                if (player2.light == null) player2.Draw(spriteBatch, camera);
                else
                {
                    spriteBatch.End();
                    colorShader.Parameters["DestColor"].SetValue(Color.White.ToVector4());
                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, colorShader, camera.transform);
                    player2.Draw(spriteBatch, camera);
                    spriteBatch.End();
                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);

                }
            }

            if (player1.light == null) player1.Draw(spriteBatch, camera);
            else
            {
                spriteBatch.End();
                colorShader.Parameters["DestColor"].SetValue(Color.White.ToVector4());
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, colorShader, camera.transform);
                player1.Draw(spriteBatch, camera);
                spriteBatch.End();
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);
            }

            if (playerIndex == PlayerIndex.Two)
            {
                if (player2.light == null) player2.Draw(spriteBatch, camera);
                else
                {
                    spriteBatch.End();
                    colorShader.Parameters["DestColor"].SetValue(Color.White.ToVector4());
                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, colorShader, camera.transform);
                    player2.Draw(spriteBatch, camera);
                    spriteBatch.End();
                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, camera.transform);
                }
            }

            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, camera.transform);

            foreach (PickUpObj pickUp in pickUpList) if (pickUp.playerVisible == PlayerObjectMode.None) pickUp.Draw(spriteBatch, camera);
            foreach (SpriteIMG tile in frontFGList) if (tile.playerVisible == PlayerObjectMode.None) tile.Draw(spriteBatch, camera);
            spriteBatch.End();
            #endregion

            #region Objects Composite
            //if (playerIndex == PlayerIndex.One)
            gameStateManager.game.GraphicsDevice.SetRenderTarget(finalTarget);
            //else gameStateManager.game.GraphicsDevice.SetRenderTarget(finalTarget2);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            //if (playerIndex == PlayerIndex.One)
            //{
            spriteBatch.Draw(renderTarget, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
            spriteBatch.Draw(alphaPlayer, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
            spriteBatch.Draw(nonAlphaPlayer, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
            //}
            //else
            //{
            //    spriteBatch.Draw(renderTarget2, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
            //    spriteBatch.Draw(alphaPlayer2, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
            //    spriteBatch.Draw(nonAlphaPlayer2, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
            //}
            spriteBatch.End();
            #endregion

            #region Light pass and mirror pass

            if (GameStateManager.isMultiplayer)
            {
                if (playerIndex == PlayerIndex.One)
                {
                    gameStateManager.game.GraphicsDevice.SetRenderTarget(multiFinalTarget1);
                    gameStateManager.game.GraphicsDevice.Viewport = player1Viewport;
                }
                else
                {
                    gameStateManager.game.GraphicsDevice.SetRenderTarget(multiFinalTarget2);
                    gameStateManager.game.GraphicsDevice.Viewport = player2Viewport;
                }
            }
            else gameStateManager.game.GraphicsDevice.SetRenderTarget(null);

            gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
            //if (playerIndex == PlayerIndex.One)
            lightingShader.Parameters["lightMask"].SetValue(lightMask);
            //else lightingShader.Parameters["lightMask"].SetValue(lightMask2);
            lightingShader.CurrentTechnique.Passes[0].Apply();

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.LinearClamp, null, null, lightingShader); //Alpha testing
            SpriteEffects mirror = SpriteEffects.None;
            if (playerIndex == PlayerIndex.Two) mirror = SpriteEffects.FlipHorizontally;

            Vector2 drawPos = Vector2.Zero;
            Rectangle srcRect = finalTarget.Bounds;

            if (GameStateManager.isMultiplayer)
            {

                drawPos.X = -player1Viewport.Width / 2;

                //srcRect = new Rectangle(finalTarget.Width / 4, 0, finalTarget.Width / 2, finalTarget.Height);

            }

            //if (playerIndex == PlayerIndex.One)
            spriteBatch.Draw(finalTarget, drawPos, null, Color.White, 0, Vector2.Zero, 1, mirror, 0);
            //else spriteBatch.Draw(finalTarget2, drawPos, null, Color.White, 0, Vector2.Zero, 1, mirror, 0);
            spriteBatch.End();
            #endregion
        }
예제 #5
0
        public void DrawParallaxLayers(SpriteBatch spriteBatch, Camera camera)
        {
            #region Player neutral bgs
            //if (playerIndex == PlayerIndex.One)
            gameStateManager.game.GraphicsDevice.SetRenderTarget(bgTarget);
            //else gameStateManager.game.GraphicsDevice.SetRenderTarget(bgTarget2);
            gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
            foreach (ParallaxLayer bg in bgLayerList)
            {

                camera.parallaxRatio = bg.parallaxRatio;
                camera.UpdateMatrixValues();
                GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, camera.transform);
                foreach (SpriteIMG img in bg.imageList)
                {
                    if (img.playerVisible == PlayerObjectMode.None)
                        img.Draw(spriteBatch, camera);
                }
                spriteBatch.End();
            }
            camera.parallaxRatio = 1;
            camera.UpdateMatrixValues();
            #endregion

            #region Player 1 bgs

            gameStateManager.game.GraphicsDevice.SetRenderTarget(bgTarget1);
            //else gameStateManager.game.GraphicsDevice.SetRenderTarget(bgTarget2);
            gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
            foreach (ParallaxLayer bg in bgLayerList)
            {

                camera.parallaxRatio = bg.parallaxRatio;
                camera.UpdateMatrixValues();
                GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, camera.transform);
                foreach (SpriteIMG img in bg.imageList)
                {
                    if (img.playerVisible == PlayerObjectMode.One)
                        img.Draw(spriteBatch, camera);
                }
                spriteBatch.End();
            }
            camera.parallaxRatio = 1;
            camera.UpdateMatrixValues();

            #endregion

            #region Player 2 bgs

            gameStateManager.game.GraphicsDevice.SetRenderTarget(bgTarget2);
            //else gameStateManager.game.GraphicsDevice.SetRenderTarget(bgTarget2);
            gameStateManager.game.GraphicsDevice.Clear(Color.Transparent);
            foreach (ParallaxLayer bg in bgLayerList)
            {

                camera.parallaxRatio = bg.parallaxRatio;
                camera.UpdateMatrixValues();
                GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, camera.transform);
                foreach (SpriteIMG img in bg.imageList)
                {
                    if (img.playerVisible == PlayerObjectMode.Two)
                        img.Draw(spriteBatch, camera);
                }
                spriteBatch.End();
            }
            camera.parallaxRatio = 1;
            camera.UpdateMatrixValues();

            #endregion
        }
예제 #6
0
 public bool IsOnScreen(Camera camera)
 {
     Rectangle textureArea = new Rectangle((int)position.X - texture.Width / 2, (int)position.Y - texture.Width / 2, texture.Width, texture.Height);
     return textureArea.Intersects(camera.visibleArea);
 }
예제 #7
0
 public void Draw(SpriteBatch spriteBatch, Camera camera)
 {
     foreach (Lightning lightning in lightningList) lightning.Draw(spriteBatch, camera);
 }
예제 #8
0
 public bool IsOnScreen(Camera camera)
 {
     Rectangle textureArea = new Rectangle((int)position.X - 150, (int)position.Y - 150, 300, 300);
     return textureArea.Intersects(camera.visibleArea);
 }