Esempio n. 1
0
        public Character(List <string> data, int x, int y, Location loc) : base(loc)
        {
            drawToolInteractBox      = true;
            interactBoxTexture       = Game1.content.Load <Texture2D>("spriteSheets/simplebox");
            interactToolBoxRectangle = FindInteractToolBoxRectangle();
            interactBoxRectangle     = FindInteractBoxRectangle();

            velocityX = 0;
            velocityY = 0;

            curSprite = "";
            speed     = 0.15f;

            events = new List <Event>();

            spriteFactory = Game1.CreateAnimationFactory(data[2], data[3]);
            float frameDuration = float.Parse(data[4]);

            for (int i = 5; i < data.Count; i++)
            {
                var   indexes         = data[i].Split(',');
                int[] animationFrames = new int[indexes.Count() - 1];
                for (int j = 0; j < indexes.Count() - 1; j++)
                {
                    animationFrames[j] = Int32.Parse(indexes[j + 1]);
                }
                spriteFactory.Add(indexes[0], new SpriteSheetAnimationData(animationFrames, frameDuration, (animationFrames.Count() > 1)));
            }
            curSprite       = "down_idle";
            facingDirection = Direction.Down;
            sprite          = Game1.CreateAnimatedSprite(spriteFactory, curSprite);
            collisionBox    = MakeCollisionBoundingBox();
            posX            = x;
            posY            = y;
        }
Esempio n. 2
0
        public Plant(Rectangle pos, Seed seed, Location loc) : base(loc)
        {
            posX                 = pos.X;
            posY                 = pos.Y;
            spriteFactory        = Game1.CreateAnimationFactory(seed.SpriteName(), seed.AnimationName());
            plantAnimationFrames = seed.PlantAnimationFrames();
            plantSchedule        = seed.PlantSchedule();

            if (plantAnimationFrames.Count() != plantSchedule.Count())
            {
                throw new Exception(seed.Name() + " item has mismatching animation frames and schedule");
            }

            for (int i = 0; i < plantAnimationFrames.Count(); i++)
            {
                spriteFactory.Add(i.ToString(), new SpriteSheetAnimationData(new[] { plantAnimationFrames[i] }, isLooping: false));
            }
            curSprite    = 0;
            curDate      = 0;
            sprite       = Game1.CreateAnimatedSprite(spriteFactory, curSprite.ToString());
            collisionBox = MakeCollisionBoundingBox();
            datePlanted  = Game1.gameDateTime.DaysSinceStart;
            cropYield    = seed.CropYield();
        }
Esempio n. 3
0
 private void CheckForPlantGrowth()
 {
     if (Game1.gameDateTime.DaysSinceStart != curDate)
     {
         curDate = Game1.gameDateTime.DaysSinceStart;
         int s = 0;
         for (int i = 0; i < plantSchedule.Count(); i++)
         {
             if ((curDate - datePlanted) >= plantSchedule[i])
             {
                 s = plantAnimationFrames[i];
             }
             else
             {
                 break;
             }
         }
         if (s != curSprite)
         {
             curSprite = s;
             sprite    = Game1.CreateAnimatedSprite(spriteFactory, curSprite.ToString());
         }
     }
 }
Esempio n. 4
0
        public Vector2 Move(float mx, float my)
        {
            Vector2 result    = new Vector2(posX, posY);
            string  oldSprite = curSprite;

            if (my > 0)
            {
                curSprite       = "down";
                facingDirection = Direction.Down;
            }
            else if (my < 0)
            {
                curSprite       = "up";
                facingDirection = Direction.Up;
            }
            else if (mx < 0)
            {
                curSprite       = "left";
                facingDirection = Direction.Left;
            }
            else if (mx > 0)
            {
                curSprite       = "right";
                facingDirection = Direction.Right;
            }
            else if (!curSprite.Contains("idle"))
            {
                curSprite += "_idle";
            }

            if (oldSprite != curSprite)
            {
                sprite = Game1.CreateAnimatedSprite(spriteFactory, curSprite); //TODO should we just store this?
            }
            velocityX += mx;
            velocityY += my;

            if (location != null)
            {
                var obj = location.GetCollidingObject(GetCollisionBox((int)velocityX, (int)velocityY), this);
                if (obj != null)
                {
                    obj.Collide(this);
                }
            }

            if ((location != null) && (location.IsColliding(GetCollisionBox((int)velocityX, 0), this)))
            {
                velocityX /= 16;
            }
            else if (Math.Abs(velocityX) < 1)
            {
                velocityX = 0;
            }
            else
            {
                posX       = posX + (int)velocityX;
                velocityX %= 1;
            }

            if ((location != null) && (location.IsColliding(GetCollisionBox(0, (int)velocityY), this)))
            {
                velocityY /= 16;
            }
            else if (Math.Abs(velocityY) < 1)
            {
                velocityY = 0;
            }
            else
            {
                posY       = posY + (int)velocityY;
                velocityY %= 1;
            }
            result.X -= posX;
            result.Y -= posY;
            return(result);
        }