示例#1
0
        public override void Update(GameTime gameTime)
        {
            resumeCounter -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (scene.MatchPaused)
            {
                foreach (Player p in scene.GetPlayers())
                {
                    p.Update(gameTime);
                    ActionSet actions = p.GetCurrentActionSet();

                    foreach (int t in actions.actions)
                    {
                        if (t == InputConfig.Actions.JUMP)
                        {
                            ResumeGame();
                            resumeCounter = 0.2f;
                        }

                        if (t == InputConfig.Actions.TRAP)
                        {
                            TransitionToMenu();
                        }
                    }

                    if (actions.actions.Count != 0)
                    {
                        actions.actions.Clear();
                    }
                }
            }
            else
            {
                scene.MatchShopKeeper.Update(gameTime);

                if (resumeCounter <= 0)
                {
                    foreach (Player p in scene.GetPlayers())
                    {
                        p.Update(gameTime);
                        ActionSet actions = p.GetCurrentActionSet();

                        foreach (int t in actions.actions)
                        {
                            if (t == InputConfig.Actions.MENU)
                            {
                                PauseGame();
                            }
                        }
                    }
                }

                List <AiController> aiControllers = scene.GetAiControllers();
                foreach (AiController controller in aiControllers)
                {
                    controller.Update(gameTime);
                }

                foreach (AiController controller in scene.GetAndClearPendingAiRemovals())
                {
                    aiControllers.Remove(controller);
                }

                weatherSystem.Update(gameTime);

                if (weatherSystem.IsRaining && previouslyRaining)
                {
                    rainTimeDelta += gameTime.ElapsedGameTime.TotalSeconds;
                    if (rainTimeDelta >= 5)
                    {
                        scene.MatchSoundManager.PlaySoundEffect(SoundEffectEnumeration.Rain);
                        rainTimeDelta = 0;
                    }
                }
                else if (weatherSystem.IsRaining && !previouslyRaining)
                {
                    scene.MatchSoundManager.PlaySoundEffect(SoundEffectEnumeration.Rain);
                    previouslyRaining = true;
                }
                else
                {
                    rainTimeDelta = 0;
                }

                //Update moving foliages
                foreach (Foliage foliage in scene.GetFoliage())
                {
                    foliage.Update(gameTime);
                }

                //Update snakes
                foreach (Snake snake in scene.GetSnakes())
                {
                    snake.Update(gameTime);
                }

                foreach (ParticleEffectManager pEffect in scene.ParticleEffects)
                {
                    pEffect.Update(gameTime);
                }

                scene.LightningManager.Update();

                //Winning Condition: End Match if there are no treasures left
                if (scene.TreasuresLeft <= 0)
                {
                    TransitionToWinningScreen();
                }

                // DEBUG! TODO: REMOVE LATER
#if DEBUG
                if (Keyboard.GetState() != null)
                {
                    KeyboardState state = Keyboard.GetState();
                    if (state.IsKeyDown(Keys.I) && scene.GetAiControllers().Count < 1)
                    {
                        Character ch;
                        ch =
                            CharacterImporter.ImportCharacter(
                                MainConfig.CONTENT_CHARACTERS_DIRECTORY + "IndigenousChar.xml", director.Content, scene);
                        ch.InitCharacter(new Vector3(500, 500 - 70, 0f));
                        ch.InitCharacter();
                        AiIndigenController c = new AiIndigenController(scene, scene.NavigationGraph, new AiBehavior());
                        c.Possess(ch);
                        scene.Characters.Add(ch);
                        scene.GetActors().Add(ch);
                        scene.AddAiController(c);
                    }
                }
#endif
            }
        }
