コード例 #1
0
ファイル: Shot.cs プロジェクト: Yefimov/Game1.9
 //Конструктор Пули
 public Shot(Vector2 Position, SpriteInfo spriteInfoShot, float Speed, SpriteInfo spriteInfoBigBang, Func<MovedObject, bool> HasCollisions)
     : base(Position, spriteInfoShot, 1.0f, Speed)
 {
     this.HasCollisions = HasCollisions;
     this.ShotHasCollisions = false;
     this.spriteInfoBigBang = spriteInfoBigBang;
     origin = new Vector2(spriteInfoShot.FrameWidth / 2f, spriteInfoShot.FrameHeight / 2f);
 }
コード例 #2
0
ファイル: RectGameObject.cs プロジェクト: Yefimov/Game1.9
 protected RectGameObject(Vector2 Position, SpriteInfo Sprite, float Scale)
 {
     this.Position = Position;
     this.Width = Scale * Sprite.Texture.Bounds.Width;
     this.Height = Scale * Sprite.Texture.Bounds.Height;
     this.Sprite = Sprite;
     this.Scale = Scale;
     Origin = new Vector2(Scale * Sprite.Texture.Bounds.Width / 2f, Scale * Sprite.Texture.Bounds.Height / 2f);
 }
コード例 #3
0
 /*********
 ** Private methods
 *********/
 /// <summary>Get the internal drop list entries.</summary>
 /// <param name="drops">The possible drops.</param>
 /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param>
 private IEnumerable <Tuple <ItemDropData, SObject, SpriteInfo> > GetEntries(IEnumerable <ItemDropData> drops, GameHelper gameHelper)
 {
     foreach (ItemDropData drop in drops)
     {
         SObject    item   = this.GameHelper.GetObjectBySpriteIndex(drop.ItemID);
         SpriteInfo sprite = gameHelper.GetSprite(item);
         yield return(Tuple.Create(drop, item, sprite));
     }
 }
コード例 #4
0
ファイル: RectGameObject.cs プロジェクト: Yefimov/Game1.9
 protected RectGameObject(Vector2 Position, SpriteInfo Sprite, float Scale)
 {
     this.Position = Position;
     this.Width    = Scale * Sprite.Texture.Bounds.Width;
     this.Height   = Scale * Sprite.Texture.Bounds.Height;
     this.Sprite   = Sprite;
     this.Scale    = Scale;
     Origin        = new Vector2(Scale * Sprite.Texture.Bounds.Width / 2f, Scale * Sprite.Texture.Bounds.Height / 2f);
 }
コード例 #5
0
        protected virtual void DrawLine(SpriteInfo start, SpriteInfo end)
        {
            var painter  = _startTurleInfo.Painter;
            var startPos = start.Position;
            var endPos   = end.Position;
            var pen      = start.Pen;

            painter.DrawLine(startPos, endPos, pen.Size, pen.Color);
        }
コード例 #6
0
        public override Task Load()
        {
            return(Task.Run
                   (
                       () =>
            {
                string path = UOFileManager.GetUOFilePath("texmaps.mul");
                string pathidx = UOFileManager.GetUOFilePath("texidx.mul");

                FileSystemHelper.EnsureFileExists(path);
                FileSystemHelper.EnsureFileExists(pathidx);

                _file = new UOFileMul(path, pathidx, Constants.MAX_LAND_TEXTURES_DATA_INDEX_COUNT, 10);
                _file.FillEntries(ref Entries);
                string pathdef = UOFileManager.GetUOFilePath("TexTerr.def");

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

                using (DefReader defReader = new DefReader(pathdef))
                {
                    while (defReader.Next())
                    {
                        int index = defReader.ReadInt();

                        if (index < 0 || index >= Entries.Length)
                        {
                            continue;
                        }

                        int[] group = defReader.ReadGroup();

                        if (group == null)
                        {
                            continue;
                        }

                        for (int i = 0; i < group.Length; i++)
                        {
                            int checkindex = group[i];

                            if (checkindex < 0 || checkindex >= Entries.Length)
                            {
                                continue;
                            }

                            Entries[index] = Entries[checkindex];
                        }
                    }
                }

                _spriteInfos = new SpriteInfo[Entries.Length];
            }
                   ));
        }
コード例 #7
0
        /*[IniName("map")]
         * public string MappingsFile { get; set; }
         * [IniName("mapgame")]
         * public EngineVersion MappingsGame { get; set; }
         * [IniName("mapfmt")]
         * public MappingsFormat MappingsFormat { get; set; }
         * [IniName("dplc")]
         * public string DPLCFile { get; set; }
         * [IniName("dplcgame")]
         * public EngineVersion DPLCGame { get; set; }
         * [IniName("dplcfmt")]
         * public MappingsFormat DPLCFormat { get; set; }
         * [IniName("anim")]
         * public string AnimationFile { get; set; }
         * [IniName("animfmt")]
         * public MappingsFormat AnimationFormat { get; set; }
         * [IniName("startpal")]
         * public int StartPalette { get; set; }*/

        public static Dictionary <string, AnimationInfo> Load(string filename)
        {
            Dictionary <string, Dictionary <string, string> > ini = IniFile.Load(filename);
            string userfile = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename) + ".user" + Path.GetExtension(filename));

            if (File.Exists(userfile))
            {
                ini = IniFile.Combine(ini, IniFile.Load(userfile));
            }
            Dictionary <string, AnimationInfo> result = IniSerializer.Deserialize <Dictionary <string, AnimationInfo> >(ini);

            foreach (KeyValuePair <string, AnimationInfo> anim in result)
            {
                /*if (anim.Value.MappingsGame == EngineVersion.Invalid)
                 *      anim.Value.MappingsGame = anim.Value.Game;
                 * if (anim.Value.DPLCGame == EngineVersion.Invalid)
                 *      anim.Value.DPLCGame = anim.Value.Game;
                 * if (anim.Value.MappingsFormat == MappingsFormat.Invalid)
                 *      anim.Value.MappingsFormat = MappingsFormat.Binary;
                 * if (anim.Value.DPLCFormat == MappingsFormat.Invalid)
                 *      anim.Value.DPLCFormat = MappingsFormat.Binary;
                 * if (anim.Value.AnimationFormat == MappingsFormat.Invalid)
                 *      anim.Value.AnimationFormat = MappingsFormat.Binary;*/
                Dictionary <string, string> inisection = ini[anim.Key];
                List <byte> frmspd = new List <byte>();
                Dictionary <string, int> frmspr = new Dictionary <string, int>();
                anim.Value.SprList = new List <SpriteInfo[]>();
                for (int i = 0; i < anim.Value.Frames.Length; i++)
                {
                    string sprName = anim.Value.Frames[i].Sprite;
                    if (anim.Value.Frames[i].Speed >= 0xF0)
                    {
                        frmspd.Add(0);
                        frmspd.Add(anim.Value.Frames[i].Speed);
                        break;
                    }

                    if (!frmspr.ContainsKey(sprName))
                    {
                        frmspr[sprName] = anim.Value.SprList.Count;

                        string[]     vals    = inisection[sprName].Split('|');
                        SpriteInfo[] sprinfs = new SpriteInfo[vals.Length];
                        for (int j = 0; j < vals.Length; j++)
                        {
                            sprinfs[j] = new SpriteInfo(vals[j]);
                        }
                        anim.Value.SprList.Add(sprinfs);
                    }
                    frmspd.Add((byte)frmspr[sprName]);
                    frmspd.Add((byte)(anim.Value.Frames[i].Speed * 2));
                }
                anim.Value.Animation = new Animation(frmspd.ToArray(), 0, anim.Key + "_Load");
            }
            return(result);
        }
