Example #1
0
 public override void Update(GameTime gameTime)
 {
     m_icon.Y         = m_iconYPos + (float)Math.Sin(Game.TotalGameTime * 2f) * 5f;
     m_speechBubble.Y = m_iconYPos - 30f + (float)Math.Sin(Game.TotalGameTime * 20f) * 2f;
     if (!RoomCompleted)
     {
         if (CollisionMath.Intersects(Player.Bounds, m_pedestal.Bounds))
         {
             m_speechBubble.Visible = true;
             if (Game.GlobalInput.JustPressed(16) || Game.GlobalInput.JustPressed(17))
             {
                 var rCScreenManager = Player.AttachedLevel.ScreenManager as RCScreenManager;
                 rCScreenManager.DialogueScreen.SetDialogue("Special Item Prayer");
                 rCScreenManager.DialogueScreen.SetDialogueChoice("ConfirmTest1");
                 rCScreenManager.DialogueScreen.SetConfirmEndHandler(this, "TakeItem");
                 rCScreenManager.DialogueScreen.SetCancelEndHandler(typeof(Console), "WriteLine",
                                                                    "Canceling Selection");
                 rCScreenManager.DisplayScreen(13, true);
             }
         }
         else
         {
             m_speechBubble.Visible = false;
         }
     }
     else
     {
         m_icon.Visible = false;
     }
     base.Update(gameTime);
 }
Example #2
0
        public Vector3[] GetCollisions(Ray ray, Matrix transform)
        {
            var results = new List <Vector3>(1);

            foreach (var face in _faces)
            {
                var v0 = Vector3.Transform(face[0], transform);
                var v1 = Vector3.Transform(face[1], transform);
                var v2 = Vector3.Transform(face[2], transform);
                var(hit, pos) = CollisionMath.CollideTri(
                    ray,
                    v0,
                    v1,
                    v2
                    );
                //Console.WriteLine($"Faces: ({face[0]}), ({face[1]}), ({face[2]})");
                //Console.WriteLine($"Pos: {ray.Position}  Direction: {ray.Direction}");
                if (hit)
                {
                    //Console.WriteLine($"hit {v0} {v1} {v2}       {pos}");

                    results.Add(pos);
                }
            }
            return(results.ToArray());
        }
Example #3
0
        public override void CollisionResponse(CollisionBox thisBox, CollisionBox otherBox, int collisionResponseType)
        {
            var terrainObj = otherBox.Parent as TerrainObj;

            if (terrainObj != null && !(terrainObj is DoorObj) && terrainObj.CollidesBottom && terrainObj.CollidesLeft &&
                terrainObj.CollidesRight && terrainObj.CollidesTop)
            {
                var value = CollisionMath.RotatedRectIntersectsMTD(thisBox.AbsRect, (int)thisBox.AbsRotation,
                                                                   Vector2.Zero, otherBox.AbsRect, (int)otherBox.AbsRotation, Vector2.Zero);
                if (value != Vector2.Zero)
                {
                    var heading  = Heading;
                    var vector   = new Vector2(value.Y, value.X * -1f);
                    var heading2 = 2f * (CDGMath.DotProduct(heading, vector) / CDGMath.DotProduct(vector, vector)) *
                                   vector - heading;
                    X      += value.X;
                    Y      += value.Y;
                    Heading = heading2;
                    SoundManager.Play3DSound(this, Game.ScreenManager.Player, "GiantSpike_Bounce_01",
                                             "GiantSpike_Bounce_02", "GiantSpike_Bounce_03");
                    m_selfDestructCounter++;
                    m_selfDestructTimer = 1f;
                }
            }
        }
Example #4
0
        /*
         * Provides raycast data based on where a SphereCast would have contacted
         * the specified normal.
         * Raycasting downwards from a point along the controller's bottom sphere,
         * based on the provided normal.
         */
        private bool SimulateSphereCast(CollisionSphere collisionSphere, Vector3 groundNormal, out RaycastHit hit)
        {
            float groundAngle = Vector3.Angle(groundNormal, playerView.Up) * Mathf.Deg2Rad;

            Vector3 secondaryOrigin = playerView.Position + (playerView.Up * settings.tolerance);

            if (!Mathf.Approximately(groundAngle, 0))
            {
                float horizontal = Mathf.Sin(groundAngle) * collisionSphere.Radius;
                float vertical   = (1f - Mathf.Cos(groundAngle)) * collisionSphere.Radius;

                Vector3 upslopeDirection = -CollisionMath.DownslopeDirection(groundNormal, playerView.Down);

                Vector3 horizontalDirection = Math3d.ProjectVectorOnPlane(playerView.Up, upslopeDirection).normalized;
                secondaryOrigin += horizontalDirection * horizontal + playerView.Up * vertical;
            }

            if (SphereCast(secondaryOrigin, settings.epsilon, playerView.Down, out hit))
            {
                hit.distance -= settings.tolerance;
                return(true);
            }

            return(false);
        }
