Esempio n. 1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            //IsMouseVisible = true;
            graphics.PreferredBackBufferWidth  = Globals.SCREEN_WIDTH;
            graphics.PreferredBackBufferHeight = Globals.SCREEN_HEIGHT;
            graphics.ApplyChanges();

            res = new ResourcePool(Content);

            base.Initialize();
        }
Esempio n. 2
0
        public static Level ParseLevel(string path, ResourcePool res)
        {
            var levelTemplate = JsonConvert.DeserializeObject <LevelJ>(File.ReadAllText(path));

            float translateX = 1 / (100f / Globals.SCREEN_WIDTH);
            float translateY = 1 / (100f / Globals.SCREEN_HEIGHT);

            // Add all enemies to the list
            var enemies = new List <Enemy>();

            if (levelTemplate.Enemies != null)
            {
                levelTemplate.Enemies.ForEach(enemyT => {
                    var func = GetLambda(enemyT.Path.Func);
                    enemies.Add(new Enemy(
                                    sprite: new Sprite(res.GetTexture(enemyT.Texture),
                                                       X: enemyT.Rectangle.X * translateX - enemyT.Rectangle.X / 2,
                                                       Y: enemyT.Rectangle.Y * translateY - enemyT.Rectangle.Y / 2,
                                                       W: enemyT.Rectangle.W,
                                                       H: enemyT.Rectangle.H,
                                                       color: new Color(enemyT.Color.R / 255f, enemyT.Color.G / 255f, enemyT.Color.B / 255f)),
                                    healthBarTexture: res.GetTexture("pixel"),
                                    health: enemyT.Health,
                                    value: enemyT.Value,
                                    path: new Path(enemyT.Path.Speed, enemyT.Path.Angle, func),
                                    delay: enemyT.Delay));
                });
            }

            if (levelTemplate.Templates != null)
            {
                levelTemplate.Templates.ForEach(enemyT => {
                    var tmp = ParseEnemyTemplate(res, enemyT);
                    tmp.X  *= translateX;
                    enemies.Add(tmp);
                });
            }

            // create player
            var player = new Player(
                res,
                levelTemplate.Player.Rectangle.X * translateX - levelTemplate.Player.Rectangle.W / 2,
                levelTemplate.Player.Rectangle.Y * translateY - levelTemplate.Player.Rectangle.H / 2,
                levelTemplate.Player.Rectangle.W,
                levelTemplate.Player.Rectangle.H,
                new Color(levelTemplate.Player.Color.R / 255f, levelTemplate.Player.Color.G / 255f, levelTemplate.Player.Color.B / 255f)
                );

            return(new Level(enemies, player, res.GetFont(levelTemplate.UiFont), res));
        }
Esempio n. 3
0
        public Player(ResourcePool res, float X, float Y, float W, float H, Color color, int health = 1)
        {
            sprite = new SpriteSheet(res.GetTexture("VoidShipSpriteSheet"), X, Y, W, H, color);
            sprite.AutoTile(512, 512);
            move            = new Vector2();
            direction       = Direction.Center;
            this.health     = health;
            this.shootSound = res.GetSound("Shoot");
            gun             = new Gun(
                ammo: 14, fireRate: 0.35f, reloadTime: 2f,
                template: new Bullet(
                    new Sprite(res.GetTexture("BulletSpriteSheet"), sprite.X + sprite.Width / 2 - 10, sprite.Y, 20, 34, new Rectangle(466, 254, 10, 17), Color.White),
                    1, new Path(500, 90, x => 0)));

            ammoBar = new Bar(res.GetTexture("pixel"), 10, Globals.SCREEN_HEIGHT - 20, 100, 10, gun.MagazineSize, gun.MagazineSize, Color.Yellow);
        }