void closeButton_ButtonPressed(Button sender) { if (game.SaveLevel(nameInput.Text)) game.OpenMenu(); else nameInput.Text += " allready exists."; }
/// <summary> /// Creates a new HighScores view /// </summary> /// <param name="game">The Game instance that will show this view</param> /// <param name="levelName">The name of the level which high scores this view will /// show</param> public HighScores(Game1 game, String levelName) : base(game) { level = levelName.Replace('_', ' '); recordHandler = new RecordHandler(level); recordHandler.LoadRecords(); for (int i = 0; i < recordHandler.Records.Count; i++) { TimeSpan time = TimeSpan.FromMilliseconds(recordHandler.Records[i].Time); scoresList += (i + 1) + " " + recordHandler.Records[i].Name + " " + String.Format("{0:d2}:{1:d2}:{2:d3}", time.Minutes, time.Seconds, time.Milliseconds) + "\n"; } font = game.Content.Load<SpriteFont>("SpriteFont1"); topic = game.Content.Load<Texture2D>("Images/highScores"); topicPos = new Vector2(game.getWidth() * 0.5f - topic.Width * 0.5f, 0); namePos = new Vector2(game.getWidth() * 0.5f - font.MeasureString(level).X * 0.5f, topic.Height); closeButton = new Button("ok", new Vector2(game.getWidth() * 0.7f, game.getHeight() * 0.75f), game.Content); closeButton.Position = new Vector2(game.getWidth() * 0.5f - closeButton.Width * 0.5f, game.getHeight() * 0.78f); closeButton.ButtonPressed += new Action<Button>(closeButton_ButtonPressed); backButton = new Button("back", new Vector2(game.relativeX(10), game.relativeY(430)), game.Content, true); backButton.Width = 70; backButton.Height = 43; backButton.ButtonPressed += new Action<Button>(backButton_ButtonPressed); }
/// <summary> /// Creates a new level saving view /// </summary> /// <param name="game">The Game instance that will show this view</param> public LevelSaver(Game1 game) : base(game) { nameInput = new TextInput("Enter the name of you level", new Vector2(200, 200), game.Content, 400, 50); closeButton = new Button("ok", new Vector2(300, 350), game.Content); closeButton.ButtonPressed += new Action<Button>(closeButton_ButtonPressed); }
/// <summary> /// Creates a new info view /// </summary> /// <param name="game">The Game instance that will show this view</param> public InfoView(Game1 game) : base(game) { maxY = (int)(game.getHeight() * 0.1f); infoText = game.Content.Load<String>(@"infotexts"); font = game.Content.Load<SpriteFont>("SpriteFont1"); textHeight = font.MeasureString(infoText).Y; textPos = new Vector2(game.getWidth() * 0.25f, game.getHeight() * 0.1f); closeButton = new Button("ok", buttonPos, game.Content); closeButton.ButtonPressed += new Action<Button>(closeButton_ButtonPressed); buttonPos = new Vector2(game.getWidth() * 0.5f - closeButton.Width * 0.5f, textPos.Y + textHeight); closeButton.Position = buttonPos; }
/// <summary> /// Creates a new main menu view /// </summary> /// <param name="game">The Game instance that will show this view</param> public Menu(Game1 game) : base(game) { Vector2 pos = new Vector2(game.getWidth() * 0.88f, 0); infoButton = new Button("info", pos, game.Content); infoButton.ButtonPressed += (sender => game.ShowInfo()); if (game.paused && !game.won) { Button tmp = new Button("resume", pos, game.Content); tmp.ButtonPressed += (sender => game.Resume()); buttons.Add(tmp); } Button button = new Button("newGame", pos, game.Content); button.ButtonPressed += (sender => game.ShowLevelSelector(true)); buttons.Add(button); button = new Button("levelEditor", pos, game.Content); button.ButtonPressed += (sender => game.StartLevelEditor()); buttons.Add(button); button = new Button("highScores", pos, game.Content); button.ButtonPressed += (sender => game.ShowLevelSelector(false)); buttons.Add(button); button = new Button("exit", pos, game.Content); button.ButtonPressed += (sender => game.Exit()); buttons.Add(button); int menuHeight = (buttons.Count - 1) * spacing; foreach (Button but in buttons) { menuHeight += but.Height; } pos.Y = game.getHeight() * 0.5f - menuHeight * 0.5f; for (int i = 0; i < buttons.Count; i++) { pos.X = game.getWidth() * 0.5f - buttons[i].Width * 0.5f; buttons[i].Position = pos; pos.Y += (buttons[i].Height + spacing); } }
/// <summary> /// Creates a new view for telling that the player has completed the level /// </summary> /// <param name="game">The Game instance that will show this view</param> public WinView(Game1 game) : base(game) { recordHandler = new RecordHandler(game.currentLevelName); recordHandler.LoadRecords(); closeButton = new Button("ok", new Vector2(0, 0), game.Content); closeButton.ButtonPressed += new Action<Button>(closeButton_ButtonPressed); closeButton.Position = new Vector2(game.getWidth() * 0.5f - closeButton.Width * 0.5f, game.getHeight() * 0.75f); textInput = new TextInput("Enter your name here", new Vector2(game.getWidth() * 0.3f, game.relativeY(200)), game.Content, (int)(game.getWidth() * 0.4f), (int)(game.getHeight() * 0.1f)); font = game.Content.Load<SpriteFont>("SpriteFont2"); placement = recordHandler.GetPlacement((int)(game.finishTime.TotalMilliseconds)); }
void finishButton_ButtonPressed(Button obj) { float x = finishButtonPos.X + finishButton.Width * 0.5f + camPos[0]; float y = finishButtonPos.Y + finishButton.Height * 1.5f + camPos[1]; Add(LevelComponentType.finish, x, y, 0).SetCamPos(camPos); }
void closeButton_ButtonPressed(Button obj) { game.OpenMenu(); if (placement != -1 && textInput.Text != textInput.HintText) { recordHandler.SetRecord(placement, textInput.Text, (int)(game.finishTime.TotalMilliseconds)); recordHandler.SaveRecords(); } }
void button_ButtonPressed(Button sender) { buttons = myButtons; }
void jumpButton_ButtonPressed(Button obj) { float x = jumpButtonPos.X + camPos[0]; float y = jumpButtonPos.Y + jumpButton.Height * 1.0f + camPos[1]; Add(LevelComponentType.jump, x, y, 0).SetCamPos(camPos); }
/// <summary> /// Creates a new level editor. /// </summary> /// <param name="audioPlayer">The AudioPlayer intance /// that playes all the sound effects</param> /// <param name="content">Used ContentManager</param> /// <param name="pSpriteBatch">Used SpriteBatch</param> public LevelEditor(AudioPlayer audioPlayer, ContentManager content) : base(audioPlayer, content) { bikePosTexture = content.Load<Texture2D>("Images/bikePos"); bikePosDestination = bikePosUnActiveDestination; bike.SetInitPos(bikePosDestination.X, bikePosDestination.Y); CreateUI(content); activeZoomButton = unZoomButton; TireFail += new Action<Level>(CloseTesting); HeadFail += new Action<Level>(CloseTesting); Win += new Action<Level>(CloseTesting); }
private void CreateUI(ContentManager content) { grassButton = new Button("grass", grassButtonPos, content, true); grassButton.Width = 100; grassButton.Height = 80; grassButton.ButtonPressed += new Action<Button>(grassButton_ButtonPressed); jumpButton = new Button("jump", jumpButtonPos, content, true); jumpButton.Width = 100; jumpButton.Height = 80; jumpButton.ButtonPressed += new Action<Button>(jumpButton_ButtonPressed); nailButton = new Button("nail", nailButtonPos, content, true); nailButton.Width = 50; nailButton.Height = 80; nailButton.ButtonPressed += new Action<Button>(nailButton_ButtonPressed); finishButton = new Button("finish", finishButtonPos, content, true); finishButton.Width = 100; finishButton.Height = 80; finishButton.ButtonPressed += new Action<Button>(finishButton_ButtonPressed); saveButton = new Button("save", saveButtonPos, content, true); saveButton.Width = 100; saveButton.Height = 43; saveButton.ButtonPressed += new Action<Button>(saveButton_ButtonPressed); backButton = new Button("back", backButtonPos, content, true); backButton.Width = 70; backButton.Height = 43; backButton.ButtonPressed += new Action<Button>(backButton_ButtonPressed); closeButton = new Button("ok", closeButtonPos, content); closeButton.Width = 200; closeButton.Height = 100; closeButton.ButtonPressed += new Action<Button>(closeButton_ButtonPressed); testButton = new Button("test", testButtonPos, content, true); testButton.Width = 88; testButton.Height = 43; testButton.ButtonPressed += new Action<Button>(testButton_ButtonPressed); zoomButton = new Button("zoom", zoomButtonPos, content, true); zoomButton.ButtonPressed += new Action<Button>(zoomButton_ButtonPressed); unZoomButton = new Button("unZoom", zoomButtonPos, content, true); unZoomButton.ButtonPressed += new Action<Button>(unZoomButton_ButtonPressed); }
void unZoomButton_ButtonPressed(Button obj) { zoomStartPos.X = camPos[0]; zoomStartPos.Y = camPos[1]; zoom = 0.5f; camPos[0] -= zoom * 840; camPos[1] -= zoom * 400; activeZoomButton = zoomButton; }
void zoomButton_ButtonPressed(Button obj) { activeZoomButton = unZoomButton; zoom = 1.0f; camPos[0] = zoomStartPos.X; camPos[1] = zoomStartPos.Y; }
void testButton_ButtonPressed(Button obj) { bike.Reset(); zoomStartPos.X = camPos[0]; zoomStartPos.Y = camPos[1]; testing = true; EnableControl(); audioPlayer.PlayMotor(); }
void saveButton_ButtonPressed(Button obj) { if (Ready != null) Ready(true); bike.Reset(); testing = true; isReady = true; }
void nailButton_ButtonPressed(Button obj) { float x = nailButtonPos.X + nailButton.Width * 0.5f + camPos[0]; float y = nailButtonPos.Y + nailButton.Height * 1.5f + camPos[1]; Add(LevelComponentType.nail, x, y, 0).SetCamPos(camPos); }
void backButton_ButtonPressed(Button sender) { if (level != "level1" && level != "level2" && level != "level3") game.ShowMyLevelsSelector(false); else game.ShowLevelSelector(false); }
void tmpButton_ButtonLongPressed(Button sender) { deleteCandidate = sender.Name.Replace(' ', '_'); if (buttons == myButtons) deleteQuestion = "Do you want to delete " + sender.Name + "?"; }
void closeButton_ButtonPressed(Button sender) { game.OpenMenu(); }
void yesButton_ButtonPressed(Button sender) { DeleteLevel(sender.Name); }
void backButton_ButtonPressed(Button sender) { if (buttons == preDefinedButtons) game.OpenMenu(); else { speed = 0; buttons = preDefinedButtons; } }
void closeButton_ButtonPressed(Button obj) { camPos[0] = zoomStartPos.X; camPos[1] = zoomStartPos.Y; zoom = 1; testing = false; audioPlayer.StopMotor(); }
void noButton_ButtonPressed(Button sender) { deleteCandidate = ""; deleteQuestion = ""; }
void grassButton_ButtonPressed(Button obj) { float x = grassButtonPos.X + grassButton.Width * 0.5f + camPos[0]; float y = grassButtonPos.Y + grassButton.Height * 1.5f + camPos[1]; Add(LevelComponentType.grass, x, y, 0).SetCamPos(camPos); }
void tmpButton_ButtonPressed(Button sender) { if (newGame) { if (buttons == preDefinedButtons) game.NewGame(Convert.ToInt32(sender.Name.Substring(sender.Name.Length - 1))); else if (Math.Abs(speed) < 1) game.NewGame(sender.Name); } else { if (Math.Abs(speed) < 1) game.ShowHighScores(sender.Name); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); audioPlayer = new AudioPlayer(Content); level = new Level(1, audioPlayer, this.Content); level.HeadFail += new Action<Level>(HeadFail); level.TireFail += new Action<Level>(TireFail); level.Win += new Action<Level>(Win); background = this.Content.Load<Texture2D>("Images/sky"); font = this.Content.Load<SpriteFont>("SpriteFont3"); view = new SplashScreen(this); optionsButton = new Button("options", new Vector2(getWidth() * 0.015f, getHeight() * 0.89f), this.Content); optionsButton.ButtonPressed += (sender => Pause()); float aspect = (float)optionsButton.Width / (float)optionsButton.Height; optionsButton.Height = (int)(0.1f * getHeight()); optionsButton.Width = (int)(aspect * optionsButton.Height); exitButton = new Button("exit", new Vector2(getWidth() * 0.89f, getHeight() * 0.88f), this.Content); exitButton.ButtonPressed += (sender => Exit()); aspect = (float)exitButton.Width / (float)exitButton.Height; exitButton.Height = (int)(0.1f * (float)getHeight()); exitButton.Width = (int)(aspect * (float)exitButton.Height); leftButton = new Button("left", new Vector2(10, 20), this.Content, true); leftButton.ButtonPressed += (sender => level.leanBikeBackwards()); leftButton.Height = 70; rightButton = new Button("right", new Vector2(relativeX(735), relativeY(20)), this.Content, true); rightButton.Height = 70; rightButton.ButtonPressed += (sender => level.leanBikeForwards()); clockPos = new Vector2(0.45f * getWidth(), 0.89f * getHeight()); }
/// <summary> /// Creates a new level selecting view /// </summary> /// <param name="game">The Game instance that will show this view</param> /// <param name="pNewGame">true if the level is going to be /// selected for the new game, false otherwise</param> /// <param name="myLevelsPage">true if the view is wanted to /// be opened on the custom level page</param> public LevelSelector(Game1 game, bool pNewGame, bool myLevelsPage) : base(game) { maxY = (int)(game.getHeight() * 0.1f); newGame = pNewGame; float screenXMiddle = game.getWidth() / 2; int spacing = 90; int top = 70; Button button = new Button("level1", Vector2.Zero, game.Content); button.ButtonPressed += new Action<Button>(tmpButton_ButtonPressed); preDefinedButtons.Add(button); button.Position = new Vector2(screenXMiddle - button.Width * 0.5f, spacing * (preDefinedButtons.Count-1) + top); button = new Button("level2", Vector2.Zero, game.Content); button.ButtonPressed += new Action<Button>(tmpButton_ButtonPressed); preDefinedButtons.Add(button); button.Position = new Vector2(screenXMiddle - button.Width * 0.5f, spacing * (preDefinedButtons.Count-1) + top); button = new Button("level3", Vector2.Zero, game.Content); button.ButtonPressed += new Action<Button>(tmpButton_ButtonPressed); preDefinedButtons.Add(button); button.Position = new Vector2(screenXMiddle - button.Width * 0.5f, spacing * (preDefinedButtons.Count-1) + top); button = new Button("myLevels", Vector2.Zero, game.Content); button.ButtonPressed += new Action<Button>(button_ButtonPressed); preDefinedButtons.Add(button); button.Position = new Vector2(screenXMiddle - button.Width * 0.5f, spacing * (preDefinedButtons.Count-1) + top); IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication(); String[] fileNames = savegameStorage.GetFileNames(); for (int i = 0; i < fileNames.Length; i++) { String[] pieces = fileNames[i].Split('.'); if (pieces.Length > 1 && pieces[1] == "lvl") { var tmpButton = new Button(pieces[0].Replace('_', ' '), Vector2.Zero, game.Content, false); tmpButton.ButtonPressed += new Action<Button>(tmpButton_ButtonPressed); tmpButton.ButtonLongPressed += new Action<Button>(tmpButton_ButtonLongPressed); myButtons.Add(tmpButton); tmpButton.Position = new Vector2(screenXMiddle - tmpButton.Width * 0.5f, 60 * (myButtons.Count)); } } minY = -myButtons.Count * 60 + (int)(0.5f * game.getHeight()); yesButton = new Button("Yes", new Vector2(game.relativeX(290), game.relativeY(280)), game.Content, false); yesButton.ButtonPressed += new Action<Button>(yesButton_ButtonPressed); noButton = new Button("No", new Vector2(game.relativeX(490), game.relativeY(280)), game.Content, false); noButton.ButtonPressed += new Action<Button>(noButton_ButtonPressed); backButton = new Button("back", new Vector2(game.relativeX(10), game.relativeY(430)), game.Content, true); backButton.ButtonPressed += new Action<Button>(backButton_ButtonPressed); backButton.Width = 70; backButton.Height = 43; if (myLevelsPage) buttons = myButtons; else buttons = preDefinedButtons; font = game.Content.Load<SpriteFont>("SpriteFont1"); }
void backButton_ButtonPressed(Button obj) { if (Ready != null) Ready(false); }