Ejemplo n.º 1
0
 public static void DrawSprite(Graphics g, SpriteAnimation sprite, int variantID, Point2I position, Point2I sourceSize)
 {
     if (sprite.IsAnimation)
         DrawSprite(g, sprite.Animation.GetFrameAsSprite(0), variantID, position.X, position.Y, sourceSize.X, sourceSize.Y);
     else
         DrawSprite(g, sprite.Sprite, variantID, position.X, position.Y, sourceSize.X, sourceSize.Y);
 }
Ejemplo n.º 2
0
        private SpriteAnimation sprite; // NOTE: This would only be visible in the editor.

        #endregion Fields

        #region Constructors

        //private bool			isVisible;	// Is the event visible in-game?
        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        public EventTileData()
        {
            sprite			= new SpriteAnimation();
            position		= Point2I.Zero;
            size			= Point2I.One;

            properties.Set("image_variant", 0)
                .SetDocumentation("Image Variant ID", "", "", "Internal",
                "The image variant to draw the sprtie with.", true, true);
        }
Ejemplo n.º 3
0
        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        public RewardItem(string id, string itemID, int level, RewardHoldTypes holdType, string message, SpriteAnimation animation)
        {
            InitAnimation(animation);

            this.id				= id;
            this.message		= message;
            this.hasDuration	= false;
            this.holdType		= holdType;
            this.isCollectibleWithItems	= false;

            this.itemID			= itemID;
            this.level			= level;
        }
Ejemplo n.º 4
0
        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        public RewardAmmo(string id, string ammoID, int amount, string message, SpriteAnimation animation)
        {
            InitAnimation(animation);

            this.id				= id;
            this.message		= message;
            this.hasDuration	= true;
            this.holdType		= RewardHoldTypes.Raise;
            this.isCollectibleWithItems	= true;
            this.onlyShowMessageInChest = true;

            this.ammoID			= ammoID;
            this.amount			= amount;
        }