コード例 #8
0
        /// <summary>Draw the value (or return <c>null</c> to render the <see cref="GenericField.Value"/> using the default format).</summary>
        /// <param name="spriteBatch">The sprite batch being drawn.</param>
        /// <param name="font">The recommended font.</param>
        /// <param name="position">The position at which to draw.</param>
        /// <param name="wrapWidth">The maximum width before which content should be wrapped.</param>
        /// <returns>Returns the drawn dimensions, or <c>null</c> to draw the <see cref="GenericField.Value"/> using the default format.</returns>
        public override Vector2?DrawValue(SpriteBatch spriteBatch, SpriteFont font, Vector2 position, float wrapWidth)
        {
            if (!this.Drops.Any())
            {
                return(spriteBatch.DrawTextBlock(font, this.DefaultText, position, wrapWidth));
            }

            float height = 0;

            // draw preface
            if (!string.IsNullOrWhiteSpace(this.Preface))
            {
                Vector2 prefaceSize = spriteBatch.DrawTextBlock(font, this.Preface, position, wrapWidth);
                height += (int)prefaceSize.Y;
            }

            // list drops
            Vector2 iconSize = new Vector2(font.MeasureString("ABC").Y);

            foreach (var entry in this.Drops)
            {
                // get data
                ItemDropData drop           = entry.Item1;
                SObject      item           = entry.Item2;
                SpriteInfo   sprite         = entry.Item3;
                bool         isGuaranteed   = drop.Probability > .99f;
                bool         shouldFade     = this.FadeNonGuaranteed && !isGuaranteed;
                bool         shouldCrossOut = this.CrossOutNonGuaranteed && !isGuaranteed;

                // draw icon
                spriteBatch.DrawSpriteWithin(sprite, position.X, position.Y + height, iconSize, shouldFade ? Color.White * 0.5f : Color.White);

                // draw text
                string text = isGuaranteed ? item.DisplayName : I18n.Generic_PercentChanceOf(percent: (int)(Math.Round(drop.Probability, 4) * 100), label: item.DisplayName);
                if (drop.MinDrop != drop.MaxDrop)
                {
                    text += $" ({I18n.Generic_Range(min: drop.MinDrop, max: drop.MaxDrop)})";
                }
                else if (drop.MinDrop > 1)
                {
                    text += $" ({drop.MinDrop})";
                }
                Vector2 textSize = spriteBatch.DrawTextBlock(font, text, position + new Vector2(iconSize.X + 5, height + 5), wrapWidth, shouldFade ? Color.Gray : Color.Black);

                // cross out item if it definitely won't drop
                if (shouldCrossOut)
                {
                    spriteBatch.DrawLine(position.X + iconSize.X + 5, position.Y + height + iconSize.Y / 2, new Vector2(textSize.X, 1), this.FadeNonGuaranteed ? Color.Gray : Color.Black);
                }

                height += textSize.Y + 5;
            }

            // return size
            return(new Vector2(wrapWidth, height));
        }
コード例 #9
0
ファイル: GameHelper.cs プロジェクト: Andrey1225/StardewMods
        /// <summary>Get the sprite for an item.</summary>
        /// <param name="item">The item.</param>
        /// <param name="onlyCustom">Only return the sprite info if it's custom.</param>
        /// <returns>Returns a tuple containing the sprite sheet and the sprite's position and dimensions within the sheet.</returns>
        public SpriteInfo GetSprite(Item item, bool onlyCustom = false)
        {
            SObject obj = item as SObject;

            // Custom Farming Redux
            if (obj != null && this.CustomFarmingRedux.IsLoaded)
            {
                SpriteInfo data = this.CustomFarmingRedux.GetSprite(obj);
                if (data != null)
                {
                    return(data);
                }
            }

            if (onlyCustom)
            {
                return(null);
            }

            // standard object
            if (obj != null)
            {
                return(obj.bigCraftable.Value
                    ? new SpriteInfo(Game1.bigCraftableSpriteSheet, SObject.getSourceRectForBigCraftable(obj.ParentSheetIndex))
                    : new SpriteInfo(Game1.objectSpriteSheet, Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, obj.ParentSheetIndex, SObject.spriteSheetTileSize, SObject.spriteSheetTileSize)));
            }

            // boots or ring
            if (item is Boots || item is Ring)
            {
                int indexInTileSheet = (item as Boots)?.indexInTileSheet ?? ((Ring)item).indexInTileSheet;
                return(new SpriteInfo(Game1.objectSpriteSheet, Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, indexInTileSheet, SObject.spriteSheetTileSize, SObject.spriteSheetTileSize)));
            }

            // clothing
            if (item is Clothing clothing)
            {
                switch (clothing.clothesType.Value)
                {
                case (int)Clothing.ClothesType.SHIRT:
                    return(new ShirtSpriteInfo(clothing));

                case (int)Clothing.ClothesType.PANTS:
                    return(new SpriteInfo(FarmerRenderer.pantsTexture, new Rectangle(192 * (clothing.indexInTileSheetMale.Value % (FarmerRenderer.pantsTexture.Width / 192)), 688 * (clothing.indexInTileSheetMale.Value / (FarmerRenderer.pantsTexture.Width / 192)) + 672, 16, 16)));
                }
            }

            // hat
            if (item is Hat hat)
            {
                return(new SpriteInfo(FarmerRenderer.hatsTexture, new Rectangle(hat.which.Value * 20 % FarmerRenderer.hatsTexture.Width, hat.which.Value * 20 / FarmerRenderer.hatsTexture.Width * 20 * 4, 20, 20)));
            }

            // unknown item
            return(null);
        }
コード例 #10
0
 /*********
 ** Private methods
 *********/
 /// <summary>Get a fish pond's possible drops by population.</summary>
 /// <param name="currentPopulation">The current population for showing unlocked drops.</param>
 /// <param name="data">The fish pond data.</param>
 /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param>
 /// <remarks>Derived from <see cref="FishPond.dayUpdate"/> and <see cref="FishPond.GetFishProduce"/>.</remarks>
 private IEnumerable <FishPondDrop> GetEntries(int currentPopulation, FishPondData data, GameHelper gameHelper)
 {
     foreach (var drop in gameHelper.GetFishPondDrops(data))
     {
         bool       isUnlocked = currentPopulation >= drop.MinPopulation;
         SObject    item       = this.GameHelper.GetObjectBySpriteIndex(drop.ItemID);
         SpriteInfo sprite     = gameHelper.GetSprite(item);
         yield return(new FishPondDrop(drop, item, sprite, isUnlocked));
     }
 }
コード例 #11
0
        public static Sprite InfoToSprite(SpriteInfo info)
        {
            var image  = Resources.Load <Texture2D>(info.SpritePath);
            var rect   = new Rect(0, 0, image.width, image.height);
            var sprite = Sprite.Create(image, rect, Vector2FromPosition(info.PivotPoint), info.PixelsPerUnit,
                                       uint.MinValue,
                                       SpriteMeshType.Tight);

            return(sprite);
        }
コード例 #12
0
ファイル: Panzer.cs プロジェクト: Yefimov/Game1.9
        //Конструктор Танка
        public Panzer(Vector2 Position, SpriteInfo spriteInfoPanzer, float Speed, SpriteInfo spriteInfoShot, SpriteInfo spriteInfoBigBang, 
            Func<MovedObject,bool> HasCollisions) : base(Position, spriteInfoPanzer, 0.2f, Speed)
        {
            this.HasCollisions = HasCollisions;
            this.spriteInfoPanzer = spriteInfoPanzer;
            this.spriteInfoShot = spriteInfoShot;
            this.spriteInfoBigBang = spriteInfoBigBang;

            origin = new Vector2(spriteInfoPanzer.FrameWidth / 2f, spriteInfoPanzer.FrameHeight / 2f);
        }
コード例 #13
0
        private void ctrlSpriteList_SpriteSelected(SpriteInfo sprite)
        {
            if (_options.SelectedSprite == sprite?.Index)
            {
                return;
            }

            SelectSprite(sprite);
            RefreshViewer();
        }
コード例 #14
0
        //Конструктор Танка
        public Panzer(Vector2 Position, SpriteInfo spriteInfoPanzer, float Speed, SpriteInfo spriteInfoShot, SpriteInfo spriteInfoBigBang,
                      Func <MovedObject, bool> HasCollisions) : base(Position, spriteInfoPanzer, 0.2f, Speed)
        {
            this.HasCollisions     = HasCollisions;
            this.spriteInfoPanzer  = spriteInfoPanzer;
            this.spriteInfoShot    = spriteInfoShot;
            this.spriteInfoBigBang = spriteInfoBigBang;

            origin = new Vector2(spriteInfoPanzer.FrameWidth / 2f, spriteInfoPanzer.FrameHeight / 2f);
        }
