コード例 #1
0
        public Mine(Azul.Rect destRect, int owner, Azul.Color color)
            : base(GAMEOBJECT_TYPE.MINE, new Azul.Rect(0, 0, 12, 12), destRect, GameObject.mineTexture, color)
        {
            PhysicBody_Data data = new PhysicBody_Data();

            data.position = new Vec2(destRect.x, destRect.y);
            data.size     = new Vec2(destRect.width, destRect.height);
            //data.radius = 25f;
            data.isSensor   = true;
            data.angle      = 0;
            data.shape_type = PHYSICBODY_SHAPE_TYPE.DYNAMIC_BOX;

            ownerID = owner;

            lifeTime = 5.0f;

            armDelay = 2.0f;

            mine1 = pSprite;
            mine2 = new Azul.Sprite(GameObject.mineTexture2, new Azul.Rect(0, 0, 12, 12), destRect, new Azul.Color(1, 0, 0));

            drawMine2 = false;

            CreatePhysicBody(data);
            lifeTimer = new Stopwatch();

            animTimer = new Stopwatch();
            animTimer.Start();
            armedTimer = new Stopwatch();
            armedTimer.Start();


            state = MINE_STATE.LAYED;
        }
コード例 #2
0
ファイル: Ship.cs プロジェクト: Danielg686/DataDriven
        public Ship(Azul.Rect screenRect, Azul.Color color)
            : base(GAMEOBJECT_TYPE.SHIP, new Azul.Rect(0, 0, 32, 32), screenRect, GameObject.shipTexture, color)
        {
            PhysicBody_Data data = new PhysicBody_Data();

            data.position   = new Vec2(screenRect.x, screenRect.y);
            data.size       = new Vec2(screenRect.width, screenRect.height);
            data.active     = true;
            data.angle      = 0;
            data.shape_type = PHYSICBODY_SHAPE_TYPE.SHIP_MANIFOLD;
            //data.isSensor = true;
            CreatePhysicBody(data);

            // maxSpeed is m/s
            maxSpeed = 150.0f;

            maxForce    = 20f;
            rotateSpeed = 5.0f;
            heading     = new Vec2((float)System.Math.Cos(pBody.GetAngleDegs()), (float)System.Math.Sin(pBody.GetAngleDegs()));

            mineCount    = 5;
            missileCount = 3;
            shipColor    = color;

            respawnPos = new Vec2(screenRect.x, screenRect.y);
        }
コード例 #3
0
        public FencePost(Azul.Rect dRect)
            : base(GAMEOBJECT_TYPE.FENCEPOST, new Azul.Rect(0, 0, 12, 12), dRect, fencePostTexture, new Azul.Color(1, 1, 1))
        {
            PhysicBody_Data data = new PhysicBody_Data();

            data.position   = new Vec2(dRect.x, dRect.y);
            data.size       = new Vec2(dRect.width, dRect.height);
            data.angle      = 0;
            data.shape_type = PHYSICBODY_SHAPE_TYPE.STATIC_BOX;
            CreatePhysicBody(data);
        }
コード例 #4
0
        public Fence(Azul.Rect dRect, float angle)
            : base(GAMEOBJECT_TYPE.FENCE, new Azul.Rect(0, 0, 6, 209), dRect, fenceTexture, new Azul.Color(0, 0, 0))
        {
            PhysicBody_Data data = new PhysicBody_Data();

            data.position   = new Vec2(dRect.x, dRect.y);
            data.size       = new Vec2(dRect.width, dRect.height);
            data.angle      = angle;
            data.shape_type = PHYSICBODY_SHAPE_TYPE.STATIC_BOX;
            CreatePhysicBody(data);
        }
コード例 #5
0
ファイル: Missile.cs プロジェクト: Danielg686/DataDriven
        public Missile(Azul.Rect destRect, int owner, Vec2 direction, Azul.Color color)
            : base(GAMEOBJECT_TYPE.MISSILE, new Azul.Rect(0, 0, 24, 6), destRect, GameObject.missileTexture, color)
        {
            MissileID = MissileId_index++;

            PhysicBody_Data data = new PhysicBody_Data();

            data.position = new Vec2(destRect.x, destRect.y);
            data.size     = new Vec2(destRect.width, destRect.height);
            //data.radius = 25f;
            data.isSensor   = true;
            data.angle      = 0;
            data.shape_type = PHYSICBODY_SHAPE_TYPE.DYNAMIC_BOX;

            ownerID  = owner;
            MaxForce = 1000f;

            CreatePhysicBody(data);

            LaunchAt(direction);
        }
コード例 #6
0
ファイル: GameObject.cs プロジェクト: Danielg686/DataDriven
 public void CreatePhysicBody(PhysicBody_Data _data)
 {
     pBody = new PhysicBody(_data, this);
 }
