Beispiel #1
0
        private void UpdateWorld(Player player)
        {
            var oldCalculatedStart = calculatedStart;
            var oldCalculatedEnd = calculatedEnd;
            calculatedStart = new Vector2(player.X, player.Y) - maxPosition;
            calculatedEnd = new Vector2(player.X, player.Y) + maxPosition;

            var defaultBackground = objectsSpawnRate[1].Keys.ElementAt(0);
            var defaultDetails = objectsSpawnRate[0].Keys.ElementAt(0);

            // SPAWN BACKGROUND
            // 1
            for (var x = (int) calculatedStart.X; x < calculatedEnd.X; x += (int) defaultBackground.Width)
                for (var y = (int) calculatedStart.Y; y < oldCalculatedStart.Y; y += (int) defaultBackground.Height)
                    PickRandomObject(x, y, 1);
            // 2
            for (var x = (int) oldCalculatedEnd.X; x < calculatedEnd.X; x += (int) defaultBackground.Width)
                for (var y = (int) oldCalculatedStart.Y; y < calculatedEnd.Y; y += (int) defaultBackground.Height)
                    PickRandomObject(x, y, 1);
            // 3
            for (var x = (int) oldCalculatedStart.X; x < oldCalculatedEnd.X; x += (int) defaultBackground.Width)
                for (var y = (int) oldCalculatedEnd.Y; y < calculatedEnd.Y; y += (int) defaultBackground.Height)
                    PickRandomObject(x, y, 1);
            // 4
            for (var x = (int) calculatedStart.X; x < oldCalculatedStart.X; x += (int) defaultBackground.Width)
                for (var y = (int) oldCalculatedStart.Y; y < calculatedEnd.Y; y += (int) defaultBackground.Height)
                    PickRandomObject(x, y, 1);

            // SPAWN ENEMIES
            // 1
            //for (int x = (int)calculatedStart.X; x < calculatedEnd.X; x += (int)defaultBackground.Width)
            //    for (int y = (int)calculatedStart.Y; y < oldCalculatedStart.Y; y += (int)defaultBackground.Height)
            //        PickRandomObject(x, y, 2);
            //// 2
            //for (int x = (int)oldCalculatedEnd.X; x < calculatedEnd.X; x += (int)defaultBackground.Width)
            //    for (int y = (int)oldCalculatedStart.Y; y < calculatedEnd.Y; y += (int)defaultBackground.Height)
            //        PickRandomObject(x, y, 2);
            //// 3
            //for (int x = (int)oldCalculatedStart.X; x < oldCalculatedEnd.X; x += (int)defaultBackground.Width)
            //    for (int y = (int)oldCalculatedEnd.Y; y < calculatedEnd.Y; y += (int)defaultBackground.Height)
            //        PickRandomObject(x, y, 2);
            //// 4
            //for (int x = (int)calculatedStart.X; x < oldCalculatedStart.X; x += (int)defaultBackground.Width)
            //    for (int y = (int)oldCalculatedStart.Y; y < calculatedEnd.Y; y += (int)defaultBackground.Height)
            //        PickRandomObject(x, y, 2);

            // SPAWN RANDOM OBJECTS
            // 1
            for (var x = (int) calculatedStart.X; x < calculatedEnd.X; x += (int) defaultDetails.Width)
                for (var y = (int) calculatedStart.Y; y < oldCalculatedStart.Y; y += (int) defaultDetails.Height)
                    PickRandomObject(x, y, 0);
            // 2
            for (var x = (int) oldCalculatedEnd.X; x < calculatedEnd.X; x += (int) defaultDetails.Width)
                for (var y = (int) oldCalculatedStart.Y; y < calculatedEnd.Y; y += (int) defaultDetails.Height)
                    PickRandomObject(x, y, 0);
            // 3
            for (var x = (int) oldCalculatedStart.X; x < oldCalculatedEnd.X; x += (int) defaultDetails.Width)
                for (var y = (int) oldCalculatedEnd.Y; y < calculatedEnd.Y; y += (int) defaultDetails.Height)
                    PickRandomObject(x, y, 0);
            // 4
            for (var x = (int) calculatedStart.X; x < oldCalculatedStart.X; x += (int) defaultDetails.Width)
                for (var y = (int) oldCalculatedStart.Y; y < calculatedEnd.Y; y += (int) defaultDetails.Height)
                    PickRandomObject(x, y, 0);
        }
Beispiel #2
0
 public void UpdateHp(Player player)
 {
     hpBar.Box.scale = new Vector2((float) Math.Round(player.Stats.Hp/player.Stats.MaxHp, 2), 1f);
     hpNumber.Text = $"{(int) player.Stats.Hp} - {(int) player.Stats.MaxHp}";
     var hpNumberMeasure = hpNumber.Measure();
     hpNumber.X = hpBarBorder.X + hpBarBorder.Width/2 - hpNumberMeasure.X/2;
     hpNumber.Y = hpBarBorder.Y + hpBarBorder.Height/2 - hpNumberMeasure.Y/2;
 }
Beispiel #3
0
 public void UpdateXp(Player player)
 {
     xpBar.Box.scale = new Vector2((float) Math.Round((float) player.Stats.Xp/player.Stats.XpForNextLevel, 2), 1f);
     xpNumber.Text = $"{player.Stats.Xp} - {player.Stats.XpForNextLevel}";
     var xpNumberMeasure = xpNumber.Measure();
     xpNumber.X = xpBarBorder.X + xpBarBorder.Width/2 - xpNumberMeasure.X/2;
     xpNumber.Y = xpBarBorder.Y + xpBarBorder.Height/2 - xpNumberMeasure.Y/2;
     lvl.Text = $"Level {player.Stats.Level + 1}";
 }
Beispiel #4
0
        public override void Start()
        {
            base.Start();

            AudioSource.Volume = 0.4f;
            AudioSource.Stream(Engine.GetAsset("sound_soundtrack").FileName, true);

            GameManager.MainWindow = "game";
            // spawn player
            var player = new Player("player", 251/3, 300/3);
            Engine.SpawnObject(player);

            // spawn world (procederal background + background parts + enemies + rituals)
            var world = new World();
            Engine.SpawnObject("world", world);

            SpawnEnemies();
        }