コード例 #15
0
 /*/// <summary>
  * ///  Tries to parse the sprite's draw size.
  * /// </summary>
  * /// <param name="s">The sprite info to assign the parsed value to.</param>
  * /// <param name="m">The regex match to get the value to parse from.</param>
  * /// <returns>True if the parse was successful, otherwise false.</returns>
  * protected bool TryParseSize(SpriteInfo s, Match m) {
  *      if (AttributeHelper.TryParseCode(m.Groups["size"].Value, out SpriteSize s)) {
  *              s.Size = s;
  *              return true;
  *      }
  *      return false;
  * }*/
 /// <summary>
 ///  Tries to parse the sprite's part type and Id.
 /// </summary>
 /// <param name="s">The sprite info to assign the parsed value to.</param>
 /// <param name="m">The regex match to get the value to parse from.</param>
 /// <returns>True if the parse was successful, otherwise false.</returns>
 protected bool TryParsePart(SpriteInfo s, Match m)
 {
     if (PartRule.TryParse(m.Groups["part_id"].Value, out int part))
     {
         s.PartType = m.Groups["part_type"].Value.Length;
         s.PartId   = part;
         return(true);
     }
     return(false);
 }
コード例 #16
0
 public Animation(SpriteInfo spriteInfo, Vector2 center, Vector2 size, Color?mask = null, Vector2?rotationOrigin = null, Action <Animation> callback = null, int drawLayer = 0)
 {
     Position           = center;
     SpriteInfo         = spriteInfo;
     Size               = size;
     CompletionCallback = callback;
     DrawLayer          = drawLayer;
     Mask               = mask ?? Color.White;
     RotationOrigin     = rotationOrigin ?? Size / 2;
 }
コード例 #17
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="gameHelper">Provides utility methods for interacting with the game code.</param>
 /// <param name="label">A short field label.</param>
 /// <param name="item">The item for which to display an icon.</param>
 /// <param name="text">The text to display (if not the item name).</param>
 public ItemIconField(GameHelper gameHelper, string label, Item item, string text = null)
     : base(label, hasValue: item != null)
 {
     this.Sprite = gameHelper.GetSprite(item);
     if (item != null)
     {
         this.Value = !string.IsNullOrWhiteSpace(text)
             ? this.FormatValue(text)
             : this.FormatValue(item.DisplayName);
     }
 }
コード例 #18
0
ファイル: BigBang.cs プロジェクト: Yefimov/Game1.9
        //Конструктор Взрыва
        public BigBang(Vector2 Position, SpriteInfo spriteInfoBigBang ) : base(Position, spriteInfoBigBang, 1.0f)
        {

            this.spriteInfoBigBang = spriteInfoBigBang;

            origin = new Vector2(spriteInfoBigBang.FrameWidth / 2f, spriteInfoBigBang.FrameHeight / 2f);

            double frameCount = spriteInfoBigBang.FrameCount;//кол-во Frame
            double timeToFrame = spriteInfoBigBang.TimeToFrame.TotalMilliseconds;//время на один Frame
            this.timerForBigBang = TimeSpan.FromMilliseconds(frameCount * timeToFrame);//время на взрыв = время на один Frame * на кол-во Frame
        }
コード例 #19
0
    public void SetPlayerDataInfo(Stats stat, SpriteInfo spriteInfo, bool ForceSave = false)
    {
        playerDataInfo.Clear();
        playerDataInfo.statsList.Add(stat);
        playerDataInfo.spriteList.Add(spriteInfo);

        if (ForceSave)
        {
            Utility.WriteDataToJSON <ListDataInfo>(Constants.JSONIndex.DATA_PLAYER, ref playerDataInfo);
        }
    }
コード例 #20
0
        //Конструктор Взрыва
        public BigBang(Vector2 Position, SpriteInfo spriteInfoBigBang) : base(Position, spriteInfoBigBang, 1.0f)
        {
            this.spriteInfoBigBang = spriteInfoBigBang;

            origin = new Vector2(spriteInfoBigBang.FrameWidth / 2f, spriteInfoBigBang.FrameHeight / 2f);

            double frameCount  = spriteInfoBigBang.FrameCount;                          //кол-во Frame
            double timeToFrame = spriteInfoBigBang.TimeToFrame.TotalMilliseconds;       //время на один Frame

            this.timerForBigBang = TimeSpan.FromMilliseconds(frameCount * timeToFrame); //время на взрыв = время на один Frame * на кол-во Frame
        }
コード例 #21
0
 /// <summary>
 /// Determine if an object is completely outside of the screen's bounds
 /// </summary>
 public static bool OutOfBounds(SpriteInfo obj)
 {
     return(obj.transform.position.x
            - obj.SpriteRenderer.bounds.extents.x > Right ||
            obj.transform.position.x
            + obj.SpriteRenderer.bounds.extents.x < Left ||
            obj.transform.position.y
            - obj.SpriteRenderer.bounds.extents.y > Bottom ||
            obj.transform.position.y
            + obj.SpriteRenderer.bounds.extents.y < Top);
 }
コード例 #22
0
ファイル: AssetFinder.cs プロジェクト: pashcovich/mptanks2d
        /// <summary>
        /// Retrieves an asset by name
        /// </summary>
        /// <param name="asset"></param>
        /// <param name="sheet"></param>
        /// <returns></returns>
        public Sprite RetrieveAsset(ref SpriteInfo info)
        {
            if (info.IsAnimation)
            {
                var frame = GetAnimationFrameInfo(info);
                return(Cache.GetSprite(frame));
            }

            //If not animated, just do the simple thing and...
            return(Cache.GetSprite(info));
        }
コード例 #23
0
            public SpriteInfo Trim(Color trimAgainst, int marginX, int marginY)
            {
                var top   = frame.y;
                var right = frame.x;
                var btm   = frame.y + frame.height;
                var left  = frame.x + frame.width;

                for (int y = frame.y; y < frame.y + frame.height; ++y)
                {
                    for (int x = frame.x; x < frame.x + frame.width; ++x)
                    {
                        var color = tex.GetPixel(x, y);
                        if (color.a == 0)
                        {
                            color = new Color();
                        }
                        if (color != trimAgainst)
                        {
                            if (top <= y)
                            {
                                top = y + 1;
                            }
                            if (right <= x)
                            {
                                right = x + 1;
                            }
                            if (btm > y)
                            {
                                btm = y;
                            }
                            if (left > x)
                            {
                                left = x;
                            }
                        }
                    }
                }

                top   = Mathf.Min(frame.y + frame.height, top + marginY);
                right = Mathf.Min(frame.x + frame.width, right + marginX);
                btm   = Mathf.Max(frame.y, btm - marginY);
                left  = Mathf.Max(frame.x, left - marginX);

                var pivotT = new Vector2(frame.x + pivotN.x * frame.width, frame.y + pivotN.y * frame.height);

                var ret = new SpriteInfo
                {
                    tex   = this.tex,
                    frame = new RectInt(left, btm, right - left, top - btm),
                };

                ret.pivotN = new Vector2((pivotT.x - ret.frame.x) / ret.frame.width, (pivotT.y - ret.frame.y) / ret.frame.height);
                return(ret);
            }