コード例 #7
0
ファイル: PhysicBody.cs プロジェクト: Danielg686/DataDriven
        public PhysicBody(PhysicBody_Data _data, GameObject gameObject)
        {
            float xMeters = PhysicWorld.PIXELSTOMETERS * _data.position.X;
            float yMeters = PhysicWorld.PIXELSTOMETERS * _data.position.Y;

            float sizeXMeters = PhysicWorld.PIXELSTOMETERS * _data.size.X;
            float sizeYMeters = PhysicWorld.PIXELSTOMETERS * _data.size.Y;

            BodyDef bodyDef = new BodyDef();


            Debug.Assert(_data.shape_type != PHYSICBODY_SHAPE_TYPE.NULL);

            if (_data.shape_type == PHYSICBODY_SHAPE_TYPE.DYNAMIC_BOX)
            {
                bodyDef.Position.Set(xMeters, yMeters);
                pBody = PhysicWorld.GetWorld().CreateBody(bodyDef);
                pBody.AllowSleeping(false);
                pBody.SetFixedRotation(true);
                pBody.SetAngle(_data.angle * PhysicWorld.MATH_PI_180);

                PolygonDef shapeDef = new PolygonDef();
                shapeDef.SetAsBox(sizeXMeters / 2, sizeYMeters / 2);

                shapeDef.Density     = 1.0f;
                shapeDef.Friction    = 0.0f;
                shapeDef.Restitution = 0.9f;

                shapeDef.UserData = gameObject;
                shapeDef.IsSensor = _data.isSensor;

                pBody.CreateFixture(shapeDef);
            }
            else if (_data.shape_type == PHYSICBODY_SHAPE_TYPE.DYNAMIC_CIRCLE)
            {
                bodyDef.Position.Set(xMeters, yMeters);
                pBody = PhysicWorld.GetWorld().CreateBody(bodyDef);

                pBody.SetAngle(_data.angle * PhysicWorld.MATH_PI_180);

                CircleDef circleDef = new CircleDef();
                circleDef.Radius        = _data.radius * PhysicWorld.PIXELSTOMETERS;
                circleDef.Density       = 1.0f;
                circleDef.Friction      = 0.0f;
                circleDef.Restitution   = 0.9f;
                circleDef.LocalPosition = new Vec2(0f, 0f);
                circleDef.UserData      = gameObject;
                circleDef.IsSensor      = _data.isSensor;

                pBody.CreateFixture(circleDef);
            }
            else if (_data.shape_type == PHYSICBODY_SHAPE_TYPE.STATIC_BOX)
            {
                bodyDef.Position.Set(xMeters, yMeters);
                pBody = PhysicWorld.GetWorld().CreateBody(bodyDef);
                pBody.AllowSleeping(false);


                pBody.SetAngle(_data.angle * PhysicWorld.MATH_PI_180);


                PolygonDef shapeDef = new PolygonDef();
                shapeDef.SetAsBox(sizeXMeters / 2, sizeYMeters / 2);
                shapeDef.UserData = gameObject;
                shapeDef.IsSensor = _data.isSensor;
                //shapeDef.Density = 1.0f;
                shapeDef.Friction    = 0.0f;
                shapeDef.Restitution = 0.9f;

                pBody.CreateFixture(shapeDef);
            }
            else if (_data.shape_type == PHYSICBODY_SHAPE_TYPE.SHIP_MANIFOLD)
            {
                bodyDef.Position.Set(xMeters, yMeters);
                pBody = PhysicWorld.GetWorld().CreateBody(bodyDef);
                pBody.AllowSleeping(false);
                pBody.SetFixedRotation(true);

                pBody.SetAngle(_data.angle * PhysicWorld.MATH_PI_180);

                PolygonDef shapeDef = new PolygonDef();
                shapeDef.VertexCount = 3;
                shapeDef.Vertices[0] = new Vec2(sizeXMeters / 2, 0);
                shapeDef.Vertices[1] = new Vec2(-sizeXMeters / 2, sizeYMeters / 2);
                shapeDef.Vertices[2] = new Vec2(-sizeXMeters / 2, -sizeYMeters / 2);

                shapeDef.UserData    = gameObject;
                shapeDef.IsSensor    = _data.isSensor;
                shapeDef.Density     = 1.0f;
                shapeDef.Friction    = 0.0f;
                shapeDef.Restitution = 0.9f;


                pBody.CreateFixture(shapeDef);
            }
            else
            {
                Debug.Assert(false, "You did not set the shape type");
            }



            pBody.SetUserData(this);
            pBody.SetMassFromShapes();
        }