示例#1
0
        /// <summary>
        /// Creates a blank SM3DW Scene
        /// </summary>
        public SM3DWorldScene(SM3DWorldZone zone)
        {
            mainZone = zone;

            multiSelect = true;

            StaticObjects.Add(new LinkRenderer(this));
        }
示例#2
0
        public SM3DWorldScene()
        {
            multiSelect = true;

            StaticObjects.Add(new LinkRenderer(this));

            StaticObjects.Add(new ZonePlacementRenderer(this));
        }
示例#3
0
        private void h_FillByFile(int iLevel)
        {
            string sFn = $"../$Data/{iLevel}.csv";

            if (!File.Exists(sFn))
            {
                return;
            }

            string[] arLines = File.ReadAllLines(sFn);
            for (int iY = 0; iY < arLines.Length; iY++)
            {
                string[] arCells = arLines[iY].Split(';');
                for (int iX = 0; iX < arCells.Length; iX++)
                {
                    string s = arCells[iX];
                    // s @ iX, iY
                    switch (s)
                    {
                    case "+":
                    {
                        CPlayerDynamicObject pO =
                            new CPlayerDynamicObject("Player", iX, iY);
                        DynamicObjects.Add(pO);
                        break;
                    }

                    case "*": {
                        CWallStaticObject pO =
                            new CWallStaticObject(iX, iY);
                        StaticObjects.Add(pO);
                        break;
                    }

                    //case "-": {
                    //  CEmptyStaticObject pO =
                    //    new CEmptyStaticObject(iX, iY);
                    //  StaticObjects.Add(pO);
                    //  break;
                    //}
                    case "?": {
                        CBoxDynamicObject pO =
                            new CBoxDynamicObject(iX, iY);
                        DynamicObjects.Add(pO);
                        break;
                    }

                    case "!": {
                        CExitStaticObject pO =
                            new CExitStaticObject(iX, iY);
                        StaticObjects.Add(pO);
                        break;
                    }
                    }
                }
            }
        }
        /// <summary>
        /// Creates a serializable texture
        /// </summary>
        /// <param name="texture">Source</param>
        public SerializableTexture2D(Texture2D texture) : base(texture)
        {
            _imageFilePath = "Textures/" + texture.name + ".png";

            byte[] textureData = Utility.EncodeToPNG(texture);

            _imageFilePath = StaticObjects.Add(_imageFilePath, textureData);

            _alphaIsTransparency = texture.alphaIsTransparency;
            _format      = (int)texture.format;
            _mipMapCount = texture.mipmapCount;
        }
示例#5
0
 private void MoveToCollidable(IObject gameObject)
 {
     NonCollidableObjects.Remove(gameObject);
     if (gameObject is IDynamic)
     {
         DynamicObjects.Add((IDynamic)gameObject);
     }
     if (gameObject is IStatic)
     {
         StaticObjects.Add((IStatic)gameObject);
     }
 }
示例#6
0
        private void h_FillStage1()
        {
            CWallStaticObject pWall1 = new CWallStaticObject(0, 0);
            CWallStaticObject pWall2 = new CWallStaticObject(0, 1);
            CWallStaticObject pWall3 = new CWallStaticObject(0, 2);
            CWallStaticObject pWall4 = new CWallStaticObject(0, 3);

            StaticObjects.Add(pWall1);
            StaticObjects.Add(pWall2);
            StaticObjects.Add(pWall3);
            StaticObjects.Add(pWall4);
            ///...
        }
示例#7
0
        public void CreateObject(Type type, Vector2 position)
        {
            IObject obj = (IObject)Activator.CreateInstance(type, position);

            if (obj is IStatic)
            {
                StaticObjects.Add((IStatic)obj);
            }
            if (obj is IDynamic)
            {
                DynamicObjects.Add((IDynamic)obj);
            }
        }
