Beispiel #1
0
        public static void Load()
        {
            _inventory = new Inventory();
            ButtonBar  = new ButtonBar();
            HotBar.Initialize();
            _minimap = new Minimap();
            _minimap.StartUpdating();

            for (var i = 1; i <= Construction.Length; i++)
            {
                Construction[i - 1] = new SoundFx("Sounds/Level Editor/construct" + i);
            }
            _destruction = new SoundFx("Sounds/Level Editor/destroy1");

            _wallMode = new SoundFx("Sounds/Level Editor/changeMode");
            _close    = new SoundFx("Sounds/Level Editor/open");
            _open     = new SoundFx("Sounds/Level Editor/close");
            _select   = new SoundFx("Sounds/Level Editor/select");


            foreach (Player player in GameWorld.GetPlayers())
            {
                player.SetPosition(player.RespawnPos);
            }

            Cursor.Show();
        }
Beispiel #2
0
        /// <summary>
        /// Updates all UI components and checks for input.
        /// </summary>
        public static void Update()
        {
            if (GameDebug.IsTyping)
            {
                return;
            }

            foreach (Player player in GameWorld.GetPlayers())
            {
                player.Health = player.MaxHealth;
            }

            SoundtrackManager.PlayLevelEditorTheme();

            _inventory.Update();
            ButtonBar.Update();
            HotBar.Update();
            Brush.Update();
            CheckIfOnInventory();
            CheckIfPositioningPlayer();
            CheckIfChangedToWallMode();
            CheckForCameraMovement();
            CheckForMouseInput();

            ForceUpdateTile?.Update();

            // Auto-save functionality.
            if (IdleTimerForSave.TimeElapsedInSeconds > 1 && _hasChangedSinceLastSave)
            {
                SaveLevel();
            }
        }
