/// <summary>
        /// set the block, making sure we're in the right chunk first
        /// </summary>
        /// <param name="location"></param>
        /// <param name="newBlockType"></param>
        public void setBlock(Coordinate location, Block.Type newBlockType)
        {
            if (location.x >= bounds.x)
            {
                getNeighbor(Directions.East).setBlock(location - bounds, newBlockType);
            }
            if (location.x < 0)
            {
                getNeighbor(Directions.West).setBlock(location + bounds, newBlockType);
            }
            if (location.y >= bounds.y)
            {
                getNeighbor(Directions.Above).setBlock(location - bounds, newBlockType);
            }
            if (location.y < 0)
            {
                getNeighbor(Directions.Below).setBlock(location + bounds, newBlockType);
            }
            if (location.z >= bounds.z)
            {
                getNeighbor(Directions.North).setBlock(location - bounds, newBlockType);
            }
            if (location.z < 0)
            {
                getNeighbor(Directions.South).setBlock(location + bounds, newBlockType);
            }

            blocks.setBlock(location, newBlockType);
        }
Esempio n. 2
0
 /// <summary>
 /// Generate the given set of blockdata at the given location offset
 /// </summary>
 /// <param name="location">The xyz to use as an offset for generating these blocks</param>
 /// <param name="blockData">The block data to populate</param>
 public void generateAllAt(Coordinate location, IBlockStorage blockData)
 {
     isoSurfaceLevel = getIsoSurfaceLevel();
     Coordinate.Zero.until(blockData.bounds, (coordinate) => {
         BlocksGenerated++;
         Coordinate globalLocation    = coordinate + (location * blockData.bounds);
         float isoSurfaceDensityValue = getNoiseValueAt(globalLocation);
         Block.Type newBlockType      = getBlockTypeFor(isoSurfaceDensityValue);
         if (newBlockType != Block.Types.Air)
         {
             blockData.setBlock(coordinate, newBlockType);
         }
     });
 }
        public Block Get(Type type, Moves direction)
        {
            IDictionary <Moves, Block> movesBlocks;

            loadedBlocks.TryGetValue(type, out movesBlocks);

            if (movesBlocks == null)
            {
                movesBlocks        = new Dictionary <Moves, Block>();
                loadedBlocks[type] = movesBlocks;
            }

            BlockImageFactory.Instance.GetImage(type, direction, false);

            Block b = CreateBlock(type, direction);

            movesBlocks[direction] = b;
            return(b);
        }
 public virtual Block Find(Block.Type type)
 {
     if (lower != null && lower.IsA(type))
     {
         return(lower);
     }
     if (upper != null && upper.IsA(type))
     {
         return(upper);
     }
     if (visitorLow != null && visitorLow.IsA(type))
     {
         return(visitorLow);
     }
     if (visitorHigh != null && visitorHigh.IsA(type))
     {
         return(visitorHigh);
     }
     return(null);
 }
        public virtual CanvasBitmap GetImage(Type type, Moves moves, bool overlay)
        {
            var images = overlay ? loadedImagesOverlay : loadedImages;

            IDictionary <Moves, CanvasBitmap> moveImages;

            images.TryGetValue(type, out moveImages);
            if (moveImages == null)
            {
                moveImages   = new Dictionary <Moves, CanvasBitmap>();
                images[type] = moveImages;
            }

            CanvasBitmap im;

            moveImages.TryGetValue(moves, out im);
            if (im == null)
            {
                im = LoadImage(type, moves, overlay);
                moveImages[moves] = im;
            }

            return(im);
        }
 public abstract Block CreateBlock(Type type, Moves direction);
 public Block Get(Type type)
 {
     return(Get(type, Moves.DOWN));
 }
 public Block CreateBlock(Block.Type blockType)
 {
     return(Shared.Game.Instance.BlockFactory.Get(blockType));
 }
        private CanvasBitmap LoadImage(Type type, Moves moves, bool overlay)
        {
            // If overlay, x and y are the overlay coordinates.
            int x = 0;
            int y = 0;

            switch (type)
            {
            case Type.BLOB:
                y = 12;
                x = 5;
                break;

            case Type.BLOCK:
                y = 10;
                x = 0;
                break;

            case Type.BLUEBUTTON:
                y = 8;
                x = 2;
                break;

            case Type.BLUEKEY:
                y = 4;
                x = 6;
                break;

            case Type.BLUELOCK:
                y = 6;
                x = 1;
                break;

            case Type.BLUEWALLREAL:
            case Type.BLUEWALLFAKE:
                y = 14;
                x = 1;
                break;

            case Type.BOMB:
                y = 10;
                x = 2;
                break;

            case Type.BROWNBUTTON:
                y = 7;
                x = 2;
                break;

            case Type.BUG:
                y = 0;
                x = 4;
                break;

            case Type.BURNEDCHIP:
                y = 4;
                x = 3;
                break;

            case Type.CHIP:
                y = 12;
                x = 6;
                break;

            case Type.CLONEBLOCK:
                y = 0;
                x = 1;
                break;

            case Type.CLONEMACHINE:
                y = 1;
                x = 3;
                break;

            case Type.COMPUTERCHIP:
                y = 2;
                x = 0;
                break;

            case Type.DIRT:
                y = 11;
                x = 0;
                break;

            case Type.DROWNEDCHIP:
                y = 3;
                x = 3;
                break;

            case Type.EXIT:
                y = 5;
                x = 1;
                break;

            case Type.FAKEEXIT:
                y = 5;
                x = 1;
                break;

            case Type.FIRE:
                y = 4;
                x = 0;
                break;

            case Type.FIREBOOTS:
                y = 9;
                x = 6;
                break;

            case Type.FIREBALL:
                y = 4;
                x = 4;
                break;

            case Type.FLIPPERS:
                y = 8;
                x = 6;
                break;

            case Type.FLOOR:
                y = 0;
                x = 0;
                break;

            case Type.FORCEFLOOR:
                y = 2;
                x = 1;
                break;

            case Type.RANDOMFORCEFLOOR:
                y = 2;
                x = 3;
                break;

            case Type.GLIDER:
                y = 0;
                x = 5;
                break;

            case Type.GRAVEL:
                y = 13;
                x = 2;
                break;

            case Type.GREENBUTTON:
                y = 3;
                x = 2;
                break;

            case Type.GREENKEY:
                y = 6;
                x = 6;
                break;

            case Type.GREENLOCK:
                y = 8;
                x = 1;
                break;

            case Type.HIDDENWALL:
                y = 0;
                x = 0;
                break;

            case Type.HINT:
                y = 15;
                x = 2;
                break;

            case Type.ICE:
                y = 12;
                x = 0;
                break;

            case Type.ICECORNER:
                y = 10;
                x = 1;
                break;

            case Type.ICEBLOCK:
                y = 10;
                x = 1;
                break;

            case Type.ICESKATES:
                y = 10;
                x = 6;
                break;

            case Type.INVISIBLEWALL:
                y = 0;
                x = 0;
                break;

            case Type.LOCK:     // ?
                break;

            case Type.PARAMECIUM:
                y = 0;
                x = 6;
                break;

            case Type.PINKBALL:
                y = 8;
                x = 4;
                break;

            case Type.RECESSEDWALL:
                y = 14;
                x = 2;
                break;

            case Type.REDBUTTON:
                y = 4;
                x = 2;
                break;

            case Type.REDKEY:
                y = 5;
                x = 6;
                break;

            case Type.REDLOCK:
                y = 7;
                x = 1;
                break;

            case Type.SOCKET:
                y = 2;
                x = 2;
                break;

            case Type.SUCTIONBOOTS:
                y = 11;
                x = 6;
                break;

            case Type.SWIMMINGCHIP:
                y = 12;
                x = 3;
                break;

            case Type.TANK:
                y = 12;
                x = 4;
                break;

            case Type.TEETH:
                y = 4;
                x = 5;
                break;

            case Type.TELEPORT:
                y = 9;
                x = 2;
                break;

            case Type.THIEF:
                y = 1;
                x = 2;
                break;

            case Type.THINWALL:
                y = 6;
                x = 0;
                break;

            case Type.THINWALLSE:
                y = 0;
                x = 3;
                break;

            case Type.TOGGLEWALLCLOSED:
                y = 5;
                x = 2;
                break;

            case Type.TOGGLEWALLOPEN:
                y = 6;
                x = 2;
                break;

            case Type.TRAP:
                y = 11;
                x = 2;
                break;

            case Type.WALKER:
                y = 8;
                x = 5;
                break;

            case Type.WALL:
                y = 1;
                x = 0;
                break;

            case Type.WATER:
                y = 3;
                x = 0;
                break;

            case Type.YELLOWKEY:
                y = 7;
                x = 6;
                break;

            case Type.YELLOWLOCK:
                y = 9;
                x = 1;
                break;
            }

            if (overlay)
            {
                if (x >= 4)
                {
                    x += 3;
                }
            }

            if ((x >= 4 && !(x == 6 && y >= 4 && y <= 11)) || type == Type.SWIMMINGCHIP || type == Type.ICEBLOCK || type == Type.THINWALL || type == Type.ICECORNER)
            {
                switch (moves)
                {
                case Moves.DOWN:
                    y += 2;
                    break;

                case Moves.LEFT:
                    y += 1;
                    break;

                case Moves.RIGHT:
                    y += 3;
                    break;
                }
            }

            if (type == Type.FORCEFLOOR)
            {
                switch (moves)
                {
                case Moves.DOWN:
                    x = 0;
                    y = 13;
                    break;

                case Moves.LEFT:
                    y += 2;
                    break;

                case Moves.RIGHT:
                    y += 1;
                    break;
                }
            }

            CanvasDevice       device = CanvasDevice.GetSharedDevice();
            CanvasRenderTarget image  = new CanvasRenderTarget(device, 32, 32, 96);

            image.CopyPixelsFromBitmap(blockSprites, 0, 0, x * 32, y * 32, 32, 32);

            IDictionary <Type, IDictionary <Moves, CanvasBitmap> > images;

            if (overlay)
            {
                images = loadedImagesOverlay;
            }
            else
            {
                images = loadedImages;
            }

            IDictionary <Moves, CanvasBitmap> movesMap = images[type];

            if (movesMap == null)
            {
                movesMap        = new Dictionary <Moves, CanvasBitmap>();
                movesMap[moves] = image;
                images[type]    = movesMap;
            }
            else
            {
                movesMap[moves] = image;
            }

            return(image);
        }