コード例 #24
0
        /// <summary>
        /// 更新信息
        /// </summary>
        public void UpdateSpriteGroup()
        {
            if (_spriteAsset && _spriteAsset.TexSource && _spriteAsset.Row > 1 && _spriteAsset.Column > 1)
            {
                var count = _spriteAsset.IsStatic ? _spriteAsset.Row * _spriteAsset.Column : _spriteAsset.Row;
                // if (_spriteAsset.ListSpriteGroup.Count != count)
                {
                    _spriteAsset.ListSpriteGroup.Clear();
                    //更新
                    //----------------------------------
                    Vector2 texSize = new Vector2(_spriteAsset.TexSource.width, _spriteAsset.TexSource.height);
                    Vector2 size    = new Vector2((_spriteAsset.TexSource.width / (float)_spriteAsset.Column)
                                                  , (_spriteAsset.TexSource.height / (float)_spriteAsset.Row));

                    if (_spriteAsset.IsStatic)
                    {
                        int index = -1;
                        for (int i = 0; i < _spriteAsset.Row; i++)
                        {
                            for (int j = 0; j < _spriteAsset.Column; j++)
                            {
                                index++;
                                SpriteInfoGroup infoGroup = Pool <SpriteInfoGroup> .Get();

                                SpriteInfo info = GetSpriteInfo(index, _spriteAsset.Offset, i, j, size, texSize);

                                infoGroup.Tag = "emoji_" + info.Id;
                                infoGroup.ListSpriteInfor.Add(info);
                                _spriteAsset.ListSpriteGroup.Add(infoGroup);
                            }
                        }
                    }
                    else
                    {
                        int index = -1;
                        for (int i = 0; i < _spriteAsset.Row; i++)
                        {
                            SpriteInfoGroup infoGroup = Pool <SpriteInfoGroup> .Get();

                            infoGroup.Tag = "emoji_" + i;
                            for (int j = 0; j < _spriteAsset.Column; j++)
                            {
                                index++;

                                SpriteInfo info = GetSpriteInfo(index, _spriteAsset.Offset, i, j, size, texSize);

                                infoGroup.ListSpriteInfor.Add(info);
                            }
                            _spriteAsset.ListSpriteGroup.Add(infoGroup);
                        }
                    }
                }
            }
        }
コード例 #25
0
        public SpriteInfo GetSpriteInfo(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            SpriteInfo spriteInfo = sprites.Find(s => s.name == name);

            return(spriteInfo);
        }
コード例 #26
0
    public void applySettings()
    {
        if (playerData == null)
        {
            return;
        }
        itemList   = playerData.itemList;
        spriteInfo = playerData.spriteList.Count > 0 ? playerData.spriteList[0] : null;
        if (spriteInfo == null)
        {
            return;
        }
        itemList   = playerData.itemList;
        spriteInfo = playerData.spriteList[0];
        GetSpriteFromManager(body, spriteInfo.BodyIndex, Constants.SpriteType.BODY);
        GetSpriteFromManager(hair, spriteInfo.HairIndex, Constants.SpriteType.HAIR);
        GetSpriteFromManager(facehair, spriteInfo.FaceHairIndex, Constants.SpriteType.FACIAL_HAIR);

        for (int p = 0; p < playerData.equipedItensId.Count; p++)
        {
            for (int i = 0; i < itemList.Count; i++)
            {
                if (itemList[i].id == playerData.equipedItensId[p])
                {
                    switch (itemList[i].Item_type)
                    {
                    case Constants.ItemIndex.RIGHT_HAND:
                        GetSpriteFromManager(rightHand, itemList[i].Sprite_index, Constants.SpriteType.RIGHT_HAND);
                        break;

                    case Constants.ItemIndex.ARMOR:
                        GetSpriteFromManager(armor, itemList[i].Sprite_index, Constants.SpriteType.ARMOR);
                        break;

                    case Constants.ItemIndex.LEFT_HAND:
                        GetSpriteFromManager(leftHand, itemList[i].Sprite_index, Constants.SpriteType.LEFT_HAND);
                        break;

                    case Constants.ItemIndex.HELMET:
                        GetSpriteFromManager(helmet, itemList[i].Sprite_index, Constants.SpriteType.HELMET);
                        break;

                    case Constants.ItemIndex.PANTS:
                        GetSpriteFromManager(pants, itemList[i].Sprite_index, Constants.SpriteType.PANTS);
                        break;

                    case Constants.ItemIndex.SHOES:
                        GetSpriteFromManager(foot, itemList[i].Sprite_index, Constants.SpriteType.FOOT);
                        break;
                    }
                }
            }
        }
    }
コード例 #27
0
ファイル: Button.cs プロジェクト: FilippoLeon/Shipwreck
 public void SetSprite(SpriteInfo info)
 {
     if (info == null)
     {
         backgroundComponent.sprite = null;
     }
     else
     {
         backgroundComponent.sprite = SpriteController.spriteLoader.Load(info).sprite;
     }
 }
コード例 #28
0
ファイル: SpriteImageResource.cs プロジェクト: KHCmaster/PPD
 public SpriteImageResource(PPDDevice device, ImageResourceBase imageResource, SpriteInfo spriteInfo, ImageScale imageScale)
 {
     this.imageResource = imageResource;
     this.spriteInfo    = spriteInfo;
     this.imageScale    = imageScale;
     uv           = new Vector2(spriteInfo.X / (float)imageResource.Width, spriteInfo.Y / (float)imageResource.Height);
     uvSize       = new Vector2(spriteInfo.SpaceWidth / (float)imageResource.Width, spriteInfo.SpaceHeight / (float)imageResource.Height);
     actualUVSize = new Vector2(spriteInfo.Width / (float)imageResource.Width, spriteInfo.Height / (float)imageResource.Height);
     halfPixel    = new Vector2(0.5f / imageResource.Width, 0.5f / imageResource.Height);
     CreateVertexBuffer(device);
 }
コード例 #29
0
        //获取精灵信息
        private SpriteInfo GetSpriteInfo(int index, Vector2 offset, int row, int column, Vector2 size, Vector2 texSize)
        {
            SpriteInfo info = Pool <SpriteInfo> .Get();

            info.Id           = index;
            info.Rect         = new Rect(offset.x + size.y * column, offset.y + texSize.y - (row + 1) * size.x, size.x, size.y);
            info.DrawTexCoord = new Rect(info.Rect.x / texSize.x, info.Rect.y / texSize.y
                                         , info.Rect.width / texSize.x, info.Rect.height / texSize.y);
            info.Uv = GetSpriteUV(texSize, info.Rect);
            return(info);
        }
コード例 #30
0
    /// <summary>
    /// <para>Rectangle-to-Rectangle:</para>
    /// Determine if 2 rectangular objects are colliding under Axis-Aligned
    /// Bounding Box collision detection methods
    /// </summary>
    /// <param name="objA">The first object</param>
    /// <param name="objB">The second object</param>
    /// <returns>True if objA and objB are intersecting each other within their
    /// bounding boxes.</returns>
    public static bool AABBCollision(SpriteInfo objA, SpriteInfo objB)
    {
        if (objB.MinX < objA.MaxX &&
            objB.MaxX > objA.MinX &&
            objB.MinY < objA.MaxY &&
            objB.MaxY > objA.MinY)
        {
            return(true);
        }

        return(false);
    }
コード例 #31
0
ファイル: Entity.cs プロジェクト: FilippoLeon/Project-Pu-239
    public override void ReadElement(XmlReader reader)
    {
        switch (reader.Name)
        {
        case "Sprite":
            spriteInfo = new SpriteInfo(reader);
            break;

        default:
            break;
        }
    }
コード例 #32
0
ファイル: ButtonExEditor.cs プロジェクト: PayneC/ProjectA
 private void SpriteInfoInspector(SpriteInfo info, string name)
 {
     EditorGUILayout.LabelField(name);
     EditorGUILayout.BeginVertical(GUI.skin.box);
     EditorGUILayout.LabelField("Atlas Name", info.atlasName);
     EditorGUILayout.LabelField("Sprite Name", info.spriteName);
     if (Application.isPlaying)
     {
         EditorGUILayout.ObjectField("Atlas", info.atlas, typeof(UIAtlas), false);
     }
     EditorGUILayout.EndVertical();
 }