示例#8
0
        public void AddObject(GameObject obj, int space = 0)
        {
            if (space != 0)
            {
                ClearArea(obj, space);
            }

            if (obj.Movable)
            {
                MovableObjects.Add(obj);
            }

            else
            {
                StaticObjects.Add(obj);
            }

            AlteredObjects.Add(obj);
        }
        private void BuildLevel(List <string[]> levelData)
        {
            // iterate through lines
            for (int i = 0; i < levelData.Count(); i++)
            {
                switch (levelData[i][0])
                {
                case "00":
                    // mario
                    Mario.Instance.PlayableObjectState = new SmallRightIdleMario(Mario.Instance);
                    Mario.Instance.Position            = new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize);
                    break;

                case "01":
                    // floor tiles
                    StaticObjects.Add(new FloorTile(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), new Vector2(StringToInt(i, 3), StringToInt(i, 4)), levelData[i][5]));
                    break;

                case "02":
                    // blocks
                    Blocks.Add(new Block(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), levelData[i][3], levelData[i][4]));
                    break;

                case "03":
                    // floating coins
                    Coins.Add(new Item(new Vector2((StringToInt(i, 1) * levelCellSize) + (levelCellSize / 4), StringToInt(i, 2) * levelCellSize), "FloatingCoin"));
                    break;

                case "04":
                    // pipes
                    Pipes.Add(new Pipe(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), StringToInt(i, 3), Convert.ToBoolean(levelData[i][4]), levelData[i][5]));
                    break;

                case "05":
                    // enemies
                    Enemies.Add(new Enemy(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize - 10), levelData[i][3]));
                    break;

                case "06":
                    // hills
                    BackgroundItems.Add(new Hill(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), StringToInt(i, 3)));
                    break;

                case "07":
                    // bushes
                    BackgroundItems.Add(new Bush(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), StringToInt(i, 3)));
                    break;

                case "08":
                    // clouds
                    BackgroundItems.Add(new Cloud(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), StringToInt(i, 3)));
                    break;

                case "09":
                    // castle
                    Castle = new Castle(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize));
                    break;

                case "10":
                    // flag pole
                    Flagpoles.Add(new Flagpole(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize), levelCellSize));
                    break;

                case "11":
                    // check point
                    Checkpoints.Add(new CheckPoint(new Vector2(StringToInt(i, 1) * levelCellSize, StringToInt(i, 2) * levelCellSize)));
                    break;

                case "12":
                    // coin room
                    CoinRoomPosition = new Vector2(StringToInt(i, 1) * levelCellSize + (levelCellSize / 8), StringToInt(i, 2) * levelCellSize);
                    break;
                }
            }

            DynamicObjects.Add(Mario.Instance);

            foreach (Block block in Blocks)
            {
                DynamicObjects.Add(block);
                DynamicObjects.Add(block.Item); // Add items in each block too.
            }

            foreach (Item coin in Coins)
            {
                DynamicObjects.Add(coin);
            }

            foreach (Enemy enemy in Enemies)
            {
                // Added such that the Koopa spawns in a correct position before any updates are made, otherwise he spawns in the floor to start.
                if (enemy.EnemyState.ToString() == "SuperMario.EnemyStates.LeftWalkingKoopa" || enemy.EnemyState.ToString() == "SuperMario.EnemyStates.RightWalkingKoopa")
                {
                    enemy.Position = new Vector2(enemy.Position.X, enemy.Position.Y - GameValues.KoopaPositionOffset);
                }
                DynamicObjects.Add(enemy);
            }

            foreach (Pipe pipe in Pipes)
            {
                StaticObjects.Add(pipe);
            }

            foreach (Flagpole flagpole in Flagpoles)
            {
                StaticObjects.Add(flagpole);
            }

            if (Flagpoles.Count > 0)
            {
                Flag.Position = new Vector2(Flagpoles[0].CollisionRectangle.X - GameValues.FlagPositionOffsetVector.X, Flagpoles[0].CollisionRectangle.Y + GameValues.FlagPositionOffsetVector.Y);
            }
        }
示例#10
0
 public void AddStaticObject(IStaticObject staticObject)
 {
     StaticObjects.Add(staticObject);
 }
