Example #1
0
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------

        public override bool OnPush(int direction, float movementSpeed)
        {
            Dungeon dungeon = RoomControl.Dungeon;

            if (dungeon.HasBossKey)
            {
                Open();

                AudioSystem.PlaySound(GameData.SOUND_CHEST_OPEN);
                AudioSystem.PlaySound(GameData.SOUND_GET_ITEM);

                // Spawn the key effect.
                EffectUsedItem effect = new EffectUsedItem(GameData.SPR_REWARD_BOSS_KEY);
                RoomControl.SpawnEntity(effect, Center);

                // Disable this tile forever.
                Properties.Set("enabled", false);

                // Unlock doors connected to this one in the adjacent room.
                TileDataInstance connectedDoor = GetConnectedDoor();
                if (connectedDoor != null)
                {
                    connectedDoor.ModifiedProperties.Set("enabled", false);
                }
                return(true);
            }
            else
            {
                GameControl.DisplayMessage("This keyhole is different!");
            }

            return(false);
        }
Example #2
0
        public override BaseTileDataInstance Duplicate()
        {
            TileDataInstance copy = new TileDataInstance();

            copy.Clone(this);
            return(copy);
        }
Example #3
0
        }                                           // This is to make sure tiles are only updated once per frame.


        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------

        // Use Tile.CreateTile() instead of this constructor.
        protected Tile()
        {
            tileGridArea     = Rectangle2I.Zero;
            isAlive          = false;
            isInitialized    = false;
            location         = Point2I.Zero;
            layer            = 0;
            offset           = Point2I.Zero;
            size             = Point2I.One;
            spriteAsObject   = new SpriteAnimation();
            isSolid          = false;
            isMoving         = false;
            pushDelay        = 20;
            properties       = new Properties(this);
            tileData         = null;
            moveDirection    = Point2I.Zero;
            dropList         = null;
            hasMoved         = false;
            path             = null;
            pathTimer        = 0;
            pathMoveIndex    = 0;
            fallsInHoles     = true;
            soundMove        = GameData.SOUND_BLOCK_PUSH;
            conveyorVelocity = Vector2F.Zero;
            surfaceTile      = null;
            collisionStyle   = CollisionStyle.Rectangular;
            graphics         = new TileGraphicsComponent(this);
        }
Example #4
0
 public override void Deselect()
 {
     selectedEventTile = null;
     selectedTile = null;
     LevelDisplayControl.ClearSelectionBox();
     EditorControl.PropertyGridControl.CloseProperties();
 }
Example #5
0
        private TileDataInstance tileData; // The tile data used to create this tile.

        #endregion Fields

        #region Constructors

        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        // Use CreateTile() instead of this constructor.
        protected Tile()
        {
            location		= Point2I.Zero;
            layer			= 0;
            offset			= Point2I.Zero;
            size			= Point2I.One;
            flags			= TileFlags.Default;
            customSprite	= new SpriteAnimation();
            spriteAsObject	= new SpriteAnimation();
            isMoving		= false;
            pushDelay		= 20;
            properties		= new Properties();
            properties.PropertyObject = this;
            tileData		= null;
        }
Example #6
0
        // Construct a tile from the given tile-data.
        public static Tile CreateTile(TileDataInstance data)
        {
            Tile tile;

            // Construct the tile.
            if (data.Type == null)
            {
                tile = new Tile();
            }
            else
            {
                tile = (Tile)data.Type.GetConstructor(Type.EmptyTypes).Invoke(null);
            }

            tile.location = data.Location;
            tile.layer    = data.Layer;

            tile.tileData       = data;
            tile.flags          = data.Flags;
            tile.spriteAsObject = data.SpriteAsObject;
            tile.breakAnimation = data.BreakAnimation;
            tile.breakSound     = data.BreakSound;
            tile.collisionModel = data.CollisionModel;
            tile.size           = data.Size;

            if (data.SpriteList.Length > 0)
            {
                tile.graphics.PlaySpriteAnimation(data.SpriteList[0]);
            }

            int conveyorAngle = data.ConveyorAngle;

            if (conveyorAngle >= 0)
            {
                tile.conveyorVelocity = Angles.ToVector(conveyorAngle, true) * data.ConveyorSpeed;
            }

            //tile.properties.SetAll(data.BaseProperties);
            //tile.properties.SetAll(data.Properties);
            //data.ResetState();
            //tile.properties.BaseProperties = data.ModifiedProperties;

            // NOTE: properties.PropertyObject will refer to the tile's TileDataInstance.
            tile.properties = data.ModifiedProperties;

            return(tile);
        }
