Example #1
0
        public void Update(float dt)
        {
            image.Step(dt);

            if (image.GetX() > image.GetGame().GetWindowWidth() / 2)
            {
                State = STATE.RIGHT;
            }
            else
            {
                State = STATE.LEFT;
            }

            if (chTree != null && chTree.Decorations.Count > 0)
            {
                GImage decoration = chTree.GetDecorationNoBall();

                if (decoration != null)
                {
                    if (decoration.UserObject.ToString() == "decoration")
                    {
                        float dx = decoration.GetX();
                        float dy = decoration.GetY();

                        float cx = image.GetX();
                        float cy = image.GetY();

                        float atanAndle = (float)Math.Atan2(dy - cy, dx - cx);

                        float targetX = (float)Math.Cos(atanAndle);
                        float targetY = (float)Math.Sin(atanAndle);

                        image.SetAndle(atanAndle + 1.3f);
                        image.SetVelocityX(targetX);
                        image.SetVelocityY(targetY);

                        bool collide = GImage.IntersectObjectFromRadius(cx, cy, image.GetWidth() / 2, dx, dy, decoration.GetWidth() / 2);

                        if (collide)
                        {
                            System.Diagnostics.Debug.WriteLine(collide.ToString(), "is collide cat and decoration");
                            decoration.UserObject = "ball";
                        }
                    }
                }
                else
                {
                    image.SetVelocityX(0);
                    image.SetVelocityY(0);
                }
            }
        }