示例#11
0
        // Create platforms & environment
        private void CreateEnvironment(GraphicsDevice g)
        {
            #region Create Player & Target
            // First objects to create are the player and the target
            Player          = new Character(true);
            Player.Position = new Vector2(_nearEdge + 32, _bottomEdge - 128);
            Player.IsPlayer = true;
            RigidBody playerBody = Player.RigidBody;
            playerBody.Position         = Player.Position;
            playerBody.Width            = 32;
            playerBody.Height           = 32;
            playerBody.CollidableObject = new BoxCollider();
            Player.TexturePos           = new Vector2(Player.Position.X - playerBody.Width / 2, Player.Position.Y - playerBody.Height / 2);
            DynamicObjects.Add(Player);
            AllPhysObjects.Add(Player);

            Target            = new PhysObject();
            Target.Position   = new Vector2(_farEdge / 2, _bottomEdge - 256);
            Target.IsTarget   = true;
            Target.Elasticity = 1;
            RigidBody targetBody = Target.RigidBody;
            targetBody.Mass                      = 100.0f;
            targetBody.Position                  = Target.Position;
            targetBody.Width                     = 32;
            targetBody.Height                    = 32;
            targetBody.CollidableObject          = new BoxCollider();
            targetBody.CollidableObject.IsCircle = true;
            targetBody.AffectedByPhysics         = false;
            targetBody.IgnoreGravity             = true;

            float targetYVelocity = ((float)World.RandomGen.Next(3, 7) / 10.0f);
            if (World.RandomGen.Next(0, 1) == 0)
            {
                targetYVelocity *= -1;
            }
            float targetXVelocity = ((float)World.RandomGen.Next(3, 7) / 10.0f);
            if (World.RandomGen.Next(0, 1) == 0)
            {
                targetXVelocity *= -1;
            }
            targetBody.LinearVelocity = new Vector2(targetXVelocity * _portalSpeed, targetYVelocity * _portalSpeed);

            Target.TexturePos = new Vector2(targetBody.Position.X - targetBody.Width / 2, targetBody.Position.X - targetBody.Height / 2);
            DynamicObjects.Add(Target);
            AllPhysObjects.Add(Target);
            #endregion

            #region Edges
            // EDGES - Create the far left walls
            PhysObject block = new PhysObject();
            block.Position = new Vector2(_nearEdge - 480, _bottomEdge / 2);
            RigidBody body = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = _farEdge / 2;
            body.Height           = _bottomEdge;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // EDGES - Create the far right wall
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge + 480, _bottomEdge / 2);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = _farEdge / 2;
            body.Height           = _bottomEdge;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // EDGES - Create the main floor
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2, _bottomEdge + 480);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 4096;
            body.Height           = 1024;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // EDGES - Create the roof
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2, _topEdge - 480);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 4096;
            body.Height           = 1024;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion

            #region Platforms - Tier 0
            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_nearEdge + 320, _bottomEdge - 32);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 640;
            body.Height           = 64;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);


            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge - 320, _bottomEdge - 32);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 640;
            body.Height           = 64;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion

            #region Platforms - Tier 1
            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_nearEdge + 256, _bottomEdge - 240);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 256;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Moving Platform
            block = new MovingPlatform(new Vector2(_nearEdge + 256, _bottomEdge - 144),
                                       new Vector2(_nearEdge + 192, _bottomEdge - 144),
                                       new Vector2(_nearEdge + (_farEdge / 2) - 160, _bottomEdge - 144),
                                       new Vector2(100, 0));
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 256;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Moving Platform
            block = new MovingPlatform(new Vector2(_farEdge - 256, _bottomEdge - 144),
                                       new Vector2((_farEdge / 2) + 160, _bottomEdge - 144),
                                       new Vector2(_farEdge - 192, _bottomEdge - 144),
                                       new Vector2(-100, 0));
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 256;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge - 256, _bottomEdge - 240);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 256;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion

            #region Platforms - Tier 2
            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2 - 448, _bottomEdge - 400);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 128;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2 + 448, _bottomEdge - 400);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 128;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion

            #region Platforms - Tier 3
            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2, _bottomEdge - 496);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 512;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            /*
             * // Pendulum (spins, collisions partially broken though, uncomment if you want to see (spawns to the right of the player start))
             * block = new Pendulum(new Vector2(_farEdge / 2, _bottomEdge - 496), new Vector2(0, 128));
             * DynamicObjects.Add(block);
             * AllPhysObjects.Add(block);
             */

            #endregion

            #region Platforms - Tier 4
            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_nearEdge + 256, _bottomEdge - 592);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 512;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge - 256, _bottomEdge - 592);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 512;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion

            #region Platforms - Tier 5
            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_nearEdge + 128, _bottomEdge - 784);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 256;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2 - 208, _bottomEdge - 784);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 352;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Thicker block
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2 + 80, _bottomEdge - 704);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 96;
            body.Height           = 128;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Thicker block
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2 - 80, _bottomEdge - 704);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 96;
            body.Height           = 128;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2 + 208, _bottomEdge - 784);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 352;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge - 128, _bottomEdge - 784);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 256;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion

            #region Platforms - Tier 6
            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_nearEdge + 432, _bottomEdge - 1008);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 288;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Thicker block
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2 - 80, _bottomEdge - 1040);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 96;
            body.Height           = 160;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Thicker block
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2 + 80, _bottomEdge - 1040);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 96;
            body.Height           = 160;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge - 432, _bottomEdge - 1008);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 288;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion

            #region Platforms - Tier 7
            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_nearEdge + 560, _bottomEdge - 1072);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 32;
            body.Height           = 96;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge - 560, _bottomEdge - 1072);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 32;
            body.Height           = 96;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion

            #region Platforms - Tier 8
            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2 - 256, _bottomEdge - 1136);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 448;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2 + 256, _bottomEdge - 1136);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 448;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion

            #region Platforms - Tier 9
            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_nearEdge + 128, _bottomEdge - 1424);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 256;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2 - 288, _bottomEdge - 1424);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 256;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2 + 288, _bottomEdge - 1424);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 256;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge - 128, _bottomEdge - 1424);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 256;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion

            #region Platforms - Tier 10
            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2, _bottomEdge - 1680);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 640;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion

            #region Platforms - Tier 11
            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2, _bottomEdge - 1760);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 256;
            body.Height           = 128;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion

            #region Platforms - Tier 12
            // Moving Platform
            block = new MovingPlatform(new Vector2(_nearEdge + 256, _bottomEdge - 2000),
                                       new Vector2(_nearEdge + 160, _bottomEdge - 2000),
                                       new Vector2(_nearEdge + (_farEdge / 2) - 160, _bottomEdge - 2000),
                                       new Vector2(100, 0));
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 256;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);

            // Moving Platform
            block = new MovingPlatform(new Vector2(_farEdge - 256, _bottomEdge - 2000),
                                       new Vector2((_farEdge / 2) + 160, _bottomEdge - 2000),
                                       new Vector2(_farEdge - 160, _bottomEdge - 2000),
                                       new Vector2(-100, 0));
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 256;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion

            #region Platforms - Tier 13
            // Platform
            block                 = new PhysObject();
            block.Position        = new Vector2(_farEdge / 2, _bottomEdge - 2288);
            body                  = block.RigidBody;
            body.Mass             = _maximumMass;
            body.IgnoreGravity    = true;
            body.IsDynamic        = false;
            body.Position         = block.Position;
            body.Width            = 512;
            body.Height           = 32;
            body.CollidableObject = new BoxCollider();
            StaticObjects.Add(block);
            AllPhysObjects.Add(block);
            #endregion
        }
