Ejemplo n.º 1
0
        public Player(Vector2 pos, World world, ContentManager content)
        {
            firstName  = "Player One";
            this.world = world;
            this.pos   = pos;
            inventory  = new Inventory();
            inventory.Add(new Item("Iron Ore", 100));
            gender = Gender.Male;

            sprites = new CharSprites(gender, content);

            facing            = CharSprites.DOWN;
            lastAnimationTime = TimeSpan.FromMilliseconds(0);
        }
Ejemplo n.º 2
0
        protected override void Initialize()
        {
            base.Initialize();
            graphicsManager.PreferredBackBufferHeight   = 1080;
            graphicsManager.PreferredBackBufferWidth    = 1920;
            graphicsManager.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;
            graphicsManager.ApplyChanges();
            graphics     = GraphicsDevice;
            windowHeight = GraphicsDevice.Viewport.Bounds.Height;
            windowWidth  = GraphicsDevice.Viewport.Bounds.Width;
            numTilesX    = windowWidth / (float)World.tileSize;
            numTilesY    = windowHeight / (float)World.tileSize;
            maxDist      = (float)Math.Sqrt(numTilesX * numTilesX + numTilesY * numTilesY);

            wordBank = new WordBank();
            CharSprites.Initialize(Content);
            Dialogue.Initialize(Content);
            NPC.Initialize();

            world    = new World(500, 500, Content);
            player   = new Player(new Vector2(world.width / 2, world.height / 2), world, Content);
            worldPos = player.pos;
        }
Ejemplo n.º 3
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;
        }