Ejemplo n.º 5
0
        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        public RewardDungeonItem(string id, SpriteAnimation animation, RewardHoldTypes holdType, string message)
        {
            InitAnimation(animation);

            this.id				= id;
            this.message		= message;
            this.holdType		= holdType;

            this.hasDuration	= false;
            this.isCollectibleWithItems	= (id != "small_key");
            this.onlyShowMessageInChest = (id == "small_key");

            if (id == "small_key" || id == "boss_key")
                this.soundBounce = GameData.SOUND_KEY_BOUNCE;
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
0
        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        public TileData()
        {
            type				= null;
            size				= Point2I.One;
            flags				= TileFlags.Default;
            spriteList			= new SpriteAnimation[0];
            spriteAsObject		= new SpriteAnimation();
            breakAnimation		= null;
            collisionModel		= null;
            sheetLocation		= Point2I.Zero;
            tileset				= null;
            properties			= new Properties();

            properties.Set("id", "")
                .SetDocumentation("ID", "", "", "The id used to refer to this tile.", true, false);
            properties.Set("sprite_index", 0)
                .SetDocumentation("Sprite Index", "sprite_index", "", "The current sprite in the sprite list to draw.", true, true);
        }
Ejemplo n.º 8
0
        public TileData(TileData copy)
            : this()
        {
            type				= copy.type;
            size				= copy.size;
            flags				= copy.flags;
            spriteList			= new SpriteAnimation[copy.spriteList.Length];
            spriteAsObject		= new SpriteAnimation(copy.spriteAsObject);
            breakAnimation		= copy.breakAnimation;
            collisionModel		= copy.collisionModel;
            sheetLocation		= copy.sheetLocation;
            tileset				= copy.tileset;
            properties			= new Properties();

            properties.Merge(copy.properties, true);

            for (int i = 0; i < spriteList.Length; i++)
                spriteList[i] = new SpriteAnimation(copy.spriteList[i]);
        }
Ejemplo n.º 9
0
        //-----------------------------------------------------------------------------
        // Constructor
        //-----------------------------------------------------------------------------
        public NPC()
        {
            // Physics.
            EnablePhysics(PhysicsFlags.Solid | PhysicsFlags.HasGravity);
            Physics.CollisionBox = new Rectangle2F(-8, -11, 16, 13);
            Physics.SoftCollisionBox = new Rectangle2F(-10, -15, 20, 19);

            // Graphics.
            Graphics.DepthLayer	= DepthLayer.PlayerAndNPCs;
            Graphics.DrawOffset = new Point2I(-8, -14);

            // General.
            centerOffset		= Graphics.DrawOffset + new Point2I(8, 8);
            actionAlignDistance	= 5;
            flags				= NPCFlags.FacePlayerOnTalk | NPCFlags.FacePlayerWhenNear;

            message = null;
            animationTalk = null;

            // Bounding box for talking is 4 pixels beyond the hard collision box (inclusive).
            // Alignment limit is a max 5 pixels in either direction (inclusive).
        }
Ejemplo n.º 10
0
        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        public TileData()
        {
            spriteList			= new SpriteAnimation[0];
            //size				= Point2I.One;
            spriteAsObject		= new SpriteAnimation();
            breakAnimation		= null;

            // General.
            properties.SetGeneric("size", Point2I.One)
                .SetDocumentation("Size", "General", "");
            properties.Set("flags", (int) TileFlags.Default)
                .SetDocumentation("Tile Flags", "General", "");
            properties.Set("solidity", (int) TileSolidType.NotSolid)
                .SetDocumentation("Solid Type", "General", "");
            properties.Set("ledge_direction", Directions.Down)
                .SetDocumentation("Ledge Direction", "General", "");
            properties.Set("collision_model", "")
                .SetDocumentation("Collision Model", "collision_model", "", "General", "");
            properties.Set("environment_type", (int) TileEnvironmentType.Normal)
                .SetDocumentation("Environment Type", "General", "");
            properties.Set("reset_condition", (int) TileResetCondition.LeaveRoom)
                .SetDocumentation("Reset Condition", "General", "The condition for when the tile resets its properties.");

            properties.Set("disable_on_destroy", false)
                .SetDocumentation("Disable on Destroy", "General", "");

            // Motion.
            properties.Set("path", "")
                .SetDocumentation("Path", "Motion", "A path the tile follows in.");
            properties.Set("conveyor_angle", -1);
            properties.Set("conveyor_speed", 0.0f);

            // Interaction Options.
            properties.Set("move_once", false)
                .SetDocumentation("Move Once", "Interactions", "");
            properties.Set("move_direction", -1)
                .SetDocumentation("Move Direction", "Interactions", "");
            properties.Set("cuttable_sword_level", 0)
                .SetDocumentation("Cuttable Sword Level", "Interactions", "");
            properties.Set("pickupable_bracelet_level", 0)
                .SetDocumentation("Pickupable Bracelet Level", "Interactions", "");
            properties.Set("cling_on_stab", true)
                .SetDocumentation("Cling on Stab", "Interactions", "True if a cling effect should be spawned when the tile is stabbed with the sword.");
            properties.Set("raised_on_buttons", false)
                .SetDocumentation("Raised on Buttons", "Interactions", "True if a the tile appears raised when pushed onto a button.");

            properties.Set("hurt_area_point", new Point2I(-1, -1));
            properties.Set("hurt_area_size", new Point2I(18, 18));
            properties.Set("hurt_damage", 0);

            // Spawning.
            properties.Set("spawn_from_ceiling", false)
                .SetDocumentation("Spawn from Ceiling", "Spawning", "");
            properties.Set("spawn_poof_effect", false)
                .SetDocumentation("Spawn with Poof Effect", "Spawning", "");
            properties.Set("spawn_delay_after_poof", 31)
                .SetDocumentation("Spawn Delay after Poof", "Spawning", "");

            // Events.
            properties.Set("on_move", "")
                .SetDocumentation("On Move", "script", "", "Events",
                "Occurs when the tile is moved.", true, false);
        }
Ejemplo n.º 11
0
        public TileData(TileData copy)
            : base(copy)
        {
            //size				= copy.size;
            spriteAsObject		= new SpriteAnimation(copy.spriteAsObject);
            breakAnimation		= copy.breakAnimation;
            spriteList			= new SpriteAnimation[copy.spriteList.Length];

            for (int i = 0; i < spriteList.Length; i++)
                spriteList[i] = new SpriteAnimation(copy.spriteList[i]);
        }
Ejemplo n.º 12
0
        public override void Clone(BaseTileData copy)
        {
            base.Clone(copy);
            if (copy is TileData) {
                TileData copyTileData = (TileData) copy;
                //size				= copyTileData.size;
                spriteAsObject		= new SpriteAnimation(copyTileData.spriteAsObject);
                breakAnimation		= copyTileData.breakAnimation;
                breakSound			= copyTileData.breakSound;
                events				= new ObjectEventCollection(copyTileData.events);

                if (copyTileData.spriteList.Length > 0) {
                    spriteList = new SpriteAnimation[copyTileData.spriteList.Length];
                    for (int i = 0; i < spriteList.Length; i++) {
                        spriteList[i] = new SpriteAnimation(copyTileData.spriteList[i]);
                    }
                }
            }
        }
Ejemplo n.º 13
0
 public TilesetBuilder SetAnims(params Animation[] animations)
 {
     SpriteAnimation[] spriteAnimations = new SpriteAnimation[animations.Length];
     for (int i = 0; i < animations.Length; i++)
         spriteAnimations[i] = animations[i];
     return this;
 }
Ejemplo n.º 14
0
 protected void InitAnimation(SpriteAnimation animation)
 {
     if (animation.IsSprite)
         InitSprite(animation.Sprite);
     else if (animation.IsAnimation)
         InitAnimation(animation.Animation);
     else
         this.animation = null;
 }
Ejemplo n.º 15
0
 // Draw an animation during at the given time stamp and position.
 public void DrawAnimation(SpriteAnimation animation, int variantID, float time, float x, float y, Color color, float depth = 0.0f)
 {
     if (animation.IsAnimation)
     DrawAnimation(animation.Animation, variantID, time, x, y, color, depth);
     else
     DrawSprite(animation.Sprite, variantID, x, y, color, depth);
 }
Ejemplo n.º 16
0
 // Draw an sprite or animation at the given playback time.
 public void DrawSpriteAnimation(SpriteAnimation spriteAnimation, float time, Vector2F position, DepthLayer depth, Vector2F depthOrigin)
 {
     DrawSpriteAnimation(spriteAnimation, 0, time, position, depth, depthOrigin);
 }
Ejemplo n.º 17
0
 // Play the given animation or sprite from the beginning.
 public void Play(SpriteAnimation spriteAnimation)
 {
     if (spriteAnimation.IsAnimation)
         Play(spriteAnimation.Animation);
     else if (spriteAnimation.IsSprite)
         Play(spriteAnimation.Sprite);
     else
         Clear();
 }
Ejemplo n.º 18
0
 // Change to the given sprite or animation without interrupting playback.
 public void SetSpriteAnimation(SpriteAnimation spriteAnimation)
 {
     if (spriteAnimation.IsAnimation)
         SetAnimation(spriteAnimation.Animation);
     else if (spriteAnimation.IsSprite)
         SetSprite(spriteAnimation.Sprite);
     else
         Clear();
 }
Ejemplo n.º 19
0
 public void PlaySpriteAnimation(SpriteAnimation spriteAnimation)
 {
     animationPlayer.Play(spriteAnimation);
 }
Ejemplo n.º 20
0
 public SpriteAnimation(SpriteAnimation spriteAnimation)
 {
     this.value	= spriteAnimation.value;
 }
Ejemplo n.º 21
0
        //-----------------------------------------------------------------------------
        // Override
        //-----------------------------------------------------------------------------
        public TilesetSR()
        {
            this.tilesetCommands	= new List<ScriptCommand>();
            this.animationCommands	= new List<ScriptCommand>();
            this.spriteCommands		= new List<ScriptCommand>();

            this.loadingMode	= LoadingModes.Tilesets;
            this.resources		= new TemporaryResources();
            this.useTemporary	= false;

            this.animationBuilder	= new AnimationBuilder();
            this.spriteBuilder	= new SpriteBuilder();

            // Tileset <name> <sheet-name> <size(width, height)>
            AddCommand("Load", delegate(CommandParam parameters) {
                string loadType = parameters.GetString(0).ToLower();
                if (loadType == "tilesets")
                    loadingMode = LoadingModes.Tilesets;
                else if (loadType == "animations")
                    loadingMode = LoadingModes.Animations;
                else if (loadType == "sprites")
                    loadingMode = LoadingModes.Sprites;
                else
                    ThrowParseError("Invalid Load type", true);
            });

            // BEGIN/END.

            // Tileset <name> <sheet-name> <size(width, height)>
            AddTilesetCommand("Tileset", delegate(CommandParam parameters) {
                SpriteSheet sheet = Resources.GetSpriteSheet(parameters.GetString(1));
                tileset = new Tileset(parameters.GetString(0),
                    sheet, parameters.GetPoint(2));
            });
            // With a tileset:
            //   Tile <sheet-location>
            // Without a tileset:
            //   Tile <name>
            AddTilesetCommand("Tile", delegate(CommandParam parameters) {
                useTemporary = false;
                if (tileset != null) {
                    Point2I location = parameters.GetPoint(0);
                    tileData = tileset.TileData[location.X, location.Y];
                }
                else {
                    tileData = new TileData();
                    tileDataName = parameters.GetString(0);
                }
            });
            // TempTile <name>
            AddTilesetCommand("TempTile", delegate(CommandParam parameters) {
                useTemporary = true;
                tileData = new TileData();
                tileDataName = parameters.GetString(0);
            });
            AddTilesetCommand("End", delegate(CommandParam parameters) {
                if (tileData != null) {
                    if (tileData.Tileset == null) {
                        if (useTemporary)
                            resources.AddResource<TileData>(tileDataName, tileData);
                        else
                            Resources.AddResource<TileData>(tileDataName, tileData);
                    }
                    tileData = null;
                }
                else if (tileset != null) {
                    Resources.AddResource<Tileset>(tileset.ID, tileset);
                    tileset = null;
                }
            });

            // TILESETS.

            // Default <default-tile-location(x, y)>
            AddTilesetCommand("Default", delegate(CommandParam parameters) {
                tileset.DefaultTile = parameters.GetPoint(0);
            });
            // Config: data to configure tiles with a single character per tile.
            AddTilesetCommand("Config", delegate(CommandParam parameters) {
                string line = NextLine();
                int y = 0;
                while (!line.StartsWith("END;", StringComparison.OrdinalIgnoreCase)) {
                    if (y < tileset.Height) {
                        for (int x = 0; x < line.Length && x < tileset.Width; x++)
                            tileset.ConfigureTile(tileset.TileData[x, y], line[x]);
                    }
                    line = NextLine();
                    y++;
                }
            });

            // TILES.

            // Type <type>
            AddTilesetCommand("Type", delegate(CommandParam parameters) {
                tileData.Type = Tile.GetType(parameters.GetString(0), true);

            });
            // Flags <flags[]...>
            AddTilesetCommand("Flags", delegate(CommandParam parameters) {
                for (int i = 0; i < parameters.Count; i++) {
                    tileData.Flags |= (TileFlags) Enum.Parse(typeof(TileFlags), parameters.GetString(i), true);
                }
            });
            // Properties <(type, name, value, editor-type, category, description)...>
            // Properties <(hide, name)...>
            // Properties <(show, name)...>
            AddTilesetCommand("Properties", delegate(CommandParam parameters) {
                // TODO: handle lists.
                for (int i = 0; i < parameters.Count; i++) {
                    CommandParam param = parameters[i];

                    string name = param.GetString(1);

                    if (String.Compare(param.GetString(0), "hide", StringComparison.CurrentCultureIgnoreCase) == 0) {
                        tileData.Properties[name].Documentation.IsHidden = true;
                    }
                    else if (String.Compare(param.GetString(0), "show", StringComparison.CurrentCultureIgnoreCase) == 0) {
                        tileData.Properties[name].Documentation.IsHidden = false;
                    }
                    else {

                        Property property = null;
                        PropertyType type = (PropertyType)Enum.Parse(typeof(PropertyType), param.GetString(0), true);

                        if (type == PropertyType.String)
                            property = Property.CreateString(name, param.GetString(2));
                        else if (type == PropertyType.Integer)
                            property = Property.CreateInt(name, param.GetInt(2));
                        else if (type == PropertyType.Float)
                            property = Property.CreateFloat(name, param.GetFloat(2));
                        else if (type == PropertyType.Boolean)
                            property = Property.CreateBool(name, (param.GetString(2) == "true"));
                        else
                            ThrowParseError("Unsupported property type for " + name);

                        if (param.Count > 3) {
                            property.SetDocumentation(
                                param.GetString(3),
                                param.GetString(4),
                                param.GetString(5),
                                param.GetString(6),
                                true,
                                param.GetBool(7));
                        }

                        if (property != null)
                            tileData.Properties.Add(property);
                    }
                }
            });
            // Sprite <sprite-animation>
            // Sprite <spritesheet> <x-index> <y-index> <x-offset> <y-offset>
            AddTilesetCommand("Sprite", delegate(CommandParam parameters) {
                if (parameters.Count >= 2) {
                    spriteBuilder.Begin(new Sprite(
                        resources.GetResource<SpriteSheet>(parameters.GetString(0)),
                        parameters.GetPoint(1),
                        parameters.GetPoint(2, Point2I.Zero)
                    ));
                    tileData.Sprite = spriteBuilder.End();
                }
                else {
                    tileData.Sprite = resources.GetSpriteAnimation(parameters.GetString(0));
                }
            });
            // SpriteIndex <index> <sprite-animation>
            // SpriteIndex <index> <spritesheet> <x-index> <y-index> <x-offset> <y-offset>
            AddTilesetCommand("SpriteIndex", delegate(CommandParam parameters) {
                int index = parameters.GetInt(0);
                if (tileData.SpriteList.Length <= index) {
                    SpriteAnimation[] spriteList = new SpriteAnimation[index + 1];
                    for (int i = 0; i < spriteList.Length; i++) {
                        if (i < tileData.SpriteList.Length)
                            spriteList[i] = tileData.SpriteList[i];
                        else
                            spriteList[i] = null;
                    }
                    tileData.SpriteList = spriteList;
                }
                if (parameters.Count >= 3) {
                    spriteBuilder.Begin(new Sprite(
                        resources.GetResource<SpriteSheet>(parameters.GetString(1)),
                        parameters.GetPoint(2),
                        parameters.GetPoint(3, Point2I.Zero)
                    ));
                    tileData.SpriteList[index] = spriteBuilder.End();
                }
                else {
                    tileData.SpriteList[index] = resources.GetSpriteAnimation(parameters.GetString(1));
                }
            });
            // SpriteList [sprite-animation-1] [sprite-animation-2]...
            AddTilesetCommand("SpriteList", delegate(CommandParam parameters) {
                SpriteAnimation[] spriteList = new SpriteAnimation[parameters.Count];
                for (int i = 0; i < parameters.Count; i++)
                    spriteList[i] = resources.GetSpriteAnimation(parameters.GetString(i));

                tileData.SpriteList = spriteList;
            });
            // SpriteObj <sprite-animation>
            // SpriteObj <spritesheet> <x-index> <y-index> <x-offset> <y-offset>
            AddTilesetCommand("SpriteObj", delegate(CommandParam parameters) {
                if (parameters.Count >= 2) {
                    spriteBuilder.Begin(new Sprite(
                        resources.GetResource<SpriteSheet>(parameters.GetString(0)),
                        parameters.GetPoint(1),
                        parameters.GetPoint(2, Point2I.Zero)
                    ));
                    tileData.SpriteAsObject = spriteBuilder.End();
                }
                else {
                    tileData.SpriteAsObject = resources.GetSpriteAnimation(parameters.GetString(0));
                }
            });
            // BreakAnim <animation>
            AddTilesetCommand("BreakAnim", delegate(CommandParam parameters) {
                tileData.BreakAnimation = resources.GetResource<Animation>(parameters.GetString(0));
            });
            // Model <collision-model>
            AddTilesetCommand("Model", delegate(CommandParam parameters) {
                tileData.CollisionModel = resources.GetResource<CollisionModel>(parameters.GetString(0));
            });
            // Solid <collision-model>
            AddTilesetCommand("Solid", delegate(CommandParam parameters) {
                tileData.Flags |= TileFlags.Solid;
                tileData.CollisionModel = resources.GetResource<CollisionModel>(parameters.GetString(0));
            });
            // Ledge <collision-model> <direction>
            AddTilesetCommand("Ledge", delegate(CommandParam parameters) {
                tileData.Flags |= TileFlags.Solid;
                tileData.CollisionModel = resources.GetResource<CollisionModel>(parameters.GetString(0));
                string dirName = parameters.GetString(1);
                if (dirName == "right" || dirName == "east")
                    tileData.Flags |= TileFlags.LedgeRight;
                else if (dirName == "left" || dirName == "west")
                    tileData.Flags |= TileFlags.LedgeLeft;
                else if (dirName == "up" || dirName == "north")
                    tileData.Flags |= TileFlags.LedgeUp;
                else if (dirName == "down" || dirName == "south")
                    tileData.Flags |= TileFlags.LedgeDown;
            });
            // Clone <tiledata>
            AddTilesetCommand("Clone", delegate(CommandParam parameters) {
                tileData.Clone(resources.GetResource<TileData>(parameters.GetString(0)));// = new TileData();
                //tileData.Tileset = tileset;
            });

            // SPRITE SHEET.

            AddAnimationCommand("SpriteSheet", delegate(CommandParam parameters) {
                SpriteSheet sheet = Resources.GetResource<SpriteSheet>(parameters.GetString(0));
                animationBuilder.SpriteSheet = sheet;
            });

            // BEGIN/END.

            AddAnimationCommand("Anim", delegate(CommandParam parameters) {
                animationName = parameters.GetString(0);
                animationBuilder.BeginNull();
                animation = null;
                useTemporary = false;
            });
            AddAnimationCommand("TempAnim", delegate(CommandParam parameters) {
                animationName = parameters.GetString(0);
                animationBuilder.BeginNull();
                animation = null;
                useTemporary = true;
            });
            AddAnimationCommand("End", delegate(CommandParam parameters) {
                if (animation != null) {
                    animationBuilder.End();
                    if (useTemporary)
                        resources.AddResource<Animation>(animationName, animation);
                    else
                        Resources.AddResource<Animation>(animationName, animation);
                }
            });
            AddAnimationCommand("SubStrip", delegate(CommandParam parameters) {
                LoopMode loopMode = LoopMode.Repeat;
                if (parameters.GetString(0) == "reset")
                    loopMode = LoopMode.Reset;
                else if (parameters.GetString(0) == "repeat" || parameters.GetString(0) == "loop")
                    loopMode = LoopMode.Repeat;
                else if (parameters.GetString(0) == "clamp")
                    loopMode = LoopMode.Clamp;
                else
                    ThrowParseError("Unknown loop mode '" + parameters.GetString(0) + "' for animation");

                animationBuilder.CreateSubStrip();
                animationBuilder.SetLoopMode(loopMode);
                if (animation == null)
                    animation = animationBuilder.Animation;
            });
            AddAnimationCommand("Clone", delegate(CommandParam parameters) {
                if (resources.ExistsResource<Animation>(parameters.GetString(0))) {
                    animationBuilder.CreateClone(resources.GetResource<Animation>(parameters.GetString(0)));
                    animation = animationBuilder.Animation;
                }
                else {
                    // ERROR: can't clone nonexistant animation.
                }
            });

            // FRAME BUILDING.

            AddAnimationCommand("Add", delegate(CommandParam parameters) {
                if (parameters.GetString(0) == "strip") {
                    animationBuilder.AddFrameStrip(
                        parameters.GetInt(1),
                        parameters.GetPoint(3).X,
                        parameters.GetPoint(3).Y,
                        parameters.GetInt(2),
                        parameters.GetPoint(4, Point2I.Zero).X,
                        parameters.GetPoint(4, Point2I.Zero).Y,
                        parameters.GetPoint(5, new Point2I(1, 0)).X,
                        parameters.GetPoint(5, new Point2I(1, 0)).Y);
                }
                else if (parameters.GetString(0) == "frame") {
                    animationBuilder.AddFrame(
                        parameters.GetInt(1),
                        parameters.GetPoint(2).X,
                        parameters.GetPoint(2).Y,
                        parameters.GetPoint(3, Point2I.Zero).X,
                        parameters.GetPoint(3, Point2I.Zero).Y);
                }
                else if (parameters.GetString(0) == "part") {
                    animationBuilder.AddPart(
                        parameters.GetInt(1),
                        parameters.GetPoint(2).X,
                        parameters.GetPoint(2).Y,
                        parameters.GetPoint(3, Point2I.Zero).X,
                        parameters.GetPoint(3, Point2I.Zero).Y);
                }
                else
                    ThrowParseError("Unknown add type '" + parameters.GetString(0) + "' for animation");
            });
            AddAnimationCommand("Insert", delegate(CommandParam parameters) {
                if (parameters.GetString(0) == "strip") {
                    animationBuilder.InsertFrameStrip(
                        parameters.GetInt(1),
                        parameters.GetInt(2),
                        parameters.GetPoint(4).X,
                        parameters.GetPoint(4).Y,
                        parameters.GetInt(3),
                        parameters.GetPoint(5, Point2I.Zero).X,
                        parameters.GetPoint(5, Point2I.Zero).Y,
                        parameters.GetPoint(6, new Point2I(1, 0)).X,
                        parameters.GetPoint(6, new Point2I(1, 0)).Y);
                }
                else if (parameters.GetString(0) == "frame") {
                    animationBuilder.InsertFrame(
                        parameters.GetInt(1),
                        parameters.GetInt(2),
                        parameters.GetPoint(3).X,
                        parameters.GetPoint(3).Y,
                        parameters.GetPoint(4, Point2I.Zero).X,
                        parameters.GetPoint(4, Point2I.Zero).Y);
                }
                else
                    ThrowParseError("Unknown insert type '" + parameters.GetString(0) + "' for animation");
            });

            // MODIFICATIONS.

            AddAnimationCommand("MakeQuad", delegate(CommandParam parameters) {
                animationBuilder.MakeQuad();
            });
            AddAnimationCommand("MakeDynamic", delegate(CommandParam parameters) {
                animationBuilder.MakeDynamic(
                    parameters.GetInt(0),
                    parameters.GetPoint(1).X,
                    parameters.GetPoint(1).Y);
            });
            AddAnimationCommand("Offset", delegate(CommandParam parameters) {
                animationBuilder.Offset(
                    parameters.GetPoint(0).X,
                    parameters.GetPoint(0).Y);
            });
            AddAnimationCommand("Flicker", delegate(CommandParam parameters) {
                // FLICKER <alternateDelay> <on/off>

                bool startOn = true;
                if (parameters.GetString(1) == "on")
                    startOn = true;
                else if (parameters.GetString(1) == "off")
                    startOn = false;
                else
                    ThrowParseError("Must be either on or off for flicker start state");

                animationBuilder.MakeFlicker(parameters.GetInt(0), startOn);
            });

            // SPRITE SHEET.

            AddSpriteCommand("SpriteSheet", delegate(CommandParam parameters) {
                if (parameters.Count == 1) {
                    // Start using the given sprite sheet.
                    SpriteSheet sheet = Resources.GetResource<SpriteSheet>(parameters.GetString(0));
                    spriteBuilder.SpriteSheet = sheet;
                }
                else {
                    int i = 1;
                    // Create a new sprite sheet.
                    Image image = null;
                    string imagePath = parameters.GetString(0);
                    string sheetName = imagePath;

                    if (parameters.Count == 5) {
                        imagePath = parameters.GetString(1);
                        i = 2;
                    }

                    if (Resources.ImageExists(imagePath))
                        image = Resources.GetResource<Image>(imagePath);
                    else
                        image = Resources.LoadImage(Resources.ImageDirectory + imagePath);

                    if (sheetName.IndexOf('/') >= 0)
                        sheetName = sheetName.Substring(sheetName.LastIndexOf('/') + 1);

                    SpriteSheet sheet = new SpriteSheet(image,
                            parameters.GetPoint(i + 0),
                            parameters.GetPoint(i + 2),
                            parameters.GetPoint(i + 1));
                    if (useTemporary)
                        resources.AddResource<SpriteSheet>(sheetName, sheet);
                    else
                        Resources.AddResource<SpriteSheet>(sheetName, sheet);
                    spriteBuilder.SpriteSheet = sheet;
                }
            });

            // BEGIN/END.

            // Sprite <name> <grid-location> <draw-offset = (0, 0)>
            AddSpriteCommand("Sprite", delegate(CommandParam parameters) {
                spriteName = parameters.GetString(0);
                sprite = new Sprite(
                    spriteBuilder.SpriteSheet,
                    parameters.GetPoint(1),
                    parameters.GetPoint(2, Point2I.Zero));
                spriteBuilder.Begin(sprite);
                useTemporary = false;
            });
            // TempSprite <name> <grid-location> <draw-offset = (0, 0)>
            AddSpriteCommand("TempSprite", delegate(CommandParam parameters) {
                spriteName = parameters.GetString(0);
                sprite = new Sprite(
                    spriteBuilder.SpriteSheet,
                    parameters.GetPoint(1),
                    parameters.GetPoint(2, Point2I.Zero));
                spriteBuilder.Begin(sprite);
                useTemporary = true;
            });
            AddSpriteCommand("End", delegate(CommandParam parameters) {
                if (sprite != null) {
                    spriteBuilder.End();
                    if (useTemporary)
                        resources.AddResource<Sprite>(spriteName, sprite);
                    else
                        Resources.AddResource<Sprite>(spriteName, sprite);
                    sprite = null;
                }
            });

            // BUILDING.

            // Add <grid-location> <draw-offset = (0, 0)>
            AddSpriteCommand("Add", delegate(CommandParam parameters) {
                spriteBuilder.AddPart(
                    parameters.GetPoint(0).X,
                    parameters.GetPoint(0).Y,
                    parameters.GetPoint(1, Point2I.Zero).X,
                    parameters.GetPoint(1, Point2I.Zero).Y);
            });
            // Size <size>
            AddSpriteCommand("Size", delegate(CommandParam parameters) {
                spriteBuilder.SetSize(
                    parameters.GetPoint(0).X,
                    parameters.GetPoint(0).Y);
            });

            // Add each command type as a command.

            for (int i = 0; i < tilesetCommands.Count; i++) {
                string command = tilesetCommands[i].Name;
                AddCommand(tilesetCommands[i].Name, delegate(CommandParam parameters) {
                    ReadSpecialCommand(command, parameters);
                });
            }
            for (int i = 0; i < animationCommands.Count; i++) {
                string command = animationCommands[i].Name;
                AddCommand(animationCommands[i].Name, delegate(CommandParam parameters) {
                    ReadSpecialCommand(command, parameters);
                });
            }
            for (int i = 0; i < spriteCommands.Count; i++) {
                string command = spriteCommands[i].Name;
                AddCommand(spriteCommands[i].Name, delegate(CommandParam parameters) {
                    ReadSpecialCommand(command, parameters);
                });
            }
        }
Ejemplo n.º 22
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);
 }