Example #7
0
        // Find a door that's connected to this one in an adjacent room.
        public TileDataInstance GetConnectedDoor()
        {
            // Find the location of the adjacent room.
            int     dir          = Directions.Reverse(Properties.GetInteger("direction", 0));
            Point2I roomLocation = RoomControl.RoomLocation + Directions.ToPoint(dir);

            if (RoomControl.Level.ContainsRoom(roomLocation))
            {
                Room adjacentRoom = RoomControl.Level.GetRoomAt(roomLocation);

                // Find the location of the adjacent door tile.
                Point2I doorLocation = Location;
                if (dir == Directions.Down)
                {
                    doorLocation.Y = 0;
                }
                else if (dir == Directions.Up)
                {
                    doorLocation.Y = adjacentRoom.Height - 1;
                }
                else if (dir == Directions.Right)
                {
                    doorLocation.X = 0;
                }
                else if (dir == Directions.Left)
                {
                    doorLocation.X = adjacentRoom.Width - 1;
                }

                // Look for a tile of the same type among the tile layers.
                for (int i = 0; i < adjacentRoom.LayerCount; i++)
                {
                    TileDataInstance t = adjacentRoom.GetTile(doorLocation, i);
                    if (t != null && t.Type == GetType())
                    {
                        return(t);
                    }
                }
            }
            return(null);
        }
Example #8
0
        //-----------------------------------------------------------------------------
        // Drawing
        //-----------------------------------------------------------------------------
        // Draw a tile.
        private void DrawTile(Graphics2D g, TileDataInstance tile, Color color)
        {
            Point2I position = tile.Location * GameSettings.TILE_SIZE;

            // Draw tile sprite/animation.
            if (!tile.CurrentSprite.IsNull)
                g.DrawAnimation(tile.CurrentSprite, tile.Room.Zone.ImageVariantID, editorControl.Ticks, position, color);

            // Draw rewards.
            if (editorControl.ShowRewards && tile.Properties.Exists("reward") &&
                editorControl.RewardManager.HasReward(tile.Properties.GetString("reward")))
            {
                Animation anim = editorControl.RewardManager.GetReward(tile.Properties.GetString("reward")).Animation;
                g.DrawAnimation(anim, editorControl.Ticks, position, color);
            }
        }
Example #9
0
        // Construct a tile from the given tile-data.
        public static Tile CreateTile(TileDataInstance data)
        {
            Tile tile;

            // Construct the tile.
            if (data.Type == null)
                tile = new Tile();
            else
                tile = (Tile) data.Type.GetConstructor(Type.EmptyTypes).Invoke(null);

            tile.location			= data.Location;
            tile.layer				= data.Layer;

            tile.tileData			= data;
            tile.flags				= data.Flags;
            tile.spriteAsObject		= data.SpriteAsObject;
            tile.breakAnimation		= data.BreakAnimation;
            tile.breakSound			= data.BreakSound;
            tile.collisionModel		= data.CollisionModel;
            tile.size				= data.Size;

            if (data.SpriteList.Length > 0)
                tile.graphics.PlaySpriteAnimation(data.SpriteList[0]);

            int conveyorAngle = data.ConveyorAngle;
            if (conveyorAngle >= 0)
                tile.conveyorVelocity = Angles.ToVector(conveyorAngle, true) * data.ConveyorSpeed;

            //tile.properties.SetAll(data.BaseProperties);
            //tile.properties.SetAll(data.Properties);
            //data.ResetState();
            //tile.properties.BaseProperties = data.ModifiedProperties;

            // NOTE: properties.PropertyObject will refer to the tile's TileDataInstance.
            tile.properties = data.ModifiedProperties;

            return tile;
        }
