Example #1
0
        public static void InitTextures(GraphicsDevice GraphicsDevice, BiomeData.Biome biome)
        {
            BasicEffect    effect = new BasicEffect(GraphicsDevice);
            RenderTarget2D canvas = new RenderTarget2D(GraphicsDevice, Size, Size * 2);

            GraphicsDevice.SetRenderTarget(canvas);
            GraphicsDevice.RasterizerState = new RasterizerState()
            {
                CullMode = CullMode.None, MultiSampleAntiAlias = false
            };

            effect.World              = Matrix.Identity;
            effect.View               = Matrix.CreateLookAt(Vector3.UnitZ, Vector3.Zero, Vector3.Up);
            effect.Projection         = Matrix.CreateOrthographicOffCenter(0, Tile.Size, Tile.Size * 2, 0, 0.1f, 100f);
            effect.VertexColorEnabled = true;

            for (int i = 0; i < Tileset.Length; i++)
            {
                GraphicsDevice.Clear(Color.Transparent);

                Tileset[i].Draw(GraphicsDevice, effect, biome);

                Color[] textureData = new Color[canvas.Width * canvas.Height];
                canvas.GetData(textureData);
                Tileset[i].Texture = new Texture2D(GraphicsDevice, canvas.Width, canvas.Height);
                Tileset[i].Texture.SetData(textureData);
            }

            GraphicsDevice.SetRenderTarget(null);
            effect.Dispose();
            canvas.Dispose();
        }
Example #2
0
        private void Draw(GraphicsDevice GraphicsDevice, BasicEffect effect, BiomeData.Biome biome)
        {
            if (Id == 0)
            {
                return;
            }

            const int height = 20;

            for (int h = 0; h < height; h++)
            {
                Color color = (h == height - 1) ? biome.WallTopColor : biome.WallColor;
                VertexPositionColor[] verts;
                int primitivesCount = 2;
                verts = new VertexPositionColor[4] {
                    new VertexPositionColor(new Vector3(Edges[0].A.X, Edges[0].A.Y + Size - h, 0), color),
                    new VertexPositionColor(new Vector3(Edges[1].A.X, Edges[1].A.Y + Size - h, 0), color),
                    new VertexPositionColor(new Vector3(Edges[3].A.X, Edges[3].A.Y + Size - h, 0), color),
                    new VertexPositionColor(new Vector3(Edges[2].A.X, Edges[2].A.Y + Size - h, 0), color),
                };

                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleStrip, verts, 0, primitivesCount);
                }
            }
        }
Example #3
0
        public void Initialize(GraphicsDevice GraphicsDevice, ContentManager Content)
        {
            BiomeData.Biome biome = BiomeData.GetBiome(3);
            int mapId = 0;

            pixel = Content.Load<Texture2D>("pixel");
            Tile.InitTextures(GraphicsDevice, biome);
            world = new GameWorld();
            world.maze = Cell.ParseData(MapData.GetMap(mapId));

            renderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
            renderTargetRectangle = new Rectangle(0, 0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
            cameraMatrix = Matrix.CreateTranslation(GraphicsDevice.PresentationParameters.BackBufferWidth / 2 - Tile.Size * 11, Tile.Size, 0);
            floorRectangle = new Rectangle(0, 0, world.maze.GetLength(1) * Tile.Size, world.maze.GetLength(0) * Tile.Size);


            this.biome = new Biome
            {
                BackgroundColor = biome.BackgroundColor,
                FloorColor = biome.GroundColor,
                WallColor = biome.WallColor,
                WallTopColor = biome.WallTopColor,

                BackgroundOverlayTexture = null,
                FloorOverlayTexture = Content.Load<Texture2D>("gravelOverlay"),
                WallOverlayTexture = Content.Load<Texture2D>("gravelOverlay"),
                WallTopOverlayTexture = Content.Load<Texture2D>("iceOverlay"),

                BackgroundBlendingMode = Biome.BlendingMode.Normal,
                FloorBlendingMode = Biome.BlendingMode.Reflect,
                WallBlendingMode = Biome.BlendingMode.Reflect,
                WallTopBlendingMode = Biome.BlendingMode.Reflect,
            };

            biomeBackgroundEffect = Content.Load<Effect>("floor_shader");
            biomeEffect = Content.Load<Effect>("walls_shader");
            biomeEffect.Parameters["u_wallBlendingMode"]?.SetValue((int)this.biome.WallBlendingMode);
            biomeEffect.Parameters["u_wallColor"]?.SetValue(this.biome.WallColor.ToVector3());
            biomeEffect.Parameters["u_wallOverlayTexture"]?.SetValue(this.biome.WallOverlayTexture);
            biomeEffect.Parameters["u_wallOverlayTextureSize"]?.SetValue(new Vector2(this.biome.WallOverlayTexture.Width, this.biome.WallOverlayTexture.Height));
            biomeEffect.Parameters["u_wallTopBlendingMode"]?.SetValue((int)this.biome.WallTopBlendingMode);
            biomeEffect.Parameters["u_wallTopColor"]?.SetValue(this.biome.WallTopColor.ToVector3());
            biomeEffect.Parameters["u_wallTopOverlayTexture"]?.SetValue(this.biome.WallTopOverlayTexture);
            biomeEffect.Parameters["u_wallTopOverlayTextureSize"]?.SetValue(new Vector2(this.biome.WallTopOverlayTexture.Width, this.biome.WallTopOverlayTexture.Height));
            biomeEffect.Parameters["u_screenSize"]?.SetValue(new Vector2(GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight));
        }
Example #4
0
 private LoadGameScreen(int PlayersCount, int MapId, int BiomeId)
 {
     ExpectedPlayers = PlayersCount;
     this.MapId      = MapId;
     this.biome      = BiomeData.GetBiome(BiomeId);
 }