Beispiel #3
0
 /// <summary>
 /// Tests level as the player.
 /// </summary>
 public static void TestLevel()
 {
     if (TMBAW_Game.CurrentGameMode != GameMode.Play && _switchEditAndPlayTimer.TimeElapsedInMilliSeconds > 1000)
     {
         try
         {
             SaveLevel();
             GameWorld.IsTestingLevel   = true;
             GameWorld.PlayerTrail      = new PlayerTrail();
             TMBAW_Game.CurrentGameMode = GameMode.Play;
             GameWorld.PrepareLevelForTesting();
             foreach (Player player in GameWorld.GetPlayers())
             {
                 player.ComplexAnimation.RemoveAllFromQueue();
                 player.SetVelX(0);
                 player.SetVelY(0);
             }
             Overlay.FlashWhite();
             _switchEditAndPlayTimer.Reset();
             _testSound.Play();
             Cursor.Hide();
             // DataFolder.PlayLevel(DataFolder.CurrentLevelFilePath);
         }
         catch (Exception e)
         {
             TMBAW_Game.MessageBox.Show(e.Message);
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Checks for input to move the camera.
        /// </summary>
        private static void CheckForCameraMovement()
        {
            TMBAW_Game.Camera.UpdateSmoothly(GameWorld.GetPlayers()[0].GetCollRectangle(), GameWorld.WorldData.LevelWidth,
                                             GameWorld.WorldData.LevelHeight, true);
            float speed = 9f;

            foreach (Player player in GameWorld.GetPlayers())
            {
                if (player.IsMoveLeftPressed())
                {
                    IdleTimerForSave.Reset();
                    player.MoveBy(-speed, 0);
                }
                if (player.IsMoveRightPressed())
                {
                    IdleTimerForSave.Reset();
                    player.MoveBy(speed, 0);
                }
                if (player.IsMoveUpPressed())
                {
                    IdleTimerForSave.Reset();
                    player.MoveBy(0, -speed);
                }
                if (player.IsMoveDownPressed())
                {
                    IdleTimerForSave.Reset();
                    player.MoveBy(0, speed);
                }
                if (player.IsTestLevelPressed())
                {
                    TestLevel();
                }
            }


            //Prevent camera box from moving out of screen
            if (EditorRectangle.X < 0)
            {
                EditorRectangle.X = 0;
            }
            if (EditorRectangle.X > (GameWorld.WorldData.LevelWidth * TMBAW_Game.Tilesize) - EditorRectangle.Width)
            {
                EditorRectangle.X = (GameWorld.WorldData.LevelWidth * TMBAW_Game.Tilesize) - EditorRectangle.Width;
            }
            if (EditorRectangle.Y < 0)
            {
                EditorRectangle.Y = 0;
            }
            if (EditorRectangle.Y > (GameWorld.WorldData.LevelHeight * TMBAW_Game.Tilesize) - EditorRectangle.Height)
            {
                EditorRectangle.Y = (GameWorld.WorldData.LevelHeight * TMBAW_Game.Tilesize) - EditorRectangle.Height;
            }
        }
Beispiel #5
0
        public static void Draw(SpriteBatch spriteBatch)
        {
            if (TMBAW_Game.CurrentGameMode == GameMode.Edit)
            {
                LevelEditor.DrawBehindTiles(spriteBatch);
            }

            int[] indexes = ChunkManager.GetVisibleIndexes();
            if (indexes != null)
            {
                foreach (var tileNumber in indexes)
                {
                    if (tileNumber >= 0 && tileNumber < TileArray.Length)
                    {
                        TileArray[tileNumber].Draw(spriteBatch);
                    }
                }
            }

            foreach (Player player in GameWorld.GetPlayers())
            {
                player.Draw(spriteBatch);
            }

            for (var i = 0; i < Entities.Count; i++)
            {
                if (!Entities[i].IsDead)
                {
                    Entities[i].Draw(spriteBatch);
                }
            }

            ProjectileSystem.Draw(spriteBatch);

            //ParticleSystem.DrawNormalParticles(spriteBatch);

            if (TMBAW_Game.CurrentGameMode == GameMode.Edit)
            {
                LevelEditor.Draw(spriteBatch);
            }
        }
Beispiel #6
0
        public static void Update()
        {
            StoryTimer.Increment();
            switch (Profile.CurrentLevel)
            {
            case "GreenHills01":
                if (GetVal("CaveMustBeOnlyWay") && !GetVal("CaveMustBeOnlyWay-2"))
                {
                    AddTrigger("CaveMustBeOnlyWay-2");
                    comNPC.ShowDialog("greenHills01-cave", 0);
                }
                if (GetVal("Door") && !GetVal("Door-2"))
                {
                    AddTrigger("Door-2");
                    comNPC.ShowDialog("greenHills01-door", 0);
                }

                if (StoryTimer.TimeElapsedInMilliSeconds > 1000 && !GetVal("hasStartedWakeupDialog"))
                {
                    AddTrigger("hasStartedWakeupDialog");
                    comNPC.ShowDialog("greenhills01-wakeup", 0);
                }
                if (GetVal("hasWokenUp"))
                {
                    if (!GetVal("resetTimer"))
                    {
                        MediaPlayer.Resume();
                        StoryTimer.Reset();
                        GameWorld.GetPlayers()[0].IsFacingRight = false;
                        AddTrigger("resetTimer");
                    }
                    else
                    {
                        if (StoryTimer.TimeElapsedInMilliSeconds > 2000 && !GetVal("hasLookedRight"))
                        {
                            if (!GetVal("hasLookedLeft"))
                            {
                                GameWorld.GetPlayers()[0].IsFacingRight = true;
                                AddTrigger("hasLookedLeft");
                                StoryTimer.Reset();
                            }
                            else if (!GetVal("hasLookedRight"))
                            {
                                GameWorld.GetPlayers()[0].IsFacingRight = false;
                                AddTrigger("hasLookedRight");
                                StoryTimer.Reset();
                            }
                        }
                    }
                    if (GetVal("hasLookedRight") && !GetVal("whatHappened"))
                    {
                        comNPC.ShowDialog("greenhills01-whathappened", 0);
                        AddTrigger("whatHappened");
                    }
                    if (GetVal("sentCoordinates"))
                    {
                        InCutscene = false;
                        Overlay.BlackBars.Hide();
                    }
                }

                break;

            default:
                break;
            }
        }
Beispiel #7
0
        public static void UpdateWorld()
        {
            ParticleSystem.Update();
            //ParticleSystem.Update();
            Weather.Update();

            if (TMBAW_Game.CurrentGameMode == GameMode.Edit)
            {
                foreach (Player player in GetPlayers())
                {
                    player.ComplexAnimation.RemoveAllFromQueue();
                    player.AddAnimationToQueue("editMode");
                }
                LevelEditor.Update();
            }
            else
            {
                if (IsTestingLevel)
                {
                    if (GetPlayers()[0].IsTestLevelPressed())
                    {
                        LevelEditor.GoBackToEditing();
                    }
                }
                UpdateVisual();
            }

            TimesUpdated++;

            ProjectileSystem.Update();

            for (var i = Entities.Count - 1; i >= 0; i--)
            {
                var entity = Entities[i];
                if (entity.ToDelete)
                {
                    entity.Destroy();
                }
            }
            foreach (Player player in GetPlayers())
            {
                player.Update();
            }

            if (TMBAW_Game.CurrentGameMode == GameMode.Play)
            {
                foreach (Player player in GameWorld.GetPlayers())
                {
                    PlayerTrail.Add(player);
                }
            }

            foreach (var c in _clouds)
            {
                c.CheckOutOfRange();
                c.Update();
            }
            for (var i = 0; i < Entities.Count; i++)
            {
                var entity = Entities[i];
                if (entity.IsDead)
                {
                    continue;
                }
                entity.Update();

                //// Check enemy collision with other enemies.
                //for (int j = i + 1; j < Entities.Count; j++)
                //{
                //    if (Entities[i].IsTouchingEntity(Entities[j]))
                //    {
                //        if (Entities[i].Position.X > Entities[j].Position.X)
                //        {
                //            Entities[i].SetX(Entities[j].Position.X + Entities[j].CollRectangle.Width / 2);
                //        }
                //        else
                //        {
                //            Entities[i].SetX(Entities[j].Position.X - Entities[i].CollRectangle.Width / 2);
                //        }
                //        Entities[i].ForceUpdateCollisionRectangle();
                //    }
                //}
            }


            foreach (var tileNumber in ChunkManager.GetVisibleIndexes())
            {
                if (tileNumber >= 0 && tileNumber < TileArray.Length)
                {
                    TileArray[tileNumber]?.Update();
                }
            }

            if (Session.IsHost)
            {
                Session.SendEntityUpdates();
            }
        }