private void Awake() { if (instance == null) { instance = this; } }
/// <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); // TODO: use this.Content to load your game content here Shared.Stage = new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); // instantiate all scenes startScene = new StartScene(this, spriteBatch); this.Components.Add(startScene); actionScene = new ActionScene(this, spriteBatch); this.Components.Add(actionScene); helpScene = new HelpScene(this, spriteBatch); this.Components.Add(helpScene); highScoreScene = new HighScoreScene(this, spriteBatch); this.Components.Add(highScoreScene); aboutScene = new AboutScene(this, spriteBatch); this.Components.Add(aboutScene); gameOverScene = new GameOverScene(this, spriteBatch); this.Components.Add(gameOverScene); // show start scene startScene.Show(); }
public static void Main() { ConsoleWindow.CustomizeConsole(); IDrawManager drawManager = new ConsoleDrawManager(); IBorder border = new Border( new Point(middleConsoleWidth - 25, middleConsoleHeight - 15), new Point(middleConsoleWidth + 25, middleConsoleHeight + 15)); IFoodFactory foodFactory = new FoodFactory(new Random(), border); IScene pauseScene = new PauseScene(drawManager); IScene infoScene = new InfoScene(drawManager); IScene gameOverScene = new GameOverScene ( drawManager, new PlayAgainButton(new Point(middleConsoleWidth, 30)), new MenuButton(new Point(middleConsoleWidth, 35)) ); IButton playButton = new PlayButton ( new Point(middleConsoleWidth, 30), new Point(border.TopLeftCorner.CoordinateX + 2, border.TopLeftCorner.CoordinateY + 2), drawManager, foodFactory, border, pauseScene, gameOverScene); IScene startMenu = new StartMenuScene(drawManager, playButton, new InfoButton(new Point(middleConsoleWidth, 35), infoScene), new ExitButton(new Point(middleConsoleWidth, 40))); Engine engine = new Engine(startMenu); engine.Run(); }
private void ResetGame() { worldScene?.Dispose(); worldScene = new WorldScene(GameplayScene.InitialGameState) .OnPause(() => { PauseScene(worldScene); }) .OnGetIntoShip((gameState) => { shipScene.ResetCamera(); SetNextScene(shipScene.WithGameState(gameState)); }) .OnGameOver(() => { SoundManager.Play(SoundManager.Death); SetNextScene(gameOverScene); }); shipScene = new ShipScene(GameplayScene.InitialGameState) .OnGoToWater((gameState) => { SoundManager.Play(SoundManager.Metal); worldScene.ResetCamera(); SetNextScene(worldScene.WithGameState(gameState)); }) .OnPause(() => { PauseScene(shipScene); }); gameOverScene = new GameOverScene() .WithPreRender(worldScene.Render) .OnGoToStartScreen(() => { SetNextScene(this.startMenu); ResetGame(); }); }
private void OnGameOver(object sender, EventArgs e) { var levelScene = sender as LevelScene; UnregisterLevelSceneHandlers(levelScene); var gameOverScene = new GameOverScene(); gameOverScene.SceneSkipped += OnGameOverSceneSkipped; StartTransitionToNextScene(gameOverScene); }
/// <summary> /// Assets are loaded in from the CreateResources method /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void OnCreateResources(CanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args) { _screenSize = new Vector2((float)Cvs.Size.Width, (float)Cvs.Size.Height); //set parent canvas for image manager ImageManager.ParentCanvas = sender; //Animated Hero Images await ImageManager.AddImage("Hero_Up_1", @"Assets/Hero_Up_1.gif"); await ImageManager.AddImage("Hero_Right_1", @"Assets/Hero_Right_1.gif"); await ImageManager.AddImage("Hero_Left_1", @"Assets/Hero_Left_1.gif"); await ImageManager.AddImage("Hero", @"Assets/Hero.gif"); //Minion Images await ImageManager.AddImage("MinionLeft", @"Assets/MinionLeft.png"); await ImageManager.AddImage("MinionRight", @"Assets/MinionRight.png"); // await ImageManager.AddImage("Arrow", @"Assets/Arrow.png"); await ImageManager.AddImage("Boss", @"Assets/BossEdit.png"); await ImageManager.AddImage("BossHurt", @"Assets/Boss_Hurt.png"); await ImageManager.AddImage("Title", @"Assets/Evilution.png"); await ImageManager.AddImage("GameOver", @"Assets/GameOver.png"); await AudioManager.AddAudio("Generic Title Scene", "TitleTheme.mp3"); await AudioManager.AddAudio("Main Game Scene", "BattleTheme.mp3"); await AudioManager.AddAudio("Game Over Scene", "GameOver.mp3"); // set up the scene var ts = new TitleScene((int)this._screenSize.X, (int)this._screenSize.Y); StoryBoard.AddScene(ts); StoryBoard.CurrentScene = ts; //create scenes var game_scene = new GameScene((int)this._screenSize.X, (int)this._screenSize.Y); var game_over_scene = new GameOverScene((int)this._screenSize.X, (int)this._screenSize.Y); //add scenes to storyboard StoryBoard.AddScene(game_scene); StoryBoard.AddScene(game_over_scene); }
public void GoombaIsCoinboxTest() { var game = new GameObject("Mario"); ResourceManager.Instance.LoadSpriteSheetFromFile("sm-mario-sprites", @"resources\sm-mario-sprites.png", 10); ResourceManager.Instance.LoadFontFromFile("arial", @"resources\arial.ttf"); // gets current level file var levelFilePath = Directory.GetCurrentDirectory() + @"\leveldata.xml"; var levelText = File.ReadAllText(levelFilePath); var levelXml = XDocument.Parse(levelText); var rows = levelXml.XPathSelectElements("//row"); // replaces all goombas (50) with coinboxes (3) foreach (var row in rows.Where(row => row.Value.Contains("50"))) { row.Value = row.Value.Replace("50", "3"); } // saves new temporary level file var tempLevelFilePath = Path.GetTempFileName(); File.WriteAllText(tempLevelFilePath, levelXml.ToString()); var s = new MainScene(game, tempLevelFilePath) { Name = "play" }; game.SceneManager.AddScene(s); var s2 = new StartScene(game) { Name = "start" }; game.SceneManager.AddScene(s2); var s3 = new GameOverScene(game) { Name = "gameover" }; game.SceneManager.AddScene(s3); game.SceneManager.StartScene("play"); }
private void restartRenderers() { if (this.galaxyRenderer != null) { this.galaxyRenderer.Deactivate(); } this.galaxyRenderer = new GalaxyScene(this, () => postDelayedEvent(showMainMenu)); this.galaxyRenderer.SwitchPlayer(this.currentPlayer); this.bombardRenderer = new BombardmentScene(); this.systemRenderer = new StarSystemScene(switchToGalaxyView); this.combatRenderer = new SpaceCombatScene(); this.gameOverRenderer = new GameOverScene(); switchToGalaxyView(); }
/// <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. this.spriteBatch = new SpriteBatch(GraphicsDevice); Services.AddService(typeof(SpriteBatch), spriteBatch); this.scene1 = new OpeningScene(this); this.scene2 = new InstructionsScene(this, scene1); this.scene4 = new GameOverScene(this); this.scene3 = new GamePlayScene(this, scene4); this.scene1.Show(); Components.Add(scene1); Components.Add(scene2); Components.Add(scene3); Components.Add(scene4); // TODO: use this.Content to load your game content here }
protected override void LoadContent() { TileFactory.ContentManager = Content; ButtonFactory.ContentManager = Content; _spriteBatch = new SpriteBatch(GraphicsDevice); _generalFont = Content.Load <SpriteFont>("GeneralFont"); _background = Content.Load <Texture2D>("Background"); _backgroundSong = Content.Load <Song>("BackgroundSong"); _menuScene = new MenuScene(_generalFont); _menuScene.PlayButton.Click += OnPlayButtonClick; _gameOverScene = new GameOverScene(_generalFont); _gameOverScene.OkButton.Click += OnOkButtonClick; _currentScene = _menuScene; MediaPlayer.Play(_backgroundSong); MediaPlayer.IsRepeating = true; }
/// <summary> /// Loads all of the content to play the game, loads all the scenes and the music for the scenes /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Adding our scenes to our components aswell as to the services // to be able to directly access the components list from other classes menuScene = new MenuScene(this, spriteBatch); this.Components.Add(menuScene); this.Services.AddService <MenuScene>(menuScene); menuScene.Show(); actionScene = new ActionScene(this, spriteBatch); this.Components.Add(actionScene); this.Services.AddService <ActionScene>(actionScene); actionScene.Hide(); helpScene = new HelpScene(this, spriteBatch); this.Components.Add(helpScene); this.Services.AddService <HelpScene>(helpScene); helpScene.Hide(); creditScene = new CreditScene(this, spriteBatch); this.Components.Add(creditScene); this.Services.AddService <CreditScene>(creditScene); creditScene.Hide(); gameOverScene = new GameOverScene(this, spriteBatch); this.Components.Add(gameOverScene); this.Services.AddService <GameOverScene>(gameOverScene); gameOverScene.Hide(); // Getting the music for the scenes menuSong = this.Content.Load <Song>("Music/Menu"); actionSong = this.Content.Load <Song>("Music/Action"); MediaPlayer.Play(menuSong); MediaPlayer.IsRepeating = true; MediaPlayer.Volume = 0.1f; }
public Program() { gameWindow = new GameWindow() { WindowState = WindowState.Maximized, Title = "Medieval Commander", }; scenes = new Dictionary <string, IScene>(); serviceProvider = new ServiceProvider(gameWindow, scene => { if (scene == null) { gameWindow.Exit(); return; } IScene nextScene; if (scenes.ContainsKey(scene)) { nextScene = scenes[scene]; } else { nextScene = new GameScene(serviceProvider, scene); } nextScene.OnChange(); // Reset OpenGL Viewport for next scene GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); GL.LoadIdentity(); if (gameWindow.Height > gameWindow.Width) { GL.Scale(1f, (float)gameWindow.Width / gameWindow.Height, 1f); } else { GL.Scale((float)gameWindow.Height / gameWindow.Width, 1f, 1f); } nextScene.Resize(gameWindow); currentScene = nextScene; }); StartMenuScene startMenuScene = new StartMenuScene(serviceProvider); GameOverScene gameOverScene = new GameOverScene(serviceProvider); LevelSelection levelSelection = new LevelSelection(serviceProvider); scenes.Add("MainMenu", startMenuScene); scenes.Add("GameOver", gameOverScene); scenes.Add("LevelSelection", levelSelection); currentScene = startMenuScene; gameWindow.UpdateFrame += (s, e) => currentScene.Update(); gameWindow.Resize += (s, e) => { GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height); GL.LoadIdentity(); if (gameWindow.Height > gameWindow.Width) { GL.Scale(1f, (float)gameWindow.Width / gameWindow.Height, 1f); } else { GL.Scale((float)gameWindow.Height / gameWindow.Width, 1f, 1f); } currentScene.Resize(gameWindow); }; gameWindow.UpdateFrame += (s, e) => serviceProvider.Update(); Stream cursorImage = serviceProvider.GetService <IFileResourceService>().Open("cursor_shiny.png"); using (var image = new MagickImage(cursorImage)) { gameWindow.Cursor = new MouseCursor(0, 0, 32, 32, image.GetPixelsUnsafe().ToArray()); } gameWindow.Run(); }
/// <summary> /// Assets are loaded in from the CreateResources method /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void CanvasControl_CreateResources(CanvasControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args) { //set parent canvas for image manager ImageManager.ParentCanvas = sender; #region -------[Load images] //Animated Hero Images await ImageManager.AddImage("Hero_Up_1", @"Assets/Hero_Up_1.gif"); await ImageManager.AddImage("Hero_Right_1", @"Assets/Hero_Right_1.gif"); await ImageManager.AddImage("Hero_Left_1", @"Assets/Hero_Left_1.gif"); await ImageManager.AddImage("Hero", @"Assets/Hero.gif"); //Minion Images await ImageManager.AddImage("MinionLeft", @"Assets/MinionLeft.png"); await ImageManager.AddImage("MinionRight", @"Assets/MinionRight.png"); // await ImageManager.AddImage("Arrow", @"Assets/Arrow.png"); await ImageManager.AddImage("Boss", @"Assets/BossEdit.png"); await ImageManager.AddImage("BossHurt", @"Assets/Boss_Hurt.png"); await ImageManager.AddImage("Title", @"Assets/Evilution.png"); await ImageManager.AddImage("GameOver", @"Assets/GameOver.png"); #endregion #region -------[Load audio] await AudioManager.AddAudio("Generic Title Scene", "TitleTheme.mp3"); await AudioManager.AddAudio("Main Game Scene", "BattleTheme.mp3"); await AudioManager.AddAudio("Game Over Scene", "GameOver.mp3"); #endregion // set scene CanvasControl cc = sender; TitleScene ts = new TitleScene((int)cc.RenderSize.Width, (int)cc.RenderSize.Height); StoryBoard.AddScene(ts); StoryBoard.CurrentScene = ts; //create scenes GameScene game_scene = new GameScene((int)cc.RenderSize.Width, (int)cc.RenderSize.Height); GameOverScene game_over_scene = new GameOverScene((int)cc.RenderSize.Width, (int)cc.RenderSize.Height); //add scenes to storyboard StoryBoard.AddScene(game_scene); StoryBoard.AddScene(game_over_scene); IsAllImagesLoaded = true; GameTimer gt = new GameTimer(sender, 120, 100); }