Esempio n. 10
0
        public override Block CreateBlock(Type type, Moves facing)
        {
            Block ret = null;
            IBlockTickBehavior   nullTick       = NullTickBehavior.Instance;
            IButtonBehavior      nullButton     = NullButtonBehavior.Instance;
            CloneBehavior        nullClone      = NullCloneBehavior.Instance;
            ITrapReleaseBehavior defaultTrap    = DefaultTrapReleaseBehavior.Instance;
            BlockReaction        canMove        = CanMove.Instance;
            BlockReaction        cannotMove     = CannotMove.Instance;
            IDestroyBehavior     defaultDestroy = DefaultDestroyBehavior.Instance;

            switch (type)
            {
            case Type.BLOB:
                ret = new Block(type, facing, BlobTickBehavior.Instance, canMove, CreatureTo.Instance, nullButton, BlobCloneBehavior.Instance, defaultTrap, defaultDestroy);
                break;

            case Type.BLOCK:
                ret = new Block(type, facing, nullTick, canMove, BlockTo.Instance, nullButton, CloneSameDirection.Instance, defaultTrap, defaultDestroy);
                break;

            case Type.BLUEBUTTON:
                ret = new Block(type, facing, nullTick, canMove, BlueButtonTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.BLUEKEY:
                ret = new Block(type, facing, nullTick, canMove, BlueKeyTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.BLUELOCK:
                ret = new Block(type, facing, nullTick, canMove, BlueLockTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.BLUEWALLFAKE:
                ret = new Block(type, facing, nullTick, canMove, BlueWallFakeTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.BLUEWALLREAL:
                ret = new Block(type, facing, nullTick, canMove, BlueWallRealTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.BOMB:
                ret = new Block(type, facing, nullTick, canMove, BombTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.BROWNBUTTON:
                ret = new Block(type, facing, nullTick, BrownButtonFrom.Instance, BrownButtonTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.BUG:
                ret = new Block(type, facing, BugTickBehavior.Instance, canMove, CreatureTo.Instance, nullButton, CloneBoss.Instance, ControllerTrapReleaseBehavior.Instance, defaultDestroy);
                break;

            case Type.BURNEDCHIP:
                break;

            case Type.CHIP:
                ret = new Block(type, facing, ChipTickBehavior.Instance, canMove, ChipTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                Game.Instance.Chip = ret;
                break;

            case Type.CLONEBLOCK:
                break;

            case Type.CLONEMACHINE:
                ret = new Block(type, facing, nullTick, cannotMove, cannotMove, CloneMachineBehavior.Instance, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.COMPUTERCHIP:
                ret = new Block(type, facing, nullTick, canMove, ComputerChipTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.DIRT:
                ret = new Block(type, facing, nullTick, canMove, DirtTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.DROWNEDCHIP:
                break;

            case Type.EXIT:
                ret = new Block(type, facing, nullTick, canMove, ExitTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.FAKEEXIT:
                break;

            case Type.FIRE:
                ret = new Block(type, facing, nullTick, canMove, FireTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.FIREBOOTS:
                ret = new Block(type, facing, nullTick, canMove, FirebootsTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.FIREBALL:
                ret = new Block(type, facing, FireballTickBehavior.Instance, canMove, CreatureTo.Instance, nullButton, CloneSameDirection.Instance, defaultTrap, defaultDestroy);
                break;

            case Type.FLIPPERS:
                ret = new Block(type, facing, nullTick, canMove, FlippersTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.FLOOR:
                ret = new Block();
                ret.SetType(Type.FLOOR);
                break;

            case Type.FORCEFLOOR:
                ret = new Block(type, facing, nullTick, canMove, ForceFloorTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.RANDOMFORCEFLOOR:
                ret = new Block(type, facing, nullTick, canMove, RandomForceFloorTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.GLIDER:
                ret = new Block(type, facing, GliderTickBehavior.Instance, canMove, CreatureTo.Instance, nullButton, CloneSameDirection.Instance, defaultTrap, defaultDestroy);
                break;

            case Type.GRAVEL:
                ret = new Block(type, facing, nullTick, canMove, GravelTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.GREENBUTTON:
                ret = new Block(type, facing, nullTick, canMove, GreenButtonTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.GREENKEY:
                ret = new Block(type, facing, nullTick, canMove, GreenKeyTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.GREENLOCK:
                ret = new Block(type, facing, nullTick, canMove, GreenLockTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.HIDDENWALL:
                ret = new Block(type, facing, nullTick, canMove, BlueWallRealTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.HINT:
                ret = new Block(type, facing, nullTick, HintFrom.Instance, HintTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.ICE:
                ret = new Block(type, facing, nullTick, IceFrom.Instance, IceTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.ICECORNER:
                ret = new Block(type, facing, nullTick, IceFrom.Instance, IceCornerTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.ICEBLOCK:     // ?
                break;

            case Type.ICESKATES:
                ret = new Block(type, facing, nullTick, canMove, IceskatesTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.INVISIBLEWALL:
                ret = new Block(type, facing, nullTick, canMove, cannotMove, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.LOCK:
                break;

            case Type.PARAMECIUM:
                ret = new Block(type, facing, ParameciumTickBehavior.Instance, canMove, CreatureTo.Instance, nullButton, CloneBoss.Instance, ControllerTrapReleaseBehavior.Instance, defaultDestroy);
                break;

            case Type.PINKBALL:
                ret = new Block(type, facing, PinkballTickBehavior.Instance, canMove, CreatureTo.Instance, nullButton, CloneSameDirection.Instance, defaultTrap, defaultDestroy);
                break;

            case Type.RECESSEDWALL:
                ret = new Block(type, facing, nullTick, canMove, RecessedWallTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.REDBUTTON:
                ret = new Block(type, facing, nullTick, canMove, RedButtonTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.REDKEY:
                ret = new Block(type, facing, nullTick, canMove, RedKeyTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.REDLOCK:
                ret = new Block(type, facing, nullTick, canMove, RedLockTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.SOCKET:
                ret = new Block(type, facing, nullTick, canMove, SocketTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.SUCTIONBOOTS:
                ret = new Block(type, facing, nullTick, canMove, SuctionbootsTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.SWIMMINGCHIP:
                break;

            case Type.TANK:
                TankBehavior    tb = new TankBehavior();
                IButtonBehavior bb = tb;
                ret = new Block(type, facing, tb, canMove, CreatureTo.Instance, bb, CloneSameDirection.Instance, defaultTrap, defaultDestroy);
                Buttons.AddBlueButtonsListener(ret);
                break;

            case Type.TEETH:
                ret = new Block(type, facing, TeethTickBehavior.Instance, canMove, CreatureTo.Instance, nullButton, CloneBoss.Instance, ControllerTrapReleaseBehavior.Instance, defaultDestroy);
                break;

            case Type.TELEPORT:
                ret = new Block(type, facing, nullTick, canMove, TeleportTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.THIEF:
                ret = new Block(type, facing, nullTick, canMove, ThiefTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.THINWALL:
                ret = new Block(type, facing, nullTick, ThinWallFrom.Instance, ThinWallTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.THINWALLSE:
                ret = new Block(type, facing, nullTick, ThinWallSeFrom.Instance, ThinWallSeTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.TOGGLEWALLCLOSED:     // Yes, fallthrough
            case Type.TOGGLEWALLOPEN:
                ret = new Block(type, facing, nullTick, canMove, ToggleWallTo.Instance, ToggleWallBehavior.Instance, nullClone, defaultTrap, defaultDestroy);
                Buttons.AddGreenButtonsListener(ret);
                break;

            case Type.TRAP:
                ret = new Block(type, facing, nullTick, cannotMove, TrapTo.Instance, TrapBehavior.Instance, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.WALKER:
                ret = new Block(type, facing, WalkerTickBehavior.Instance, canMove, CreatureTo.Instance, nullButton, CloneSameDirection.Instance, defaultTrap, defaultDestroy);
                break;

            case Type.WALL:
                ret = new Block(type, facing, nullTick, canMove, cannotMove, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.WATER:
                ret = new Block(type, facing, nullTick, WaterFrom.Instance, WaterTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.YELLOWKEY:
                ret = new Block(type, facing, nullTick, canMove, YellowKeyTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;

            case Type.YELLOWLOCK:
                ret = new Block(type, facing, nullTick, canMove, YellowLockTo.Instance, nullButton, nullClone, defaultTrap, defaultDestroy);
                break;
            }

            if (ret == null)
            {
                // System.out.println("The block requested hasn't been implemented. Using default behaviors");
                ret = new Block(type, facing);
            }

            return(ret);
        }
 /// <summary>
 /// Overwrite the entire block at the given location
 /// </summary>
 /// <param name="location">the x,y,z of the block to set</param>
 /// <param name="newBlockType">the new type to set for the given block</param>
 public void setBlock(Coordinate location, Block.Type newBlockType)
 {
     setBlock(location, newBlockType.Id);
 }