Exemple #1
0
        public void Update(GameTime gameTime, Player player, ContentManager content)
        {
            var distSquared = Vector2.DistanceSquared(pos, player.pos);

            if (distSquared <= PRPGame.maxDist * PRPGame.maxDist)
            {
                onScreen = true;
                if (distSquared < PRPGame.actionDist)
                {
                    hello = true;
                }
                else
                {
                    hello = false;
                }
            }
            else
            {
                onScreen = false;
                hello    = false;
            }

            if (onScreen && sprites == null)
            {
                sprites = new CharSprites(gender, content);
            }

            switch (state)
            {
            case CraftingState crafting:
                CheckIfDoneCrafting(crafting);
                break;

            case RestingState resting:
                CheckIfCanCraft();
                break;

            default:
                break;
            }


            if (destination == Vector2.Zero)
            {
                if (RandUtil.OneInN(1000))
                {
                    var destVector = new Vector2(RandUtil.Int(-10, 10), RandUtil.Int(-10, 10));
                    destination = pos + destVector;
                }
            }
            else
            {
                Vector2 toDestination = (destination - pos);
                toDestination.Normalize();
                toDestination *= 0.05f;
                pos           += toDestination;
                if (Vector2.Distance(pos, destination) < 0.2)
                {
                    destination = Vector2.Zero;
                }
            }

            if (pos == oldPos)
            {
                return;
            }
            lastAnimationTime += gameTime.ElapsedGameTime;
            if (lastAnimationTime.TotalMilliseconds > 100)
            {
                animIndex         = (animIndex + 1) % CharSprites.WALKING_WIDTH;
                lastAnimationTime = TimeSpan.FromMilliseconds(0);
            }
            Vector2 dir = pos - oldPos;

            if (Abs(dir.X) > Abs(dir.Y))
            {
                if (dir.X > 0)
                {
                    facing = CharSprites.RIGHT;
                }
                else
                {
                    facing = CharSprites.LEFT;
                }
            }
            else
            {
                if (dir.Y > 0)
                {
                    facing = CharSprites.DOWN;
                }
                else
                {
                    facing = CharSprites.UP;
                }
            }
            oldPos = pos;
        }
Exemple #2
0
        public CharSprites(Gender gender, ContentManager content)
        {
#if DEBUG
            PRPGame.npcSprited++;
#endif

            if (gender == Gender.Male)
            {
                baseSheet = RandUtil.Index(maleBodySheets);
                hairSheet = RandUtil.Index(maleHairSheets);
                eyeSheet  = RandUtil.Index(maleEyeSheets);
            }
            else
            {
                baseSheet = RandUtil.Index(femaleBodySheets);
                hairSheet = RandUtil.Index(femaleHairSheets);
                eyeSheet  = RandUtil.Index(femaleHairSheets);
            }


            // Compose a bunch of sprite sheets to make a uniqe npc as they
            // come on screen. The sheets contain all the animation frames.
            shirtSheet = RandUtil.Index(shirtSheets);
            pantSheet  = RandUtil.Index(pantsSheets);
            shoeSheet  = RandUtil.Index(shoeSheets);

            hairColor = new Color(new Vector3(RandUtil.Float(1.0f), RandUtil.Float(1.0f), RandUtil.Float(1.0f)));

            walkingAnimation = new Rectangle[4, WALKING_WIDTH];
            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < WALKING_WIDTH; x++)
                {
                    int walkIndex = y + WALKING_INDEX;
                    walkingAnimation[y, x] = new Rectangle(x * CHAR_SIZE, walkIndex * CHAR_SIZE, CHAR_SIZE, CHAR_SIZE);
                }
            }


            swingAnimation = new Rectangle[4, SWING_WIDTH];
            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < SWING_WIDTH; x++)
                {
                    int swingIndex = y + SWING_INDEX;
                    swingAnimation[y, x] = new Rectangle(x * CHAR_SIZE, swingIndex * CHAR_SIZE, CHAR_SIZE, CHAR_SIZE);
                }
            }

            oversizeWeaponAnimation = new Rectangle[4, SWING_WIDTH];
            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < SWING_WIDTH; x++)
                {
                    int swingIndex = y;
                    oversizeWeaponAnimation[y, x] = new Rectangle(x * OVERSIZE_WEAPON_SIZE, swingIndex * OVERSIZE_WEAPON_SIZE, OVERSIZE_WEAPON_SIZE, OVERSIZE_WEAPON_SIZE);
                }
            }
        }
Exemple #3
0
 public string GetIdleChat()
 {
     return(RandUtil.Index(idleChat));
 }