Example #5
0
 public override void Update(GameTime gameTime)
 {
     if (!RoomCompleted)
     {
         var bounds = m_fountain.Bounds;
         bounds.X     -= 50;
         bounds.Width += 100;
         if (CollisionMath.Intersects(Player.Bounds, bounds) && Player.IsTouchingGround)
         {
             m_speechBubble.Y       = m_fountain.Y - 150f + (float)Math.Sin(Game.TotalGameTime * 20f) * 2f;
             m_speechBubble.Visible = true;
         }
         else
         {
             m_speechBubble.Visible = false;
         }
         if (m_speechBubble.Visible && (Game.GlobalInput.JustPressed(16) || Game.GlobalInput.JustPressed(17)))
         {
             var num  = (int)(Player.MaxHealth * 0.3f);
             var num2 = (int)(Player.MaxMana * 0.3f);
             Player.CurrentHealth += num;
             Player.CurrentMana   += num2;
             Console.WriteLine("Healed");
             SoundManager.PlaySound("Collect_Mana");
             Player.AttachedLevel.TextManager.DisplayNumberStringText(num, "hp recovered", Color.LawnGreen,
                                                                      new Vector2(Player.X, Player.Bounds.Top - 30));
             Player.AttachedLevel.TextManager.DisplayNumberStringText(num2, "mp recovered", Color.CornflowerBlue,
                                                                      new Vector2(Player.X, Player.Bounds.Top));
             RoomCompleted           = true;
             m_fountain.TextureColor = new Color(100, 100, 100);
             m_speechBubble.Visible  = false;
         }
     }
     base.Update(gameTime);
 }
Example #6
0
 public override void Update(GameTime gameTime)
 {
     if (!IsPaused)
     {
         if (Game.PlayerStats.Traits.X != 23f && Game.PlayerStats.Traits.Y != 23f)
         {
             if (CollisionMath.Intersects(AbsDetectionRect, m_target.Bounds))
             {
                 if (CurrentFrame == 1 || CurrentFrame == TotalFrames)
                 {
                     IsCollidable = true;
                     m_extractLS.Execute();
                 }
             }
             else if (CurrentFrame == 5 && !m_extractLS.IsActive)
             {
                 IsCollidable = false;
                 PlayAnimation("StartRetract", "RetractComplete");
             }
         }
         if (m_extractLS.IsActive)
         {
             m_extractLS.Update(gameTime);
         }
     }
     base.Update(gameTime);
 }
Example #7
0
 public override void Update(GameTime gameTime)
 {
     m_icon.Y         = m_iconYPos - 10f + (float)Math.Sin(Game.TotalGameTime * 2f) * 5f;
     m_speechBubble.Y = m_iconYPos - 90f + (float)Math.Sin(Game.TotalGameTime * 20f) * 2f;
     if (!RoomCompleted)
     {
         m_icon.Visible = true;
         if (CollisionMath.Intersects(Player.Bounds, m_pedestal.Bounds))
         {
             m_speechBubble.Visible = true;
             if (Game.GlobalInput.JustPressed(16) || Game.GlobalInput.JustPressed(17))
             {
                 TakeItem();
             }
         }
         else
         {
             m_speechBubble.Visible = false;
         }
     }
     else
     {
         m_icon.Visible = false;
     }
     base.Update(gameTime);
 }
Example #8
0
        public void Update(GameTime gameTime, PlayerObj player)
        {
            var flag = false;

            if (Flip == SpriteEffects.None && player.X > X)
            {
                flag = true;
            }
            if (Flip != SpriteEffects.None && player.X < X)
            {
                flag = true;
            }
            if (player != null &&
                CollisionMath.Intersects(player.TerrainBounds,
                                         new Rectangle(Bounds.X - 50, Bounds.Y, Bounds.Width + 100, Bounds.Height)) && flag &&
                player.Flip != Flip && CanTalk)
            {
                m_talkIcon.Visible = true;
            }
            else
            {
                m_talkIcon.Visible = false;
            }
            if (Flip == SpriteEffects.None)
            {
                m_talkIcon.Position = new Vector2(Bounds.Left - m_talkIcon.AnchorX,
                                                  Bounds.Top - m_talkIcon.AnchorY + (float)Math.Sin(Game.TotalGameTime * 20f) * 2f);
                return;
            }
            m_talkIcon.Position = new Vector2(Bounds.Right + m_talkIcon.AnchorX,
                                              Bounds.Top - m_talkIcon.AnchorY + (float)Math.Sin(Game.TotalGameTime * 20f) * 2f);
        }
Example #9
0
        private TerrainObj FindClosestCeiling()
        {
            var        num         = 2147483647;
            TerrainObj result      = null;
            var        currentRoom = m_levelScreen.CurrentRoom;

            foreach (var current in currentRoom.TerrainObjList)
            {
                var b = new Rectangle(Bounds.Left, Bounds.Top - 2000, Bounds.Width, Bounds.Height + 2000);
                if (current.CollidesBottom && CollisionMath.Intersects(current.Bounds, b))
                {
                    var num2 = 3.40282347E+38f;
                    if (current.Bounds.Bottom < TerrainBounds.Top)
                    {
                        num2 = TerrainBounds.Top - current.Bounds.Bottom;
                    }
                    if (num2 < num)
                    {
                        num    = (int)num2;
                        result = current;
                    }
                }
            }
            return(result);
        }
Example #10
0
 public override void Draw(Camera2D camera)
 {
     if (this.ShowTerrain && CollisionMath.Intersects(this.Bounds, camera.Bounds) || base.ForceDraw)
     {
         camera.Draw(Game.GenericTexture, base.Position, new Rectangle(0, 0, this.Width, this.Height), base.TextureColor, MathHelper.ToRadians(base.Rotation), Vector2.Zero, 1f, SpriteEffects.None, 0f);
     }
 }