コード例 #33
0
        protected override IEnumerable <AssetItem> CreateAssets(AssetTemplateGeneratorParameters parameters)
        {
            var sources = parameters.Tags.Get(SourceFilesPathKey);

            if (sources == null)
            {
                return(base.CreateAssets(parameters));
            }

            SpriteSheetAsset asset;

            if (parameters.Description.Id == SpriteSheetId)
            {
                asset = SpriteSheetSprite2DFactory.Create();
            }
            else if (parameters.Description.Id == UISpriteSheetId)
            {
                asset = SpriteSheetUIFactory.Create();
            }
            else
            {
                throw new ArgumentException("Invalid template description for this generator.");
            }

            using (var textureTool = new TextureTool())
            {
                foreach (var source in sources)
                {
                    int width  = 0;
                    int height = 0;
                    parameters.Logger.Verbose($"Processing image \"{source}\"");
                    try
                    {
                        var image = textureTool.Load(source.ToString(), false);
                        width  = image.Width;
                        height = image.Height;
                    }
                    catch (Exception)
                    {
                        parameters.Logger.Warning($"Unable to retrieve the size of \"{source}\"");
                    }
                    var spriteInfo = new SpriteInfo
                    {
                        Name          = source.GetFileNameWithoutExtension(),
                        TextureRegion = new Rectangle(0, 0, width, height),
                        Source        = source
                    };
                    asset.Sprites.Add(spriteInfo);
                }
            }

            return(new AssetItem(GenerateLocation(parameters), asset).Yield());
        }
コード例 #34
0
 // Start is called before the first frame update
 void Start()
 {
     if (!isFrag) //Only initializes the position if the asteroid is not a fragment
     {
         asteroidRenderer = this.GetComponent <SpriteRenderer>();
         velX             = Random.Range(-0.01f, 0.02f);
         velY             = Random.Range(-0.01f, 0.02f);
         velocity         = new Vector3(velX, velY, 0);
         direction        = (velocity / velocity.magnitude);
     }
     info = gameObject.GetComponent <SpriteInfo>();
 }
コード例 #35
0
ファイル: DerpAttack.cs プロジェクト: GoodSky/derp-adventure
        public DerpAttack(double x, double y, int dir)
        {
            this.x = x;
            this.y = y;
            this.dir = dir;

            key = new SortKey(y);

            graphic = textures["small-close"];
            graphicInfo = textureInfo["small-close"];

            lastTick = DateTime.Now;
        }
コード例 #36
0
ファイル: ReaderMap.cs プロジェクト: Yefimov/Game1.9
 public static HashSet<ScenicObject> getMap(string[,] MasMapsToDraw, HashSet<ScenicObject> scenicObjects, SpriteInfo[] images)
 {
     int cell = 16; // Ширина блока
     for (int i = 0; i < MasMapsToDraw.GetLength(0); i++)
     {
         for (int j = 0; j < MasMapsToDraw.GetLength(1); j++)
         {
             int type = Int32.Parse(MasMapsToDraw[i, j]);
             if (type > 0)
             {
                 scenicObjects.Add(new ScenicObject(new Vector2(i * cell, j * cell), type, images[type - 1], 1f));
             }
         }
     }
     return scenicObjects;
 }
コード例 #37
0
ファイル: Utils.cs プロジェクト: kampfi/SAwarenessBeta
 public static void LoadTexture(String name, ref SpriteInfo texture, TextureType type)
 {
     if (texture == null)
         texture = new SpriteInfo();
     Bitmap bmp;
     if ((type == TextureType.Default || type == TextureType.Summoner) && MyResources.ContainsKey(name.ToLower()))
     {
         try
         {
             using (var ms = new MemoryStream(MyResources[name.ToLower()]))
             {
                 bmp = new Bitmap(ms);
             }
             texture.Bitmap = (Bitmap)bmp.Clone();
             texture.Sprite = new Render.Sprite(bmp, new Vector2(0, 0));
             texture.DownloadFinished = true;
             //texture.Sprite.UpdateTextureBitmap(bmp);
             //texture = new Render.Sprite(bmp, new Vector2(0, 0));
         }
         catch (Exception ex)
         {
             if (texture == null)
             {
                 texture = new SpriteInfo();
                 texture.Sprite = new Render.Sprite(MyResources["questionmark"], new Vector2(0, 0));
             }
             Console.WriteLine("SAwarness: Couldn't load texture: " + name + "\n Ex: " + ex);
         }
     }
     else if (type == TextureType.Summoner && MyResources.ContainsKey(name.ToLower().Remove(name.Length - 1)))
     {
         try
         {
             //texture = new Render.Sprite((Bitmap)Resources.ResourceManager.GetObject(name.ToLower().Remove(name.Length - 1)), new Vector2(0, 0));
         }
         catch (Exception ex)
         {
             if (texture == null)
             {
                 texture = new SpriteInfo();
                 texture.Sprite = new Render.Sprite(MyResources["questionmark"], new Vector2(0, 0));
             }
             Console.WriteLine("SAwarness: Couldn't load texture: " + name + "\n Ex: " + ex);
         }
     }
     else if (type == TextureType.Item && MyResources.ContainsKey(name.ToLower().Insert(0, "_")))
     {
         try
         {
             //texture = new Render.Sprite((Bitmap)Resources.ResourceManager.GetObject(name.ToLower().Insert(0, "_")), new Vector2(0, 0));
         }
         catch (Exception ex)
         {
             if (texture == null)
             {
                 texture = new SpriteInfo();
                 texture.Sprite = new Render.Sprite(MyResources["questionmark"], new Vector2(0, 0));
             }
             Console.WriteLine("SAwarness: Couldn't load texture: " + name + "\n Ex: " + ex);
         }
     }
     else
     {
         if (texture == null)
         {
             texture = new SpriteInfo();
             texture.Sprite = new Render.Sprite(MyResources["questionmark"], new Vector2(0, 0));
         }
         Console.WriteLine("SAwarness: " + name + " is missing. Please inform Screeder!");
     }
 }
コード例 #38
0
ファイル: Utils.cs プロジェクト: kampfi/SAwarenessBeta
 public static void LoadTexture(String name, ref SpriteInfo spriteInfo, String subFolder)
 {
     if (name == null)
         return;
     if (spriteInfo == null)
         spriteInfo = new SpriteInfo();
     Byte[] bitmap = null;
     name = ConvertNames(name);
     string loc = Path.Combine(new[]
     {
         SandboxConfig.DataDirectory, "Assemblies", "cache",
         "SAssemblies", subFolder, name
     });
     try
     {
         bitmap = File.ReadAllBytes(loc);
         spriteInfo.Bitmap = (Bitmap)new ImageConverter().ConvertFrom(bitmap);
         spriteInfo.Sprite = new Render.Sprite(bitmap, new Vector2(0, 0));
         spriteInfo.DownloadFinished = true;
     }
     catch (Exception ex)
     {
         //Console.WriteLine("Cannot load file: {0}, Exception: {1}", name, ex);
     }
 }
コード例 #39
0
ファイル: Utils.cs プロジェクト: kampfi/SAwarenessBeta
 public async static Task<SpriteInfo> LoadTextureAsync(String name, SpriteInfo texture, DownloadType type)
 {
     try
     {
         if (texture == null)
             texture = new SpriteInfo();
         Render.Sprite tex = texture.Sprite;
         LoadTextureAsyncInternal(name, () => texture, x => texture = x, type);
         //texture.Sprite = tex;
         texture.LoadingFinished = true;
         return texture;
         //texture = new Render.Sprite(map, new Vector2(0, 0));
     }
     catch (Exception ex)
     {
         Console.WriteLine("SAwarness: Couldn't load texture: " + name + "\n Ex: " + ex);
         return new SpriteInfo();
     }
 }
コード例 #40
0
ファイル: Tilengine.cs プロジェクト: rlugojr/Tilengine
 public static extern bool GetSpriteInfo(IntPtr spriteset, int entry, ref SpriteInfo info);
コード例 #41
0
 private Color GetColorFromPalette(int PaletteIndex, SpriteInfo SInfo)
 {
     return Color.FromArgb(SInfo.Sprite.Pal.RGBTable[PaletteIndex].Red,
         SInfo.Sprite.Pal.RGBTable[PaletteIndex].Green, SInfo.Sprite.Pal.RGBTable[PaletteIndex].Blue);
 }
