Exemple #1
0
        public OdeSolid(dWorldID worldID, dSpaceID spaceID)
        {
            this.worldID         = worldID;
            this.spaceID         = spaceID;
            isPlaceable          = true;
            collisionCount       = 0;
            nonSymmetricInertia  = false;
            isFreelySpinning     = true;
            prevAngVelMagSquared = 0;

            data = new SolidData();

            if (!data.IsStatic)
            {
                // Create an ODE body with default ODE mass parameters (total
                // mass = 1).  This should have an initial mass of 0 until shapes
                // are added, but ODE won't allow a mass of 0.  This will be
                // adjusted appropriately when the first shape is added.

                bodyID = this.worldID.CreateBody();

                //mBodyID = new Body(mWorldID);
            }

            Init(data);
        }
Exemple #2
0
        public override void Init(SolidData data)
        {
            // The order of function calls here is important.

            // Destroy the old Shapes.
            //this.data.DestroyShapes(); //http://www.codeplex.com/WorkItem/View.aspx?ProjectName=xnadevru&WorkItemId=4301

            this.data = data;

            // Destroy the old ODE geoms.
            DestroyGeoms();

            // Set whether the Solid is static.
            Static = data.IsStatic;

            // Set the new transform.
            Transform = data.Transform;

            // Add the new Shapes.
            for (int i = 0; i < data.NumShapes; ++i)
            {
                AddShape(data.GetShapeData(i));
            }

            // Set whether the Solid is sleeping.
            Sleeping = data.Sleeping;

            // Set the Solid's sleepiness level.
            Sleepiness = data.Sleepiness;

            // Set whether the Solid is enabled.
            Enabled = data.Enabled;

            // Set damping levels.
            LinearDamping  = data.LinearDamping;
            AngularDamping = data.AngularDamping;

            // Set velocities.
            GlobalLinearVel  = data.GlobalLinearVel;
            GlobalAngularVel = data.GlobalAngularVel;

            // Set the Solid's name.
            Name = data.Name;
        }