Example #11
0
        public override void Update(GameTime gameTime)
        {
            if (m_bossDoorOpening && !Player.ControlsLocked)
            {
                Player.LockControls();
            }
            if (!SoundManager.IsMusicPlaying)
            {
                SoundManager.PlayMusic("CastleSong", true);
            }
            if (Player.X < m_castleGate.Bounds.Right)
            {
                Player.X = m_castleGate.Bounds.Right + 20;
                Player.AttachedLevel.UpdateCamera();
            }
            var bounds = m_diary.Bounds;

            bounds.X        -= 50;
            bounds.Width    += 100;
            m_speechBubble.Y = m_diary.Y - m_speechBubble.Height - 20f - 30f +
                               (float)Math.Sin(Game.TotalGameTime * 20f) * 2f;
            if (CollisionMath.Intersects(Player.Bounds, bounds) && Player.IsTouchingGround)
            {
                if (m_speechBubble.SpriteName == "ExclamationSquare_Sprite")
                {
                    m_speechBubble.ChangeSprite("UpArrowSquare_Sprite");
                }
            }
            else if (m_speechBubble.SpriteName == "UpArrowSquare_Sprite")
            {
                m_speechBubble.ChangeSprite("ExclamationSquare_Sprite");
            }
            if (Game.PlayerStats.DiaryEntry < 1 || CollisionMath.Intersects(Player.Bounds, bounds))
            {
                m_speechBubble.Visible = true;
            }
            else if (Game.PlayerStats.DiaryEntry >= 1 && !CollisionMath.Intersects(Player.Bounds, bounds))
            {
                m_speechBubble.Visible = false;
            }
            if (CollisionMath.Intersects(Player.Bounds, bounds) && Player.IsTouchingGround &&
                (Game.GlobalInput.JustPressed(16) || Game.GlobalInput.JustPressed(17)))
            {
                if (Game.PlayerStats.DiaryEntry < 1)
                {
                    var rCScreenManager = Player.AttachedLevel.ScreenManager as RCScreenManager;
                    rCScreenManager.DialogueScreen.SetDialogue("DiaryEntry0");
                    rCScreenManager.DisplayScreen(13, true);
                    var expr_24E = Game.PlayerStats;
                    expr_24E.DiaryEntry += 1;
                }
                else
                {
                    var rCScreenManager2 = Player.AttachedLevel.ScreenManager as RCScreenManager;
                    rCScreenManager2.DisplayScreen(20, true);
                }
            }
            base.Update(gameTime);
        }
