Пример #1
0
 public ObjectManager(Map map)
 {
     _map = map;
     _sem = new Semaphore(1, 1);
     _objects = new List<GameObject>();
     _draw = new List<GameObject>();
     SetUpAttacks();
 }
Пример #2
0
        private void UnShadowTiles(Camera cam, SpriteBatch batch, Map map)
        {
            shadowEffect.CurrentTechnique = shadowEffect.Techniques["Tile"];
            shadowEffect.CurrentTechnique.Passes[0].Apply();
            batch.Begin(SpriteSortMode.Immediate, generateShadow, null, preventShadowStencil, RasterizerState.CullNone, shadowEffect);
            map.DrawTileHighlight(cam, batch);
            batch.End();

            batch.Begin(SpriteSortMode.Immediate, generateShadow, null, preventShadowStencil, RasterizerState.CullNone, shadowEffect);
            map.DrawForegroundTileHighlight(cam, batch, shadowEffect);
            batch.End();
        }
Пример #3
0
 public void SetMap(Map map)
 {
     this.map = map;
     _hasLightmap = false;
     map.TryLoadLightmap();
 }
Пример #4
0
 public void DrawMapOutline(SpriteBatch batch, Map map)
 {
 }
Пример #5
0
        public void DrawLight(Camera cam, LightSource light, Map map, SpriteBatch batch)
        {
            //Clear stencil buffer
            device.Clear(ClearOptions.Stencil, Color.White, 0, 1);

            if (light.shadows)
            {
                Vector2 camPosition = cam.Position;
                //cam.MoveTo(light.position, 1);
                UnShadowTiles(cam, batch, map);
                //cam.MoveTo(camPosition,1);

                //Build shadow geometry for the light
                int vertexCount = map.CreateShadowGeometry(light.position, new Rectangle((int)(light.position.X - light.radius), (int)(light.position.Y - light.radius), (int)(2*light.radius), (int)(2*light.radius)), shadowVB);

                //Draw Shadows into stencil buffer
                device.BlendState = generateShadow;
                device.DepthStencilState = generateShadowStencil;
                shadowEffect.CurrentTechnique = shadowEffect.Techniques["Shadow"];
                device.SetVertexBuffer(shadowVB);
                device.Indices = shadowIB;
                shadowEffect.CurrentTechnique.Passes[0].Apply();

                //Check necessary because empty draw calls cause crashes
                if (vertexCount > 0)
                    device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexCount, 0, 4 * vertexCount / 6);
            }
            //Draw glow over everything that has not been stenciled out
            shadowEffect.CurrentTechnique = shadowEffect.Techniques["Glow"];
            batch.Begin(SpriteSortMode.Immediate, addLight, null, drawShadowedLight, RasterizerState.CullNone, shadowEffect);
            //I need to specify a texture to use this call, but since I use a custom shader it is never used, it might actually be null I am not sure
            batch.Draw(_unusedTexture, new Rectangle((int)(light.position.X - light.radius), (int)(light.position.Y - light.radius), (int)(light.radius * 2), (int)(light.radius * 2)), Color.Lerp(light.color, Color.Black, 1-light.brightness));
            batch.End();
        }
Пример #6
0
        public void ComputeLightMap(SpriteBatch batch, Map map, string Path)
        {
            Camera cam = new Camera(Vector2.Zero, map.MapBoundaries);
            cam.Zoom(-1);
            Vector2 viewFieldDiagonal = new Vector2(cam.ViewSpace.Width *0.5f, cam.ViewSpace.Height *0.5f);
            cam.SetPos(viewFieldDiagonal);
            lightMapTarget = new RenderTarget2D(device, map.MapBoundaries.Width, map.MapBoundaries.Height,false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
            Matrix baseProjection = cam.ProjectionMatrix;
            map.SetUpLightMapPrecomputeLights();
            device.SetRenderTarget(lightMapTarget);

            //Clear Target first

            device.DepthStencilState = clearStencil;
            device.RasterizerState = RasterizerState.CullNone;
            device.BlendState = BlendState.Opaque;
            shadowEffect.Parameters["View"].SetValue(cam.ViewMatrix);
            shadowEffect.Parameters["Projection"].SetValue(Matrix.Identity);
            shadowEffect.Parameters["shadowDarkness"].SetValue(0.9f - 1);
            shadowEffect.Parameters["viewDistance"].SetValue((float)(1 / (0.001f + 0.999 )));
            shadowEffect.CurrentTechnique = shadowEffect.Techniques["Clear"];
            device.SetVertexBuffer(clearVBuffer);
            device.Indices = clearIBuffer;
            shadowEffect.CurrentTechnique.Passes[0].Apply();
            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2);

            //Matrix UpperLeftShift = Matrix.CreateTranslation(-1+(float)cam.ViewSpace.Width / (float)map.MapBoundaries.Width, 1-(float)cam.ViewSpace.Height / (float)map.MapBoundaries.Height, 0);
            //cam.ProjectionMatrix = baseProjection * Matrix.CreateScale((float)cam.ViewSpace.Width / map.MapBoundaries.Width, (float)cam.ViewSpace.Height / map.MapBoundaries.Height, 1) * UpperLeftShift * Matrix.CreateTranslation(cam.ViewSpace.Left / map.MapBoundaries.Width, cam.ViewSpace.Top / map.MapBoundaries.Height, 0);
            DrawLights(1, cam, batch, lightMapTarget);
            //cam.Move(new Vector2(0, viewFieldDiagonal.Y * 2));

            RenderTarget2D blurTarget = new RenderTarget2D(device,lightMapTarget.Width,lightMapTarget.Height);

            shadowEffect.Parameters["xTexelDist"].SetValue(1.0f / (blurTarget.Width / lightMapDownSample));
            shadowEffect.Parameters["yTexelDist"].SetValue(1.0f / (blurTarget.Height / lightMapDownSample));
            BlurShadowTarget(batch, lightMapTarget, blurTarget);
            BlurShadowTarget(batch, lightMapTarget, blurTarget);
            shadowEffect.Parameters["xTexelDist"].SetValue(1.0f / (device.PresentationParameters.BackBufferWidth / lightMapDownSample));
            shadowEffect.Parameters["yTexelDist"].SetValue(1.0f / (device.PresentationParameters.BackBufferHeight / lightMapDownSample));

            device.SetRenderTarget(null);
            Clear();

            System.IO.FileStream fs = System.IO.File.Open(Path, System.IO.FileMode.Create);
            lightMapTarget.SaveAsPng(fs, lightMapTarget.Width, lightMapTarget.Height);
            fs.Close();

            lightMap = lightMapTarget;
            _hasLightmap = true;
        }
Пример #7
0
 public void LoadMap(int id)
 {
     _mapMutex.WaitOne();
     map = null;
     player = null;
     Map NewMap = MapManager.GetMapByID(id);
     objectManager.SetMap(NewMap);
     _lightMap.SetMap(NewMap);
     cam.JumpNext();
     map = NewMap;
     mapChanged = true;
     _mapMutex.ReleaseMutex();
 }
Пример #8
0
 public void SetMap(Map map)
 {
     _map = map;
 }