public Line() : base(Game1.Self.Content.Load <Texture2D>("particulaLinha")) { Self = this; lineList = new List <Objeto2D>(); this.position = new Vector2(0, Game1.Self.Window.ClientBounds.Height / 6 * 4); this.position.X = 100; idealPosition = position.Y; random = new Random(); #region GaussianBlur gaussianBlur = new GaussianBlur(Game1.Self); gaussianBlur.ComputeKernel(BLUR_RADIUS, blurAmount); InitRenderTargets(Game1.Self.GraphicsDevice); lineRenderTarget = new RenderTarget2D(Game1.Self.GraphicsDevice, Game1.GameRactangle.Width, Game1.GameRactangle.Height); #endregion }
public override void LargeLoadContent(object sender) { var Content = gameRef.Content; background = new DrawableRectangle(gameRef.GraphicsDevice, new Vector2(10, 10), Color.Black, true).Texture; levelManager = new LevelManager(gameRef); Camera.Initialize(Vector2.Zero, new Rectangle(0, 0, MainGame.GAME_WIDTH, MainGame.GAME_HEIGHT), new Vector2(LevelManager.CurrentLevel.WidthInPixels, LevelManager.CurrentLevel.HeightInPixels)); Camera.MaxClamp -= new Vector2(Camera.View.Width / 2, Camera.View.Height / 2); entityManager = new EntityManager(gameRef); if (!loadedGame) { EntityManager.Player.Name = Config.currentlyPlaying; if (LevelManager.CurrentLevel.PlayerSpawnPoint.X > -1 && LevelManager.CurrentLevel.PlayerSpawnPoint.Y > -1) { EntityManager.Player.Position = new Vector2(LevelManager.CurrentLevel.PlayerSpawnPoint.X, LevelManager.CurrentLevel.PlayerSpawnPoint.Y) * Engine.TileWidth; } } else { Config.SetLastLogin(loadedProps.Name); Config.currentlyPlaying = loadedProps.Name; EntityManager.Player.LoadFromData(loadedProps); } new Pathfinder(LevelManager.CurrentLevel); #region Pause_Normal pauseControls_Normal = new ControlManager(gameRef, gameRef.Content.Load <SpriteFont>("Fonts\\default")); { Label lblPauseDisplay = new Label() { Name = "lblPauseDisplay", Text = "P A U S E D", Color = Color.White }; lblPauseDisplay.Position = new Vector2(MainGame.GAME_WIDTH / 2 - lblPauseDisplay.Width / 2, MainGame.GAME_HEIGHT / 1.8f - lblPauseDisplay.Height - 10); var back = new LinkLabel(1) { Name = "lnklblBack", Text = "Resume" }; var save = new LinkLabel(2) { Name = "lnklblSave", Text = "Save Game" }; var quit = new LinkLabel(3) { Name = "lnklblQuit", Text = "Quit to Menu" }; pauseControls_Normal.Add(lblPauseDisplay); pauseControls_Normal.Add(back); pauseControls_Normal.Add(save); pauseControls_Normal.Add(quit); Vector2 startPos = new Vector2(MainGame.GAME_WIDTH / 2, MainGame.GAME_HEIGHT / 1.8f); foreach (Control c in pauseControls_Normal) { if (c is LinkLabel) { var l = (LinkLabel)c; var offset = new Vector2(c.Width / 2, 0); c.Position = startPos - offset; c.Selected += new EventHandler(LinkLabel_Selected); c.Effect = ControlEffect.PULSE; c.Color = Color.Black; l.OnMouseIn += LinkLabel_OnMouseIn; startPos.Y += c.Height + 10f; } } } #endregion #region Pause_Save pauseControls_Save = new ControlManager(gameRef, gameRef.Content.Load <SpriteFont>("Fonts\\default")); Label status = new Label(); status.AutoSize = true; status.Text = "Save game success!"; status.Position = new Vector2(MainGame.GAME_WIDTH / 2 - status.Width / 2, MainGame.GAME_HEIGHT / 2 - status.Height); pauseControls_Save.Add(status); LinkLabel goBack_Save = new LinkLabel(0); goBack_Save.AutoSize = true; goBack_Save.Text = "Go Back"; goBack_Save.Position = new Vector2(MainGame.GAME_WIDTH / 2 - goBack_Save.Width / 2, status.Position.Y + status.Height + 10); goBack_Save.Selected += (o, e) => { pauseState = State_Paused.Normal; }; goBack_Save.OnMouseIn += LinkLabel_OnMouseIn; pauseControls_Save.Add(goBack_Save); #endregion #region Pause_Quit pauseControls_Quit = new ControlManager(gameRef, gameRef.Content.Load <SpriteFont>("Fonts\\default")); Label areYouSure1 = new Label(); areYouSure1.Name = "lblAreYouSure?"; areYouSure1.Text = "Are you sure you want to quit?"; areYouSure1.Position = new Vector2(MainGame.GAME_WIDTH / 2 - areYouSure1.SpriteFont.MeasureString( areYouSure1.Text).X / 2, 140); pauseControls_Quit.Add(areYouSure1); LinkLabel yes = new LinkLabel(1) { Name = "lnklblYes", Text = "Yes" }; yes.Position = new Vector2(areYouSure1.Position.X + 40, areYouSure1.Position.Y + areYouSure1.Height + 50); yes.OnMouseIn += LinkLabel_OnMouseIn; yes.Selected += (o, e) => { SwitchStateWithFade(new MainMenuState(gameRef, StateManager)); }; yes.Effect = ControlEffect.PULSE; LinkLabel no = new LinkLabel(2) { Name = "lnklblNo", Text = "No" }; no.Position = new Vector2(areYouSure1.Position.X + areYouSure1.Width - no.Width - 40, yes.Position.Y); no.OnMouseIn += LinkLabel_OnMouseIn; no.Selected += (o, e) => { pauseState = State_Paused.Normal; }; no.Effect = ControlEffect.PULSE; pauseControls_Quit.Add(yes); pauseControls_Quit.Add(no); #endregion blurOverlay = new GaussianBlur(gameRef); renderTargetWidth = MainGame.GAME_WIDTH; renderTargetHeight = MainGame.GAME_HEIGHT; blurOverlay.ComputeKernel(7, 2.0f); mainTarget = new RenderTarget2D(gameRef.GraphicsDevice, MainGame.GAME_WIDTH, MainGame.GAME_HEIGHT); target1 = new RenderTarget2D(gameRef.GraphicsDevice, renderTargetWidth, renderTargetHeight, false, gameRef.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None); target2 = new RenderTarget2D(gameRef.GraphicsDevice, renderTargetWidth, renderTargetHeight, false, gameRef.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None); blurOverlay.ComputeOffsets(renderTargetWidth, renderTargetHeight); quests = new QuestManager(); Quest q = new Quest(0, (QuestGiver)EntityManager.Npcs[0], EntityManager.Player); q.CheckSuccess += (delegate() { return(EntityManager.Player.NoClip == true); }); quests.AddQuest(q); ((QuestGiver)EntityManager.Npcs[0]).Quest = q; ((QuestGiver)EntityManager.Npcs[0]).OnQuestCompleted += (delegate(object sender2, EventArgs args) { var questGiverSender = (QuestGiver)sender2; questGiverSender.Dialogues[0] = "Good job!"; }); base.LargeLoadContent(sender); }
/// <summary> /// Primary draw method. /// </summary> /// <param name="gameTime">Handeled by the framework, the passage of time is updated automagically.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); _skybox.Draw(_camera.View, _camera.Projection, _camera.Position); foreach (BasicModel model in _models) { if (_camera.BoundingVolumeIsInView(model.BoundingSphere)) { model.Draw(_camera.View, _camera.Projection, _camera.Position); } } _lineDrawer.Begin(_camera.View, _camera.Projection); _lineDrawer.DrawHexagonGrid(Vector2.One * -9930, (new Vector2(80, 40)), 200, Color.Red); _lineDrawer.DrawLine(_models[0].Position, new Vector3(_models[0].Position.X, 0, _models[0].Position.Z), Color.CornflowerBlue); ShipMovement.DrawHeading(); ShipMovement.DrawMarker(); _lineDrawer.End(); _stars.Draw(_camera.View, _camera.Projection, _camera.Up, _camera.Right); // if rendered card buffer is null, initialize it here if (_renderedCardBuffer == null) { // Choosing a random card for testing... Random r = new Random(); //Card c = _cards[r.Next(_cards.Count)]; Card c = null; foreach (Card cx in _cards) { if (cx.Title == "Patrol Drone") //if (_rulesTextFont.MeasureString(WrapText(_rulesTextFont, cx.RulesText, _cardRulesWidth)).Y > _cardRulesHeight) { c = cx; //Debug.WriteLine("{0}", _rulesTextFont.MeasureString(WrapText(_rulesTextFont, cx.RulesText, _cardRulesWidth)).Y - _cardRulesHeight); break; } } string someRandomText = c.RulesText; someRandomText = WrapText(_rulesTextFont, someRandomText, _cardRulesWidth); Vector2 textSize = _rulesTextFont.MeasureString(someRandomText); string titleString = c.Title; Vector2 titleSize = _titleFont.MeasureString(titleString); string typeString = c.Supertype.ToString(); string subtypeString = c.Subtype.ToString(); if (subtypeString != "None") { typeString = typeString + " - " + c.Subtype.ToString(); } Vector2 typeSize = _typeFont.MeasureString(typeString); string costString = (c.EnergyCostType == AmountType.Variable) ? Description.ToDescription(c.EnergyCostVar).Replace("+", string.Empty) : c.EnergyCost.ToString(); Vector2 costSize = _statFont.MeasureString(costString); Rectangle cardRect = new Rectangle( 0, 0, _cardTexture.Width, _cardTexture.Height); float titleScale = 1; if (titleSize.X > _cardTitleWidth) { titleScale = _cardTitleWidth / titleSize.X; } float typeScale = 1; if (typeSize.X > _cardTypeWidth) { typeScale = _cardTypeWidth / typeSize.X; } float costScale = 1; if (costSize.X > _cardCostWidth) { costScale = _cardCostWidth / costSize.X; } // render the title text's shadow RenderTarget2D titleShadowTarget = new RenderTarget2D(GraphicsDevice, _cardTitleWidth, _cardTitleHeight, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); GraphicsDevice.SetRenderTarget(titleShadowTarget); GraphicsDevice.Clear(Color.Transparent); _spriteBatch.Begin(); _spriteBatch.DrawString(_titleFont, titleString, new Vector2((int)((_cardTitleWidth - titleSize.X * titleScale) / 2), (int)((_cardTitleHeight - titleSize.Y * titleScale) / 2)), Color.White, 0, Vector2.Zero, titleScale, SpriteEffects.None, 0); _spriteBatch.End(); // do blur GaussianBlur gaussianBlur = new GaussianBlur(this); gaussianBlur.ComputeKernel(4, 2); int renderTargetWidth = titleShadowTarget.Width / 2; int renderTargetHeight = titleShadowTarget.Height / 2; RenderTarget2D rt1 = new RenderTarget2D(GraphicsDevice, renderTargetWidth, renderTargetHeight, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None); RenderTarget2D rt2 = new RenderTarget2D(GraphicsDevice, renderTargetWidth, renderTargetHeight, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None); gaussianBlur.ComputeOffsets(renderTargetWidth, renderTargetHeight); Texture2D titleShadowResult = gaussianBlur.PerformGaussianBlur(titleShadowTarget, rt1, rt2, _spriteBatch); // render the type text's shadow RenderTarget2D typeShadowTarget = new RenderTarget2D(GraphicsDevice, _cardTypeWidth, _cardTypeHeight, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); GraphicsDevice.SetRenderTarget(typeShadowTarget); GraphicsDevice.Clear(Color.Transparent); _spriteBatch.Begin(); _spriteBatch.DrawString(_typeFont, typeString, new Vector2((int)((_cardTypeWidth - typeSize.X * typeScale) / 2), (int)((_cardTypeHeight - typeSize.Y * typeScale) / 2)), Color.White, 0, Vector2.Zero, typeScale, SpriteEffects.None, 0); _spriteBatch.End(); // do blur renderTargetWidth = typeShadowTarget.Width / 2; renderTargetHeight = typeShadowTarget.Height / 2; rt1 = new RenderTarget2D(GraphicsDevice, renderTargetWidth, renderTargetHeight, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None); rt2 = new RenderTarget2D(GraphicsDevice, renderTargetWidth, renderTargetHeight, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None); gaussianBlur.ComputeOffsets(renderTargetWidth, renderTargetHeight); Texture2D typeShadowResult = gaussianBlur.PerformGaussianBlur(typeShadowTarget, rt1, rt2, _spriteBatch); // render the card _renderedCardBuffer = new RenderTarget2D(GraphicsDevice, _cardTexture.Width, _cardTexture.Height, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); GraphicsDevice.SetRenderTarget(_renderedCardBuffer); GraphicsDevice.Clear(Color.Transparent); _spriteBatch.Begin(); _spriteBatch.Draw(_cardTexture, cardRect, Color.White); _spriteBatch.DrawString(_rulesTextFont, someRandomText, new Vector2(_cardRulesLeftX, (int)(_cardRulesTopY + (_cardRulesHeight - textSize.Y) / 2)), Color.Black, 0, Vector2.Zero, 1, SpriteEffects.None, 0); _spriteBatch.Draw(titleShadowResult, new Rectangle((int)(_cardTitleLeftX + (_cardTitleWidth - titleShadowResult.Width * 2) / 2), (int)(_cardTitleTopY + (_cardTitleHeight - titleShadowResult.Height * 2) / 2), titleShadowResult.Width * 2, titleShadowResult.Height * 2), new Rectangle(0, 0, titleShadowResult.Width, titleShadowResult.Height), Color.White); _spriteBatch.Draw(typeShadowResult, new Rectangle((int)(_cardTypeLeftX + (_cardTypeWidth - typeShadowResult.Width * 2) / 2), (int)(_cardTypeTopY + (_cardTypeHeight - typeShadowResult.Height * 2) / 2), typeShadowResult.Width * 2, typeShadowResult.Height * 2), new Rectangle(0, 0, typeShadowResult.Width, typeShadowResult.Height), Color.White); _spriteBatch.DrawString(_titleFont, titleString, new Vector2((int)(_cardTitleLeftX + (_cardTitleWidth - titleSize.X * titleScale) / 2), (int)(_cardTitleTopY + (_cardTitleHeight - titleSize.Y * titleScale) / 2)), Color.Black, 0, Vector2.Zero, titleScale, SpriteEffects.None, 0); _spriteBatch.DrawString(_typeFont, typeString, new Vector2((int)(_cardTypeLeftX + (_cardTypeWidth - typeSize.X * typeScale) / 2), (int)(_cardTypeTopY + (_cardTypeHeight - typeSize.Y * typeScale) / 2)), Color.Black, 0, Vector2.Zero, typeScale, SpriteEffects.None, 0); _spriteBatch.DrawString(_statFont, costString, new Vector2((int)(_cardCostLeftX + (_cardCostWidth - costSize.X * costScale) / 2), (int)(_cardCostTopY + (_cardCostHeight - costSize.Y * costScale) / 2)), Color.Black, 0, Vector2.Zero, costScale, SpriteEffects.None, 0); _spriteBatch.End(); GraphicsDevice.SetRenderTarget(null); } // Draw cards *this should always appear at the end so its on top _spriteBatch.Begin(); float scale = .4f; // Note: this is arbitrary rules text for testing... Rectangle retval = new Rectangle( 0 + 10, GraphicsDevice.Viewport.Height - (int)(_cardTexture.Height * scale) - 10, (int)(_cardTexture.Width * scale), (int)(_cardTexture.Height * scale)); _spriteBatch.Draw(_renderedCardBuffer, retval, Color.White); _spriteBatch.End(); base.Draw(gameTime); }
protected override void LoadContent() { base.LoadContent(); var Content = gameRef.Content; IOManager.Init(); blackOverlay = new DrawableRectangle(GraphicsDevice, new Vector2(MainGame.GAME_WIDTH, MainGame.GAME_HEIGHT), Color.White, true).Texture; blurOverlay = new GaussianBlur(gameRef); blurOverlay.ComputeKernel(7, 2.0f); titleImage = Content.Load <Texture2D>("Images\\title"); title = new Label(); title.SpriteFont = Content.Load <SpriteFont>("Fonts\\title"); title.Text = ""; title.Color = Color.White; title.Position = new Vector2(MainGame.GAME_WIDTH / 2 - title.Width / 2, 90); controls.Add(title); Texture2D[] images = new Texture2D[8]; for (int i = 0; i < images.Length; i++) { images[i] = Content.Load <Texture2D>("Images\\waterfall\\water" + i.ToString()); } anim = new Animation(images); #region Menu State menuControls = new ControlManager(gameRef, Content.Load <SpriteFont>("Fonts\\default")); var start = new LinkLabel(0) { Name = "lnklblStart", Text = "New Game" }; var load = new LinkLabel(1) { Name = "lnklblLoad", Text = "Load Game" }; var options = new LinkLabel(2) { Name = "lnklblOptions", Text = "Options" }; var quit = new LinkLabel(3) { Name = "lnklblQuit", Text = "Quit Game" }; menuControls.Add(start); menuControls.Add(load); menuControls.Add(options); menuControls.Add(quit); Vector2 startPos = new Vector2(MainGame.GAME_WIDTH / 2, MainGame.GAME_HEIGHT / 1.8f); foreach (Control c in menuControls) { if (c is LinkLabel) { var l = (LinkLabel)c; var offset = new Vector2(c.Width / 2, 0); c.Position = startPos - offset; c.Selected += new EventHandler(LinkLabel_Selected); c.Effect = ControlEffect.PULSE; c.Color = Color.Black; ((LinkLabel)c).SelectedColor = Color.DarkBlue; l.OnMouseIn += LinkLabel_OnMouseIn; startPos.Y += c.Height + 10f; } } menuControls.SelectControl(0); #endregion #region New Game State newGameControls = new ControlManager(gameRef, Content.Load <SpriteFont>("Fonts\\default")); Label prompt = new Label(); prompt.Text = "Enter your name"; prompt.Name = "lblNamePrompt"; prompt.Position = new Vector2(MainGame.GAME_WIDTH / 2 - prompt.SpriteFont.MeasureString(prompt.Text).X / 2, 200); newGameControls.Add(prompt); TextBox name = new TextBox(GraphicsDevice); name.Name = "txtName"; name.Position = new Vector2(prompt.Position.X + 40, prompt.Position.Y + prompt.Height + 10); name.BackColor = Color.Transparent; name.ForeColor = Color.White; newGameControls.Add(name); LinkLabel startGame = new LinkLabel(2) { Name = "lnklblNewGame", Text = "Start" }; startGame.Position = new Vector2(prompt.Position.X, name.Position.Y + 44); startGame.OnMouseIn += LinkLabel_OnMouseIn; startGame.Selected += (o, e) => { Config.currentlyPlaying = newGameControls[1].Text; SwitchStateWithFade(new LoadingState(gameRef, StateManager, new GameplayState(gameRef, StateManager))); }; startGame.Effect = ControlEffect.PULSE; LinkLabel cancel = new LinkLabel(3) { Name = "lnklblCancel", Text = "Cancel" }; cancel.Position = new Vector2(prompt.Position.X + prompt.Width - cancel.Width, startGame.Position.Y); cancel.OnMouseIn += LinkLabel_OnMouseIn; cancel.Selected += (o, e) => { currentState = State.Menu; }; cancel.Effect = ControlEffect.PULSE; newGameControls.Add(startGame); newGameControls.Add(cancel); #endregion #region Load Game State loadGameControls = new ControlManager(gameRef, Content.Load <SpriteFont>("Fonts\\default")); List <EntityProperties> saves = new List <EntityProperties>(); saves = IOManager.GetAllPlayerDatas(); startPos = new Vector2(MainGame.GAME_WIDTH / 2, 0); int counter = 0; foreach (EntityProperties ep in saves) { var lnklblLoadSave = new LinkLabel(counter++); lnklblLoadSave.AutoSize = true; lnklblLoadSave.Name = "lnklblLoadSave"; lnklblLoadSave.Text = ep.Name + " | " + ep.TimeOfSave; lnklblLoadSave.OnMouseIn += LinkLabel_OnMouseIn; lnklblLoadSave.Selected += (o, e) => { SwitchStateWithFade(new LoadingState(gameRef, StateManager, new GameplayState(gameRef, StateManager, ep))); }; lnklblLoadSave.Effect = ControlEffect.PULSE; var offset = new Vector2(lnklblLoadSave.Width / 2, 0); lnklblLoadSave.Position = startPos - offset; startPos.Y += lnklblLoadSave.Height + 10; loadGameControls.Add(lnklblLoadSave); } var goBack_Load = new LinkLabel(loadGameControls.Count); goBack_Load.Name = "lnklblGoBackLoad"; goBack_Load.Text = "Go Back"; goBack_Load.Effect = ControlEffect.PULSE; goBack_Load.Position = new Vector2(MainGame.GAME_WIDTH / 2 - goBack_Load.Width / 2, MainGame.GAME_HEIGHT - goBack_Load.Height - 100); goBack_Load.OnMouseIn += LinkLabel_OnMouseIn; goBack_Load.Selected += (o, e) => { currentState = State.Menu; }; loadGameControls.Add(goBack_Load); #endregion #region Options Game State #endregion #region Quit State quitControls = new ControlManager(gameRef, Content.Load <SpriteFont>("Fonts\\default")); Label areYouSure1 = new Label(); areYouSure1.Name = "lblAreYouSure?"; areYouSure1.Text = "Are you sure you want to quit?"; areYouSure1.Position = new Vector2(MainGame.GAME_WIDTH / 2 - areYouSure1.SpriteFont.MeasureString( areYouSure1.Text).X / 2, 140); quitControls.Add(areYouSure1); LinkLabel yes = new LinkLabel(1) { Name = "lnklblYes", Text = "Yes" }; yes.Position = new Vector2(areYouSure1.Position.X + 40, areYouSure1.Position.Y + areYouSure1.Height + 50); yes.OnMouseIn += LinkLabel_OnMouseIn; yes.Selected += (o, e) => { gameRef.Exit(); }; yes.Effect = ControlEffect.PULSE; LinkLabel no = new LinkLabel(2) { Name = "lnklblNo", Text = "No" }; no.Position = new Vector2(areYouSure1.Position.X + areYouSure1.Width - no.Width - 40, yes.Position.Y); no.OnMouseIn += LinkLabel_OnMouseIn; no.Selected += (o, e) => { currentState = State.Menu; }; no.Effect = ControlEffect.PULSE; quitControls.Add(yes); quitControls.Add(no); #endregion debugFont = Content.Load <SpriteFont>("Fonts\\version"); }