示例#12
0
        public LinkEdit3DWScene()
        {
            linkManager = new LinkManager(this);

            StaticObjects.Add(linkManager);
        }
示例#13
0
        public WorldMapScene(SarcData sarc, string sarcName)
        {
            multiSelect = true;

            #region read files
            this.sarc     = sarc;
            this.sarcName = sarcName;

            bfresEntry = sarc.Files.First(x => x.Key.EndsWith(".bfres"));

            pointEntry = sarc.Files.First(x => x.Key.StartsWith("pointW"));

            routeEntry = sarc.Files.First(x => x.Key.StartsWith("routeW"));

            bfres = new ResFile(new MemoryStream(bfresEntry.Value));
            bones = bfres.Models[0].Skeleton.Bones;

            pointCsv = Encoding.GetEncoding("shift-jis").GetString(sarc.Files.First(file => file.Key.StartsWith("pointW")).Value).
                       Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None).Reverse().Skip(1).Select(row =>
            {
                int pos = 0;
                List <string> fields = new List <string>();

                while (pos < row.Length)
                {
                    string value;

                    // Special handling for quoted field
                    if (row[pos] == '"')
                    {
                        // Skip initial quote
                        pos++;

                        // Parse quoted value
                        int start = pos;
                        while (pos < row.Length)
                        {
                            // Test for quote character
                            if (row[pos] == '"')
                            {
                                // Found one
                                pos++;

                                // If two quotes together, keep one
                                // Otherwise, indicates end of value
                                if (pos >= row.Length || row[pos] != '"')
                                {
                                    pos--;
                                    break;
                                }
                            }
                            pos++;
                        }
                        value = row.Substring(start, pos - start);
                        value = value.Replace("\"\"", "\"");
                    }
                    else
                    {
                        // Parse unquoted value
                        int start = pos;
                        while (pos < row.Length && row[pos] != ',')
                        {
                            pos++;
                        }
                        value = row.Substring(start, pos - start);
                    }

                    // Add field to list
                    fields.Add(value);

                    // Eat up to and including next comma
                    while (pos < row.Length && row[pos] != ',')
                    {
                        pos++;
                    }
                    if (pos < row.Length)
                    {
                        pos++;
                    }
                }

                return(fields.ToArray());
            }).Reverse().ToArray().ToDictionary(x => x[1]);

            routeCsv = Encoding.GetEncoding("shift-jis").GetString(sarc.Files.First(file => file.Key.StartsWith("routeW")).Value).
                       Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None).Reverse().Skip(1).Select(row =>
            {
                int pos = 0;
                List <string> fields = new List <string>();

                while (pos < row.Length)
                {
                    string value;

                    // Special handling for quoted field
                    if (row[pos] == '"')
                    {
                        // Skip initial quote
                        pos++;

                        // Parse quoted value
                        int start = pos;
                        while (pos < row.Length)
                        {
                            // Test for quote character
                            if (row[pos] == '"')
                            {
                                // Found one
                                pos++;

                                // If two quotes together, keep one
                                // Otherwise, indicates end of value
                                if (pos >= row.Length || row[pos] != '"')
                                {
                                    pos--;
                                    break;
                                }
                            }
                            pos++;
                        }
                        value = row.Substring(start, pos - start);
                        value = value.Replace("\"\"", "\"");
                    }
                    else
                    {
                        // Parse unquoted value
                        int start = pos;
                        while (pos < row.Length && row[pos] != ',')
                        {
                            pos++;
                        }
                        value = row.Substring(start, pos - start);
                    }

                    // Add field to list
                    fields.Add(value);

                    // Eat up to and including next comma
                    while (pos < row.Length && row[pos] != ',')
                    {
                        pos++;
                    }
                    if (pos < row.Length)
                    {
                        pos++;
                    }
                }

                return(fields.ToArray());
            }).Reverse().ToArray().ToDictionary(x => x[0]);


            //SaveFileDialog sfd = new SaveFileDialog()
            //{
            //    FileName = sarcName
            //};

            //if (sfd.ShowDialog() == DialogResult.OK)
            //{
            //    var stream = new MemoryStream();
            //    bfres.Save(stream, true);

            //    sarc.Files[bfresEntry.Key] = stream.ToArray();

            //    Yaz0.Compress(new FileStream(sfd.FileName, FileMode.OpenOrCreate), SARC.PackN(sarc));
            //}

            #endregion

            #region read map from bones
            Matrix4 rootMatrix = bones[0].CalculateRelativeMatrix();

            var boneIter = new BoneIter(bones);

            boneIter.MoveNext(); //first bone is the root, we don't need to read it

            while (boneIter.MoveNext())
            {
                var bone = boneIter.Current;

                if (bone.ParentIndex == -1) //there is more than one root (should never happen)
                {
                    break;
                }

                if (bone.Name.StartsWith("R")) //indicates a Route
                {
                    Routes.Add(new WorldMapRoute(boneIter, rootMatrix, pointCsv));
                    continue;
                }

                if (bone.ParentIndex != 0)
                {
                    throw new Exception(bone.Name + " is in an unexpected Layer, proceeding might currupt the file");
                }

                Vector4 pos = new Vector4(
                    bone.Position.X / 100,
                    bone.Position.Y / 100,
                    bone.Position.Z / 100,
                    1
                    );

                if (bone.Name == "course")
                {
                    Matrix4 courseBoneMatrix = boneIter.Current.CalculateRelativeMatrix() * rootMatrix;

                    short courseBoneIndex = (short)boneIter.CurrentBoneIndex;
                    while (boneIter.PeekNext()?.ParentIndex == courseBoneIndex)
                    {
                        boneIter.MoveNext();
                        if (pointCsv.ContainsKey(boneIter.Current.Name))
                        {
                            WorldMapObjects.Add(new WorldMapPoint(boneIter, courseBoneMatrix, pointCsv[boneIter.Current.Name]));
                        }
                        else
                        {
                            WorldMapObjects.Add(new UnknownWorldMapBone(boneIter, rootMatrix));
                        }
                    }
                }
                else if (pointCsv.ContainsKey(bone.Name))
                {
                    WorldMapObjects.Add(new WorldMapPoint(boneIter, rootMatrix, pointCsv[bone.Name]));
                }
                else if (bone.Name.StartsWith("cob"))
                {
                    WorldMapObjects.Add(new WorldMapCob(boneIter, rootMatrix));
                }
                else
                {
                    WorldMapObjects.Add(new UnknownWorldMapBone(boneIter, rootMatrix));
                }
            }
            #endregion

            foreach (var route in Routes)
            {
                TryGetPoint(route.Name.Substring(1, 4), out WorldMapPoint start);
                TryGetPoint(route.Name.Substring(5, 4), out WorldMapPoint end);

                route.Start = start;
                route.End   = end;
            }

            //ModelObjectReplace();

            StaticObjects.Add(new StaticModel(bfresEntry.Key, bfres));
            StaticObjects.Add(new ConnectionDrawer(this));

            SelectionChanged += WorldMapScene_SelectionChanged;
        }
示例#14
0
 public void AddObject(IStatic gameObject)
 {
     StaticObjects.Add(gameObject);
 }