Ejemplo n.º 23
0
 // Draw an sprite or animation at the given playback time.
 public void DrawSpriteAnimation(SpriteAnimation spriteAnimation, int imageVariant, float time, Vector2F position, DepthLayer depth)
 {
     DrawSpriteAnimation(spriteAnimation, imageVariant, time, position, depth, Vector2F.Zero);
 }
Ejemplo n.º 24
0
 public void PlayAnimation(SpriteAnimation sprite)
 {
     if (sprite.IsSprite) {
         this.sprite = sprite.Sprite;
         animationPlayer.Animation = null;
     }
     else {
         animationPlayer.Play(sprite.Animation);
     }
 }
Ejemplo n.º 25
0
 public TilesetBuilder SetSprite(SpriteAnimation spriteAnimation)
 {
     tileData.Sprite = spriteAnimation;
     return this;
 }
Ejemplo n.º 26
0
 // Draw an animation during at the given time stamp and position.
 public void DrawAnimation(SpriteAnimation animation, int variantID, float time, Vector2F position, Color color, float depth = 0.0f)
 {
     if (animation.IsAnimation)
     DrawAnimation(animation.Animation, variantID, time, position.X, position.Y, color, depth);
     else
     DrawSprite(animation.Sprite, variantID, position.X, position.Y, color, depth);
 }
