Exemple #1
0
        public NPC(Vector2 pos, ContentManager content)
        {
            state             = new RestingState();
            this.pos          = pos;
            firstName         = RandUtil.Index(namePool);
            npcClass          = RandUtil.Index(classPool);
            lastAnimationTime = TimeSpan.FromMilliseconds(0);
            inventory         = new Inventory();

            facing = CharSprites.DOWN;

            if (RandUtil.Bool())
            {
                gender = Gender.Male;
            }
            else
            {
                gender = Gender.Female;
            }

            //Give them some things relevant to their class
            int numItems = RandUtil.Int(0, 5);

            for (int i = 0; i < numItems; i++)
            {
                inventory.Add(new Item(RandUtil.Index(npcClass.desires), 1));
            }



            desires = new HashSet <Desire>();
            var numDesires = RandUtil.Int(0, 4);

            for (int i = 0; i < numDesires; i++)
            {
                var    item       = RandUtil.Index(npcClass.desires);
                var    level      = RandUtil.Int(1, 10);
                var    sufficient = RandUtil.Int(1, 10);
                Desire d          = new Desire(new Item(item, 0), level, sufficient);
                desires.Add(d);
            }

            var lastNamePrefx  = RandUtil.Index(npcClass.lastNamePrefixes);
            var lastNameSuffix = RandUtil.Index(npcClass.lastNameSuffixes);

            lastName = lastNamePrefx + lastNameSuffix;

            personality = RandUtil.Index(personalityPool);
        }
Exemple #2
0
        public World(int w, int h, ContentManager content)
        {
            Noise.InitNoise(tileSize, 5, 2.0f, 0.6f, 0.6f);
            texColor  = new Color[(tileSize) * (tileSize)];
            texCache  = new LRACache <int, Texture2D>(10000);
            simpleTex = new Dictionary <TerrainTile, Texture2D>();
            simpleTex.Add(TerrainTile.WATER, GetSolidTex(tileSize, tileSize, Color.Blue));
            simpleTex.Add(TerrainTile.GRASS, GetSolidTex(tileSize, tileSize, Color.ForestGreen));
            simpleTex.Add(TerrainTile.DIRT, GetSolidTex(tileSize, tileSize, Color.SaddleBrown));
            simpleTex.Add(TerrainTile.ROCK, GetSolidTex(tileSize, tileSize, Color.Gray));
            simpleTex.Add(TerrainTile.SNOW, GetSolidTex(tileSize, tileSize, Color.White));


            width  = w;
            height = h;

            var pal        = new List <Color>(2560);
            var tilePal    = new List <TerrainTile>(2560);
            int waterRange = 800;

            for (int i = 0; i < waterRange; i++)
            {
                pal.Add(Color.Lerp(Color.DarkBlue, Color.DeepSkyBlue, (float)i / (float)waterRange));
                tilePal.Add(TerrainTile.WATER);
            }

            tilePal.Add(TerrainTile.GRASS);
            pal.Add(Color.LightGoldenrodYellow);
            tilePal.Add(TerrainTile.GRASS);
            pal.Add(Color.LightGoldenrodYellow);
            tilePal.Add(TerrainTile.GRASS);
            pal.Add(Color.LightGoldenrodYellow);
            tilePal.Add(TerrainTile.GRASS);
            pal.Add(Color.LightGoldenrodYellow);

            int grassRange = 1100;

            for (int i = 0; i < grassRange; i++)
            {
                pal.Add(Color.Lerp(Color.ForestGreen, Color.DarkGreen, (float)i / (float)grassRange));
                tilePal.Add(TerrainTile.GRASS);
            }
            int dirtRange = 100;

            for (int i = 0; i < dirtRange; i++)
            {
                pal.Add(Color.Lerp(Color.DarkGreen, Color.SaddleBrown, (float)i / (float)dirtRange));
                tilePal.Add(TerrainTile.DIRT);
            }
            float rockRange = 550;

            for (int i = 0; i < rockRange; i++)
            {
                pal.Add(Color.Lerp(Color.Gray, Color.White, (float)i / (float)rockRange));
                if (i < rockRange / 2)
                {
                    tilePal.Add(TerrainTile.ROCK);
                }
                else
                {
                    tilePal.Add(TerrainTile.SNOW);
                }
            }

            tilePallette = tilePal.ToArray();
            pallette     = pal.ToArray();

            resources     = new List <Resource>(TREE_COUNT + COAL_COUNT + IRON_COUNT);
            deadResources = new List <Resource>(32);


            for (int i = 0; i < IRON_COUNT; i++)
            {
                var pos = RandUtil.Vector2(width, height);
                while (GetTile(pos) != TerrainTile.ROCK)
                {
                    pos = RandUtil.Vector2(width, height);
                }
                resources.Add(new IronMine(pos, RandUtil.Int(10, 1000), content));
            }
            for (int i = 0; i < COAL_COUNT; i++)
            {
                var pos = RandUtil.Vector2(width, height);
                while (GetTile(pos) != TerrainTile.GRASS)
                {
                    pos = RandUtil.Vector2(width, height);
                }
                resources.Add(new CoalMine(pos, RandUtil.Int(10, 1000), content));
            }
            for (int i = 0; i < TREE_COUNT; i++)
            {
                var pos = RandUtil.Vector2(width, height);
                while (GetTile(pos) != TerrainTile.GRASS)
                {
                    pos = RandUtil.Vector2(width, height);
                }
                resources.Add(new Tree(pos, RandUtil.Int(1, 3), content));
            }



            npcs = new List <NPC>(NPC_COUNT);

            var worldArea = w * h;
            var numCities = (int)(worldArea * cityDensity);

            int npcIndex    = 0;
            int npcsPerCity = 5;

            for (int i = 0; i < numCities; i++)
            {
                var cityPos = new Vector2(RandUtil.IntEx(4, w - 4), RandUtil.IntEx(4, h - 4));
                var tile    = GetTile(cityPos);
                if (tile != TerrainTile.WATER)
                {
                    for (int j = 0; j < npcsPerCity; j++)
                    {
                        var npcVector = new Vector2(RandUtil.Float(-2.0f, 2.0f), RandUtil.Float(-2.0f, 2.0f));
                        var npcPos    = cityPos + npcVector;
                        tile = GetTile(npcPos);
                        if (tile != TerrainTile.WATER)
                        {
                            npcs.Add(new NPC(npcPos, content));
                            npcIndex++;
                        }
                    }
                }
            }

            while (npcIndex < NPC_COUNT)
            {
                var npcPos = new Vector2(RandUtil.Float(w - 1), RandUtil.Float(h - 1));
                var tile   = GetTile(npcPos);
                if (tile != TerrainTile.WATER)
                {
                    npcs.Add(new NPC(npcPos, content));
                    npcIndex++;
                }
            }
        }
Exemple #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;
        }