コード例 #42
0
        public void ProcessDGRPs()
        {
            List<IffChunk> DGRPs = new List<IffChunk>();

            foreach (IffChunk Chunk in m_Chunks)
            {
                if (Chunk.Type == "DGRP")
                    DGRPs.Add(Chunk);
            }

            foreach (IffChunk Chunk in DGRPs)
            {
                BinaryReader ChunkReader = new BinaryReader(new MemoryStream(Chunk.Data));
                DrawGroup DGRP = new DrawGroup();
                DGRP.Version = ChunkReader.ReadInt16();

                if (DGRP.Version == 20000 || DGRP.Version == 20001)
                {
                    DGRP.Count = Convert.ToInt32(ChunkReader.ReadBytes(2));

                    for (int i = 0; i < DGRP.Count; i++)
                    {
                        DGRPImg Img = new DGRPImg();
                        Img.SpriteInfoCount = Convert.ToInt32(ChunkReader.ReadBytes(2));
                        Img.DirFlags = ChunkReader.ReadByte();
                        Img.ZoomFactor = ChunkReader.ReadByte();

                        for (int j = 0; j < Img.SpriteInfoCount; j++)
                        {
                            SpriteInfo SInfo = new SpriteInfo();
                            SInfo.Tag = ChunkReader.ReadInt16();
                            SInfo.SprID = Convert.ToInt32(ChunkReader.ReadBytes(2));
                            SInfo.SprFrame = Convert.ToInt32(ChunkReader.ReadBytes(2));
                            SInfo.Flags = Convert.ToInt32(ChunkReader.ReadBytes(2));
                            SInfo.PixelX = Convert.ToInt32(ChunkReader.ReadBytes(2));
                            SInfo.PixelY = Convert.ToInt32(ChunkReader.ReadBytes(2));

                            if (DGRP.Version == 20001)
                                SInfo.ZOffset = ChunkReader.ReadInt32();

                            SInfo.Sprite = new SPR2();
                            IffChunk TmpChunk = new IffChunk();

                            foreach (IffChunk C in m_Chunks)
                            {
                                if (C.TypeNum == SInfo.SprID)
                                {
                                    if (C.Type == "SPR2")
                                    {
                                        TmpChunk = C;
                                        break;
                                    }
                                }
                            }

                            BinaryReader SpriteReader = new BinaryReader(new MemoryStream(TmpChunk.Data));
                            SInfo.Sprite.Version1 = SpriteReader.ReadInt16();

                            if (SInfo.Sprite.Version1 == 0)
                                SInfo.Sprite.Version2 = ReadBigShort(SpriteReader);
                            else
                                SInfo.Sprite.Version2 = SpriteReader.ReadInt16();

                            SInfo.Sprite.FrameCount = SpriteReader.ReadInt32();
                            SInfo.Sprite.PaletteID = SpriteReader.ReadInt32();
                            SInfo.Sprite.OffsetTable = new int[SInfo.Sprite.FrameCount];

                            for (int k = 0; k < SInfo.Sprite.FrameCount; k++)
                                SInfo.Sprite.OffsetTable[k] = SpriteReader.ReadInt32();

                            for (int k = 0; k < SInfo.Sprite.FrameCount; k++)
                            {
                                SpriteFrame Frame = new SpriteFrame();
                                Frame.Width = SpriteReader.ReadInt16();
                                Frame.Height = SpriteReader.ReadInt16();
                                Frame.Flags = SpriteReader.ReadInt16();
                                Frame.Unknown = SpriteReader.ReadInt16();
                                Frame.PaletteID = SpriteReader.ReadInt16();
                                Frame.TransparentPixel = SpriteReader.ReadInt16();
                                Frame.XPos = SpriteReader.ReadInt16();
                                Frame.YPos = SpriteReader.ReadInt16();

                                BinaryWriter SpriteWriter = new BinaryWriter(Frame.SpriteData);

                                for (int l = 0; l <= Frame.Height; l++)
                                {
                                    SpriteWriter.Write(SpriteReader.ReadBytes(2));
                                    SpriteWriter.Write(SpriteReader.ReadBytes(Frame.Width));
                                }

                                SInfo.Sprite.AddFrame(Frame);

                                SpriteWriter.Close();
                            }

                            SpriteReader.Close();

                            //Each SPR2 resource contains a reference to a PALT chunk/resource.
                            SInfo.Sprite.Pal = new Palette();

                            foreach (IffChunk C in m_Chunks)
                            {
                                if (C.TypeNum == SInfo.Sprite.PaletteID)
                                {
                                    //Guess what? The typenumber of each chunk is
                                    //NOT unique, so you have to check on type as
                                    //well!
                                    if (C.Type == "PALT")
                                    {
                                        TmpChunk = C;
                                        break;
                                    }
                                }
                            }

                            BinaryReader PaltReader = new BinaryReader(new MemoryStream(TmpChunk.Data));
                            SInfo.Sprite.Pal.AlwaysOne = PaltReader.ReadInt32();
                            SInfo.Sprite.Pal.Always256 = PaltReader.ReadInt32();
                            PaltReader.ReadBytes(8); //The PALT header has 8 additional bytes of 0.

                            SInfo.Sprite.Pal.RGBTable = new Palette.RGB[SInfo.Sprite.Pal.Always256];

                            for (int l = 0; l < SInfo.Sprite.Pal.Always256; l++)
                            {
                                SInfo.Sprite.Pal.RGBTable[l] = new Palette.RGB();
                                SInfo.Sprite.Pal.RGBTable[l].Red = PaltReader.ReadByte();
                                SInfo.Sprite.Pal.RGBTable[l].Green = PaltReader.ReadByte();
                                SInfo.Sprite.Pal.RGBTable[l].Blue = PaltReader.ReadByte();
                            }

                            PaltReader.Close();

                            Img.AddSpriteInfo(SInfo);
                        }

                        DGRP.AddImage(Img);
                    }
                }
                else if (DGRP.Version == 20003 || DGRP.Version == 20004)
                {
                    DGRP.Count = ChunkReader.ReadInt32();

                    for (int i = 0; i < DGRP.Count; i++)
                    {
                        DGRPImg Img = new DGRPImg();
                        Img.DirFlags = ChunkReader.ReadInt32();
                        Img.ZoomFactor = ChunkReader.ReadInt32();
                        Img.SpriteInfoCount = ChunkReader.ReadInt32();

                        //Each DrawGroup Image contains a number of SpriteInfo resources.

                        for (int j = 0; j < Img.SpriteInfoCount; j++)
                        {
                            SpriteInfo SInfo = new SpriteInfo();
                            SInfo.SprID = ChunkReader.ReadInt32();
                            SInfo.SprFrame = ChunkReader.ReadInt32();
                            SInfo.PixelX = ChunkReader.ReadInt32();
                            SInfo.PixelY = ChunkReader.ReadInt32();
                            SInfo.ZOffset = ChunkReader.ReadInt32();
                            SInfo.Flags = ChunkReader.ReadInt32();
                            SInfo.XOffset = ChunkReader.ReadInt32();
                            SInfo.YOffset = ChunkReader.ReadInt32();

                            //Each SpriteInfo resource contains a reference to a SPR2 chunk/resource.

                            SInfo.Sprite = new SPR2();
                            IffChunk TmpChunk = new IffChunk();

                            foreach (IffChunk C in m_Chunks)
                            {
                                if (C.TypeNum == SInfo.SprID)
                                {
                                    //Guess what? The typenumber of each chunk is
                                    //NOT unique, so you have to check on type as
                                    //well!
                                    if (C.Type == "SPR2")
                                    {
                                        TmpChunk = C;
                                        break;
                                    }
                                }
                            }

                            BinaryReader SpriteReader = new BinaryReader(new MemoryStream(TmpChunk.Data));
                            SInfo.Sprite.Version1 = SpriteReader.ReadInt16();

                            if (SInfo.Sprite.Version1 == 0)
                                SInfo.Sprite.Version2 = ReadBigShort(SpriteReader);
                            else
                                SInfo.Sprite.Version2 = SpriteReader.ReadInt16();

                            SInfo.Sprite.FrameCount = SpriteReader.ReadInt32();
                            SInfo.Sprite.PaletteID = SpriteReader.ReadInt32();
                            SInfo.Sprite.OffsetTable = new int[SInfo.Sprite.FrameCount];

                            for (int k = 0; k < SInfo.Sprite.FrameCount; k++)
                                SInfo.Sprite.OffsetTable[k] = SpriteReader.ReadInt32();

                            for (int k = 0; k < SInfo.Sprite.FrameCount; k++)
                            {
                                SpriteFrame Frame = new SpriteFrame();
                                Frame.Width = ReadBigShort(SpriteReader);
                                MessageBox.Show("Frame.Width: " + Frame.Width.ToString());
                                Frame.Height = ReadBigShort(SpriteReader);
                                MessageBox.Show("Frame.Height: " + Frame.Height.ToString());
                                Frame.Flags = SpriteReader.ReadInt16();
                                Frame.Unknown = ReadBigShort(SpriteReader);
                                MessageBox.Show("Unknown: " + Frame.Unknown.ToString());
                                Frame.PaletteID = SpriteReader.ReadInt16();
                                Frame.TransparentPixel = SpriteReader.ReadInt16();
                                Frame.XPos = SpriteReader.ReadInt16();
                                Frame.YPos = SpriteReader.ReadInt16();

                                BinaryWriter SpriteWriter = new BinaryWriter(Frame.SpriteData);

                                for (int l = 0; l <= Frame.Height; l++)
                                {
                                    SpriteWriter.Write(SpriteReader.ReadBytes(2));
                                    SpriteWriter.Write(SpriteReader.ReadBytes(Frame.Width));
                                }

                                SInfo.Sprite.AddFrame(Frame);

                                SpriteWriter.Close();
                            }

                            SpriteReader.Close();

                            //Each SPR2 resource contains a reference to a PALT chunk/resource.
                            SInfo.Sprite.Pal = new Palette();

                            foreach (IffChunk C in m_Chunks)
                            {
                                if (C.TypeNum == SInfo.Sprite.PaletteID)
                                {
                                    //Guess what? The typenumber of each chunk is
                                    //NOT unique, so you have to check on type as
                                    //well!
                                    if (C.Type == "PALT")
                                    {
                                        TmpChunk = C;
                                        break;
                                    }
                                }
                            }

                            BinaryReader PaltReader = new BinaryReader(new MemoryStream(TmpChunk.Data));
                            SInfo.Sprite.Pal.AlwaysOne = PaltReader.ReadInt32();
                            SInfo.Sprite.Pal.Always256 = PaltReader.ReadInt32();
                            PaltReader.ReadBytes(8); //The PALT header has 8 additional bytes of 0.

                            SInfo.Sprite.Pal.RGBTable = new Palette.RGB[SInfo.Sprite.Pal.Always256];

                            for (int l = 0; l < SInfo.Sprite.Pal.Always256; l++)
                            {
                                SInfo.Sprite.Pal.RGBTable[l] = new Palette.RGB();
                                SInfo.Sprite.Pal.RGBTable[l].Red = PaltReader.ReadByte();
                                SInfo.Sprite.Pal.RGBTable[l].Green = PaltReader.ReadByte();
                                SInfo.Sprite.Pal.RGBTable[l].Blue = PaltReader.ReadByte();
                            }

                            PaltReader.Close();

                            Img.AddSpriteInfo(SInfo);
                        }

                        DGRP.AddImage(Img);
                    }
                }

                m_DGRPs.Add(DGRP);
            }
        }
