Esempio n. 1
0
        public override void LoadContent(ContentManager content, InputManager inputManager)
        {
            base.LoadContent(content, inputManager);
            fileManager   = new FileManager();
            moveAnimation = new Animation();
            ssAnimation   = new SpriteSheetAnimation();
            moveSpeed     = 150;
            Vector2 totalFrames       = Vector2.Zero;
            Vector2 modelFrames       = Vector2.Zero;
            Vector2 modelFramesOffset = Vector2.Zero;

            VisionRange = 150;

            fileManager.LoadContent("Load/" + enemyID + ".cme", attributes, contents);
            for (int i = 0; i < attributes.Count; i++)
            {
                for (int j = 0; j < attributes[i].Count; j++)
                {
                    //[Image][TotalFrames][ModelFrames][ModelFramesOffset][Health][Damage]
                    switch (attributes[i][j])
                    {
                    case "Health":
                        Health = int.Parse(contents[i][j]);
                        break;

                    case "TotalFrames":
                        string[] frames = contents[i][j].Split(' ');
                        totalFrames = new Vector2(int.Parse(frames[0]), int.Parse(frames[1]));
                        break;

                    case "ModelFrames":
                        frames      = contents[i][j].Split(' ');
                        modelFrames = new Vector2(int.Parse(frames[0]), int.Parse(frames[1]));
                        break;

                    case "ModelFramesOffset":
                        frames            = contents[i][j].Split(' ');
                        modelFramesOffset = new Vector2(int.Parse(frames[0]), int.Parse(frames[1]));
                        break;

                    case "Damage":
                        damage = int.Parse(contents[i][j]);
                        break;

                    case "Range":
                        range = int.Parse(contents[i][j]);
                        break;

                    case "DecisionCounter":
                        decisionCounterLimit = int.Parse(contents[i][j]);
                        break;

                    case "DropRate":
                        dropRate = int.Parse(contents[i][j]);
                        break;

                    case "Image":
                        image = this.content.Load <Texture2D>(contents[i][j]);
                        break;
                    }
                }
            }

            int cellHeight = image.Height / (int)totalFrames.Y;
            int cellWidth  = image.Width / (int)totalFrames.X;

            Color[] imageData = new Color[image.Width * image.Height];
            image.GetData <Color>(imageData);
            Rectangle sourceRect = new Rectangle(cellWidth * (int)modelFramesOffset.X, cellHeight * (int)modelFramesOffset.Y,
                                                 cellWidth * (int)modelFrames.X, cellHeight * (int)modelFrames.Y);

            Color[] imagePiece = GetImageData(imageData, image.Width, sourceRect);

            Texture2D subtexture = new Texture2D(image.GraphicsDevice, sourceRect.Width, sourceRect.Height);

            image.Dispose();
            image = subtexture;
            subtexture.SetData <Color>(imagePiece);

            moveAnimation.Frames = modelFrames;
            moveAnimation.LoadContent(content, image, enemyID, Position);
            hpBar = new HealthBar(content, Health, Position + new Vector2(0, moveAnimation.FrameHeight));
            hpBar.SetHealth(Health);
        }