protected override void DoDraw(GameTime gameTime) { this.penumbra.BeginDraw(); this.GraphicsDevice.Clear(ColorExtensions.FromHex(0x161214)); if (this.map != null) { this.SpriteBatch.Begin(SpriteSortMode.FrontToBack, null, SamplerState.PointClamp, null, null, null, this.camera.ViewMatrix); this.map.Draw(this.SpriteBatch, gameTime, this.camera.GetVisibleRectangle().ToExtended()); this.SpriteBatch.End(); } this.penumbra.Draw(gameTime); base.DoDraw(gameTime); }
protected override void LoadContent() { base.LoadContent(); this.penumbra = new PenumbraComponent(this) { AmbientColor = new Color(Color.Black, 0.1F) }; this.penumbra.Initialize(); this.mapContent = new ContentManager(this.Services, this.Content.RootDirectory); this.camera = new Camera(this.GraphicsDevice) { AutoScaleWithScreen = true, Scale = 4 }; this.UiSystem.AutoScaleWithScreen = true; this.UiSystem.Style.Font = new GenericSpriteFont(LoadContent <SpriteFont>("Fonts/Font")); this.UiSystem.Style.TextScale = 0.3F; this.UiSystem.Style.ButtonTexture = this.SpriteBatch.GenerateTexture(Color.Transparent, Color.Transparent); this.UiSystem.OnSelectedElementDrawn = (e, time, batch, alpha) => { batch.FillRectangle(e.DisplayArea.ToExtended(), ColorExtensions.FromHex(0x493443)); }; var controls = this.UiSystem.Controls; controls.HandleMouse = controls.HandleTouch = false; UiControls.AddButtons(ref controls.LeftButtons, Keys.Left); UiControls.AddButtons(ref controls.RightButtons, Keys.Right); UiControls.AddButtons(ref controls.UpButtons, Keys.Up); UiControls.AddButtons(ref controls.DownButtons, Keys.Down); this.fade = new Group(Anchor.TopLeft, Vector2.One, false) { OnDrawn = (e, time, batch, alpha) => { batch.FillRectangle(e.DisplayArea.ToExtended(), Color.Black * alpha); } }; this.UiSystem.Add("Fade", this.fade).Priority = 10; this.caption = new Group(Anchor.Center, Vector2.One); this.UiSystem.Add("Caption", this.caption).Priority = 20; this.trigger = new Paragraph(Anchor.TopLeft, 1, "", true) { OnUpdated = (e, time) => { if (this.map == null) { return; } var pos = this.player.Position + new Vector2(0.5F, -0.45F); var trans = this.camera.ToCameraPos(pos * this.map.TileSize); trans.X -= e.DisplayArea.Width / 2; trans.Y -= e.Root.Element.DisplayArea.Height; e.Root.Transform = Matrix.CreateTranslation(trans.X, trans.Y, 0); }, DrawAlpha = 0, TextScale = 0.15F }; this.UiSystem.Add("Trigger", this.trigger); this.mainMenu = new Group(Anchor.TopLeft, Vector2.One, false); this.UiSystem.Add("Menu", this.mainMenu); var center = this.mainMenu.AddChild(new Group(Anchor.Center, Vector2.One)); center.AddChild(new Paragraph(Anchor.AutoCenter, 1, "Don't Wake Up", true) { TextScale = 0.6F }); center.AddChild(new VerticalSpace(100)); center.AddChild(new Button(Anchor.AutoCenter, new Vector2(400, 70), "Start") { Padding = new Vector2(5), OnPressed = e => { if (this.cutscene != null && !this.cutscene.IsFinished) { return; } this.Fade(0.007F, g => { this.CloseMainMenu(g2 => { g2.StartMap(Levels[0], g3 => g3.Fade(0.01F)); }); }); } }); center.AddChild(new Button(Anchor.AutoCenter, new Vector2(400, 70), "Continue") { Padding = new Vector2(5), OnUpdated = (e, time) => e.IsHidden = this.savedLevel == null, OnPressed = e => { if (this.cutscene != null && !this.cutscene.IsFinished) { return; } this.Fade(0.007F, g => { this.CloseMainMenu(g2 => { this.StartMap(this.savedLevel, g3 => g3.Fade(0.01F)); }); }); } }); center.Root.SelectElement(center.GetChildren(c => c.CanBeSelected).First(), true); this.mainMenu.AddChild(new Paragraph(Anchor.BottomLeft, 1, "A small game by Ellpeck") { TextScale = 0.2F, Padding = new Vector2(5) }); this.OpenMainMenu(); this.Fade(0.01F); }