Example #10
0
 public void RemoveTile(TileDataInstance tile)
 {
     if (tile.Room == this) {
         Point2I size = tile.Size;
         for (int x = 0; x < size.X; x++) {
             for (int y = 0; y < size.Y; y++) {
                 Point2I loc = new Point2I(tile.Location.X + x, tile.Location.Y + y);
                 if (loc.X < Width && loc.Y < Height)
                     tileData[loc.X, loc.Y, tile.Layer] = null;
             }
         }
     }
 }
Example #11
0
 //-----------------------------------------------------------------------------
 // Tile Management
 //-----------------------------------------------------------------------------
 public void PlaceTile(TileDataInstance tile, int x, int y, int layer)
 {
     PlaceTile(tile, new Point2I(x, y), layer);
 }
Example #12
0
        //-----------------------------------------------------------------------------
        // Drawing
        //-----------------------------------------------------------------------------
        // Draw a tile.
        private void DrawTile(Graphics2D g, TileDataInstance tile, Point2I position, Color drawColor)
        {
            Sprite sprite = null;
            Animation animation = null;
            float playbackTime = editorControl.Ticks;
            int substripIndex = tile.Properties.GetInteger("substrip_index", 0);

            //-----------------------------------------------------------------------------
            // Platform.
            if (tile.Type == typeof(TilePlatform)) {
                if (!tile.CurrentSprite.IsNull) {
                    // Draw the tile once per point within its size.
                    for (int y = 0; y < tile.Size.Y; y++) {
                        for (int x = 0; x < tile.Size.X; x++) {
                            Point2I drawPos = position +
                                (new Point2I(x, y) * GameSettings.TILE_SIZE);
                            g.DrawAnimation(tile.CurrentSprite,
                                tile.Room.Zone.ImageVariantID,
                                editorControl.Ticks, position, drawColor);
                        }
                    }
                }
                return;
            }
            //-----------------------------------------------------------------------------
            // Color Jump Pad.
            else if (tile.Type == typeof(TileColorJumpPad)) {
                PuzzleColor tileColor = (PuzzleColor) tile.Properties.GetInteger("color", 0);
                if (tileColor == PuzzleColor.Red)
                    sprite = GameData.SPR_TILE_COLOR_JUMP_PAD_RED;
                else if (tileColor == PuzzleColor.Yellow)
                    sprite = GameData.SPR_TILE_COLOR_JUMP_PAD_YELLOW;
                else if (tileColor == PuzzleColor.Blue)
                    sprite = GameData.SPR_TILE_COLOR_JUMP_PAD_BLUE;
            }
            //-----------------------------------------------------------------------------
            // Color Cube
            else if (tile.Type == typeof(TileColorCube)) {
                int orientationIndex = tile.Properties.GetInteger("orientation", 0);
                sprite = GameData.SPR_COLOR_CUBE_ORIENTATIONS[orientationIndex];
            }
            //-----------------------------------------------------------------------------
            // Crossing Gate.
            else if (tile.Type == typeof(TileCrossingGate)) {
                if (tile.Properties.GetBoolean("raised", false))
                    animation = GameData.ANIM_TILE_CROSSING_GATE_LOWER;
                else
                    animation = GameData.ANIM_TILE_CROSSING_GATE_RAISE;
                substripIndex = (tile.Properties.GetBoolean("face_left", false) ? 1 : 0);
                playbackTime = 0.0f;
            }
            //-----------------------------------------------------------------------------
            // Lantern.
            else if (tile.Type == typeof(TileLantern)) {
                if (tile.Properties.GetBoolean("lit", true))
                    animation = GameData.ANIM_TILE_LANTERN;
                else
                    sprite = GameData.SPR_TILE_LANTERN_UNLIT;
            }
            //-----------------------------------------------------------------------------
            // Chest.
            else if (tile.Type == typeof(TileChest)) {
                bool isLooted = tile.Properties.GetBoolean("looted", false);
                sprite = tile.SpriteList[isLooted ? 1 : 0].Sprite;
            }
            //-----------------------------------------------------------------------------
            // Color Lantern.
            /*else if (tile.Type == typeof(TileColorLantern)) {
                PuzzleColor color = (PuzzleColor) tile.Properties.GetInteger("color", -1);
                if (color == PuzzleColor.Red)
                    animation = GameData.ANIM_EFFECT_COLOR_FLAME_RED;
                else if (color == PuzzleColor.Yellow)
                    animation = GameData.ANIM_EFFECT_COLOR_FLAME_YELLOW;
                else if (color == PuzzleColor.Blue)
                    animation = GameData.ANIM_EFFECT_COLOR_FLAME_BLUE;
            }*/
            //-----------------------------------------------------------------------------

            if (animation == null && sprite == null && tile.CurrentSprite.IsAnimation)
                animation = tile.CurrentSprite.Animation;
            if (animation == null && sprite == null && tile.CurrentSprite.IsSprite)
                sprite = tile.CurrentSprite.Sprite;

            // Draw the custom sprite/animation
            if (animation != null) {
                g.DrawAnimation(animation.GetSubstrip(substripIndex),
                    tile.Room.Zone.ImageVariantID, playbackTime, position, drawColor);
            }
            else if (sprite != null) {
                g.DrawSprite(sprite, tile.Room.Zone.ImageVariantID, position, drawColor);
            }
            /*else if (!tile.CurrentSprite.IsNull) {
                g.DrawAnimation(tile.CurrentSprite,
                    tile.Room.Zone.ImageVariantID, editorControl.Ticks, position, drawColor);
            }*/

            // Draw rewards.
            if (editorControl.ShowRewards && tile.Properties.Exists("reward") &&
                editorControl.RewardManager.HasReward(tile.Properties.GetString("reward")))
            {
                Animation anim = editorControl.RewardManager.GetReward(tile.Properties.GetString("reward")).Animation;
                g.DrawAnimation(anim, editorControl.Ticks, position, drawColor);
            }
        }