コード例 #43
0
ファイル: PlayerPanzer.cs プロジェクト: Yefimov/Game1.9
 public PlayerPanzer(Vector2 Position, SpriteInfo spriteInfoPanzer, float Speed, SpriteInfo spriteInfoShot, SpriteInfo spriteInfoBigBang, Func<MovedObject, bool> HasCollisions)
     : base(Position, spriteInfoPanzer, Speed, spriteInfoShot, spriteInfoBigBang, HasCollisions)
 {
   
 }
コード例 #44
0
        /// <summary>
        ///  <para>Loads TAI from given Zip-File and Entry and creates & loads Sprites from it.</para>
        /// </summary>
        private IEnumerable<Sprite> LoadSpritesFrom(ZipFile zipFile, ZipEntry taiEntry)
        {
            string ResourceName = Path.GetFileNameWithoutExtension(taiEntry.Name).ToLowerInvariant();

            var loadedSprites = new List<Sprite>();

            var byteBuffer = new byte[zipBufferSize];

            Stream zipStream = zipFile.GetInputStream(taiEntry);
            //Will throw exception is missing or wrong password. Handle this.

            var memStream = new MemoryStream();

            StreamUtils.Copy(zipStream, memStream, byteBuffer);
            memStream.Position = 0;

            var taiReader = new StreamReader(memStream, true);
            string loadedTAI = taiReader.ReadToEnd();

            memStream.Close();
            zipStream.Close();
            taiReader.Close();
            memStream.Dispose();
            zipStream.Dispose();
            taiReader.Dispose();

            string[] splitContents = Regex.Split(loadedTAI, "\r\n"); //Split by newlines.

            foreach (string line in splitContents)
            {
                if (String.IsNullOrWhiteSpace(line)) continue;

                string[] splitLine = line.Split(',');
                string[] fullPath = Regex.Split(splitLine[0], "\t");

                string originalName = Path.GetFileNameWithoutExtension(fullPath[0]).ToLowerInvariant();
                //The name of the original picture without extension, before it became part of the atlas. 
                //This will be the name we can find this under in our Resource lists.

                string[] splitResourceName = fullPath[2].Split('.');

                string imageName = splitResourceName[0].ToLowerInvariant();

                if (!ImageCache.Images.Contains(splitResourceName[0]))
                    continue; //Image for this sprite does not exist. Possibly set to defered later.

                Image atlasTex = ImageCache.Images[splitResourceName[0]];
                //Grab the image for the sprite from the cache.

                var info = new SpriteInfo();
                info.Name = originalName;

                float offsetX = 0;
                float offsetY = 0;
                float sizeX = 0;
                float sizeY = 0;

                if (splitLine.Length > 8) //Separated with ','. This causes some problems and happens on some EU PCs.
                {
                    offsetX = float.Parse(splitLine[3] + "." + splitLine[4], CultureInfo.InvariantCulture);
                    offsetY = float.Parse(splitLine[5] + "." + splitLine[6], CultureInfo.InvariantCulture);
                    sizeX = float.Parse(splitLine[8] + "." + splitLine[9], CultureInfo.InvariantCulture);
                    sizeY = float.Parse(splitLine[10] + "." + splitLine[11], CultureInfo.InvariantCulture);
                }
                else
                {
                    offsetX = float.Parse(splitLine[3], CultureInfo.InvariantCulture);
                    offsetY = float.Parse(splitLine[4], CultureInfo.InvariantCulture);
                    sizeX = float.Parse(splitLine[6], CultureInfo.InvariantCulture);
                    sizeY = float.Parse(splitLine[7], CultureInfo.InvariantCulture);
                }

                info.Offsets = new Vector2D((float) Math.Round(offsetX*atlasTex.Width, 1),
                                            (float) Math.Round(offsetY*atlasTex.Height, 1));
                info.Size = new Vector2D((float) Math.Round(sizeX*atlasTex.Width, 1),
                                         (float) Math.Round(sizeY*atlasTex.Height, 1));

                if (!_spriteInfos.ContainsKey(originalName)) _spriteInfos.Add(originalName, info);

                loadedSprites.Add(new Sprite(originalName, atlasTex, info.Offsets, info.Size));
            }

            return loadedSprites;
        }
コード例 #45
0
ファイル: Utils.cs プロジェクト: kampfi/SAwarenessBeta
 public static void LoadTexture(Bitmap bitmap, ref SpriteInfo spriteInfo)
 {
     if (spriteInfo == null)
         spriteInfo = new SpriteInfo();
     try
     {
         if(bitmap == null)
             throw new Exception("Picture not available!");
         Texture tex = Texture.FromMemory(Drawing.Direct3DDevice, (byte[])new ImageConverter().ConvertTo(bitmap, typeof(byte[])));
         spriteInfo.Sprite = new Render.Sprite(tex, new Vector2(0, 0));
         spriteInfo.Bitmap = spriteInfo.Sprite.Bitmap;
         spriteInfo.DownloadFinished = true;
         tex.Dispose();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Cannot load texture, Exception: {0}", ex);
     }
 }