Exemple #3
0
        private void levelPanel_MouseMove(object sender, MouseEventArgs e)
        {
            if (selected != -1)
            {
                oldMouse    = new System.Drawing.Point(newMouse.X, newMouse.Y);
                newMouse    = levelPanel.PointToClient(Cursor.Position);
                newMouse.X += levelPanel.HorizontalScroll.Value;
                newMouse.Y += levelPanel.VerticalScroll.Value;

                level.solids[selected].position += new Vector2(newMouse.X - oldMouse.X, newMouse.Y - oldMouse.Y);
                level.solids[selected].position  = snap(level.solids[selected].position);
            }
            else
            {
                newMouse    = levelPanel.PointToClient(Cursor.Position);
                newMouse.X += levelPanel.HorizontalScroll.Value;
                newMouse.Y += levelPanel.VerticalScroll.Value;
                oldMouse    = new System.Drawing.Point(newMouse.X, newMouse.Y);

                if (checkBoxSnap.Checked && (Mouse.GetState().LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed ||
                                             Mouse.GetState().RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed))
                {
                    CLICK_MODE clickMode = modeRight;
                    if (Mouse.GetState().LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                    {
                        clickMode = modeLeft;
                    }
                    bool canDragPlace = true;
                    for (int i = 0; i < level.solids.Length && canDragPlace; i++)
                    {
                        SolidData            solid = level.solids[i];
                        System.Drawing.Point mouse = levelPanel.PointToClient(Cursor.Position);
                        mouse.X += levelPanel.HorizontalScroll.Value;
                        mouse.Y += levelPanel.VerticalScroll.Value;

                        if ((mouse.X >= solid.position.X) && (mouse.Y >= solid.position.Y) && (mouse.X <= solid.position.X + textures[solid.textureNo].Image.Width) && (mouse.Y <= solid.position.Y + textures[solid.textureNo].Image.Height))
                        {
                            canDragPlace = false;
                        }
                    }
                    for (int i2 = 0; i2 < level.zombieSpawners.Length && canDragPlace; i2++)
                    {
                        Vector2 spawner            = level.zombieSpawners[i2];
                        System.Drawing.Point mouse = levelPanel.PointToClient(Cursor.Position);
                        mouse.X += levelPanel.HorizontalScroll.Value;
                        mouse.Y += levelPanel.VerticalScroll.Value;
                        if ((mouse.X >= spawner.X) && (mouse.Y >= spawner.Y) && (mouse.X <= spawner.X + textures[2].Image.Width) && (mouse.Y <= spawner.Y + textures[2].Image.Height))
                        {
                            canDragPlace = false;
                        }
                    }
                    for (int i = 0; i < level.backSolids.Length && canDragPlace && comboBoxLeftClickMode.SelectedIndex == 5; i++)
                    {
                        SolidData            solid = level.backSolids[i];
                        System.Drawing.Point mouse = levelPanel.PointToClient(Cursor.Position);
                        mouse.X += levelPanel.HorizontalScroll.Value;
                        mouse.Y += levelPanel.VerticalScroll.Value;

                        if ((mouse.X >= solid.position.X) && (mouse.Y >= solid.position.Y) && (mouse.X <= solid.position.X + textures[solid.textureNo].Image.Width) && (mouse.Y <= solid.position.Y + textures[solid.textureNo].Image.Height))
                        {
                            canDragPlace = false;
                        }
                    }
                    for (int i = 0; i < level.foreSolids.Length && canDragPlace && comboBoxLeftClickMode.SelectedIndex == 6; i++)
                    {
                        SolidData            solid = level.foreSolids[i];
                        System.Drawing.Point mouse = levelPanel.PointToClient(Cursor.Position);
                        mouse.X += levelPanel.HorizontalScroll.Value;
                        mouse.Y += levelPanel.VerticalScroll.Value;

                        if ((mouse.X >= solid.position.X) && (mouse.Y >= solid.position.Y) && (mouse.X <= solid.position.X + textures[solid.textureNo].Image.Width) && (mouse.Y <= solid.position.Y + textures[solid.textureNo].Image.Height))
                        {
                            canDragPlace = false;
                        }
                    }
                    if (clickMode == CLICK_MODE.DELETE)
                    {
                        canDragPlace = true;
                    }
                    if (canDragPlace)
                    {
                        alterLevelElement(newMouse, clickMode);
                    }
                }
            }
        }
Exemple #4
0
 private void alterLevelElement(System.Drawing.Point levelPanelScrollPos, CLICK_MODE clickMode)
 {
     updateScrollPos();
     if (clickMode == CLICK_MODE.PLACE)
     {
         if (selectedSolidTexture)
         {
             SolidData[] newSolids = new SolidData[level.solids.Length + 1];
             for (int i = 0; i < level.solids.Length; i++)
             {
                 newSolids[i] = level.solids[i];
             }
             System.Drawing.Point point = levelPanel.PointToClient(Cursor.Position);
             point.X += levelPanel.HorizontalScroll.Value;
             point.Y += levelPanel.VerticalScroll.Value;
             point.X -= textures[comboBoxSolidTexture.SelectedIndex].Image.Width / 2;
             point.Y -= textures[comboBoxSolidTexture.SelectedIndex].Image.Height / 2;
             point    = snap(point);
             newSolids[level.solids.Length] = new SolidData(new Vector2(point.X, point.Y), comboBoxSolidTexture.SelectedIndex, Microsoft.Xna.Framework.Color.White);
             level.solids = newSolids;
             PutPicturesInPanel();
         }
     }
     if (clickMode == CLICK_MODE.DELETE)
     {
         bool deletedSomething = false;
         for (int i = 0; i < level.solids.Length; i++)
         {
             SolidData            solid = level.solids[i];
             System.Drawing.Point mouse = levelPanel.PointToClient(Cursor.Position);
             mouse.X += levelPanel.HorizontalScroll.Value;
             mouse.Y += levelPanel.VerticalScroll.Value;
             if ((mouse.X >= solid.position.X) && (mouse.Y >= solid.position.Y) && (mouse.X <= solid.position.X + textures[solid.textureNo].Image.Width) && (mouse.Y <= solid.position.Y + textures[solid.textureNo].Image.Height))
             {
                 int         newLength    = level.solids.Length - 1;
                 SolidData[] newSolids    = new SolidData[newLength];
                 bool        foundDeleted = false;
                 for (int i2 = 0; i2 < level.solids.Length; i2++)
                 {
                     if (foundDeleted)
                     {
                         newSolids[i2 - 1] = level.solids[i2];
                     }
                     else
                     {
                         if (i == i2)
                         {
                             foundDeleted = true;
                         }
                         else
                         {
                             newSolids[i2] = level.solids[i2];
                         }
                     }
                 }
                 level.solids     = newSolids;
                 deletedSomething = true;
                 break;
             }
         }
         if (!deletedSomething)
         {
             for (int i = 0; i < level.foreSolids.Length; i++)
             {
                 SolidData            solid = level.foreSolids[i];
                 System.Drawing.Point mouse = levelPanel.PointToClient(Cursor.Position);
                 mouse.X += levelPanel.HorizontalScroll.Value;
                 mouse.Y += levelPanel.VerticalScroll.Value;
                 if ((mouse.X >= solid.position.X) && (mouse.Y >= solid.position.Y) && (mouse.X <= solid.position.X + textures[solid.textureNo].Image.Width) && (mouse.Y <= solid.position.Y + textures[solid.textureNo].Image.Height))
                 {
                     int         newLength    = level.foreSolids.Length - 1;
                     SolidData[] newSolids    = new SolidData[newLength];
                     bool        foundDeleted = false;
                     for (int i2 = 0; i2 < level.foreSolids.Length; i2++)
                     {
                         if (foundDeleted)
                         {
                             newSolids[i2 - 1] = level.foreSolids[i2];
                         }
                         else
                         {
                             if (i == i2)
                             {
                                 foundDeleted = true;
                             }
                             else
                             {
                                 newSolids[i2] = level.foreSolids[i2];
                             }
                         }
                     }
                     level.foreSolids = newSolids;
                     deletedSomething = true;
                     break;
                 }
             }
         }
         if (!deletedSomething)
         {
             for (int i2 = 0; i2 < level.zombieSpawners.Length; i2++)
             {
                 Vector2 spawner            = level.zombieSpawners[i2];
                 System.Drawing.Point mouse = levelPanel.PointToClient(Cursor.Position);
                 mouse.X += levelPanel.HorizontalScroll.Value;
                 mouse.Y += levelPanel.VerticalScroll.Value;
                 if ((mouse.X >= spawner.X) && (mouse.Y >= spawner.Y) && (mouse.X <= spawner.X + textures[2].Image.Width) && (mouse.Y <= spawner.Y + textures[2].Image.Height))
                 {
                     int       newLength    = level.zombieSpawners.Length - 1;
                     Vector2[] newSpawners  = new Vector2[newLength];
                     bool      foundDeleted = false;
                     for (int i3 = 0; i3 < level.zombieSpawners.Length; i3++)
                     {
                         if (foundDeleted)
                         {
                             newSpawners[i3 - 1] = level.zombieSpawners[i3];
                         }
                         else
                         {
                             if (i2 == i3)
                             {
                                 foundDeleted = true;
                             }
                             else
                             {
                                 newSpawners[i3] = level.zombieSpawners[i3];
                             }
                         }
                     }
                     level.zombieSpawners = newSpawners;
                     break;
                 }
             }
         }
         if (!deletedSomething)
         {
             for (int i = 0; i < level.backSolids.Length; i++)
             {
                 SolidData            solid = level.backSolids[i];
                 System.Drawing.Point mouse = levelPanel.PointToClient(Cursor.Position);
                 mouse.X += levelPanel.HorizontalScroll.Value;
                 mouse.Y += levelPanel.VerticalScroll.Value;
                 if ((mouse.X >= solid.position.X) && (mouse.Y >= solid.position.Y) && (mouse.X <= solid.position.X + textures[solid.textureNo].Image.Width) && (mouse.Y <= solid.position.Y + textures[solid.textureNo].Image.Height))
                 {
                     int         newLength    = level.backSolids.Length - 1;
                     SolidData[] newSolids    = new SolidData[newLength];
                     bool        foundDeleted = false;
                     for (int i2 = 0; i2 < level.backSolids.Length; i2++)
                     {
                         if (foundDeleted)
                         {
                             newSolids[i2 - 1] = level.backSolids[i2];
                         }
                         else
                         {
                             if (i == i2)
                             {
                                 foundDeleted = true;
                             }
                             else
                             {
                                 newSolids[i2] = level.backSolids[i2];
                             }
                         }
                     }
                     level.backSolids = newSolids;
                     deletedSomething = true;
                     break;
                 }
             }
         }
         PutPicturesInPanel();
     }
     if (clickMode == CLICK_MODE.PLAYER)
     {
         System.Drawing.Point point = levelPanel.PointToClient(Cursor.Position);
         //System.Drawing.Point point =  new System.Drawing.Point(levelPanel.PointToClient(Cursor.Position).X - textures[2].Image.Width / 2,
         //                                                        levelPanel.PointToClient(Cursor.Position).Y - textures[2].Image.Height / 2);
         point.X            -= textures[2].Image.Width / 2;
         point.Y            -= textures[2].Image.Height / 2;
         point               = snap(point);
         level.playerSpawn.X = point.X + levelPanel.HorizontalScroll.Value;
         level.playerSpawn.Y = point.Y + levelPanel.VerticalScroll.Value;
         PutPicturesInPanel();
     }
     if (clickMode == CLICK_MODE.ZOMBIE)
     {
         Vector2[] newSpawns = new Vector2[level.zombieSpawners.Length + 1];
         for (int i = 0; i < level.zombieSpawners.Length; i++)
         {
             newSpawns[i] = level.zombieSpawners[i];
         }
         System.Drawing.Point point = levelPanel.PointToClient(Cursor.Position);
         point.X += levelPanel.HorizontalScroll.Value;
         point.Y += levelPanel.VerticalScroll.Value;
         point.X -= textures[2].Image.Width / 2;
         point.Y -= textures[2].Image.Height / 2;
         point    = snap(point);
         newSpawns[level.zombieSpawners.Length] = new Vector2(point.X, point.Y);
         level.zombieSpawners = newSpawns;
         PutPicturesInPanel();
     }
     if (clickMode == CLICK_MODE.POINTER)
     {
         //not implemented
     }
     if (clickMode == CLICK_MODE.BACKGROUND)
     {
         if (selectedSolidTexture)
         {
             SolidData[] newSolids = new SolidData[level.backSolids.Length + 1];
             for (int i = 0; i < level.backSolids.Length; i++)
             {
                 newSolids[i] = level.backSolids[i];
             }
             System.Drawing.Point point = levelPanel.PointToClient(Cursor.Position);
             point.X += levelPanel.HorizontalScroll.Value;
             point.Y += levelPanel.VerticalScroll.Value;
             point.X -= textures[comboBoxSolidTexture.SelectedIndex].Image.Width / 2;
             point.Y -= textures[comboBoxSolidTexture.SelectedIndex].Image.Height / 2;
             point    = snap(point);
             newSolids[level.backSolids.Length] = new SolidData(new Vector2(point.X, point.Y), comboBoxSolidTexture.SelectedIndex, Microsoft.Xna.Framework.Color.White);
             level.backSolids = newSolids;
             PutPicturesInPanel();
         }
     }
     if (clickMode == CLICK_MODE.FOREGROUND)
     {
         if (selectedSolidTexture)
         {
             SolidData[] newSolids = new SolidData[level.foreSolids.Length + 1];
             for (int i = 0; i < level.foreSolids.Length; i++)
             {
                 newSolids[i] = level.foreSolids[i];
             }
             System.Drawing.Point point = levelPanel.PointToClient(Cursor.Position);
             point.X += levelPanel.HorizontalScroll.Value;
             point.Y += levelPanel.VerticalScroll.Value;
             point.X -= textures[comboBoxSolidTexture.SelectedIndex].Image.Width / 2;
             point.Y -= textures[comboBoxSolidTexture.SelectedIndex].Image.Height / 2;
             point    = snap(point);
             newSolids[level.foreSolids.Length] = new SolidData(new Vector2(point.X, point.Y), comboBoxSolidTexture.SelectedIndex, Microsoft.Xna.Framework.Color.White);
             level.foreSolids = newSolids;
             PutPicturesInPanel();
         }
     }
 }
Exemple #5
0
 public Solid(Coordinates coords, bool serverBlock, SolidData data) : base(coords, serverBlock, data)
 {
 }