예제 #1
0
        public InfoBody AddVert(float x, float y, Vec2[] vert, float angle, float density,
                                float friction, float restetution, float mass, GImage image, bool IsBullet = true,
                                bool IsSensor = false, bool AllowSleep = false, short group_index = 1, Object userDate = null)
        {
            for (int i = 0; i < vert.Length; i++)
            {
                vert[i].X /= 2;
                vert[i].Y /= 2;

                vert[i].X /= metric;
                vert[i].Y /= metric;
            }

            BodyDef bDef = new BodyDef();

            bDef.Position.Set(x / metric, y / metric);
            bDef.Angle      = angle;
            bDef.AllowSleep = AllowSleep;
            bDef.IsBullet   = IsBullet;

            PolygonDef pDef = new PolygonDef();

            pDef.Restitution = restetution;
            pDef.Friction    = friction;
            pDef.Density     = density;
            pDef.SetAsBox(image.GetWidth() / metric / 2, image.GetHeight() / metric / 2);
            pDef.Vertices          = vert;
            pDef.Filter.GroupIndex = group_index;
            pDef.IsSensor          = IsSensor;

            Body body = world.CreateBody(bDef);

            body.CreateShape(pDef);
            body.SetMassFromShapes();

            float    Inertia = body.GetInertia();
            MassData md      = new MassData();

            md.I    = Inertia;
            md.Mass = mass;
            body.SetMass(md);

            InfoBody info = new InfoBody();

            info.image    = image;
            info.body     = body;
            info.userDate = userDate;

            body.SetUserData(info);

            return(info);
        }
예제 #2
0
        public override void Resume()
        {
            imgLMD = new GImage(Game);
            imgLMD.SetImage(GameResource.text_lmd);
            imgLMD.SetWidth(50);
            imgLMD.SetHeight(1);
            imgLMD.SetX(Game.GetWindowWidth() / 2 + 90);
            imgLMD.SetY(200);
            ScaleImg_x = imgLMD.GetWidth();
            ScaleImg_y = imgLMD.GetHeight();
            AddElement(imgLMD);

            intent_to_menu = new Intent(Game);
            intent_to_menu.SetScreenLoading(null);
        }
예제 #3
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);
                }
            }
        }