コード例 #46
0
ファイル: ScenicObject.cs プロジェクト: Yefimov/Game1.9
        public int Type { get; set; } // Тип этого объекта
        // 1 - кирпич
        // 2 - бетон
        // 3 - лес
        // 4 - вода
        // 5 - границы карты
        // 6 - орел_штаб

        public ScenicObject(Vector2 Position, int Type, SpriteInfo Image, float Scale)
            : base(Position, Image, Scale)
        {
            this.Position = Position;
            this.Type = Type;
        }       
コード例 #47
0
    /*
    void MoveTilesForward() {
        _tileCount++;
        GameObject go = _backgroundSpriteGOs.Dequeue();
        go.transform.position = _initPosition + new Vector3(_spriteWidth * _tileCount, 0f, 0f);
        _nextSwitchX = go.transform.position.x - _spriteWidth * 1f;
        _backgroundSpriteGOs.Enqueue(go);
    }*/

    List<SpriteInfo> CreateSpriteInstances() {
        List<SpriteInfo> itemGameObjects = new List<SpriteInfo>();

        List<int> itemsToSpawn = new List<int>();
        for (int i = 0; i < BackgroundSpritePrefabs.Length; i++) {
            for (int j = 0; j < PrefabCopies; j++) {
                itemsToSpawn.Add(i);
            }
		}
        _nextPositionX = Random.Range(MinDistance, MaxDistance);

        while (itemsToSpawn.Count > 0) {
            int nextIndex = Random.Range(0, itemsToSpawn.Count);
            int nextItem = itemsToSpawn[nextIndex] % (BackgroundSpritePrefabs.Length);
            GameObject go = Instantiate(BackgroundSpritePrefabs[nextItem]) as GameObject;
            go.transform.parent = gameObject.transform;
            SpriteInfo si = new SpriteInfo(go);
            go.transform.position = new Vector3(_nextPositionX + si.SpriteBounds.max.x, 0f, 0f);
            float rightX = go.transform.position.x + si.SpriteBounds.max.x;
            itemGameObjects.Add(si);
            _nextPositionX = rightX + Random.Range(MinDistance, MaxDistance);
            itemsToSpawn.RemoveAt(nextIndex);
        }
        return itemGameObjects;
    }
コード例 #48
0
ファイル: Utils.cs プロジェクト: kampfi/SAwarenessBeta
 public static void LoadTexture(String name, ref SpriteInfo spriteInfo, String optionalName, RafLoader.ImageList list)
 {
     if (spriteInfo == null)
         spriteInfo = new SpriteInfo();
     Byte[] bitmap = null;
     bitmap = RafLoader.GetImage(name, list, optionalName);
     try
     {
         if (bitmap == null)
             throw new Exception("Picture not available!");
         Texture tex = Texture.FromMemory(Drawing.Direct3DDevice, bitmap);
         spriteInfo.Sprite = new Render.Sprite(tex, new Vector2(0, 0));
         spriteInfo.Bitmap = spriteInfo.Sprite.Bitmap;
         spriteInfo.DownloadFinished = true;
         tex.Dispose();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Cannot load file: {0}, Exception: {1}", name, ex);
     }
 }
コード例 #49
0
ファイル: MovedObject.cs プロジェクト: Yefimov/Game1.9
 public MovedObject(Vector2 Position, SpriteInfo Sprite, float Scale, float Speed) : base(Position, Sprite, Scale)
 {
     this.Speed = Speed;
 }
コード例 #50
0
        /// <summary>
        /// Adds a temporary sprite to the list of sprites that make up the crosshair
        /// </summary>
        /// <param name="spriteEnum">Texture of the sprite to use</param>
        /// <param name="spriteId">An id that will be checked to prevent adding the same sprite twice</param>
        /// <param name="timeout">Time the sprite will be visible (includes fadeout time)</param>
        /// <param name="fadeTime">For how long should the sprite fade out when it disappears</param>
        public void AddTemporarySprite(MyHudTexturesEnum spriteEnum, MyStringId spriteId, int timeout = 2000, int fadeTime = 1000, Color? color = null, float size = 0.02f)
        {
            SpriteInfo sprite = new SpriteInfo();
            sprite.Color = color.HasValue ? color.Value : MyHudConstants.HUD_COLOR_LIGHT;
            sprite.FadeoutTime = fadeTime;
            sprite.HalfSize = Vector2.One * size;
            sprite.SpriteId = spriteId;
            sprite.SpriteEnum = spriteEnum;
            sprite.TimeRemaining = timeout;
            sprite.Visible = true;

            for (int i = 0; i < m_sprites.Count; ++i)
            {
                if (m_sprites[i].SpriteId == spriteId)
                {
                    m_sprites[i] = sprite;
                    return;
                }
            }

            m_sprites.Add(sprite);
        }
コード例 #51
0
        private static List<SpriteInfo> GetSpriteInfo(Texture source)
        {
            //Debug.Log("Creating new Sprite Asset.");

            string filePath = UnityEditor.AssetDatabase.GetAssetPath(source);

            // Get all the Sprites sorted by Index
            Sprite[] sprites = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(filePath).Select(x => x as Sprite).Where(x => x != null).OrderByDescending(x => x.rect.y).ThenBy(x => x.rect.x).ToArray();

            List<SpriteInfo> spriteInfoList = new List<SpriteInfo>();

            for (int i = 0; i < sprites.Length; i++)
            {
                SpriteInfo spriteInfo = new SpriteInfo();
                Sprite sprite = sprites[i];

                //spriteInfo.fileID = UnityEditor.Unsupported.GetLocalIdentifierInFile(sprite.GetInstanceID());
                spriteInfo.id = i;
                spriteInfo.name = sprite.name;

                Rect spriteRect = sprite.rect;
                spriteInfo.x = spriteRect.x;
                spriteInfo.y = spriteRect.y;
                spriteInfo.width = spriteRect.width;
                spriteInfo.height = spriteRect.height;

                // Compute Sprite pivot position
                Vector2 pivot = new Vector2(0 - (sprite.bounds.min.x) / (sprite.bounds.extents.x * 2), 0 - (sprite.bounds.min.y) / (sprite.bounds.extents.y * 2));
                spriteInfo.pivot = new Vector2(0 - pivot.x * spriteRect.width, spriteRect.height - pivot.y * spriteRect.height);

                //spriteInfo.sprite = sprite;

                // Properties the can be modified
                spriteInfo.xAdvance = spriteRect.width;
                spriteInfo.scale = 1.0f;
                spriteInfo.xOffset = 0;
                spriteInfo.yOffset = 0;

                spriteInfoList.Add(spriteInfo);

            }

            return spriteInfoList;
        }
コード例 #52
0
ファイル: IconHandler.ashx.cs プロジェクト: brianmatic/n2cms
 //TODO: Add unit test
 private SpriteInfo ParseCssLine(string input)
 {
     SpriteInfo result = new SpriteInfo();
     input = EatTo(input, ".");
     result.Key = input.Substring(0, input.IndexOf(" {", StringComparison.Ordinal));
     input = EatTo(input, "width:");
     result.R.Width = GetNumber(input);
     input = EatTo(input, "height:");
     result.R.Height = GetNumber(input);
     input = EatTo(input, "position: -");
     result.R.X = GetNumber(input);
     input = EatTo(input, " -");
     result.R.Y = GetNumber(input);
     return result;
 }
コード例 #53
0
        private void CreateDefaultSprite()
        {
            SpriteInfo newSprite = new SpriteInfo();
            newSprite.Color = MyHudConstants.HUD_COLOR_LIGHT;
            newSprite.FadeoutTime = 0;
            newSprite.HalfSize = Vector2.One * 0.02f;
            newSprite.SpriteId = m_defaultSpriteId;
            newSprite.SpriteEnum = MyHudTexturesEnum.crosshair;
            newSprite.TimeRemaining = 0;
            newSprite.Visible = true;

            bool found = false;
            for (int i = 0; i < m_sprites.Count; ++i)
            {
                if (m_sprites[i].SpriteId == m_defaultSpriteId)
                {
                    m_sprites[i] = newSprite;
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                m_sprites.Add(newSprite);
            }
        }