Example #12
0
        public override void Update(GameTime gameTime)
        {
            if (m_target.AttachedLevel.CurrentRoom.Name != "Ending")
            {
                m_gallopSound.Update();
            }
            var num = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (Difficulty >= GameTypes.EnemyDifficulty.ADVANCED && m_fireDropTimer > 0f)
            {
                m_fireDropTimer -= num;
                if (m_fireDropTimer <= 0f)
                {
                    DropFireProjectile();
                    m_fireDropTimer = m_fireDropInterval;
                }
            }
            if (Difficulty == GameTypes.EnemyDifficulty.EXPERT && !IsPaused && m_fireShieldList.Count < 1)
            {
                CastFireShield(m_numFireShieldObjs);
            }
            if ((Bounds.Left < m_levelScreen.CurrentRoom.Bounds.Left ||
                 Bounds.Right > m_levelScreen.CurrentRoom.Bounds.Right) && m_collisionCheckTimer <= 0f)
            {
                TurnHorse();
            }
            var b  = default(Rectangle);
            var b2 = default(Rectangle);

            if (Flip == SpriteEffects.FlipHorizontally)
            {
                b  = new Rectangle(Bounds.Left - 10, Bounds.Bottom + 20, 5, 5);
                b2 = new Rectangle(Bounds.Right + 50, Bounds.Bottom - 20, 5, 5);
            }
            else
            {
                b  = new Rectangle(Bounds.Right + 10, Bounds.Bottom + 20, 5, 5);
                b2 = new Rectangle(Bounds.Left - 50, Bounds.Bottom - 20, 5, 5);
            }
            var flag = true;

            foreach (var current in m_levelScreen.CurrentRoom.TerrainObjList)
            {
                if (CollisionMath.Intersects(current.Bounds, b) || CollisionMath.Intersects(current.Bounds, b2))
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
            {
                TurnHorse();
            }
            if (m_collisionCheckTimer > 0f)
            {
                m_collisionCheckTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            base.Update(gameTime);
        }
Example #13
0
 public override void Update(GameTime gameTime)
 {
     if (CollisionMath.Intersects(Player.Bounds, m_teleporter.Bounds) && Player.IsTouchingGround &&
         (Game.GlobalInput.JustPressed(16) || Game.GlobalInput.JustPressed(17)))
     {
         TeleportPlayer();
     }
 }
Example #14
0
 public override void Draw(Camera2D camera)
 {
     if ((ShowTerrain && CollisionMath.Intersects(Bounds, camera.Bounds)) || ForceDraw)
     {
         camera.Draw(Game.GenericTexture, Position, new Rectangle(0, 0, Width, Height), TextureColor,
                     MathHelper.ToRadians(Rotation), Vector2.Zero, 1f, SpriteEffects.None, 0f);
     }
 }
Example #15
0
        private void HandleEdgeCollision(CollisionSphere collisionSphere, RaycastHit hit)
        {
            Vector3 towardCenter = Math3d.ProjectVectorOnPlane(
                playerView.Up,
                (playerView.Position - hit.point).normalized * settings.epsilon
                );

            Quaternion planeAwayRotation = Quaternion.AngleAxis(
                settings.edgeCollisionRotateDegree,
                Vector3.Cross(towardCenter, playerView.Up)
                );

            Vector3 awayCenter = planeAwayRotation * -towardCenter;

            Vector3 nearPoint = hit.point + towardCenter + (playerView.Up * settings.epsilon);
            Vector3 farPoint  = hit.point + (awayCenter * settings.edgeCollisionFarPointMultiplier);

            RaycastHit nearHit;
            RaycastHit farHit;

            Raycast(nearPoint, playerView.Down, out nearHit);
            Raycast(farPoint, playerView.Down, out farHit);

            nearGround = new GroundHit(nearHit);
            farGround  = new GroundHit(farHit);

            // If we are standing on surface that should be counted as a
            // wall, attempt to flush against it on the ground
            if (Vector3.Angle(hit.normal, playerView.Up) > collidable.StandAngle)
            {
                FlushGround(collisionSphere, hit);
            }

            // If we are standing on a ledge then face the nearest center of
            // the player view, which should be steep enough to be counted as
            // a wall. Retrieve the ground it is connected to at its base, if
            // there is one.
            if ((Vector3.Angle(nearHit.normal, playerView.Up) > collidable.StandAngle) || (nearHit.distance > settings.tolerance))
            {
                Collidable nearCollidable = GetCollidable(nearHit);

                if (Vector3.Angle(nearHit.normal, playerView.Up) > nearCollidable.StandAngle)
                {
                    Vector3 downslopeDirection = CollisionMath.DownslopeDirection(nearHit.normal, playerView.Down);

                    RaycastHit stepHit;

                    if (Raycast(nearPoint, downslopeDirection, out stepHit))
                    {
                        stepGround = new GroundHit(stepHit);
                    }
                }
                else
                {
                    stepGround = new GroundHit(nearHit);
                }
            }
        }
Example #16
0
 public override void Update(GameTime gameTime)
 {
     if (m_levelScreen != null && m_levelScreen.CurrentRoom != null && !IsKilled &&
         !CollisionMath.Intersects(TerrainBounds, m_levelScreen.CurrentRoom.Bounds))
     {
         Kill();
     }
     base.Update(gameTime);
 }
Example #17
0
        // Update is called once per frame
        void Update()
        {
            Vector3         trp    = transform.position;
            CollisionResult cr     = new CollisionResult();
            var             hitbox = target !.Hitbox;

            if (debug == DebugColliderType.AABB)
            {
                cr = new CollisionResult(false,
                                         CollisionMath.CircleOnAABB(
                                             new AABB(trp, new Vector2(rectHalfX, rectHalfY))
                                             , target.location, target.largeRadius));
            }
            else if (debug == DebugColliderType.WeakAABB)
            {
                cr = new CollisionResult(false,
                                         CollisionMath.WeakCircleOnAABB(-rectHalfX, -rectHalfY, rectHalfX, rectHalfY,
                                                                        target.location.x - trp.x, target.location.y - trp.y, target.largeRadius));
            }
            else if (colliderType == ColliderType.Circle)
            {
                cr = CollisionMath.GrazeCircleOnCircle(hitbox, trp, radius * scale);
            }
            else if (colliderType == ColliderType.Line)
            {
                float maxdist = Mathf.Max(point2.magnitude, point1.magnitude) + radius;
                cr = CollisionMath.GrazeCircleOnRotatedSegment(hitbox, trp, radius,
                                                               point1, point2 - point1, scale, (point2 - point1).sqrMagnitude, maxdist * maxdist,
                                                               Mathf.Cos(rotationDeg * Mathf.PI / 180f), Mathf.Sin(rotationDeg * Mathf.PI / 180f));
            }
            else if (colliderType == ColliderType.Rectangle)
            {
                cr = CollisionMath.GrazeCircleOnRect(hitbox, trp, rectHalfX, rectHalfY, rectHalfX * rectHalfX + rectHalfY * rectHalfY, scale,
                                                     Mathf.Cos(rotationDeg * Mathf.PI / 180f), Mathf.Sin(rotationDeg * Mathf.PI / 180f));
            }
            else if (colliderType == ColliderType.RectPtColl)
            {
                cr = new CollisionResult(CollisionMath.PointInRect(target.location, new CRect(
                                                                       trp.x, trp.y,
                                                                       rectHalfX, rectHalfY, rotationDeg
                                                                       )), false);
            }
            else if (colliderType == ColliderType.Segments)
            {
                cr = CollisionMath.GrazeCircleOnSegments(hitbox, transform.position, points, start, skip, end, radius,
                                                         Mathf.Cos(rotationDeg * Mathf.PI / 180f), Mathf.Sin(rotationDeg * Mathf.PI / 180f));
            }
            if (cr.graze)
            {
                Debug.Break();
            }
        }
Example #18
0
        public override void CollisionResponse(CollisionBox thisBox, CollisionBox otherBox, int collisionResponseType)
        {
            var terrainObj = otherBox.AbsParent as TerrainObj;

            if (otherBox.AbsParent.Bounds.Top < TerrainBounds.Bottom - 20 && terrainObj != null &&
                terrainObj.CollidesLeft && terrainObj.CollidesRight && terrainObj.CollidesBottom &&
                collisionResponseType == 1 && otherBox.AbsRotation == 0f && m_collisionCheckTimer <= 0f &&
                CollisionMath.CalculateMTD(thisBox.AbsRect, otherBox.AbsRect).X != 0f)
            {
                TurnHorse();
            }
            base.CollisionResponse(thisBox, otherBox, collisionResponseType);
        }
Example #19
0
        public override void Update(GameTime gameTime)
        {
            m_speechBubble.Y = m_diary.Y - m_speechBubble.Height - 20f - 30f +
                               (float)Math.Sin(Game.TotalGameTime * 20f) * 2f;
            var bounds = m_diary.Bounds;

            bounds.X     -= 50;
            bounds.Width += 100;
            if (!CollisionMath.Intersects(Player.Bounds, bounds) && m_speechBubble.SpriteName == "UpArrowSquare_Sprite")
            {
                m_speechBubble.ChangeSprite("ExclamationSquare_Sprite");
            }
            if (!RoomCompleted || CollisionMath.Intersects(Player.Bounds, bounds))
            {
                m_speechBubble.Visible = true;
            }
            else if (RoomCompleted && !CollisionMath.Intersects(Player.Bounds, bounds))
            {
                m_speechBubble.Visible = false;
            }
            if (m_diaryIndex >= 24)
            {
                m_speechBubble.Visible = false;
            }
            if (CollisionMath.Intersects(Player.Bounds, bounds) && Player.IsTouchingGround)
            {
                if (m_speechBubble.SpriteName == "ExclamationSquare_Sprite")
                {
                    m_speechBubble.ChangeSprite("UpArrowSquare_Sprite");
                }
                if (Game.GlobalInput.JustPressed(16) || Game.GlobalInput.JustPressed(17))
                {
                    if (!RoomCompleted && Game.PlayerStats.DiaryEntry < 24)
                    {
                        var rCScreenManager = Player.AttachedLevel.ScreenManager as RCScreenManager;
                        rCScreenManager.DialogueScreen.SetDialogue("DiaryEntry" + m_diaryIndex);
                        rCScreenManager.DisplayScreen(13, true);
                        var expr_1DB = Game.PlayerStats;
                        expr_1DB.DiaryEntry += 1;
                        RoomCompleted        = true;
                    }
                    else
                    {
                        RoomCompleted = true;
                        var rCScreenManager2 = Player.AttachedLevel.ScreenManager as RCScreenManager;
                        rCScreenManager2.DisplayScreen(20, true);
                    }
                }
            }
            base.Update(gameTime);
        }
Example #20
0
 public void Update(List <TerrainObj> collisionList, GameTime gameTime)
 {
     if (!m_splashing)
     {
         var num = (float)gameTime.ElapsedGameTime.TotalSeconds;
         Y += m_speedY * num;
         X += m_speedX * num;
         if (IsCollidable)
         {
             var bounds = Bounds;
             foreach (var current in collisionList)
             {
                 var terrainObj = current;
                 var bounds2    = terrainObj.Bounds;
                 if (terrainObj.Visible && terrainObj.CollidesTop && terrainObj.Y > 120f &&
                     CollisionMath.Intersects(bounds, bounds2))
                 {
                     if (terrainObj.Rotation == 0f)
                     {
                         if (!m_isSnowflake)
                         {
                             Y = bounds2.Top - 10;
                         }
                         RunSplashAnimation();
                         break;
                     }
                     if (terrainObj.Rotation != 0f &&
                         CollisionMath.RotatedRectIntersects(bounds, 0f, Vector2.Zero,
                                                             new Rectangle((int)terrainObj.X, (int)terrainObj.Y, terrainObj.Width,
                                                                           terrainObj.Height), terrainObj.Rotation, Vector2.Zero))
                     {
                         if (!m_isSnowflake)
                         {
                             Y -= 12f;
                         }
                         RunSplashAnimation();
                     }
                     break;
                 }
             }
         }
         if (Y > 720f)
         {
             RunSplashAnimation();
         }
     }
     if (!IsAnimating && m_splashing && !m_isSnowflake)
     {
         KillDrop();
     }
 }
Example #21
0
        private void SlopeLimit(Vector3 initialPosition)
        {
            Vector3 groundNormal = grounding.PrimaryNormal;
            float   groundAngle  = Vector3.Angle(groundNormal, playerView.Up);

            if (groundAngle > grounding.Collidable.SlopeLimit)
            {
                Vector3 absoluteMoveDirection = Math3d.ProjectVectorOnPlane(
                    groundNormal,
                    playerView.Position - initialPosition
                    );

                Vector3 downslopeDirection = CollisionMath.DownslopeDirection(groundNormal, playerView.Down);
                float   slopeAngle         = Vector3.Angle(absoluteMoveDirection, downslopeDirection);

                if (slopeAngle <= settings.slopeLimitUpperBoundAngle)
                {
                    return;
                }

                Vector3 resolvedPosition = Math3d.ProjectPointOnLine(
                    initialPosition,
                    Vector3.Cross(groundNormal, playerView.Down),
                    playerView.Position
                    );
                Vector3 direction = Math3d.ProjectVectorOnPlane(
                    groundNormal,
                    resolvedPosition - playerView.Position
                    );

                RaycastHit hit;

                if (Physics.CapsuleCast(
                        feetSphere.Position,
                        headSphere.Position,
                        maxCollisionSphereRadius,
                        direction.normalized,
                        out hit,
                        direction.magnitude,
                        settings.walkableLayerMask
                        ))
                {
                    playerView.Position += downslopeDirection * hit.distance;
                }
                else
                {
                    playerView.Position += direction;
                }
            }
        }
Example #22
0
 public override void Update(GameTime gameTime)
 {
     if (Game.GlobalInput.JustPressed(16) || Game.GlobalInput.JustPressed(17))
     {
         var b = new Rectangle(Bounds.Center.X - 100, Bounds.Bottom - 300, 200, 200);
         if (CollisionMath.Intersects(Player.Bounds, b) && Player.IsTouchingGround && ID > -1)
         {
             var screenManager = Game.ScreenManager;
             screenManager.DialogueScreen.SetDialogue("PortraitRoomText" + ID);
             screenManager.DisplayScreen(13, true);
         }
     }
     base.Update(gameTime);
 }
Example #23
0
 public override void CollisionResponse(CollisionBox thisBox, CollisionBox otherBox, int collisionResponseType)
 {
     if (collisionResponseType == 1 && (otherBox.AbsParent is TerrainObj || otherBox.AbsParent is HazardObj) &&
         !(otherBox.AbsParent is DoorObj))
     {
         base.CollisionResponse(thisBox, otherBox, collisionResponseType);
         AccelerationX = 0f;
         Y             = (int)Y;
         if (DropType == 10 && CurrentFrame == 1 &&
             CollisionMath.CalculateMTD(thisBox.AbsRect, otherBox.AbsRect).Y < 0f)
         {
             PlayAnimation(2, TotalFrames);
         }
     }
 }
Example #24
0
        public void Update(Camera2D camera)
        {
            var player = m_screenManager.Player;

            foreach (var current in m_projectileManager.ActiveProjectileList)
            {
                if (current.ShowIcon)
                {
                    if (current.AttachedIcon == null)
                    {
                        if (!CollisionMath.Intersects(current.Bounds, camera.Bounds) &&
                            ((current.AccelerationX > 1f && current.X < player.X && current.Y > camera.Bounds.Top &&
                              current.Y < camera.Bounds.Bottom) ||
                             (current.AccelerationX < -1f && current.X > player.X && current.Y > camera.Bounds.Top &&
                              current.Y < camera.Bounds.Bottom) ||
                             (current.AccelerationY > 1f && current.Y < player.Y && current.X > camera.Bounds.Left &&
                              current.X < camera.Bounds.Right) ||
                             (current.AccelerationY < -1f && current.Y > player.Y && current.X > camera.Bounds.Left &&
                              current.X < camera.Bounds.Right)))
                        {
                            AddIcon(current);
                        }
                    }
                    else if (CollisionMath.Intersects(current.Bounds, camera.Bounds))
                    {
                        DestroyIcon(current);
                    }
                }
            }
            for (var i = 0; i < m_resourcePool.ActiveObjsList.Count; i++)
            {
                if (!m_resourcePool.ActiveObjsList[i].AttachedProjectile.IsAlive)
                {
                    DestroyIcon(m_resourcePool.ActiveObjsList[i].AttachedProjectile);
                    i--;
                }
            }
            foreach (var current2 in m_resourcePool.ActiveObjsList)
            {
                current2.Update(camera);
            }
        }
Example #25
0
 public override void Update(GameTime gameTime)
 {
     if (CollisionMath.Intersects(Player.Bounds, m_jukeBox.Bounds))
     {
         m_speechBubble.Visible = true;
         m_speechBubble.Y       = m_jukeBox.Y - m_speechBubble.Height - 110f +
                                  (float)Math.Sin(Game.TotalGameTime * 20f) * 2f;
         if (Game.GlobalInput.JustPressed(16) || Game.GlobalInput.JustPressed(17))
         {
             Tween.StopAllContaining(m_jukeBox, false);
             m_jukeBox.Scale    = new Vector2(3f, 3f);
             m_jukeBox.Rotation = 0f;
             Tween.StopAllContaining(m_nowPlayingText, false);
             Tween.StopAllContaining(m_songTitle, false);
             m_songTitle.Opacity      = 0f;
             m_nowPlayingText.Opacity = 0f;
             Tween.To(m_songTitle, 0.5f, Linear.EaseNone, "delay", "0.2", "Opacity", "1");
             m_songTitle.Opacity = 1f;
             Tween.To(m_songTitle, 0.5f, Linear.EaseNone, "delay", "2.2", "Opacity", "0");
             m_songTitle.Opacity = 0f;
             Tween.To(m_nowPlayingText, 0.5f, Linear.EaseNone, "Opacity", "1");
             m_nowPlayingText.Opacity = 1f;
             Tween.To(m_nowPlayingText, 0.5f, Linear.EaseNone, "delay", "2", "Opacity", "0");
             m_nowPlayingText.Opacity = 0f;
             SoundManager.PlayMusic(m_songList[m_songIndex], true, 1f);
             m_songTitle.Text = m_songTitleList[m_songIndex];
             m_songIndex++;
             if (m_songIndex > m_songList.Length - 1)
             {
                 m_songIndex = 0;
             }
             AnimateJukebox();
             CheckForSongRepeat();
         }
     }
     else
     {
         m_speechBubble.Visible = false;
     }
     base.Update(gameTime);
 }
Example #26
0
 public override void RegularUpdate()
 {
     if (collection != null && collection.Autocollect)
     {
         Autocollect(true);
     }
     if (State == HomingState.WAITING && time > MinTimeBeforeHome)
     {
         State = HomingState.HOMING;
     }
     if (CollisionMath.CircleOnPoint(loc, target.itemCollectRadius + CollectRadiusBonus, target.location))
     {
         CollectMe();
         return;
     }
     if (State == HomingState.HOMING)
     {
         timeHoming += ETime.FRAME_TIME;
         loc         = Vector2.Lerp(loc, target.location, Mathf.Lerp(homeRate * ETime.FRAME_TIME, peakedHomeRate, timeHoming / maxTimeHoming));
     }
     else
     {
         loc += ETime.FRAME_TIME * (Velocity(time) + summonTarget *
                                    M.DEOutSine(Mathf.Clamp01(time / lerpIntoOffsetTime)) / lerpIntoOffsetTime);
         if (Attractible && CollisionMath.CircleOnPoint(loc, target.itemAttractRadius, target.location))
         {
             SetHome();
         }
         else if (!LocationHelpers.OnScreenInDirection(loc, -screenRange * Direction) ||
                  (time > MinCullTime && !LocationHelpers.OnPlayableScreenBy(CullRadius, loc)))
         {
             PooledDone();
             return;
         }
     }
     tr.localEulerAngles = new Vector3(0, 0, 360 * RotationTurns *
                                       M.EOutSine(Mathf.Clamp01(time / RotationTime)));
     tr.position = loc;
     time       += ETime.FRAME_TIME;
 }
Example #27
0
 public override void CollisionResponse(CollisionBox thisBox, CollisionBox otherBox, int collisionResponseType)
 {
     if (otherBox.AbsParent is PlayerObj)
     {
         CurrentSpeed = 0f;
     }
     if (collisionResponseType != 1)
     {
         base.CollisionResponse(thisBox, otherBox, collisionResponseType);
         return;
     }
     if (!(otherBox.AbsParent is PlayerObj))
     {
         var physicsObj = otherBox.AbsParent as IPhysicsObj;
         if (physicsObj.CollidesBottom && physicsObj.CollidesTop && physicsObj.CollidesLeft &&
             physicsObj.CollidesRight)
         {
             Position += CollisionMath.RotatedRectIntersectsMTD(thisBox.AbsRect, thisBox.AbsRotation,
                                                                Vector2.Zero, otherBox.AbsRect, otherBox.AbsRotation, Vector2.Zero);
         }
     }
 }
Example #28
0
        private void FlushGround(CollisionSphere collisionSphere, RaycastHit hit)
        {
            Vector3 downslopeDirection = CollisionMath.DownslopeDirection(hit.normal, playerView.Down);

            Vector3 flushOrigin = hit.point + (hit.normal * settings.epsilon);

            RaycastHit flushHit;

            if (Raycast(flushOrigin, downslopeDirection, out flushHit))
            {
                RaycastHit sphereCastHit;

                if (SimulateSphereCast(collisionSphere, flushHit.normal, out sphereCastHit))
                {
                    flushGround = new GroundHit(sphereCastHit);
                }
                else
                {
                    Debug.Log("Failed to flush against ground");
                }
            }
        }
Example #29
0
        public static void RunTeleport(ProjectileObj proj)
        {
            var source = proj.Source as PhysicsObjContainer;

            int      closestDistance = int.MaxValue;
            BlankObj closestObj      = null;
            bool     flip            = source.Flip != SpriteEffects.None;

            foreach (BlankObj terrainObj in Core.GetCurrentRoomTerrainObjects())
            {
                if (terrainObj.Bounds.Top >= proj.Bounds.Bottom || terrainObj.Bounds.Bottom <= proj.Bounds.Top)
                {
                    continue;
                }

                var   point    = Vector2.Zero;
                float distance = float.MaxValue;

                Vector2 start1 = Vector2.Zero, end1 = Vector2.Zero;
                Func <Rectangle, float, Vector2, Vector2> startFunc = null, endFunc = null;

                if (!flip)
                {
                    if (terrainObj.X <= proj.X)
                    {
                        continue;
                    }

                    if (terrainObj.Rotation != 0)
                    {
                        start1 = proj.Position;
                        end1   = new Vector2(proj.X + 6600f, proj.Y);
                        if (terrainObj.Rotation < 0f)
                        {
                            startFunc = CollisionMath.UpperLeftCorner;
                            endFunc   = CollisionMath.UpperRightCorner;
                        }
                        else
                        {
                            startFunc = CollisionMath.LowerLeftCorner;
                            endFunc   = CollisionMath.UpperLeftCorner;
                        }
                    }
                }
                else
                {
                    if (terrainObj.X >= proj.X)
                    {
                        continue;
                    }

                    if (terrainObj.Rotation != 0)
                    {
                        start1 = new Vector2(proj.X - 6600f, proj.Y);
                        end1   = proj.Position;
                        if (terrainObj.Rotation < 0f)
                        {
                            startFunc = CollisionMath.UpperRightCorner;
                            endFunc   = CollisionMath.LowerRightCorner;
                        }
                        else
                        {
                            startFunc = CollisionMath.UpperLeftCorner;
                            endFunc   = CollisionMath.UpperRightCorner;
                        }
                    }
                }

                if (startFunc != null)
                {
                    var bounds = new Rectangle((int)terrainObj.X, (int)terrainObj.Y, terrainObj.Width, terrainObj.Height);
                    var start2 = startFunc(bounds, terrainObj.Rotation, Vector2.Zero);
                    var end2   = endFunc(bounds, terrainObj.Rotation, Vector2.Zero);
                    point = CollisionMath.LineToLineIntersect(start1, end1, start2, end2);
                }

                if (point == Vector2.Zero)
                {
                    distance = !flip ? (terrainObj.Bounds.Left - proj.Bounds.Right) : (proj.Bounds.Left - terrainObj.Bounds.Right);
                }
                else
                {
                    distance = !flip ? (point.X - proj.X) : (proj.X - point.X);
                }

                if (distance < closestDistance)
                {
                    closestDistance = (int)distance;
                    closestObj      = terrainObj;
                }
            }

            if (closestObj != null)
            {
                var newOffset = closestDistance - (closestObj.Rotation != 0f ? source.Width : source.TerrainBounds.Width) / 2f;
                if (flip)
                {
                    newOffset = -newOffset;
                }

                source.X += newOffset;
            }
        }
Example #30
0
        public override void Update(GameTime gameTime)
        {
            Player.CurrentMana         = Player.MaxMana;
            Player.CurrentHealth       = Player.MaxHealth;
            m_enchantressBlock.Visible = EnchantressAvailable;
            m_blacksmithBlock.Visible  = SmithyAvailable;
            m_architectBlock.Visible   = ArchitectAvailable;
            var totalGameTime = Game.TotalGameTime;

            if (!m_playerWalkedOut)
            {
                if (!Player.ControlsLocked && Player.X < Bounds.Left)
                {
                    m_playerWalkedOut = true;
                    (Player.AttachedLevel.ScreenManager as RCScreenManager).StartWipeTransition();
                    Tween.RunFunction(0.2f, Player.AttachedLevel.ScreenManager, "DisplayScreen", 6, true,
                                      typeof(List <object>));
                }
                else if (!Player.ControlsLocked && Player.X > Bounds.Right && !TollCollectorAvailable)
                {
                    m_playerWalkedOut = true;
                    LoadLevel();
                }
            }
            if (m_isRaining)
            {
                foreach (var current in TerrainObjList)
                {
                    current.UseCachedValues = true;
                }
                foreach (var current2 in m_rainFG)
                {
                    current2.Update(TerrainObjList, gameTime);
                }
            }
            m_tree1.Rotation = -(float)Math.Sin(totalGameTime) * 2f;
            m_tree2.Rotation = (float)Math.Sin(totalGameTime * 2f);
            m_tree3.Rotation = (float)Math.Sin(totalGameTime * 2f) * 2f;
            m_fern1.Rotation = (float)Math.Sin(totalGameTime * 3f) / 2f;
            m_fern2.Rotation = -(float)Math.Sin(totalGameTime * 4f);
            m_fern3.Rotation = (float)Math.Sin(totalGameTime * 4f) / 2f;
            if (!m_architectRenovating)
            {
                HandleInput();
            }
            if (SmithyAvailable)
            {
                if (m_blacksmithAnvilSound != null)
                {
                    m_blacksmithAnvilSound.Update();
                }
                m_blacksmith.Update(gameTime);
            }
            m_blacksmithIcon.Visible = false;
            if (Player != null && CollisionMath.Intersects(Player.TerrainBounds, m_blacksmith.Bounds) &&
                Player.IsTouchingGround && SmithyAvailable)
            {
                m_blacksmithIcon.Visible = true;
            }
            m_blacksmithIcon.Position = new Vector2(m_blacksmithIconPosition.X,
                                                    m_blacksmithIconPosition.Y - 70f + (float)Math.Sin(totalGameTime * 20f) * 2f);
            m_enchantressIcon.Visible = false;
            var b = new Rectangle((int)(m_enchantress.X - 100f), (int)m_enchantress.Y,
                                  m_enchantress.Bounds.Width + 100, m_enchantress.Bounds.Height);

            if (Player != null && CollisionMath.Intersects(Player.TerrainBounds, b) && Player.IsTouchingGround &&
                EnchantressAvailable)
            {
                m_enchantressIcon.Visible = true;
            }
            m_enchantressIcon.Position = new Vector2(m_enchantressIconPosition.X + 20f,
                                                     m_enchantressIconPosition.Y + (float)Math.Sin(totalGameTime * 20f) * 2f);
            if (Player != null &&
                CollisionMath.Intersects(Player.TerrainBounds,
                                         new Rectangle((int)m_architect.X - 100, (int)m_architect.Y, m_architect.Width + 200,
                                                       m_architect.Height)) && Player.X < m_architect.X && Player.Flip == SpriteEffects.None &&
                ArchitectAvailable)
            {
                m_architectIcon.Visible = true;
            }
            else
            {
                m_architectIcon.Visible = false;
            }
            m_architectIcon.Position = new Vector2(m_architectIconPosition.X,
                                                   m_architectIconPosition.Y + (float)Math.Sin(totalGameTime * 20f) * 2f);
            if (Player != null &&
                CollisionMath.Intersects(Player.TerrainBounds,
                                         new Rectangle((int)m_tollCollector.X - 100, (int)m_tollCollector.Y, m_tollCollector.Width + 200,
                                                       m_tollCollector.Height)) && Player.X < m_tollCollector.X && Player.Flip == SpriteEffects.None &&
                TollCollectorAvailable && m_tollCollector.SpriteName == "NPCTollCollectorIdle_Character")
            {
                m_tollCollectorIcon.Visible = true;
            }
            else
            {
                m_tollCollectorIcon.Visible = false;
            }
            m_tollCollectorIcon.Position = new Vector2(m_tollCollector.X - m_tollCollector.Width / 2 - 10f,
                                                       m_tollCollector.Y - m_tollCollectorIcon.Height - m_tollCollector.Height / 2 +
                                                       (float)Math.Sin(totalGameTime * 20f) * 2f);
            m_blacksmithNewIcon.Visible = false;
            if (SmithyAvailable)
            {
                if (m_blacksmithIcon.Visible && m_blacksmithNewIcon.Visible)
                {
                    m_blacksmithNewIcon.Visible = false;
                }
                else if (!m_blacksmithIcon.Visible && BlacksmithNewIconVisible)
                {
                    m_blacksmithNewIcon.Visible = true;
                }
                m_blacksmithNewIcon.Position = new Vector2(m_blacksmithIcon.X + 50f, m_blacksmithIcon.Y - 30f);
            }
            m_enchantressNewIcon.Visible = false;
            if (EnchantressAvailable)
            {
                if (m_enchantressIcon.Visible && m_enchantressNewIcon.Visible)
                {
                    m_enchantressNewIcon.Visible = false;
                }
                else if (!m_enchantressIcon.Visible && EnchantressNewIconVisible)
                {
                    m_enchantressNewIcon.Visible = true;
                }
                m_enchantressNewIcon.Position = new Vector2(m_enchantressIcon.X + 40f, m_enchantressIcon.Y - 0f);
            }
            if (m_isRaining && !m_isSnowing && m_lightningTimer > 0f)
            {
                m_lightningTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (m_lightningTimer <= 0f)
                {
                    if (CDGMath.RandomInt(0, 100) > 70)
                    {
                        if (CDGMath.RandomInt(0, 1) > 0)
                        {
                            Player.AttachedLevel.LightningEffectTwice();
                        }
                        else
                        {
                            Player.AttachedLevel.LightningEffectOnce();
                        }
                    }
                    m_lightningTimer = 5f;
                }
            }
            if (m_shakeScreen)
            {
                UpdateShake();
            }
            if (Player.Bounds.Right > m_tollCollector.Bounds.Left && TollCollectorAvailable)
            {
                Player.X = m_tollCollector.Bounds.Left - (Player.Bounds.Right - Player.X);
                Player.AttachedLevel.UpdateCamera();
            }
            base.Update(gameTime);
        }