示例#2
0
        public override void Draw(SpriteBatch batch)
        {
            batch.Begin(transformMatrix: camera.GetViewMatrix());

            foreach (Actor a in scene.GetActors())
            {
                a.Draw(batch);
            }


            batch.End();

            DrawFoliageWithAlphaMask(batch);

            foreach (ParticleEffectManager particleEffect in scene.ParticleEffects)
            {
                particleEffect.Draw(batch, camera);
            }

            scene.ParticleEffects.RemoveAll(pEffect => (pEffect.EffectDuration <= 0 && !pEffect.Continuous));

            scene.LightningManager.Draw(batch);

            batch.Begin(transformMatrix: camera.GetViewMatrix());

            //Debug code, TODO: REMOVE LATER
            SpriteFont debugFont = hud.fonts[1];

            /*Draw outlines for each of the collidables
             * foreach (Collidable polygon in scene.GetCollidables())
             * {
             * DrawPolygon(batch, polygon, Color.Red, false);
             * }
             *
             * //character Boundingbox
             * Collidable boundingBox = Polygon.RectangleToPolygon(character.CharacterPhysics.BoundingBox);
             * DrawPolygon(batch, boundingBox, Color.Green, false);*/
            //Draw  MinX and MaxX for each walkable polygon

            /*foreach (Collidable polygon in scene.WalkableCollidables)
             * {
             *  DrawLine(batch, new Vector2(polygon.WalkableMinMax.X, polygon.MaxHeight), new Vector2(polygon.WalkableMinMax.Y, polygon.MinHeight), Color.Red);
             * }
             *
             * //Draw the same numbers for climbable collidables that are connected to each other (= ClimbGroup)
             * int counter = 0;
             *
             * foreach (ClimbGroup climbGroup in scene.NavigationGraph.CurrClimbGroup)
             * {
             *  foreach (Collidable c in climbGroup.ClimbCollidables)
             *      batch.DrawString(hud.defaultFont, counter.ToString(), new Vector2(c.Center.X, c.CenterYClimbGroup), Color.White);
             *
             *  counter++;
             * }
             *
             * counter = 0;
             * //Draw the same numbers for platforms that are connected to each other via climbable polygon
             * foreach (NavGraphNode nav1 in scene.NavigationGraph.NavGraphNodes)
             * {
             *  if (nav1.ReachableNodes.Count == 0) continue;
             *
             *
             *
             *  foreach (var nav2 in nav1.ReachableNodes)
             *  {
             *      batch.DrawString(hud.defaultFont, counter.ToString(), nav2.Item2, Color.White);
             *      batch.DrawString(hud.defaultFont, counter.ToString(), nav2.Item3, Color.White);
             *  }
             *
             *  counter++;
             * }
             *
             * foreach (NavGraphNode node in scene.NavigationGraph.NavGraphNodes)
             * {
             *  DrawPolygon(batch, node.Platform, Color.White, true);
             * }*/
#if DEBUG
            // Draw the character's query point for the platforms
            for (int i = 0; i < scene.Characters.Count; i++)
            {
                DefaultCharacter c = (DefaultCharacter)scene.Characters[i];

                if (c?.CharacterPhysics == null)
                {
                    continue;
                }

                /*float tempX, tempY, tempWidth, tempHeight;
                 * tempX = (float)Math.Round(c.CharacterPhysics.GetPosition().X + c.CharacterPhysics.hitboxOffset.X - 1, MidpointRounding.AwayFromZero);
                 * tempY = (float)Math.Round(c.CharacterPhysics.GetPosition().Y + c.CharacterPhysics.hitboxOffset.Y - 1, MidpointRounding.AwayFromZero);
                 * tempWidth = c.CharacterPhysics.BoundingBox.Width;
                 * tempHeight = c.CharacterPhysics.BoundingBox.Height;
                 *
                 * // Point below character
                 * Vector2 pos = new Vector2(tempX + 0.5f * tempWidth, tempY);
                 * Vector2 p = new Vector2(pos.X, tempY + 1.5f * tempHeight);
                 *
                 * //batch.DrawString(hud.defaultFont, "o", p, Color.White);
                 * DrawLine(batch, pos, p, Color.AntiqueWhite);*/

                Collidable col = c.CharacterPhysics.QueryCurrentPlatform();
                DrawPolygon(batch, col, Color.Blue, false, "p" + i);
            }

            // Debug Rendering of Navigational-Graph
            for (int i = 0; i < scene.NavigationGraph.NavGraphNodes.Length; i++)
            {
                NavGraphNode n = scene.NavigationGraph.NavGraphNodes[i];

                DrawLine(batch, new Vector2(n.Platform.WalkableMinMax.X, n.Platform.MinHeight), new Vector2(n.Platform.WalkableMinMax.Y, n.Platform.MinHeight), Color.Yellow);

                batch.DrawString(debugFont, "n_" + i, n.Platform.Center + new Vector2(0, 10), Color.Orange);
                foreach (Tuple <NavGraphNode, Vector2, Vector2> t in n.ReachableNodes)
                {
                    DrawLine(batch, t.Item2, t.Item3, Color.Orange);
                    batch.DrawString(debugFont, "rn_" + i, t.Item2 + new Vector2(0, 0), Color.OrangeRed);
                }
            }

            // Debug Rendering of the Path of the Ai-Characters
            List <AiController> lc = scene.GetAiControllers();
            for (int i = 0; i < lc.Count; i++)
            {
                AiIndigenController c = (AiIndigenController)lc[i];
                if (c == null || c.Path.Count == 0)
                {
                    continue;
                }

                Vector3 pos = c.PossesedCharacters[0].GetCenterPosition();
                DrawLine(batch, pos, c.Path[0].Position, Color.White);
                batch.DrawString(debugFont, "w" + i, new Vector2(pos.X, pos.Y), Color.White);
                for (int j = 0; j < c.Path.Count - 1; j++)
                {
                    DrawLine(batch, c.Path[j].Position, c.Path[j + 1].Position, Color.White);
                    batch.DrawString(debugFont, (j + 1).ToString(), new Vector2(c.Path[j].Position.X, c.Path[j].Position.Y), Color.White);
                }
            }
#endif
            hud.DrawHud(batch);

            if (scene.MatchPaused)
            {
                scene.MatchPauseScreen.Draw(batch);
            }

            batch.End();
        }