Exemple #1
0
        public void Render(GraphicsDevice device, Camera camera, SpriteBatch spriteBatch, AlphaTestEffect textEffect)
        {
            Matrix bill = Matrix.CreateBillboard(_position, camera.Position, Vector3.Down, camera.Direction);
            //Matrix bill = Matrix.CreateConstrainedBillboard(_position, camera.Position, Vector3.Down, camera.Direction,
            //                                    Vector3.Forward);
            float xOffset = _font.MeasureString(_text).X/2;

            textEffect.World = bill;
            textEffect.View = camera.View;
            textEffect.Projection = camera.Projection;
            textEffect.AlphaFunction = CompareFunction.Greater;
            textEffect.ReferenceAlpha = 128;
            textEffect.VertexColorEnabled = true;

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, DepthStencilState.DepthRead,
                                  RasterizerState.CullNone, textEffect);
            for (int x = -_outlineSize; x <= _outlineSize; x++)
            {
                for (int y = -_outlineSize; y <= _outlineSize; y++)
                {
                    if (x == 0 && y == 0) continue;

                    spriteBatch.DrawString(_font, _text, new Vector2(-xOffset + x, y), _outlineColor);
                }
            }

            spriteBatch.DrawString(_font, _text, new Vector2(-xOffset, 0), _textColor);

            spriteBatch.End();
        }
Exemple #2
0
        public void OnEnter()
        {
            // setup
            SpriteSheetFactory.Initialize(GameInstance.Content);
            HardcodedAnimations.CreateAnimations();

            // music
            MusicManager.PlayMusic("music/e1m1", true);

            // fonts
            FloatingTexts = new List<TimedText>();
            DamageFont = GameInstance.Content.Load<SpriteFont>("fonts/Doom12");

            // camera
            float aspectRatio = (float)GameInstance.Window.ClientBounds.Width / GameInstance.Window.ClientBounds.Height;
            Camera = new Camera("camera", new Vector3(0, 210f, 0), new Vector3(180f, 130f, 216f), Vector3.Up,
                                aspectRatio);
            MessagingSystem.Subscribe(Camera.MoveCamera, DoomEventType.CameraMoveEvent, "camera", null);
            MessagingSystem.Subscribe(OnChargeTimeReached, DoomEventType.ChargeTimeReached, "gamestate", null);
            MessagingSystem.Subscribe(OnActorSpawn, DoomEventType.SpawnActor, "gamestate", null);
            MessagingSystem.Subscribe(OnActorDespawn, DoomEventType.DespawnActor, "gamestate", null);
            MessagingSystem.Subscribe(OnRemoveActorFromTile, DoomEventType.RemoveFromCurrentTile, "gamestate", null);
            MessagingSystem.Subscribe(OnDisplayDamage, DoomEventType.DisplayDamage, "gamestate", null);
            MessagingSystem.Subscribe(OnDespawnText, DoomEventType.DespawnText, "gamestate", null);
            MessagingSystem.Subscribe(OnActorDeath, DoomEventType.ActorDied, "gamestate", null);

            Effect = new TileEffect(GameInstance.Content);

            CreateLevelTemp(GameInstance.Content);

            SpriteBatch = new SpriteBatch(GameInstance.GraphicsDevice);
            SpriteEffect = new BasicEffect(GameInstance.GraphicsDevice);
            AlphaTestEffect = new AlphaTestEffect(GameInstance.GraphicsDevice);
            TextEffect = new AlphaTestEffect(GameInstance.GraphicsDevice);
        }
Exemple #3
0
 private Angle GetAngleToCamera(Camera camera)
 {
     return GetAngle(camera.Position);
 }
Exemple #4
0
        public void Render(GraphicsDevice device, SpriteBatch spriteBatch, AlphaTestEffect spriteEffect, Camera camera, int passNumber)
        {
            Matrix bill = Matrix.CreateConstrainedBillboard(Position, camera.Position, Vector3.Down, camera.Direction,
                                                            Vector3.Forward);

            spriteEffect.World = bill;
            spriteEffect.View = camera.View;
            spriteEffect.Projection = camera.Projection;

            SpriteRenderDetails details = SpriteSheet.GetRenderDetails(CurrentAnimation.CurrentImageName(), GetAngleToCamera(camera));

            if (passNumber == 0)
            {
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, DepthStencilState.DepthRead,
                                  RasterizerState.CullNone, spriteEffect);
                device.DepthStencilState = DepthStencilState.Default;
                spriteBatch.Draw(SpriteSheet.Texture, details.TargetRectangle, details.SourceRectangle, Color.White, 0.0f, Vector2.Zero, details.SpriteEffects, 0);
                spriteBatch.End();
            }
            else
            {
                // spritebatch begin ignores depth buffer
                spriteBatch.Begin(0, null, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone, spriteEffect);
                spriteBatch.Draw(SpriteSheet.Texture, details.TargetRectangle, details.SourceRectangle, Color.White, 0.0f, Vector2.Zero, details.SpriteEffects, 0);
                spriteBatch.End();
            }
        }