Ejemplo n.º 27
0
 public TilesetBuilder SetSprites(params Sprite[] sprites)
 {
     SpriteAnimation[] spriteAnimations = new SpriteAnimation[sprites.Length];
     for (int i = 0; i < sprites.Length; i++)
         spriteAnimations[i] = sprites[i];
     return this;
 }
Ejemplo n.º 28
0
        //-----------------------------------------------------------------------------
        // Constructor
        //-----------------------------------------------------------------------------
        public TilesetSR()
        {
            //this.loadingMode	= LoadingModes.Tilesets;
            this.resources		= new TemporaryResources();
            this.useTemporary	= false;
            this.spriteBuilder	= new SpriteBuilder();

            //=====================================================================================
            // LOADING MODE
            //=====================================================================================
            AddCommand("Load", "string resourceType",
            delegate(CommandParam parameters) {
                /*string loadType = parameters.GetString(0).ToLower();
                if (loadType == "tilesets")
                    loadingMode = LoadingModes.Tilesets;
                else if (loadType == "animations")
                    loadingMode = LoadingModes.Animations;
                else if (loadType == "sprites")
                    loadingMode = LoadingModes.Sprites;
                else
                    ThrowParseError("Invalid Load type", true);*/
            });
            //=====================================================================================
            // TILE/TILESET BEGIN/END
            //=====================================================================================
            AddCommand("Tileset", "string name, string sheetName, (int width, int height)",
            delegate(CommandParam parameters) {
                SpriteSheet sheet = Resources.GetSpriteSheet(parameters.GetString(1));
                tileset = new Tileset(parameters.GetString(0), sheet,
                                      parameters.GetPoint(2));
            });
            //=====================================================================================
            AddCommand("EventTileset", "string name, (int width, int height)",
            delegate(CommandParam parameters) {
                eventTileset = new EventTileset(parameters.GetString(0),
                    null, parameters.GetPoint(1));
            });
            //=====================================================================================
            AddCommand("Tile",
                "string name",
                "(int sheetX, int sheetY)",
            delegate(CommandParam parameters) {
                useTemporary = false;
                if (tileset != null) {
                    Point2I location = parameters.GetPoint(0);
                    tileData = tileset.TileData[location.X, location.Y];
                }
                else {
                    tileData = new TileData();
                    tileData.Name = parameters.GetString(0);
                }
                baseTileData = tileData;
            });
            //=====================================================================================
            AddCommand("TempTile", "string name",
            delegate(CommandParam parameters) {
                useTemporary = true;
                tileData = new TileData();
                tileData.Name = parameters.GetString(0);
                baseTileData = tileData;
            });
            //=====================================================================================
            AddCommand("EventTile", "string name",
            delegate(CommandParam parameters) {
                useTemporary = false;
                eventTileData = new EventTileData();
                eventTileData.Name = parameters.GetString(0);
                baseTileData = eventTileData;
            });
            //=====================================================================================
            AddCommand("Monster", "string name, string sprite, string monsterType, string monsterColor",
            delegate(CommandParam parameters) {
                useTemporary = false;
                eventTileData = new EventTileData();
                eventTileData.Clone(Resources.GetResource<EventTileData>("monster"));
                eventTileData.Name = parameters.GetString(0);
                baseTileData = eventTileData;

                if (parameters.ChildCount > 1)
                    eventTileData.Sprite = resources.GetSpriteAnimation(parameters.GetString(1));
                if (parameters.ChildCount > 2)
                    eventTileData.Properties.Set("monster_type", parameters.GetString(2));
                if (parameters.ChildCount > 3) {
                    MonsterColor color;
                    if (!Enum.TryParse<MonsterColor>(parameters.GetString(3), true, out color))
                        ThrowParseError("Invalid monster color: \"" + parameters.GetString(3) + "\"!");
                    eventTileData.Properties.Set("color", (int) color);
                    int imageVariantID = GameData.VARIANT_RED;
                    if (color == MonsterColor.Red)
                        imageVariantID = GameData.VARIANT_RED;
                    else if (color == MonsterColor.Blue)
                        imageVariantID = GameData.VARIANT_BLUE;
                    else if (color == MonsterColor.Green)
                        imageVariantID = GameData.VARIANT_GREEN;
                    else if (color == MonsterColor.Orange)
                        imageVariantID = GameData.VARIANT_ORANGE;
                    eventTileData.Properties.Set("image_variant", imageVariantID);
                }
            });
            //=====================================================================================
            AddCommand("End", "", delegate(CommandParam parameters) {
                if (tileData != null) {
                    if (tileData.Tileset == null) {
                        if (useTemporary)
                            resources.AddResource<TileData>(tileData.Name, tileData);
                        else
                            Resources.AddResource<TileData>(tileData.Name, tileData);
                    }
                    tileData = null;
                    baseTileData = null;
                }
                else if (eventTileData != null) {
                    if (eventTileData.Tileset == null) {
                        if (useTemporary)
                            resources.AddResource<EventTileData>(eventTileData.Name, eventTileData);
                        else
                            Resources.AddResource<EventTileData>(eventTileData.Name, eventTileData);
                    }
                    eventTileData = null;
                    baseTileData = null;
                }
                else if (tileset != null) {
                    Resources.AddResource<Tileset>(tileset.ID, tileset);
                    tileset = null;
                }
                else if (eventTileset != null) {
                    Resources.AddResource<EventTileset>(eventTileset.ID, eventTileset);
                    eventTileset = null;
                }
            });
            //=====================================================================================
            // TILESET SETUP
            //=====================================================================================
            AddCommand("Default", "(int defaultSheetX, int defaultSheetY)",
            delegate(CommandParam parameters) {
                tileset.DefaultTile = parameters.GetPoint(0);
            });
            //=====================================================================================
            // Config: data to configure tiles with a single character per tile.
            AddCommand("Config", "", delegate(CommandParam parameters) {
                string line = NextLine();
                int y = 0;
                while (!line.StartsWith("END;", StringComparison.OrdinalIgnoreCase)) {
                    if (y < tileset.Height) {
                        for (int x = 0; x < line.Length && x < tileset.Width; x++)
                            tileset.ConfigureTile(tileset.TileData[x, y], line[x]);
                    }
                    line = NextLine();
                    y++;
                }
            });
            //=====================================================================================
            AddCommand("SetTile", "(int sheetX, int sheetY), string tileName",
            delegate(CommandParam parameters) {
                Point2I location = parameters.GetPoint(0);

                if (tileset != null) {
                    tileset.TileData[location.X, location.Y] =
                        resources.GetResource<TileData>(parameters.GetString(1));
                }
                else if (eventTileset != null) {
                    eventTileset.TileData[location.X, location.Y] =
                        resources.GetResource<EventTileData>(parameters.GetString(1));
                }
            });
            //=====================================================================================
            // TILES
            //=====================================================================================
            AddCommand("Type", "string type",
            delegate(CommandParam parameters) {
                baseTileData.Type = Tile.GetType(parameters.GetString(0), true);
            });
            //=====================================================================================
            AddCommand("Flags", "string flags...",
            delegate(CommandParam parameters) {
                for (int i = 0; i < parameters.ChildCount; i++) {
                    TileFlags flags = TileFlags.None;
                    if (Enum.TryParse<TileFlags>(parameters.GetString(i), true, out flags))
                        tileData.Flags |= flags;
                    else
                        ThrowParseError("Invalid tile flag: \"" + parameters.GetString(i) + "\"!", parameters[i]);
                }
            });
            //=====================================================================================
            AddCommand("EnvType", "string envType",
            delegate(CommandParam parameters) {
                TileEnvironmentType envType = TileEnvironmentType.Normal;
                if (Enum.TryParse<TileEnvironmentType>(parameters.GetString(0), true, out envType))
                    tileData.Properties.Set("environment_type", (int) envType);
                else
                    ThrowParseError("Invalid tile environment type: \"" + parameters.GetString(0) + "\"!", parameters[0]);
            });
            //=====================================================================================
            AddCommand("ResetWhen", "string resetCondition",
            delegate(CommandParam parameters) {
                TileResetCondition envType = TileResetCondition.LeaveRoom;
                if (Enum.TryParse<TileResetCondition>(parameters.GetString(0), true, out envType))
                    tileData.ResetCondition = envType;
                else
                    ThrowParseError("Invalid tile reset condition: \"" + parameters.GetString(0) + "\"!", parameters[0]);
            });
            //=====================================================================================
            AddCommand("Conveyor", "string angle, float speed",
            delegate(CommandParam parameters) {
                string str = parameters.GetString(0).ToLower();
                int angle = -1;
                if (Angles.TryParse(str, true, out angle))
                    tileData.ConveyorAngle = angle;
                else if (parameters[0].Type == CommandParamType.Integer)
                    tileData.ConveyorAngle = parameters.GetInt(0);
                else
                    ThrowParseError("Unknown value for conveyor angle: " + str, parameters[0]);

                tileData.ConveyorSpeed = parameters.GetFloat(1);
            });
            //=====================================================================================
            // (string type, string name, var value)...
            // (string type, string name, var value, string readableName, string editorType, string category, string description)...
            // (string type, string name, var value, string readableName, (string editorType, string editorSubType), string category, string description, bool isHidden = false)...
            AddCommand("Properties",
                "(string type, string name, var otherData...)...",
                CommandProperties);
            //=====================================================================================
            AddCommand("Event",
                "string name, string readableName, string description",
                "string name, string readableName, string description, (string params...)", // Params = (type1, name1, type2, name2...)
            delegate(CommandParam parameters) {
                Property property = Property.CreateString(parameters.GetString(0), "");
                //property.SetDocumentation(parameters.GetString(1), "script", "", "Events", parameters.GetString(2), true, false);
                baseTileData.Properties.Set(property.Name, property)
                    .SetDocumentation(parameters.GetString(1), "script", "", "Events", parameters.GetString(2), true, false);

                // Create the event's script parameter list.
                ScriptParameter[] scriptParams;
                if (parameters.ChildCount > 3) {
                    CommandParam paramList = parameters[3];
                    scriptParams = new ScriptParameter[paramList.ChildCount / 2];
                    for (int i = 0; i < scriptParams.Length; i++) {
                        scriptParams[i] = new ScriptParameter() {
                            Type = paramList.GetString(i * 2),
                            Name = paramList.GetString((i * 2) + 1)
                        };
                    }
                }
                else
                    scriptParams = new ScriptParameter[0];

                // Add the event to the tile-data.
                baseTileData.Events.AddEvent(new ObjectEvent(
                        parameters.GetString(0), // Name
                        parameters.GetString(1), // Readable name
                        parameters.GetString(2), // Description
                        scriptParams));
            });
            //=====================================================================================
            AddCommand("Sprite",
                "string spriteOrAnimationName",
                "string spriteSheetName, (int sourceX, int sourceY), (int offsetX, int offsetY) = (0, 0)",
            delegate(CommandParam parameters) {
                if (parameters.ChildCount >= 2) {
                    spriteBuilder.Begin(new Sprite(
                        resources.GetResource<SpriteSheet>(parameters.GetString(0)),
                        parameters.GetPoint(1),
                        parameters.GetPoint(2, Point2I.Zero)
                    ));
                    baseTileData.Sprite = spriteBuilder.End();
                }
                else {
                    baseTileData.Sprite = resources.GetSpriteAnimation(parameters.GetString(0));
                }
            });
            //=====================================================================================
            AddCommand("Size", "(int width, int height)", delegate(CommandParam parameters) {
                tileData.Size = parameters.GetPoint(0);
            });
            //=====================================================================================
            AddCommand("SpriteIndex",
                "int index, string spriteOrAnim, string spriteAnimationName",
                "int index, string spriteAnimationName",
                "int index, string spriteSheetName, (int sourceX, int sourceY), (int offsetX, int offsetY) = (0, 0)",
            delegate(CommandParam parameters) {
                int index = parameters.GetInt(0);
                if (tileData.SpriteList.Length <= index) {
                    SpriteAnimation[] spriteList = new SpriteAnimation[index + 1];
                    for (int i = 0; i < spriteList.Length; i++) {
                        if (i < tileData.SpriteList.Length)
                            spriteList[i] = tileData.SpriteList[i];
                        else
                            spriteList[i] = null;
                    }
                    tileData.SpriteList = spriteList;
                }
                if (parameters.ChildCount > 2 && parameters[2].Type == CommandParamType.Array) {
                    spriteBuilder.Begin(new Sprite(
                        resources.GetResource<SpriteSheet>(parameters.GetString(1)),
                        parameters.GetPoint(2),
                        parameters.GetPoint(3, Point2I.Zero)
                    ));
                    tileData.SpriteList[index] = spriteBuilder.End();
                }
                else {
                    if (parameters.ChildCount == 3) {
                        string typeName = parameters.GetString(1);
                        if (typeName == "sprite")
                            tileData.SpriteList[index] = resources.GetResource<Sprite>(parameters.GetString(2));
                        else if (typeName == "animation")
                            tileData.SpriteList[index] = resources.GetResource<Animation>(parameters.GetString(2));
                        else
                            ThrowParseError("Unknown sprite/animation type '" + typeName + "' (expected \"sprite\" or \"animation\")");
                    }
                    else {
                        tileData.SpriteList[index] = resources.GetSpriteAnimation(parameters.GetString(1));
                    }
                }
            });
            //=====================================================================================
            AddCommand("SpriteList", "string spriteAnimationNames...", delegate(CommandParam parameters) {
                SpriteAnimation[] spriteList = new SpriteAnimation[parameters.ChildCount];
                for (int i = 0; i < parameters.ChildCount; i++)
                    spriteList[i] = resources.GetSpriteAnimation(parameters.GetString(i));

                tileData.SpriteList = spriteList;
            });
            //=====================================================================================
            AddCommand("SpriteObj",
                "string spriteAnimationName",
                "string spriteSheetName, (int sourceX, int sourceY), (int offsetX, int offsetY) = (0, 0)",
            delegate(CommandParam parameters) {
                if (parameters.ChildCount >= 2) {
                    spriteBuilder.Begin(new Sprite(
                        resources.GetResource<SpriteSheet>(parameters.GetString(0)),
                        parameters.GetPoint(1),
                        parameters.GetPoint(2, Point2I.Zero)
                    ));
                    tileData.SpriteAsObject = spriteBuilder.End();
                }
                else {
                    tileData.SpriteAsObject = resources.GetSpriteAnimation(parameters.GetString(0));
                }
            });
            //=====================================================================================
            AddCommand("BreakAnim", "string animationName",
            delegate(CommandParam parameters) {
                tileData.BreakAnimation = resources.GetResource<Animation>(parameters.GetString(0));
            });
            //=====================================================================================
            AddCommand("BreakSound", "string soundName",
            delegate(CommandParam parameters) {
                tileData.BreakSound = Resources.GetResource<Sound>(parameters.GetString(0));
            });
            //=====================================================================================
            AddCommand("Model", "string collisionModelName",
            delegate(CommandParam parameters) {
                tileData.CollisionModel = resources.GetResource<CollisionModel>(parameters.GetString(0));
            });
            //=====================================================================================
            AddCommand("Solid", "string collisionModelName",
            delegate(CommandParam parameters) {
                tileData.SolidType = TileSolidType.Solid;
                tileData.CollisionModel = resources.GetResource<CollisionModel>(parameters.GetString(0));
            });
            //=====================================================================================
            AddCommand("HalfSolid", "string collisionModelName",
            delegate(CommandParam parameters) {
                tileData.SolidType = TileSolidType.HalfSolid;
                tileData.CollisionModel = resources.GetResource<CollisionModel>(parameters.GetString(0));
            });
            //=====================================================================================
            AddCommand("Ledge", "string collisionModelName, string ledgeDirection",
            delegate(CommandParam parameters) {
                tileData.SolidType = TileSolidType.Ledge;
                tileData.CollisionModel = resources.GetResource<CollisionModel>(parameters.GetString(0));
                string dirName = parameters.GetString(1);
                int direction;
                if (Directions.TryParse(dirName, true, out direction))
                    tileData.LedgeDirection = direction;
                else
                    ThrowParseError("Unknown value for ledge direction: " + dirName);
            });
            //=====================================================================================
            AddCommand("Hurt", "int damage, (int areaX, int areaY, int areaWidth, int areaHeight)",
            delegate(CommandParam parameters) {
                tileData.HurtDamage = parameters.GetInt(0);
                tileData.HurtArea = new Rectangle2I(
                    parameters[1].GetInt(0),
                    parameters[1].GetInt(1),
                    parameters[1].GetInt(2),
                    parameters[1].GetInt(3));
            });

            AddCommand("Clone", "string tileDataName",
            delegate(CommandParam parameters) {
                if (tileData != null)
                    tileData.Clone(resources.GetResource<TileData>(parameters.GetString(0)));
                else if (eventTileData != null)
                    eventTileData.Clone(resources.GetResource<EventTileData>(parameters.GetString(0)));
            });

            // SPRITE SHEET ---------------------------------------------------------------

            AddCommand("SpriteSheet",
                "string path, (int cellWidth, int cellHeight), (int spacingX, int spacingY), (int offsetX, int offsetY)",
                "string name, string path, (int cellWidth, int cellHeight), (int spacingX, int spacingY), (int offsetX, int offsetY)",
            delegate(CommandParam parameters) {
            //AddSpriteCommand("SpriteSheet", delegate(CommandParam parameters) {
                if (parameters.ChildCount == 1) {
                    // Start using the given sprite sheet.
                    SpriteSheet sheet = Resources.GetResource<SpriteSheet>(parameters.GetString(0));
                    spriteBuilder.SpriteSheet = sheet;
                }
                else {
                    int i = 1;
                    // Create a new sprite sheet.
                    Image image = null;
                    string imagePath = parameters.GetString(0);
                    string sheetName = imagePath;

                    if (parameters.ChildCount == 5) {
                        imagePath = parameters.GetString(1);
                        i = 2;
                    }

                    if (Resources.ImageExists(imagePath))
                        image = Resources.GetResource<Image>(imagePath);
                    else
                        image = Resources.LoadImage(Resources.ImageDirectory + imagePath);

                    if (sheetName.IndexOf('/') >= 0)
                        sheetName = sheetName.Substring(sheetName.LastIndexOf('/') + 1);

                    SpriteSheet sheet = new SpriteSheet(image,
                            parameters.GetPoint(i + 0),
                            parameters.GetPoint(i + 2),
                            parameters.GetPoint(i + 1));
                    if (useTemporary)
                        resources.AddResource<SpriteSheet>(sheetName, sheet);
                    else
                        Resources.AddResource<SpriteSheet>(sheetName, sheet);
                    spriteBuilder.SpriteSheet = sheet;
                }
            });
        }
Ejemplo n.º 29
0
 // Draw an sprite or animation at the given playback time.
 public void DrawSpriteAnimation(SpriteAnimation spriteAnimation, int imageVariant, float time, Vector2F position, DepthLayer depth, Vector2F depthOrigin)
 {
     if (spriteAnimation.IsAnimation)
         DrawAnimation(spriteAnimation.Animation, imageVariant, time, position, depth, depthOrigin);
     else
         DrawSprite(spriteAnimation.Sprite, imageVariant, position, depth, depthOrigin);
 }
Ejemplo n.º 30
0
 public void SetAnimation(SpriteAnimation spriteAnimation)
 {
     animationPlayer.SetSpriteAnimation(spriteAnimation);
 }
Ejemplo n.º 31
0
 public SpriteAnimation(SpriteAnimation spriteAnimation)
 {
     this.value = spriteAnimation.value;
 }