Beispiel #1
0
        private async Task <Texture> getTexture(TiledTileset ts)
        {
            Texture t;

            if (!textures.TryGetValue(ts.FirstId, out t))
            {
                t = await pool.GetTexture();

                t.LoadImageFile(ts.Image.Source);
                textures[ts.FirstId] = t;
            }
            return(t);
        }
Beispiel #2
0
        public Level(List <Enemy> enemies, Player player, SpriteFont uiFont, ResourcePool res)
        {
            this.enemies = enemies;
            aliveEnemies = new List <Enemy>(enemies.Count);
            enemies.ForEach(x => aliveEnemies.Add(x));
            this.player    = player;
            playerStartPos = player.Position;
            activeEnemies  = new List <Enemy>();
            viewEvent      = ViewEvent.None;
            time           = 0;
            score          = 0;
            multiplier     = 1;
            scoreUi        = new Text(score.ToString(), uiFont, new Vector2(20, 0), Color.White);
            multiplierUi   = new Text(multiplier.ToString(), uiFont, new Vector2(200, 0), Color.White, Align.Right);
            winScoreText   = new Text(score.ToString(), uiFont, new Vector2(Globals.SCREEN_WIDTH / 2 - 150, Globals.SCREEN_HEIGHT / 2), Color.White);
            gameOver       = false;
            paused         = false;

            pauseMenu = new Menu();
            pauseMenu.AddInteractive(new Button(
                                         text: "Continue",
                                         font: uiFont,
                                         position: new Vector2(Globals.SCREEN_WIDTH / 2, Globals.SCREEN_HEIGHT / 2 - 50),
                                         color: Color.White,
                                         activeColor: Color.Yellow,
                                         viewEvent: ViewEvent.Back,
                                         align: Align.Center));
            pauseMenu.AddInteractive(new Button(
                                         text: "Back To Menu",
                                         font: uiFont,
                                         position: new Vector2(Globals.SCREEN_WIDTH / 2, Globals.SCREEN_HEIGHT / 2 + 50),
                                         color: Color.White,
                                         activeColor: Color.Yellow,
                                         viewEvent: ViewEvent.ChangeView(res.GetView("mainMenu")),
                                         align: Align.Center));
            pauseMenu.AddStatic(new Sprite(res.GetTexture("pixel"), 0, 0, Globals.SCREEN_WIDTH, Globals.SCREEN_HEIGHT, new Color(Color.Black, 0.8f)));

            winMenu = new Menu();
            winMenu.AddInteractive(new Button(
                                       text: "Back",
                                       font: uiFont,
                                       position: new Vector2(Globals.SCREEN_WIDTH / 2, Globals.SCREEN_HEIGHT / 2 + 50),
                                       color: Color.White,
                                       activeColor: Color.Yellow,
                                       viewEvent: ViewEvent.ChangeView(res.GetView("mainMenu")),
                                       align: Align.Center
                                       ));
            winMenu.AddStatic(new Sprite(res.GetTexture("pixel"), 0, 0, Globals.SCREEN_WIDTH, Globals.SCREEN_HEIGHT, new Color(Color.Black, 0.8f)));
            winMenu.AddStatic(new Text("You Win!", res.GetFont("Guardians"), new Vector2(Globals.SCREEN_WIDTH / 2, Globals.SCREEN_HEIGHT / 2 - 75), Color.White, Align.Center));
            winMenu.AddStatic(winScoreText);

            gameOverMenu = new Menu();
            gameOverMenu.AddInteractive(new Button(
                                            text: "Back",
                                            font: uiFont,
                                            position: new Vector2(Globals.SCREEN_WIDTH / 2, Globals.SCREEN_HEIGHT / 2 + 50),
                                            color: Color.White,
                                            activeColor: Color.Yellow,
                                            viewEvent: ViewEvent.ChangeView(res.GetView("mainMenu")),
                                            align: Align.Center
                                            ));
            gameOverMenu.AddStatic(new Sprite(res.GetTexture("pixel"), 0, 0, Globals.SCREEN_WIDTH, Globals.SCREEN_HEIGHT, new Color(Color.Black, 0.8f)));
            gameOverMenu.AddStatic(new Text("Game Over", res.GetFont("Guardians"), new Vector2(Globals.SCREEN_WIDTH / 2, Globals.SCREEN_HEIGHT / 2 - 75), Color.Red, Align.Center));
        }