Example #13
0
 // Delete an already-placed tile.
 public void DeleteTile(TileDataInstance tile)
 {
     tile.Room.RemoveTile(tile);
     editorControl.OnDeleteObject(tile);
 }
Example #14
0
 private bool Matches(TileDataInstance targetTile, Point2I current)
 {
     TileDataInstance currentTile = GetTileAt(current);
     return Matches(targetTile, GetTileAt(current));
 }
Example #15
0
        //-----------------------------------------------------------------------------
        // Static methods
        //-----------------------------------------------------------------------------
        // Instantiate a tile from the given tile-data.
        public static Tile CreateTile(TileDataInstance data)
        {
            Tile tile;

            // Construct the tile.
            if (data.Type == null)
                tile = new Tile();
            else
                tile = (Tile) data.Type.GetConstructor(Type.EmptyTypes).Invoke(null);

            tile.location			= data.Location;
            tile.layer				= data.Layer;

            tile.tileData			= data;
            tile.flags				= data.Flags;
            tile.spriteAsObject		= data.SpriteAsObject;
            tile.breakAnimation		= data.BreakAnimation;
            tile.collisionModel		= data.CollisionModel;
            tile.size				= data.Size;

            tile.properties.Merge(data.BaseProperties, true);
            tile.properties.Merge(data.Properties, true);
            tile.properties.BaseProperties	= data.Properties;

            return tile;
        }
