public override void Initialize() { base.Initialize(); this.FadeOutImmediately(); this.AddSprite("Content/menus/menu-screen.jpg"); Sprite title = this.AddSprite("Content/credits/credits.png"); // Align with top of the center area, plus our height, plus 8-16 padding title.Y = 160 + title.Texture.Height + 16; const int SPACE_BETWEEN_IMAGES = 4; const int FULL_IMAGE_SIZE = 128; const int ACTUAL_IMAGE_SIZE = FULL_IMAGE_SIZE - 2; // 2 for border Point TOP_LEFT_OF_IMAGE_AREA = new Point(-325 + FULL_IMAGE_SIZE / 2, 200 - FULL_IMAGE_SIZE / 2); // Make a 5x3 grid of sprites // See procurement plan for first 13; last two are button/titlescreen string[] images = new string[] { "titlescreen.jpg", "story-1.jpg", "story-2.jpg", "metal-background.jpg", "metal-under-board.jpg", "eroded-metal.jpg", "extruded-metal.jpg", "metal-gate.jpg", "stripes.jpg", "speaker-icon.png", "speaker-icon.png", "speaker-icon.png", "speaker-icon.png", "speaker-icon.png", "speaker-icon.png" }; int imageIndex = 0; foreach (string imageFileName in images) { TowerSprite image = new TowerSprite(this, "Content/Credits/" + imageFileName); // Shrink to 126x126 image.RightTextureCoordinate = (ACTUAL_IMAGE_SIZE / image.Texture.Width); image.BottomTextureCoordinate = (ACTUAL_IMAGE_SIZE / image.Texture.Height); FlatRedBall.Math.Geometry.AxisAlignedRectangle border = this.AddAxisAlignedRectangle(ACTUAL_IMAGE_SIZE / 2, ACTUAL_IMAGE_SIZE / 2); image.AttachTo(border, true); // Can't move image, it's bound to border border.X = TOP_LEFT_OF_IMAGE_AREA.X + (imageIndex % 5 * ((SPACE_BETWEEN_IMAGES + ACTUAL_IMAGE_SIZE))); border.Y = TOP_LEFT_OF_IMAGE_AREA.Y - ((imageIndex / 5) * (SPACE_BETWEEN_IMAGES + ACTUAL_IMAGE_SIZE)); this._imageToImageIndex[image] = imageIndex; image.OnMouseEnter += () => { int index = this._imageToImageIndex[image]; this._infoText.DisplayText = this._captions[index]; if (index >= 9) { // Sound file AudioManager.Instance.PlaySound(CoreModel.SOUND_FILE_PATH + this._soundFiles[index - 9]); } }; imageIndex++; } Sprite infoWindow = this.AddSprite("Content/Credits/credits-info-window.png"); infoWindow.Y = -219; _infoText = new TowerText(this.AddText("Some items used with the implicit permission of their authors. Hover over items for details.")); _infoText.Y = infoWindow.Y; Tower3SliceButton backButton = new Tower3SliceButton(this, "Back", "bubble", 18, -5); backButton.X = 340; backButton.Y = -275; backButton.Click += () => { this.FadeOutComplete += (fadeType) => { MoveToScreen(typeof(MainMenuScreen)); }; this.FadeOut(); }; this.FadeIn(); }
public void RemoveResource(TowerText t) { this.RemoveText(t.BaseText); this.RemoveText(t.EffectText); }
public override void Initialize() { this.FadeOutImmediately(); this.AddSprite("Content/Menus/menu-screen.jpg"); Sprite title = this.AddSprite("Content/Menus/select-level.png"); const int VERTICAL_OFFSET = 160; const int HORIZONTAL_OFFSET_FROM_SCREEN = 30; const int VERTICAL_PADDING_BETWEEN_ROWS = 10; int SQUARE_WIDTH = 0; int SQUARE_HEIGHT = 0; // Start Y of levels, plus our height, plus 8-16 padding title.Y = VERTICAL_OFFSET + title.Texture.Height + 16; int currentLevel = CoreModel.Instance.MaxLevelReached; // 12 normal levels for (int i = 1; i <= CoreModel.NUMBER_OF_LEVELS; i++) { TowerSprite square; if (i <= currentLevel) { square = new TowerSprite(this, "Content/Menus/normal-level.png"); } else { square = new TowerSprite(this, "Content/Menus/inactive-level.png"); } SQUARE_WIDTH = square.Width; SQUARE_HEIGHT = square.Height; square.X = -300 + HORIZONTAL_OFFSET_FROM_SCREEN + (((i - 1) % 3) * square.Width); square.Y = VERTICAL_OFFSET - (((i - 1) / 3) * (VERTICAL_PADDING_BETWEEN_ROWS + square.Height) ); square.Click += new TowerSprite.ClickedDelegate(levelSquare_Click); TowerText t = new TowerText(this.AddText(i.ToString())); t.X = square.X; if (i <= currentLevel) { t.Colour(0, 0, 0); t.Y = square.Y + 3; } else { t.Colour(255, 255, 255); t.Y = square.Y - 10; } t.Z = square.Z + 1; t.AttachTo(square, true); } currentLevel -= CoreModel.NUMBER_OF_LEVELS; // 12 puzzle levels for (int i = 1; i <= CoreModel.NUMBER_OF_LEVELS; i++) { TowerSprite square; if (i <= currentLevel) { square = new TowerSprite(this, "Content/Menus/puzzle-level.png"); } else { square = new TowerSprite(this, "Content/Menus/inactive-level.png"); } square.X = (square.Width / 2) + (((i - 1) % 3) * square.Width); square.Y = VERTICAL_OFFSET - (((i - 1) / 3) * (VERTICAL_PADDING_BETWEEN_ROWS + square.Height)); square.Click += new TowerSprite.ClickedDelegate(levelSquare_Click); TowerText t = new TowerText(this.AddText(string.Format("P{0}", i))); t.X = square.X; if (i <= currentLevel) { t.Colour(0, 0, 0); t.Y = square.Y + 3; } else { t.Colour(255, 255, 255); t.Y = square.Y - 10; } t.Z = square.Z + 1; t.AttachTo(square, true); } Tower3SliceButton backButton = new Tower3SliceButton(this, "Back", "bubble", 18, -5); backButton.X = 340;//;HORIZONTAL_OFFSET_FROM_SCREEN + (1.25f * SQUARE_WIDTH); backButton.Y = -275; //;VERTICAL_OFFSET - (4 * SQUARE_HEIGHT) - (6 * VERTICAL_PADDING_BETWEEN_ROWS); backButton.Click += new TowerBaseButton.ClickedDelegate(backButton_Click); if (CoreModel.Instance.MaxLevelReached >= CoreModel.AVALANCHE_LEVEL) { TowerSprite avalanche = new TowerSprite(this, "Content/Menus/avalanche-level.png"); avalanche.X = -325 + HORIZONTAL_OFFSET_FROM_SCREEN + (0.5f * SQUARE_WIDTH); avalanche.Y = VERTICAL_OFFSET - (4 * SQUARE_HEIGHT) - (6 * VERTICAL_PADDING_BETWEEN_ROWS); avalanche.Click += new TowerSprite.ClickedDelegate(avalanche_Click); TowerText avalancheText = new TowerText(this.AddText("Avalanche")); avalancheText.X = avalanche.X; avalancheText.Y = avalanche.Y + 5; avalancheText.Z = avalanche.Z + 1; avalancheText.Colour(0, 0, 0); avalancheText.AttachTo(avalanche, true); TowerSprite trickle = new TowerSprite(this, "Content/Menus/trickle-level.png"); trickle.X = avalanche.X + SQUARE_WIDTH + 50; trickle.Y = avalanche.Y; trickle.Click += new TowerSprite.ClickedDelegate(trickle_Click); TowerText trickleText = new TowerText(this.AddText("Trickle")); trickleText.X = trickle.X; trickleText.Y = trickle.Y + 9; trickleText.Z = trickle.Z + 1; trickleText.AttachTo(trickle, true); } base.Initialize(); this.FadeIn(); }
public override void Activity(bool firstTimeCalled) { base.Activity(firstTimeCalled); removeDeadSprites(); removeDeadText(); undoColourOperationsOnFadedInTiles(); if (model.GameState == CoreModel.GameStates.GameOver) { if (InputManager.Mouse.ButtonPushed(Mouse.MouseButtons.LeftButton)) { this.FadeOutComplete += new FadeEventDelegate(CoreGameScreen_MoveToMainMenuFadeOutComplete); this.FadeOut(); } } else if (model.GameState == CoreModel.GameStates.GameComplete) { if (InputManager.Mouse.ButtonPushed(Mouse.MouseButtons.LeftButton)) { this.FadeOut(); } } else { if (this._tutorialPanelShowing == false) { Tile t = findTileMouseIsOver(); if (InputManager.Mouse.ButtonPushed(Mouse.MouseButtons.LeftButton)) { // Left mouse button pushed - down this frame, not down last frame. if (t != null && t.IsEmpty()) { t.Atom = model.NextAtom; model.PickNextAtom(); this.drawTile(t); AudioManager.Instance.PlaySound(CoreModel.SOUND_FILE_PATH + "atom-placed.mp3"); this.drawNextAtom(); this.updateAtomsLeftOrPointsCounter(); BackgroundWorker reactionComputingThread = new BackgroundWorker(); reactionComputingThread.DoWork += new DoWorkEventHandler(reactionComputingThread_DoWork); reactionComputingThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(reactionComputingThread_RunWorkerCompleted); reactionComputingThread.RunWorkerAsync(t); } } else { if (t != null && !t.IsEmpty()) { if (this._startHoverTime == DateTime.MinValue) { this._startHoverTime = DateTime.Now; } else { TimeSpan time = (DateTime.Now - this._startHoverTime); if (time.TotalMilliseconds >= 500) { infoPanel.Show(t.Atom); } } } else if (InputManager.Mouse.IsOn3D(this._nextAtom, false)) { infoPanel.Show(model.NextAtom); } else { infoPanel.Hide(); this._startHoverTime = DateTime.MinValue; } } if (model.IsLevelOver()) { if (model.CurrentLevel != CoreModel.AVALANCHE_LEVEL && model.CurrentLevel != CoreModel.TRICKLE_LEVEL) { this.FadeOutHalf(); } else { // Show random "good work" message, and add 1000 points string message = this._greatWorkMessages[model.RandomGenerator.Next() % this._greatWorkMessages.Length] + " (+1000 points)"; model.Points += 1000; this.updateAtomsLeftOrPointsCounter(); AudioManager.Instance.PlaySound(CoreModel.SOUND_FILE_PATH + "ulimited-mode-atoms-cleared.mp3"); TowerText messageText = new TowerText(this.AddText(message)); messageText.YVelocity = 15; messageText.AlphaRate = -0.05f; messageText.Scale = 48; messageText.AddShadow(); messageText.Colour(255, 225, 64); this._reactionText.Add(messageText.BaseText); this._reactionText.Add(messageText.EffectText); // Generate 40 tiles on the board. int numGenerated = 0; while (numGenerated < 40) { IList<Tile> tiles = model.SpewOutAtomsFromMachine(); numGenerated += tiles.Count; foreach (Tile tile in tiles) { drawTile(tile); fadeTileIn(tile); } } } } } } }
void reactionComputingThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (!e.Cancelled) { // Don't let multiple threads eat atoms. Nor let two check for two reactions at // the same time with an overlapping atom. lock (CoreModel.Instance) { IList<Tile> tilesInReaction = e.Result as IList<Tile>; // Final check if someone ate our atoms in-between and unbalanced us. if (tilesInReaction != null && tilesInReaction.Count > 0 && tilesInReaction.Sum(t => t.Atom.IonCharge) == 0) { // Add points. Not displayed outside of Avalanche and Trickle, oh well. model.Points += tilesInReaction.Sum(t => t.Atom.Points); this.updateAtomsLeftOrPointsCounter(); StringBuilder equation = new StringBuilder(); tilesInReaction = tilesInReaction.OrderBy(tile => tile, this._orderTilesByAtomNameComparer).ToList(); String previousElement = tilesInReaction[0].Atom.Element; String currentElement = ""; int quantity = 0; Tile finalTile = tilesInReaction[tilesInReaction.Count - 1]; // Equations only on non-Avalanche and non-Trickle mode. foreach (Tile reactionTile in tilesInReaction) { // For some reason, these appear at high levels in large chains. // HACK: don't display it. if (reactionTile.IsEmpty()) { continue; } reactionTile.AtomSprite.ColorOperation = ColorOperation.Add; reactionTile.AtomSprite.RedRate = 3f; reactionTile.AtomSprite.GreenRate = 3f; reactionTile.AtomSprite.BlueRate = 3f; this._reactingTiles.Add(reactionTile); // Print out something nice, like 2Fl + H + Li. // Or, in Avalanche/Trickle, 1 + 16 + 9. if (model.CurrentLevel != CoreModel.AVALANCHE_LEVEL && model.CurrentLevel != CoreModel.TRICKLE_LEVEL) { currentElement = reactionTile.Atom.Element; if (previousElement == currentElement) { quantity++; } else if (previousElement != currentElement) { // Print nothing if quantity = 1, i.e. we like to // see "H + Cl" not "1H + 1Cl" equation.Append(string.Format("{0}{1} + ", (quantity > 1 ? quantity.ToString() : ""), previousElement)); // 1, not 0, because we won't do this elsewhere; fixes bug where // Fl-Fl-H-H becomes 2Fl + H. quantity = 1; } previousElement = reactionTile.Atom.Element; } else { equation.Append(string.Format("{0} + ", reactionTile.Atom.Points)); } reactionTile.Empty(); // Prevent quick clickers from chaining } // Dump of last element if (model.CurrentLevel != CoreModel.AVALANCHE_LEVEL && model.CurrentLevel != CoreModel.TRICKLE_LEVEL) { equation.Append(string.Format("{0}{1} + ", (quantity > 1 ? quantity.ToString() : ""), previousElement)); } if (equation.Length >= 3) { // Trickle mode bug? equation.Remove(equation.Length - 3, 3); // trailing " + " } TowerText equationText = new TowerText(this.AddText(equation.ToString())); equationText.YVelocity = 15; equationText.AlphaRate = -0.1f; equationText.Scale = 24; equationText.AddShadow(); equationText.InsertNewLines(SpriteManager.Camera.Width); AudioManager.Instance.PlaySound(CoreModel.SOUND_FILE_PATH + "reaction.mp3"); this._reactionText.Add(equationText.BaseText); this._reactionText.Add(equationText.EffectText); } if (model.CurrentLevel >= CoreModel.FIRST_PUZZLE_LEVEL && model.CurrentLevel <= CoreModel.LAST_PUZZLE_LEVEL && model.NextAtom == Atom.NONE && !model.IsLevelOver()) { // Puzzle mode, out of atoms; game over. model.SignalGameOver(); } } } }
void model_GameOver() { if (model.CurrentLevel != CoreModel.AVALANCHE_LEVEL && model.CurrentLevel != CoreModel.TRICKLE_LEVEL) { this.FadeOutComplete -= CoreGameScreen_LevelCompleteBlackOutComplete; } this.FadeInComplete += new FadeEventDelegate(CoreGameScreen_ReturnToMainMenuFadeInComplete); this.FadeOutHalf(); TowerText t = new TowerText(this.AddText("Game Over!")); t.AddShadow(); t.Scale = 72; // Go on TOP of the shadow. t.Z = this.GetTopZValueAndMoveFadeToTop() + 1; string returnToMainMenuText = ""; if (model.CurrentLevel == CoreModel.AVALANCHE_LEVEL || model.CurrentLevel == CoreModel.TRICKLE_LEVEL) { returnToMainMenuText += "(You scored " + model.Points + " points.) "; if (model.Points >= 25000) { model.FeatManager.GrantFeat(@"z00KSNDLsTvhZ1oK-8WjmdcEWRE2fF6zKCiARZp_1laXXOXd_Q1IQq_STqr4VwAe_TzKaivRDOhQdyoxiwo_HPtOOuIg9gdW79F6wy6CWjDg9tE-o7ntFhVXw_K-MgU6"); } } returnToMainMenuText += "Click to return to the main menu."; TowerText t2 = new TowerText(this.AddText(returnToMainMenuText)); t2.AddShadow(); t2.Y = t2.Y - (t.Scale / 2) - 8; // Below the above text. Pad 8px. t2.Scale = 24; t2.Z = t.Z; this.ManageForGarbageCollection(t); this.ManageForGarbageCollection(t2); }
void CoreGameScreen_LevelCompleteBlackOutComplete(TowerScreen.FadeOutMode mode) { TowerText levelUp = new TowerText(this.AddText(string.Format("Level complete! on to level {0} ...", model.CurrentLevel + 1))); levelUp.AddShadow(); levelUp.AlphaRate = -0.25f; levelUp.Scale = 44; this._reactionText.Add(levelUp.BaseText); this._reactionText.Add(levelUp.EffectText); // Detect game completion if (model.CurrentLevel == CoreModel.FIRST_PUZZLE_LEVEL - 1 && model.GameState != CoreModel.GameStates.GameComplete) { // Completed normal mode. Woohoo! AudioManager.Instance.PlaySound(CoreModel.SOUND_FILE_PATH + "machine-powers-down.mp3"); this.FadeInComplete -= CoreGameScreen_LevelCompleteBlackOutComplete; this.FadeOutComplete += new FadeEventDelegate(CoreGameScreen_MoveToMainMenuFadeOutComplete); _gameComplete = this.AddSprite("Content/Story/story-mode-complete.jpg"); _gameComplete.Z = this.GetTopZValueAndMoveFadeToTop() + 1; model.SetGameStateToGameComplete(); model.FeatManager.GrantFeat(@"mrv9c_D9NCZXnKzNUMCIXP-cqZI4ZzWld6CXZjHLeEZAKLKnvoBxsxxuUJ98xtzenJJTB8nLzXF3nwTMTMXnetEQxDDu_H53A_AB1SzZaEp8v6cc4fPfSqYUnCJ4u1T6"); } if (model.CurrentLevel == CoreModel.LAST_PUZZLE_LEVEL && model.GameState != CoreModel.GameStates.GameComplete) { // Completed puzzle mode. Woohoo! AudioManager.Instance.PlaySound(CoreModel.SOUND_FILE_PATH + "machine-powers-down.mp3"); this.FadeInComplete -= CoreGameScreen_LevelCompleteBlackOutComplete; this.FadeOutComplete += new FadeEventDelegate(CoreGameScreen_MoveToMainMenuFadeOutComplete); _gameComplete = this.AddSprite("Content/Story/game-complete.jpg"); _gameComplete.Z = this.GetTopZValueAndMoveFadeToTop() + 1; model.FeatManager.GrantFeat(@"nS9N7CWfMXA3GNRjT8Wf868wqK6MT_s7k5iS7h8txeeLl6TRTOvKcRAuobehkekHGLWXafTNAgcstbvcPamDnRHiKpBuG0H2YXANVGCE6GsajGep4tJ2SONyeVWGNLCa"); model.SetGameStateToGameComplete(); } else { // Regular mode. Not Avalanche or Trickle. model.MoveToNextLevel(); performPerLevelPreSetup(); performPerLevelPostSetup(); this.FadeIn(); } model.SaveLevelReached(); }
public override void Initialize() { model.SetGameStateToNormal(); this.FadeOutImmediately(); this.initializeLevelTutorials(); this.removeOldSprites(); model.CreateBoard(); this._levelText = new TowerText(this.AddText(string.Format("Puzzle: {0}", model.CurrentLevel))); performPerLevelPreSetup(); Sprite background = this.AddSprite("Content/metal-background.jpg"); Sprite statusBar = this.AddSprite("Content/status-bar.png"); statusBar.Y = -275; // bottom of the screen = 300, half us = 25 Sprite board = this.AddSprite("Content/metal-board.jpg"); board.Y = 25; Sprite frieze = this.AddSprite("Content/frieze.png"); frieze.Y = 25; #region status-bar this._levelText.X = -375; this._levelText.Y = statusBar.Y; this._levelText.HorizontalAlignment = FlatRedBall.Graphics.HorizontalAlignment.Left; this._levelText.Colour(0, 0, 0); this._levelText.Scale = 24; if (model.CurrentLevel >= CoreModel.FIRST_PUZZLE_LEVEL && model.CurrentLevel <= CoreModel.LAST_PUZZLE_LEVEL) { // Puzzle mode; add atom counter this._atomOrPointCountText = new TowerText(this.AddText(string.Format("Atoms Left: {0}", model.Toolbox.NumAtomsLeft))); this._atomOrPointCountText.Scale = this._levelText.Scale; this._atomOrPointCountText.Y = this._levelText.Y; this._atomOrPointCountText.X = this._levelText.X + 350; this._atomOrPointCountText.Colour(0, 0, 0); } else if (model.CurrentLevel == CoreModel.AVALANCHE_LEVEL || model.CurrentLevel == CoreModel.TRICKLE_LEVEL) { this._atomOrPointCountText = new TowerText(this.AddText(string.Format("Points: {0}", model.Points))); this._atomOrPointCountText.Scale = this._levelText.Scale; this._atomOrPointCountText.Y = this._levelText.Y; this._atomOrPointCountText.X = this._levelText.X + 300; this._atomOrPointCountText.Colour(0, 0, 0); } TowerText nextText = new TowerText(this.AddText("Next: ")); nextText.X = 300; nextText.Y = statusBar.Y; nextText.Colour(0, 0, 0); nextText.Scale = this._levelText.Scale; this._nextAtom = this.AddSprite("Content/Atoms/" + model.NextAtom.Element + ".png"); _nextAtom.X = nextText.X + 50; _nextAtom.Y = nextText.Y; this._nextAtomText = new TowerText(this.AddText(model.NextAtom.Element)); _nextAtomText.X = _nextAtom.X; _nextAtomText.Y = _nextAtom.Y; this._timeText = new TowerText(this.AddText("Time: ∞")); this._timeText.X = this._nextAtomText.X - 200; this._timeText.Y = statusBar.Y; this._timeText.Colour(0, 0, 0); this._timeText.Scale = this._levelText.Scale; #endregion for (int x = 0; x < Model.CoreModel.BOARD_WIDTH; x++) { for (int y = 0; y < Model.CoreModel.BOARD_HEIGHT; y++) { Sprite tile = this.AddSprite("Content/tile.png"); tile.X = (x * 50) - CENTER_OF_BOARD_X; tile.Y = (y * -50) + CENTER_OF_BOARD_Y; tile.Alpha = 0.75f; model.Board[x, y].Sprite = tile; } } infoPanel.InitializeToScreen(this); // Clear out old event handlers because they carry over model.ClearEventHandlers(); model.MachineCreatesAtoms += new DeenGames.Valence.Model.CoreModel.MachineCreatesAtomsDelegate(model_MachineCreatesAtoms); model.MachineTicks += new DeenGames.Valence.Model.CoreModel.MachineTicksDelegate(model_MachineTicks); model.GameOver += new DeenGames.Valence.Model.CoreModel.GameOverOccuredDelegate(model_GameOver); // Avalanche and Trickle mode NEVER end. Evar. if (model.CurrentLevel != CoreModel.AVALANCHE_LEVEL && model.CurrentLevel != CoreModel.TRICKLE_LEVEL) { this.FadeOutComplete += new FadeEventDelegate(CoreGameScreen_LevelCompleteBlackOutComplete); } performPerLevelPostSetup(); this._levelText.DisplayText = model.LevelName; this.updateAtomsLeftOrPointsCounter(); this.FadeIn(); base.Initialize(); }