Exemple #1
0
        public override void Update(RenderContext renderContext)
        {
            noteIn.UpdateTarget(targetPos);
            noteOut.UpdateTarget(targetPos);

            if ((position.X <= (targetPos.X + 800) && position.X >= (targetPos.X - 1600)))
            {
                block.CanDraw = true;
            }
            else
            {
                block.CanDraw = false;
            }

            if (CurrentState == NoteState.Enter)
            {
                block.Color = Color.SaddleBrown;

                if (!block.HitTest(targetPos) && !noteIn.Sprite.HitTest(targetPos) && !noteOut.Sprite.HitTest(targetPos))
                {
                    CurrentState = NoteState.Passed;
                    SceneManager.ActiveScene.DoSomething();
                }
            }
            else
            {
                block.Color = Color.White;
            }

            base.Update(renderContext);
        }
Exemple #2
0
        public int CheckCollision(GameObject2D sprite)
        {
            if (CurrentState == NoteState.Normal)
            {
                if (note.HitTest(sprite))
                {
                    // Find the bounds of the rectangle intersection
                    float top    = Math.Max(note.BoundingRect.Value.Top, sprite.BoundingRect.Value.Top);
                    float bottom = Math.Min(note.BoundingRect.Value.Bottom, sprite.BoundingRect.Value.Bottom);
                    float left   = Math.Max(note.BoundingRect.Value.Left, sprite.BoundingRect.Value.Left);
                    float right  = Math.Min(note.BoundingRect.Value.Right, sprite.BoundingRect.Value.Right);

                    float width  = right - left;
                    float height = bottom - top;

                    float area = width * height;

                    if (area > 100)
                    {
                        if (area > 800)
                        {
                            if (area >= 1500)
                            {
                                CurrentState = NoteState.Passed;
                                return(1);
                            }
                            CurrentState = NoteState.Passed;
                            return(3);
                        }
                        CurrentState = NoteState.Passed;
                        return(2);
                    }
                    return(0);
                }
                return(0);
            }
            return(0);
        }