Example #16
0
        public override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            Point2I mousePos	= new Point2I(e.X, e.Y);
            Room	room		= LevelDisplayControl.SampleRoom(mousePos);
            Point2I tileCoord	= LevelDisplayControl.SampleTileCoordinates(mousePos);

            if (e.Button == MouseButtons.Left && room != null) {
                if (!editorControl.EventMode) {
                    if (System.Windows.Forms.Control.ModifierKeys == Keys.Shift) {
                        selectedRoom = room;
                        Point2I levelTileCoord = LevelDisplayControl.ToLevelTileCoordinates(room, Point2I.Zero);
                        LevelDisplayControl.SetSelectionBox(levelTileCoord, room.Size);
                        EditorControl.PropertyGridControl.OpenProperties(room.Properties, room);
                    }
                    else {
                        // Select tiles.
                        selectedTile = room.GetTile(tileCoord, editorControl.CurrentLayer);

                        if (selectedTile != null) {
                            Point2I levelTileCoord = LevelDisplayControl.ToLevelTileCoordinates(room, tileCoord);
                            LevelDisplayControl.SetSelectionBox(levelTileCoord, Point2I.One);
                            EditorControl.PropertyGridControl.OpenProperties(selectedTile.Properties, selectedTile);
                        }
                        else {
                            LevelDisplayControl.ClearSelectionBox();
                            EditorControl.PropertyGridControl.CloseProperties();
                        }
                    }
                }
                else {
                    // Select events.
                    selectedEventTile = LevelDisplayControl.SampleEventTile(mousePos);

                    if (selectedEventTile != null) {
                        Point2I levelTileCoord = LevelDisplayControl.ToLevelTileCoordinates(room, tileCoord);
                        LevelDisplayControl.SetSelectionBox(levelTileCoord, Point2I.One);
                        EditorControl.PropertyGridControl.OpenProperties(selectedEventTile.Properties, selectedEventTile);
                    }
                    else {
                        LevelDisplayControl.ClearSelectionBox();
                        EditorControl.PropertyGridControl.CloseProperties();
                    }
                }
            }
        }
Example #17
0
 //-----------------------------------------------------------------------------
 // Constructors
 //-----------------------------------------------------------------------------
 // Use Tile.CreateTile() instead of this constructor.
 protected Tile()
 {
     tileGridArea	= Rectangle2I.Zero;
     isAlive				= false;
     isInitialized		= false;
     location			= Point2I.Zero;
     layer				= 0;
     offset				= Point2I.Zero;
     size				= Point2I.One;
     spriteAsObject		= new SpriteAnimation();
     isSolid				= false;
     isMoving			= false;
     pushDelay			= 20;
     properties			= new Properties(this);
     tileData			= null;
     moveDirection		= Point2I.Zero;
     dropList			= null;
     hasMoved			= false;
     path				= null;
     pathTimer			= 0;
     pathMoveIndex		= 0;
     fallsInHoles		= true;
     soundMove			= GameData.SOUND_BLOCK_PUSH;
     conveyorVelocity	= Vector2F.Zero;
     surfaceTile			= null;
     collisionStyle		= CollisionStyle.Rectangular;
     graphics			= new TileGraphicsComponent(this);
 }
Example #18
0
 //-----------------------------------------------------------------------------
 // Overridden Methods
 //-----------------------------------------------------------------------------
 public override void OnBegin()
 {
     selectedTile		= null;
     selectedEventTile	= null;
     EditorControl.HighlightMouseTile = false;
 }
Example #19
0
 public override void OnEnd()
 {
     selectedTile		= null;
     selectedEventTile	= null;
 }
Example #20
0
        public void PlaceTile(TileDataInstance tile, Point2I location, int layer)
        {
            Point2I size = tile.Size;

            for (int x = 0; x < size.X; x++) {
                for (int y = 0; y < size.Y; y++) {
                    Point2I loc = new Point2I(location.X + x, location.Y + y);
                    if (loc.X < Width && loc.Y < Height) {
                        // Remove existing tile.
                        TileGridTile t = tiles[loc.X, loc.Y, layer];
                        if (t.Tile != null)
                            RemoveTile(t);
                        tiles[loc.X, loc.Y, layer].Set(tile, location.X, location.Y, layer);
                    }
                }
            }
        }
Example #21
0
 private bool Matches(TileDataInstance tile1, TileDataInstance tile2)
 {
     if (tile1 == null)
         return (tile2 == null);
     else if (tile2 != null)
         return (tile1.TileData == tile2.TileData);
     return false;
 }
Example #22
0
 public void RemoveTile(TileDataInstance tile)
 {
     if (tile == null)
         return;
     for (int x = 0; x < size.X; x++) {
         for (int y = 0; y < size.Y; y++) {
             for (int i = 0; i < layerCount; i++) {
                 TileGridTile t = tiles[x, y, i];
                 if (t.Tile == tile) {
                     RemoveTile(t);
                     return;
                 }
             }
         }
     }
 }
