コード例 #1
0
ファイル: PurpleBlock.cs プロジェクト: AustinJGreen/Fluid
        /// <summary>
        /// Tests if a purple block is equal to a block
        /// </summary>
        /// <param name="b">The block</param>
        /// <returns>True if equal in value</returns>
        public bool EqualsBlock(Block b)
        {
            if (b is PurpleBlock)
            {
                PurpleBlock pB = (PurpleBlock)b;
                return(pB.X == X && pB.Y == Y && pB.Layer == Layer && pB.ID == ID && pB.SwitchID == SwitchID);
            }

            return(false);
        }
コード例 #2
0
        public override void Update()
        {
            base.Update();

            ammo = MaxAmmo;
            if (duck != null)
            {
                StoredItem stored = PurpleBlock.GetStoredItem(duck.profile);

                if (stored.type == GetType())
                {
                    storeSound.Play();
                    duck.onFire = true;
                    duck.Zap(this);

                    stored.sprite = null;
                    stored.type   = null;
                    stored.thing  = null;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            WorldConnection worldCon = (WorldConnection)connectionBase;
            World           world    = worldCon.World;

            int     x       = message.GetInt(0);
            int     y       = message.GetInt(1);
            BlockID blockId = (BlockID)message.GetInt(2);

            uint arg = message.GetUInt(3);

            WorldPlayer player = null;

            if (message.Count > 4)
            {
                int userId = message.GetInt(4);
                player = worldCon.Players.GetPlayer(userId);
            }

            switch (blockId)
            {
            case BlockID.BlueCoinDoor:
            case BlockID.BlueCoinGate:
            case BlockID.CoinDoor:
            case BlockID.CoinGate:
            {
                CoinBlock block = new CoinBlock(worldCon, blockId, x, y, arg)
                {
                    Placer = player
                };

                if (!handled)
                {
                    world.SetBlock(block);
                    worldCon.CheckBlock(block);
                }

                CoinBlockEvent coinBlockEvent = new CoinBlockEvent()
                {
                    Raw       = message,
                    CoinBlock = block
                };

                connectionBase.RaiseServerEvent <CoinBlockEvent>(coinBlockEvent);
            }
            break;

            case BlockID.DeathDoor:
            case BlockID.DeathGate:
            {
                DeathBlock block = new DeathBlock(worldCon, blockId, x, y, arg)
                {
                    Placer = player
                };

                if (!handled)
                {
                    world.SetBlock(block);
                    worldCon.CheckBlock(block);
                }

                DeathBlockEvent deathBlockEvent = new DeathBlockEvent()
                {
                    Raw        = message,
                    DeathBlock = block
                };

                connectionBase.RaiseServerEvent <DeathBlockEvent>(deathBlockEvent);
            }
            break;

            case BlockID.SwitchPurple:
            case BlockID.PurpleSwitchDoor:
            case BlockID.PurpleSwitchGate:
            {
                PurpleBlock block = new PurpleBlock(worldCon, blockId, x, y, arg)
                {
                    Placer = player
                };

                if (!handled)
                {
                    world.SetBlock(block);
                    worldCon.CheckBlock(block);
                }

                PurpleBlockEvent purpleBlockEvent = new PurpleBlockEvent()
                {
                    Raw         = message,
                    PurpleBlock = block
                };

                connectionBase.RaiseServerEvent <PurpleBlockEvent>(purpleBlockEvent);
            }
            break;
            }
        }
コード例 #4
0
ファイル: PhysicsEngine.cs プロジェクト: AustinJGreen/Fluid
        /// <summary>
        /// Tests if the player is overlapping a block
        /// </summary>
        /// <param name="p">The player</param>
        private bool Overlaps(WorldPlayer p)
        {
            if ((p.X < 0 || p.Y < 0) || ((p.X > World.Width * 16 - 16) || (p.Y > World.Height * 16 - 16)))
            {
                return(true);
            }

            if (p.IsGod())
            {
                return(false);
            }

            var    firstX = ((int)p.X >> 4);
            var    firstY = ((int)p.Y >> 4);
            double lastX  = (p.X + 16) / 16;
            double lastY  = (p.Y + 16) / 16;
            bool   skip   = false;

            int x;
            int y = firstY;

            int a = firstY;
            int b;

            while (y < lastY)
            {
                x = firstX;
                b = firstX;
                for (; x < lastX; x++)
                {
                    Block   block  = World[x, y, Layer.Foreground];
                    BlockID tileId = block.ID;

                    if (IsSolid(tileId))
                    {
                        if (CanJumpThrough(tileId))
                        {
                            uint rot = 0;
                            if (block is RotatableBlock)
                            {
                                RotatableBlock rotatableBlock = (RotatableBlock)block;
                                rot = (uint)rotatableBlock.Rotation;
                            }

                            if (tileId == BlockID.OneWayCyan || tileId == BlockID.OneWayPink || tileId == BlockID.OneWayRed || tileId == BlockID.OneWayYellow)
                            {
                                if ((p.SpeedY < 0 || a <= p.m_overlapy) && rot == 1)
                                {
                                    if (a != firstY || p.m_overlapy == -1)
                                    {
                                        p.m_overlapy = a;
                                    }

                                    skip = true;
                                    continue;
                                }

                                if ((p.SpeedX > 0 || b <= p.m_overlapy) && rot == 2)
                                {
                                    if (b == firstX || p.m_overlapy == -1)
                                    {
                                        p.m_overlapy = b;
                                    }

                                    skip = true;
                                    continue;
                                }

                                if ((p.SpeedY > 0 || a <= p.m_overlapy) && rot == 3)
                                {
                                    if (a == firstY || p.m_overlapy == -1)
                                    {
                                        p.m_overlapy = a;
                                    }

                                    skip = true;
                                    continue;
                                }
                                if ((p.SpeedX < 0 || b <= p.m_overlapy) && rot == 0)
                                {
                                    if (b != firstX || p.m_overlapy == -1)
                                    {
                                        p.m_overlapy = b;
                                    }

                                    skip = true;
                                    continue;
                                }
                            }
                            else
                            {
                                if (p.SpeedY < 0 || a <= p.m_overlapy)
                                {
                                    if (a != y || p.m_overlapy == -1)
                                    {
                                        p.m_overlapy = a;
                                    }

                                    skip = true;
                                    continue;
                                }
                            }
                        }

                        switch (tileId)
                        {
                        case (BlockID)23:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.Red))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)24:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.Green))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)25:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.Blue))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)26:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.Red))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)27:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.Green))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)28:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.Blue))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)156:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.TimeDoor))
                            {
                                continue;
                            }
                            break;

                        case (BlockID)157:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.TimeDoor))
                            {
                                continue;
                            }
                            break;

                        case BlockID.CyanDoor:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.Cyan))
                            {
                                continue;
                            }
                            break;

                        case BlockID.MagentaDoor:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.Magenta))
                            {
                                continue;
                            }
                            break;

                        case BlockID.YellowDoor:
                            if (m_WorldConnection.Keys.IsKeyActive(Key.Yellow))
                            {
                                continue;
                            }
                            break;

                        case BlockID.CyanGate:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.Cyan))
                            {
                                continue;
                            }
                            break;

                        case BlockID.MagentaGate:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.Magenta))
                            {
                                continue;
                            }
                            break;

                        case BlockID.YellowGate:
                            if (m_WorldConnection.Keys.IsKeyHidden(Key.Yellow))
                            {
                                continue;
                            }
                            break;

                        case BlockID.PurpleSwitchDoor:
                        {
                            PurpleBlock purpleBlock = (PurpleBlock)World[x, y, Layer.Foreground];

                            if (p.m_switches[purpleBlock.SwitchID])
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.PurpleSwitchGate:
                        {
                            PurpleBlock purpleBlock = (PurpleBlock)World[x, y, Layer.Foreground];

                            if (!p.m_switches[purpleBlock.SwitchID])
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.DeathDoor:
                        {
                            DeathBlock deathBlock = (DeathBlock)World[x, y, Layer.Foreground];

                            if (p.m_deaths >= deathBlock.RequiredDeaths)
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.DeathGate:
                        {
                            DeathBlock deathBlock = (DeathBlock)World[x, y, Layer.Foreground];

                            if (p.m_deaths < deathBlock.RequiredDeaths)
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.DoorBuildersClub:
                            if (p.HasBuildersClub)
                            {
                                continue;
                            }
                            break;

                        case BlockID.GateBuildersClub:
                            if (!p.HasBuildersClub)
                            {
                                continue;
                            }
                            break;

                        case BlockID.CoinDoor:
                        case BlockID.BlueCoinDoor:
                        {
                            CoinBlock coinBlock = (CoinBlock)World[x, y, Layer.Foreground];

                            if (coinBlock.Goal <= p.GoldCoins)
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.CoinGate:
                        case BlockID.BlueCoinGate:
                        {
                            CoinBlock coinBlock = (CoinBlock)World[x, y, Layer.Foreground];

                            if (coinBlock.Goal > p.BlueCoins)
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.GateZombie:
                        {
                            if (p.HasPotionActive(Potion.Zombie))
                            {
                                continue;
                            }
                        }
                        break;

                        case BlockID.DoorZombie:
                        {
                            if (!p.HasPotionActive(Potion.Zombie))
                            {
                                continue;
                            }
                        }
                        break;

                        case (BlockID)61:
                        case (BlockID)62:
                        case (BlockID)63:
                        case (BlockID)64:
                        case (BlockID)89:
                        case (BlockID)90:
                        case (BlockID)91:
                        case (BlockID)96:
                        case (BlockID)97:
                        case (BlockID)122:
                        case (BlockID)123:
                        case (BlockID)124:
                        case (BlockID)125:
                        case (BlockID)126:
                        case (BlockID)127:
                        case (BlockID)146:
                        case (BlockID)154:
                        case (BlockID)158:
                        case (BlockID)194:
                        case (BlockID)211:
                            if (p.SpeedY < 0 || y <= p.m_overlapy)
                            {
                                if (y != firstY || p.m_overlapy == -1)
                                {
                                    p.m_overlapy = y;
                                }

                                skip = true;
                                continue;
                            }
                            break;

                        case (BlockID)83:
                        case (BlockID)77:
                            continue;
                        }
                        return(true);
                    }
                }
                y++;
            }

            if (!skip)
            {
                p.m_overlapy = -1;
            }
            return(false);
        }
コード例 #5
0
ファイル: PhysicsEngine.cs プロジェクト: AustinJGreen/Fluid
        /// <summary>
        /// Peforms a physics tick
        /// </summary>
        /// <param name="worldPlayer">The player</param>
        private void Tick(WorldPlayer worldPlayer)
        {
            int cx = ((int)(worldPlayer.X + 8) >> 4);
            int cy = ((int)(worldPlayer.Y + 8) >> 4);

            worldPlayer.m_current = (int)World[cx, cy, Layer.Foreground].ID;
            if (worldPlayer.Current == (BlockID)4 || IsClimbable(worldPlayer.Current))
            {
                worldPlayer.m_delayed  = worldPlayer.m_queue[1];
                worldPlayer.m_queue[0] = worldPlayer.m_current;
            }
            else
            {
                worldPlayer.m_delayed  = worldPlayer.m_queue[0];
                worldPlayer.m_queue[0] = worldPlayer.m_queue[1];
            }

            worldPlayer.m_queue[1] = worldPlayer.m_current;

            if (worldPlayer.IsDead)
            {
                worldPlayer.Horizontal = 0;
                worldPlayer.Vertical   = 0;
            }

            bool isGodMode = worldPlayer.IsGod();

            if (isGodMode)
            {
                worldPlayer.m_morx = 0;
                worldPlayer.m_mory = 0;
                worldPlayer.m_mox  = 0;
                worldPlayer.m_moy  = 0;
            }
            else
            {
                switch (worldPlayer.Current)
                {
                case BlockID.GravityLeft:
                case BlockID.InvisibleGravityLeft:
                    worldPlayer.m_morx = -Gravity;
                    worldPlayer.m_mory = 0;
                    break;

                case BlockID.GravityUp:
                case BlockID.InvisibleGravityUp:
                    worldPlayer.m_morx = 0;
                    worldPlayer.m_mory = -Gravity;
                    break;

                case BlockID.GravityRight:
                case BlockID.InvisibleGravityRight:
                    worldPlayer.m_morx = Gravity;
                    worldPlayer.m_mory = 0;
                    break;

                case BlockID.BoostLeft:
                case BlockID.BoostRight:
                case BlockID.BoostUp:
                case BlockID.BoostDown:
                case BlockID.LadderNinja:
                case BlockID.LadderCastle:
                case BlockID.LadderJungleHorizontal:
                case BlockID.LadderJungleVertical:
                case BlockID.InvisibleGravityDot:
                case BlockID.GravityDot:
                    worldPlayer.m_morx = 0;
                    worldPlayer.m_mory = 0;
                    break;

                case BlockID.Water:
                    worldPlayer.m_morx = Gravity;
                    worldPlayer.m_mory = (int)WaterBuoyancy;
                    break;

                case BlockID.Mud:
                    worldPlayer.m_morx = Gravity;
                    worldPlayer.m_mory = (int)MudBuoyancy;
                    break;

                case BlockID.HazardFire:
                case BlockID.HazardSpike:
                    if (!worldPlayer.IsDead && !worldPlayer.HasProtection)
                    {
                        worldPlayer.KillPlayerInternal();
                    }
                    break;

                default:
                    worldPlayer.m_morx = 0;
                    worldPlayer.m_mory = Gravity;
                    break;
                }

                switch ((BlockID)worldPlayer.m_delayed)
                {
                case BlockID.GravityLeft:
                case BlockID.InvisibleGravityLeft:
                    worldPlayer.m_mox = -Gravity;
                    worldPlayer.m_moy = 0;
                    break;

                case BlockID.GravityUp:
                case BlockID.InvisibleGravityUp:
                    worldPlayer.m_mox = 0;
                    worldPlayer.m_moy = -Gravity;
                    break;

                case BlockID.GravityRight:
                case BlockID.InvisibleGravityRight:
                    worldPlayer.m_mox = Gravity;
                    worldPlayer.m_moy = 0;
                    break;

                case BlockID.BoostLeft:
                case BlockID.BoostRight:
                case BlockID.BoostUp:
                case BlockID.BoostDown:
                case BlockID.LadderNinja:
                case BlockID.LadderCastle:
                case BlockID.LadderJungleHorizontal:
                case BlockID.LadderJungleVertical:
                case BlockID.InvisibleGravityDot:
                case BlockID.GravityDot:
                    worldPlayer.m_mox = 0;
                    worldPlayer.m_moy = 0;
                    break;

                case BlockID.Water:
                    worldPlayer.m_mox = Gravity;
                    worldPlayer.m_moy = (int)WaterBuoyancy;
                    break;

                case BlockID.Mud:
                    worldPlayer.m_mox = Gravity;
                    worldPlayer.m_moy = (int)MudBuoyancy;
                    break;

                default:
                    worldPlayer.m_mox = 0;
                    worldPlayer.m_moy = Gravity;
                    break;
                }
            }

            if (worldPlayer.m_moy == WaterBuoyancy || worldPlayer.m_moy == MudBuoyancy)
            {
                worldPlayer.m_mx = worldPlayer.Horizontal;
                worldPlayer.m_my = worldPlayer.Vertical;
            }
            else if (worldPlayer.m_moy != 0)
            {
                worldPlayer.m_mx = worldPlayer.Horizontal;
                worldPlayer.m_my = 0;
            }
            else if (worldPlayer.m_mox != 0)
            {
                worldPlayer.m_mx = 0;
                worldPlayer.m_my = worldPlayer.Vertical;
            }
            else
            {
                worldPlayer.m_mx = worldPlayer.Horizontal;
                worldPlayer.m_my = worldPlayer.Vertical;
            }

            worldPlayer.m_mx  *= worldPlayer.SpeedMultiplier;
            worldPlayer.m_my  *= worldPlayer.SpeedMultiplier;
            worldPlayer.m_mox *= World.Gravity;
            worldPlayer.m_moy *= World.Gravity;

            worldPlayer.ModifierX = worldPlayer.m_mox + worldPlayer.m_mx;
            worldPlayer.ModifierY = worldPlayer.m_moy + worldPlayer.m_my;

            if (!ApproachingZero(worldPlayer.m_speedX) || worldPlayer.m_modifierX != 0)
            {
                worldPlayer.m_speedX += worldPlayer.m_modifierX;
                worldPlayer.m_speedX *= BaseDrag;
                if ((worldPlayer.m_mx == 0 && worldPlayer.m_moy != 0) ||
                    (worldPlayer.m_speedX < 0 && worldPlayer.m_mx > 0) ||
                    (worldPlayer.m_speedX > 0 && worldPlayer.m_mx < 0) ||
                    (IsClimbable(worldPlayer.Current) && !isGodMode))
                {
                    worldPlayer.m_speedX *= NoModifierDrag;
                }
                else if (worldPlayer.Current == BlockID.Water && !isGodMode)
                {
                    worldPlayer.m_speedX *= WaterDrag;
                }
                else if (worldPlayer.Current == BlockID.Mud && !isGodMode)
                {
                    worldPlayer.m_speedX *= MudDrag;
                }

                if (worldPlayer.m_speedX > 16)
                {
                    worldPlayer.m_speedX = 16;
                }
                else if (worldPlayer.m_speedX < -16)
                {
                    worldPlayer.m_speedX = -16;
                }
                else if (worldPlayer.m_speedX < 0.0001 && worldPlayer.m_speedX > -0.0001)
                {
                    worldPlayer.m_speedX = 0;
                }
            }
            if (!ApproachingZero(worldPlayer.m_speedY) || worldPlayer.m_modifierY != 0)
            {
                worldPlayer.m_speedY += worldPlayer.m_modifierY;
                worldPlayer.m_speedY *= BaseDrag;
                if ((worldPlayer.m_my == 0 && worldPlayer.m_mox != 0) ||
                    (worldPlayer.m_speedY < 0 && worldPlayer.m_my > 0) ||
                    (worldPlayer.m_speedY > 0 && worldPlayer.m_my < 0) ||
                    (IsClimbable(worldPlayer.Current) && !isGodMode))
                {
                    worldPlayer.m_speedY *= NoModifierDrag;
                }
                else if (worldPlayer.Current == BlockID.Water && !isGodMode)
                {
                    worldPlayer.m_speedY *= WaterDrag;
                }
                else if (worldPlayer.Current == BlockID.Mud && !isGodMode)
                {
                    worldPlayer.m_speedY *= MudDrag;
                }

                if (worldPlayer.m_speedY > 16)
                {
                    worldPlayer.m_speedY = 16;
                }
                else if (worldPlayer.m_speedY < -16)
                {
                    worldPlayer.m_speedY = -16;
                }
                else if (worldPlayer.m_speedY < 0.0001 && worldPlayer.m_speedY > -0.0001)
                {
                    worldPlayer.m_speedY = 0;
                }
            }
            if (!isGodMode)
            {
                switch (worldPlayer.Current)
                {
                case BlockID.BoostLeft:
                    worldPlayer.m_speedX = -Boost;
                    break;

                case BlockID.BoostRight:
                    worldPlayer.m_speedX = Boost;
                    break;

                case BlockID.BoostUp:
                    worldPlayer.m_speedY = -Boost;
                    break;

                case BlockID.BoostDown:
                    worldPlayer.m_speedY = Boost;
                    break;
                }
            }

            double remainderX = worldPlayer.X % 1;
            double currentSX  = worldPlayer.m_speedX;
            double remainderY = worldPlayer.Y % 1;
            double currentSY  = worldPlayer.m_speedY;

            worldPlayer.m_donex = false;
            worldPlayer.m_doney = false;

            while ((currentSX != 0 && !worldPlayer.m_donex) || (currentSY != 0 && !worldPlayer.m_doney))
            {
                ProcessPortals(worldPlayer, ref remainderX, ref currentSX, ref remainderY, ref currentSY);

                StepX(worldPlayer, ref remainderX, ref currentSX, ref remainderY, ref currentSY);
                StepY(worldPlayer, ref remainderX, ref currentSX, ref remainderY, ref currentSY);
            }

            if (!worldPlayer.IsDead)
            {
                if (worldPlayer.SpaceDown)
                {
                    if (worldPlayer.HasLevitation)
                    {
                        worldPlayer.m_isThrusting   = true;
                        worldPlayer.m_currentThrust = MaxThrust;
                    }
                }
                else if (worldPlayer.HasLevitation)
                {
                    worldPlayer.m_isThrusting = false;
                }

                switch (worldPlayer.Current)
                {
                case BlockID.CoinGold:
                    lock (worldPlayer.CollectedGoldCoins)
                    {
                        bool alreadyCollected = false;
                        for (int i = 0; i < worldPlayer.CollectedGoldCoins.Count; i++)
                        {
                            if (worldPlayer.CollectedGoldCoins[i].X == cx &&
                                worldPlayer.CollectedGoldCoins[i].Y == cy)
                            {
                                alreadyCollected = true;
                                break;
                            }
                        }

                        if (!alreadyCollected)
                        {
                            worldPlayer.CollectedGoldCoins.Add(World[cx, cy, Layer.Foreground]);
                        }
                    }
                    break;

                case BlockID.CoinBlue:
                    lock (worldPlayer.CollectedBlueCoins)
                    {
                        bool alreadyCollected = false;
                        for (int i = 0; i < worldPlayer.CollectedBlueCoins.Count; i++)
                        {
                            if (worldPlayer.CollectedBlueCoins[i].X == cx &&
                                worldPlayer.CollectedBlueCoins[i].Y == cy)
                            {
                                alreadyCollected = true;
                                break;
                            }
                        }

                        if (!alreadyCollected)
                        {
                            worldPlayer.CollectedBlueCoins.Add(World[cx, cy, Layer.Foreground]);
                        }
                    }
                    break;
                }

                if (worldPlayer.m_pastx != cx || worldPlayer.m_pasty != cy)
                {
                    switch (worldPlayer.Current)
                    {
                    case BlockID.SwitchPurple:
                        if (World[cx, cy, Layer.Foreground] is PurpleBlock)
                        {
                            PurpleBlock block = (PurpleBlock)World[cx, cy, Layer.Foreground];
                            worldPlayer.m_switches[block.SwitchID] = !worldPlayer.m_switches[block.SwitchID];
                        }
                        break;

                    case BlockID.ToolCheckpoint:
                        if (!isGodMode)
                        {
                            worldPlayer.LastCheckpoint = World[cx, cy, Layer.Foreground];
                        }
                        break;
                    }

                    worldPlayer.m_pastx = cx;
                    worldPlayer.m_pasty = cy;
                }

                if (worldPlayer.HasLevitation)
                {
                    UpdateThrust(worldPlayer);
                }
            }

            var imx = ((int)worldPlayer.m_speedX << 8);
            var imy = ((int)worldPlayer.m_speedY << 8);

            if (worldPlayer.Current != BlockID.Water && worldPlayer.Current != BlockID.Mud)
            {
                if (imx == 0)
                {
                    if (worldPlayer.m_modifierX < 0.1 && worldPlayer.m_modifierX > -0.1)
                    {
                        double tx = worldPlayer.X % 16;
                        if (tx < 2)
                        {
                            if (tx < 0.2)
                            {
                                worldPlayer.X = Math.Floor(worldPlayer.X);
                            }
                            else
                            {
                                worldPlayer.X -= tx / 15;
                            }
                        }
                        else
                        {
                            if (tx > 14)
                            {
                                if (tx > 15.8)
                                {
                                    worldPlayer.X = Math.Ceiling(worldPlayer.X);
                                }
                                else
                                {
                                    worldPlayer.X += (tx - 14) / 15;
                                }
                            }
                        }
                    }
                }

                if (imy == 0)
                {
                    if (worldPlayer.m_modifierY < 0.1 && worldPlayer.m_modifierY > -0.1)
                    {
                        double ty = worldPlayer.Y % 16;
                        if (ty < 2)
                        {
                            if (ty < 0.2)
                            {
                                worldPlayer.Y = Math.Floor(worldPlayer.Y);
                            }
                            else
                            {
                                worldPlayer.Y -= ty / 15;
                            }
                        }
                        else
                        {
                            if (ty > 14)
                            {
                                if (ty > 15.8)
                                {
                                    worldPlayer.Y = Math.Ceiling(worldPlayer.Y);
                                }
                                else
                                {
                                    worldPlayer.Y += (ty - 14) / 15;
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Deserialize's the world data
        /// </summary>
        /// <param name="message">The message</param>
        internal void Deserialize(Message message)
        {
            // Find the start of the init message's world data
            uint start = 0;

            for (uint i = 0; i < message.Count; i++)
            {
                if (message[i] is string)
                {
                    if (string.Compare(message.GetString(i), "ws", false) == 0)
                    {
                        start = i + 1;
                        break;
                    }
                }
            }

            uint index = start;

            try
            {
                while (index < message.Count)
                {
                    if (message[index] is string)
                    {
                        if (string.Compare(message.GetString(index), "we", false) == 0)
                        {
                            break;
                        }
                    }

                    int blockInt = message.GetInt(index++);
                    int layerInt = message.GetInt(index++);

                    byte[] bytesX = message.GetByteArray(index++);
                    byte[] bytesY = message.GetByteArray(index++);

                    List <FluidPoint> locations = GetLocations(bytesX, bytesY);

                    BlockID blockId = (BlockID)blockInt;
                    Layer   layer   = (Layer)layerInt;

                    switch (blockId)
                    {
                    case BlockID.HazardSpike:
                    case BlockID.DecorSciFi2013BlueSlope:
                    case BlockID.DecorSciFi2013BlueStraight:
                    case BlockID.DecorSciFi2013YellowSlope:
                    case BlockID.DecorSciFi2013YellowStraight:
                    case BlockID.DecorSciFi2013GreenSlope:
                    case BlockID.DecorSciFi2013GreenStraight:
                    case BlockID.OneWayCyan:
                    case BlockID.OneWayPink:
                    case BlockID.OneWayRed:
                    case BlockID.OneWayYellow:
                    {
                        Rotation rotation = (Rotation)message.GetUInt(index++);

                        foreach (FluidPoint p in locations)
                        {
                            RotatableBlock rotatableBlock = new RotatableBlock(blockId, p.X, p.Y, rotation);
                            SetBlock(rotatableBlock);
                        }
                    }
                    break;

                    case BlockID.CoinDoor:
                    case BlockID.BlueCoinDoor:
                    case BlockID.CoinGate:
                    case BlockID.BlueCoinGate:
                    {
                        uint goal = message.GetUInt(index++);

                        foreach (FluidPoint p in locations)
                        {
                            CoinBlock door = new CoinBlock(blockId, p.X, p.Y, goal);
                            SetBlock(door);
                        }
                    }
                    break;

                    case BlockID.MusicDrum:
                    case BlockID.MusicPiano:
                    {
                        uint musicId = message.GetUInt(index++);

                        foreach (FluidPoint p in locations)
                        {
                            MusicBlock musicBlock = new MusicBlock(blockId, p.X, p.Y, musicId);
                            SetBlock(musicBlock);
                        }
                    }
                    break;

                    case BlockID.Portal:
                    case BlockID.InvisiblePortal:
                    {
                        Rotation rotation     = (Rotation)message.GetUInt(index++);
                        uint     portalid     = message.GetUInt(index++);
                        uint     portaltarget = message.GetUInt(index++);

                        foreach (FluidPoint p in locations)
                        {
                            Portal portal = new Portal(blockId, p.X, p.Y, rotation, portalid, portaltarget);
                            SetBlock(portal);
                        }
                    }
                    break;

                    case BlockID.SwitchPurple:
                    case BlockID.PurpleSwitchDoor:
                    case BlockID.PurpleSwitchGate:
                    {
                        uint goal = message.GetUInt(index++);

                        foreach (FluidPoint p in locations)
                        {
                            PurpleBlock purpleBlock = new PurpleBlock(blockId, p.X, p.Y, goal);
                            SetBlock(purpleBlock);
                        }
                    }
                    break;

                    case BlockID.DeathDoor:
                    case BlockID.DeathGate:
                    {
                        uint goal = message.GetUInt(index++);

                        foreach (FluidPoint p in locations)
                        {
                            DeathBlock deathBlock = new DeathBlock(blockId, p.X, p.Y, goal);
                            SetBlock(deathBlock);
                        }
                    }
                    break;

                    case BlockID.WorldPortal:
                    {
                        string targetId = message.GetString(index++);

                        foreach (FluidPoint p in locations)
                        {
                            WorldPortal worldPortal = new WorldPortal(blockId, p.X, p.Y, targetId);
                            SetBlock(worldPortal);
                        }
                    }
                    break;

                    case BlockID.DecorSign:
                    {
                        string text = message.GetString(index++);

                        foreach (FluidPoint p in locations)
                        {
                            TextBlock textBlock = new TextBlock(blockId, p.X, p.Y, text);
                            SetBlock(textBlock);
                        }
                    }
                    break;

                    case BlockID.DecorLabel:
                    {
                        string text     = message.GetString(index++);
                        string hexColor = message.GetString(index++);

                        foreach (FluidPoint p in locations)
                        {
                            LabelBlock labelBlock = new LabelBlock(blockId, p.X, p.Y, text, hexColor);
                            SetBlock(labelBlock);
                        }
                    }
                    break;

                    default:
                        foreach (FluidPoint p in locations)
                        {
                            Block block = new Block(blockId, layer, p.X, p.Y);
                            SetBlock(block);
                        }
                        break;
                    }
                }
            }
            catch
            {
                m_Client.Log.Add(FluidLogCategory.Message, "World init deserializer is out of date. Check for an update.");
            }
        }
コード例 #7
0
        /// <summary>
        /// Deserialize's the world data
        /// </summary>
        /// <param name="worldObject">The world data as a database array</param>
        private void Deserialize(DatabaseObject worldObject)
        {
            Owner           = GetValue <string>(worldObject, "owner");
            Width           = GetValue <int>(worldObject, "width", 200);
            Height          = GetValue <int>(worldObject, "height", 200);
            Title           = GetValue <string>(worldObject, "name");
            Plays           = GetValue <int>(worldObject, "plays");
            WorldType       = (WorldType)GetValue <int>(worldObject, "type", 3);
            AllowPotions    = GetValue <bool>(worldObject, "allowpotions", true);
            Woots           = GetValue <int>(worldObject, "woots", 0);
            TotalWoots      = GetValue <int>(worldObject, "totalwoots", 0);
            Visible         = GetValue <bool>(worldObject, "visible", true);
            BackgroundColor = new FluidColor(GetValue <uint>(worldObject, "backgroundColor", 0));

            //Check is worlddata is present
            if (!worldObject.Contains("worlddata"))
            {
                return;
            }

            CreateEmptyWorld();

            DatabaseArray        databaseArray = (DatabaseArray)worldObject["worlddata"];
            IEnumerable <object> databaseEnum  = (IEnumerable <object>)databaseArray;

            using (IEnumerator <object> enumerator = databaseEnum.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    DatabaseObject blockData = (DatabaseObject)enumerator.Current;

                    byte[]  xBytes  = blockData.GetBytes("x");
                    byte[]  yBytes  = blockData.GetBytes("y");
                    BlockID blockId = (BlockID)blockData.GetUInt("type");

                    for (int i = 0; i < xBytes.Length; i += 2)
                    {
                        int x = xBytes[i] << 8 | xBytes[i + 1];
                        int y = yBytes[i] << 8 | yBytes[i + 1];
                        if (blockData.Contains("layer"))
                        {
                            Layer layer = (Layer)blockData.GetInt("layer");

                            switch (blockId)
                            {
                            case BlockID.HazardSpike:
                            case BlockID.DecorSciFi2013BlueSlope:
                            case BlockID.DecorSciFi2013BlueStraight:
                            case BlockID.DecorSciFi2013YellowSlope:
                            case BlockID.DecorSciFi2013YellowStraight:
                            case BlockID.DecorSciFi2013GreenSlope:
                            case BlockID.DecorSciFi2013GreenStraight:
                            case BlockID.OneWayCyan:
                            case BlockID.OneWayPink:
                            case BlockID.OneWayRed:
                            case BlockID.OneWayYellow:
                            {
                                Rotation rotation = (Rotation)blockData.GetUInt("rotation");

                                RotatableBlock rotatableBlock = new RotatableBlock(blockId, x, y, rotation);
                                SetBlock(rotatableBlock);
                            }
                            break;

                            case BlockID.CoinDoor:
                            case BlockID.BlueCoinDoor:
                            case BlockID.CoinGate:
                            case BlockID.BlueCoinGate:
                            {
                                uint goal = blockData.GetUInt("goal");

                                CoinBlock door = new CoinBlock(blockId, x, y, goal);
                                SetBlock(door);
                            }
                            break;

                            case BlockID.MusicDrum:
                            case BlockID.MusicPiano:
                            {
                                uint musicId = blockData.GetUInt("id");

                                MusicBlock musicBlock = new MusicBlock(blockId, x, y, musicId);
                                SetBlock(musicBlock);
                            }
                            break;

                            case BlockID.Portal:
                            case BlockID.InvisiblePortal:
                            {
                                Rotation rotation     = (Rotation)blockData.GetUInt("rotation");
                                uint     portalid     = blockData.GetUInt("id");
                                uint     portaltarget = blockData.GetUInt("target");

                                Portal portal = new Portal(blockId, x, y, rotation, portalid, portaltarget);
                                SetBlock(portal);
                            }
                            break;

                            case BlockID.SwitchPurple:
                            case BlockID.PurpleSwitchDoor:
                            case BlockID.PurpleSwitchGate:
                            {
                                uint goal = 0;
                                if (blockData.Contains("goal"))
                                {
                                    goal = blockData.GetUInt("goal");
                                }

                                PurpleBlock purpleBlock = new PurpleBlock(blockId, x, y, goal);
                                SetBlock(purpleBlock);
                            }
                            break;

                            case BlockID.DeathDoor:
                            case BlockID.DeathGate:
                            {
                                uint goal = blockData.GetUInt("goal");

                                DeathBlock deathBlock = new DeathBlock(blockId, x, y, goal);
                                SetBlock(deathBlock);
                            }
                            break;

                            case BlockID.WorldPortal:
                            {
                                string targetId = blockData.GetString("target");

                                WorldPortal worldPortal = new WorldPortal(blockId, x, y, targetId);
                                SetBlock(worldPortal);
                            }
                            break;

                            case BlockID.DecorSign:
                            {
                                string text = blockData.GetString("text");

                                TextBlock textBlock = new TextBlock(blockId, x, y, text);
                                SetBlock(textBlock);
                            }
                            break;

                            case BlockID.DecorLabel:
                            {
                                string text = blockData.GetString("text");
                                if (blockData.Contains("text_color"))
                                {
                                    string hexColor = blockData.GetString("text_color");

                                    LabelBlock labelBlock = new LabelBlock(blockId, x, y, text, hexColor);
                                    SetBlock(labelBlock);
                                }
                                else
                                {
                                    LabelBlock labelBlock = new LabelBlock(blockId, x, y, text);
                                    SetBlock(labelBlock);
                                }
                            }
                            break;

                            default:
                                Block block = new Block(blockId, layer, x, y);
                                SetBlock(block);
                                break;
                            }
                        }
                    }
                }
            }

            IsLoaded = true;
        }