Example #23
0
        // Place a tile in a room, deleting any other tiles in the way.
        public void PlaceTile(TileDataInstance tile, Room room, Point2I location, int layer)
        {
            // Remove any tiles in the way.
            Point2I size = tile.Size;
            for (int x = 0; x < size.X; x++) {
                for (int y = 0; y < size.Y; y++) {
                    TileDataInstance t = room.GetTile(location, layer);
                    if (t != null)
                        DeleteTile(t);
                }
            }

            // Place the tile.
            room.PlaceTile(tile, location, layer);
        }
Example #24
0
 public void Clear(int x, int y, int layer)
 {
     this.Tile		= null;
     this.Location	= new Point2I(x, y);
     this.Layer		= layer;
 }
Example #25
0
 public TileDataInstance CreateTile(TileData data, int x, int y, int layer)
 {
     TileDataInstance dataInstance = new TileDataInstance(data, x, y, layer);
     dataInstance.Room = this;
     PlaceTile(dataInstance, new Point2I(x, y), layer);
     return dataInstance;
 }
 public override BaseTileDataInstance Duplicate()
 {
     TileDataInstance copy = new TileDataInstance();
     copy.Clone(this);
     return copy;
 }
Example #27
0
 public void PlaceTile(TileDataInstance tile, Point2I location, int layer)
 {
     Point2I size = tile.Size;
     for (int x = 0; x < size.X; x++) {
         for (int y = 0; y < size.Y; y++) {
             Point2I loc = new Point2I(location.X + x, location.Y + y);
             if (loc.X < Width && loc.Y < Height) {
                 // Remove existing tile.
                 TileDataInstance t = tileData[loc.X, loc.Y, layer];
                 if (t != null)
                     RemoveTile(t);
                 tileData[loc.X, loc.Y, layer] = tile;
             }
         }
     }
     if (tile != null) {
         tile.Location	= location;
         tile.Layer		= layer;
         tile.Room		= this;
     }
 }
Example #28
0
 public void RemoveTile(TileDataInstance tile)
 {
     if (tile.Room == this) {
         tileData[tile.Location.X, tile.Location.Y, tile.Layer] = null;
     }
 }
Example #29
0
 public void Set(TileDataInstance tile, int x, int y, int layer)
 {
     this.Tile		= tile;
     this.Location	= new Point2I(x, y);
     this.Layer		= layer;
 }
Example #30
0
 //-----------------------------------------------------------------------------
 // Mutators
 //-----------------------------------------------------------------------------
 public void SetTile(TileDataInstance tile, int x, int y, int layer)
 {
     tileData[x, y, layer] = tile;
     if (tile != null) {
         tile.Location	= new Point2I(x, y);
         tile.Layer		= layer;
         tile.Room		= this;
     }
 }
Example #31
0
        // Return a copy of this tile grid.
        public TileGrid Duplicate()
        {
            TileGrid duplicate = new TileGrid(size, layerCount);

            // Duplicate tiles.
            for (int x = 0; x < size.X; x++) {
                for (int y = 0; y < size.Y; y++) {
                    for (int i = 0; i < layerCount; i++) {
                        TileGridTile tile = tiles[x, y, i];
                        if (tile.Tile != null && tile.Location == new Point2I(x, y)) {
                            TileDataInstance tileCopy = new TileDataInstance();
                            tileCopy.Clone(tile.Tile);
                            duplicate.PlaceTile(tileCopy, x, y, i);
                        }
                    }
                }
            }

            // Duplicate event tiles.
            foreach (EventTileDataInstance eventTile in eventTiles) {
                EventTileDataInstance copy = new EventTileDataInstance();
                copy.Clone(eventTile);
                duplicate.AddEventTile(copy);
            }

            return duplicate;
        }
Example #32
0
 public TileDataInstance CreateTile(TileData data, int x, int y, int layer)
 {
     TileDataInstance dataInstance = new TileDataInstance(data, x, y, layer);
     dataInstance.Room = this;
     tileData[x, y, layer] = dataInstance;
     return dataInstance;
 }